Example usage for java.lang.ref SoftReference SoftReference

List of usage examples for java.lang.ref SoftReference SoftReference

Introduction

In this page you can find the example usage for java.lang.ref SoftReference SoftReference.

Prototype

public SoftReference(T referent) 

Source Link

Document

Creates a new soft reference that refers to the given object.

Usage

From source file:org.openanzo.rdf.MemVariable.java

/**
 * Static factory method that uses an WeakHashMap cache to reuse {@link MemVariable} objects for variables with the same name.
 * /*  w  w w . ja  v  a 2  s .c om*/
 * @param variableName
 *            name of variable
 * @return {@link MemVariable} for given name
 */
static public MemVariable createVariable(String variableName) {
    if (variableName.startsWith("?")) {
        throw new AnzoRuntimeException(ExceptionConstants.CLIENT.VARIABLE_START_QUESTION, variableName);
    }
    if (!StringUtils.containsNone(variableName, " \t\n\r\f")) {
        throw new AnzoRuntimeException(ExceptionConstants.CLIENT.VARIABLE_NO_SPACES, variableName);
    }
    SoftReference<MemVariable> ref = cache.get(variableName);
    MemVariable var = (ref != null) ? ref.get() : null;
    if (var == null) {
        var = new MemVariable(variableName);
        cache.put(variableName, new SoftReference<MemVariable>(var));
    }
    return var;
}

From source file:net.sf.nmedit.jtheme.JTCursor.java

public static Cursor getJackCursor(int id) {
    if (!(0 <= id && id < names.length))
        return null;

    SoftReference<?> ref = cursors[id];

    Cursor cursor = null;//  ww  w .j a  v  a  2s  . c o  m
    if (ref == null) {
        cursor = createCursor(id);
        cursors[id] = new SoftReference<Cursor>(cursor);
        return cursor;
    }
    cursor = (Cursor) ref.get();
    if (cursor == null) {
        cursor = createCursor(id);
        cursors[id] = new SoftReference<Cursor>(cursor);
    }

    return cursor;
}

From source file:net.cs76.projects.student10792819.DrawableManager.java

/**
 * Fetch drawable. This fetches a drawable from the url and returns it. Returns null on errors.
 *
 * @param urlString the url string//from  w w  w  .java  2s  .c  om
 * @return the drawable
 */
public static Drawable fetchDrawable(String urlString) {
    if (drawableMap.containsKey(urlString)) {
        Drawable o = drawableMap.get(urlString).get();

        if (o != null)
            return o;
    }

    try {
        InputStream is = fetch(urlString);
        Drawable drawable = Drawable.createFromStream(is, "src");

        if (drawable != null) {
            drawableMap.put(urlString, new SoftReference<Drawable>(drawable));
        } else {
            Log.w("DrawableManager", "could not get thumbnail");
        }

        return drawable;
    } catch (MalformedURLException e) {
        Log.e("DrawableManager", "fetchDrawable failed", e);
        return null;
    } catch (IOException e) {
        Log.e("DrawableManager", "fetchDrawable failed", e);
        return null;
    }
}

From source file:org.copperengine.core.persistent.hybrid.StorageCache.java

@Override
public void safeWorkflowInstance(WorkflowInstance wfi, boolean initialInsert) throws Exception {
    wfCache.put(wfi.id, new SoftReference<WorkflowInstance>(wfi));
    delegate.safeWorkflowInstance(wfi, initialInsert);
}

From source file:com.eviware.soapui.impl.wsdl.testcase.TestCaseLogModel.java

public synchronized void addTestStepResult(TestStepResult result) {
    stepCount++;/*w  w w  .  j a  v  a 2  s . c o m*/

    int size = items.size();
    items.add("Step " + stepCount + " [" + result.getTestStep().getName() + "] " + result.getStatus()
            + ": took " + result.getTimeTaken() + " ms");
    SoftReference<TestStepResult> ref = new SoftReference<TestStepResult>(result);
    results.add(ref);
    for (String msg : result.getMessages()) {
        items.add(" -> " + msg);
        results.add(ref);
    }

    fireIntervalAdded(this, size, items.size() - 1);
    enforceMaxSize();
}

From source file:org.jactr.core.utils.collections.CachedMap.java

synchronized protected Collection<V> getCachedValues() {
    Collection<V> rtn = null;
    if (_cachedValuesReference == null || (rtn = _cachedValuesReference.get()) == null) {
        rtn = Collections.unmodifiableCollection(new ArrayList<V>(_backingMap.values()));
        _cachedValuesReference = new SoftReference<Collection<V>>(rtn);
    }//from   w w w  .j a va2  s. c o m
    return rtn;
}

From source file:com.slytechs.capture.file.indexer.SoftTable.java

/**
 * @param length/*  w w w.j  av  a  2s. com*/
 */
public SoftTable(final List<Long> list, PartialLoader loader) {
    this.loader = loader;
    this.length = list.size();
    this.first = list.get(0);
    this.last = list.get(list.size() - 1);

    final long[] positions = new long[length];
    for (int i = 0; i < list.size(); i++) {
        positions[i] = list.get(i);
    }

    this.positions = new SoftReference<long[]>(positions);
}

From source file:org.grouplens.lenskit.core.LenskitInfo.java

/**
 * Get the set of revisions LensKit is built from.
 * @return The set of revisions included in this build of LensKit.
 *///from  w  w w.  j ava2s .c om
public static synchronized Set<String> getRevisions() {
    Set<String> revisions = revisionSet == null ? null : revisionSet.get();
    if (revisions == null) {
        revisions = loadRevisionSet();
        revisionSet = new SoftReference<Set<String>>(revisions);
    }
    return revisions;
}

From source file:org.jboss.windup.resource.type.XmlMeta.java

protected Document hydrateDocument() {
    if (parsedDocumentRef == null) {
        FileInputStream fis = null;
        try {/*  w w  w  . ja  v a  2  s .  c  o  m*/
            fis = FileUtils.openInputStream(filePointer);
            Document parsedDocument = PositionalXmlReader.readXML(fis);

            LOG.debug("Hydrating XML Document: " + filePointer.getAbsolutePath());
            parsedDocumentRef = new SoftReference<Document>(parsedDocument);
        } catch (Exception e) {
            LOG.error("Bad XML? " + filePointer.getAbsolutePath());
            LOG.info("Skipping file. Continuing Windup Processing...");

            Summary sr = new Summary();
            sr.setDescription("Bad XML? Unable to parse.");
            sr.setLevel(NotificationLevel.CRITICAL);
            sr.setEffort(new UnknownEffort());
            this.getDecorations().add(sr);
            this.parsedDocumentRef = null;

            return null;
        } finally {
            IOUtils.closeQuietly(fis);
        }
    }
    return parsedDocumentRef.get();
}

From source file:org.seasar.mayaa.impl.engine.SpecificationCache.java

protected void postNewGabage() {
    Object gabage = new Object();
    _gabage = new SoftReference(gabage);
    _gcChecker.add(gabage);
}