Example usage for java.lang.ref SoftReference get

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

Introduction

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

Prototype

public T get() 

Source Link

Document

Returns this reference object's referent.

Usage

From source file:com.guang.eunormia.common.cache.DefaultLocalCache.java

@Override
public V remove(K key) {
    SoftReference<V> result = getCache(key).remove(key);
    expiryCache.remove(key);/*  www  . j  a v a 2  s . c  o  m*/
    return result == null ? null : result.get();
}

From source file:org.thoughtcrime.SMP.ConversationAdapter.java

private MessageRecord getMessageRecord(long messageId, Cursor cursor, String type) {
    SoftReference<MessageRecord> reference = messageRecordCache.get(type + messageId);

    if (reference != null) {
        MessageRecord record = reference.get();

        if (record != null)
            return record;
    }//from  w  w w .  ja v a  2 s  . co m

    MmsSmsDatabase.Reader reader = DatabaseFactory.getMmsSmsDatabase(context).readerFor(cursor, masterSecret);

    MessageRecord messageRecord = reader.getCurrent();
    /*
        Log.d(TAG, "messageRecord.isSMPMessage(): " + messageRecord.isSMPMessage());
        if (messageRecord.isSMPMessage()) {
          MessageRecord newMessageRecord = new SmsMessageRecord(context, messageRecord.getId(), new
            DisplayRecord.Body("SMP_" + messageRecord.getId(), true), messageRecord.getRecipients(),
            messageRecord
            .getIndividualRecipient(),
            messageRecord.getRecipientDeviceId(), messageRecord.getDateSent(), messageRecord
            .getDateReceived(), 0, messageRecord.getType(), messageRecord.getThreadId(), messageRecord
            .getDeliveryStatus(), null);
          Log.d(TAG, "messageRecord: " + newMessageRecord.getDisplayBody().toString());
          return newMessageRecord;
        }
    */
    messageRecordCache.put(type + messageId, new SoftReference<MessageRecord>(messageRecord));

    return messageRecord;
}

From source file:org.red5.cache.impl.CacheImpl.java

/** {@inheritDoc} */
public ICacheable get(String name) {
    if (log.isDebugEnabled()) {
        log.debug("Looking up " + name + " in the cache. Current size: " + CACHE.size());
    }/*  w  w w. jav a  2s. co  m*/
    ICacheable ic = null;
    SoftReference<?> sr = null;
    if (!CACHE.isEmpty() && null != (sr = CACHE.get(name))) {
        ic = (ICacheable) sr.get();
        // add a request count to the registry
        int requestCount = registry.get(name);
        registry.put(name, (requestCount += 1));
        // increment cache hits
        cacheHit += 1;
    } else {
        // add a request count to the registry
        registry.put(name, 1);
        // increment cache misses
        cacheMiss += 1;
    }
    log.debug("Registry on get: {}", registry.toString());
    return ic;
}

From source file:com.eviware.soapui.security.log.SecurityTestLogModel.java

public synchronized SecurityResult getTestStepResultAt(int index) {
    if (index >= results.size())
        return null;

    SoftReference<SecurityResult> result = results.get(index);
    return result == null ? null : result.get();
}

From source file:org.red5.server.cache.CacheImpl.java

/** {@inheritDoc} */
public ICacheable get(String name) {
    if (log.isDebugEnabled()) {
        log.debug("Looking up " + name + " in the cache. Current size: " + CACHE.size());
    }/*from   w  w w. ja v  a 2s .c o m*/
    ICacheable ic = null;
    SoftReference sr = null;
    if (!CACHE.isEmpty() && null != (sr = CACHE.get(name))) {
        ic = (ICacheable) sr.get();
        // add a request count to the registry
        int requestCount = registry.get(name);
        registry.put(name, (requestCount += 1));
        // increment cache hits
        cacheHit += 1;
    } else {
        // add a request count to the registry
        registry.put(name, 1);
        // increment cache misses
        cacheMiss += 1;
    }
    if (log.isDebugEnabled()) {
        log.debug("Registry on get: " + registry.toString());
    }
    return ic;
}

From source file:com.taobao.common.tedis.cache.DefaultLocalCache.java

public V put(K key, V value) {
    SoftReference<V> result = getCache(key).put(key, new SoftReference<V>(value));
    expiryCache.put(key, -1L);//from   w  w w.  j a  va  2 s .  c  o  m

    return result == null ? null : result.get();
}

From source file:be.fedict.trust.crl.CachedCrlRepository.java

public X509CRL findCrl(URI crlUri, X509Certificate issuerCertificate, Date validationDate) {

    SoftReference<X509CRL> crlRef = this.crlCache.get(crlUri);
    if (null == crlRef) {
        LOG.debug("no CRL entry found: " + crlUri);
        return refreshCrl(crlUri, issuerCertificate, validationDate);
    }/*from w ww  .j a v  a2s. c o  m*/
    X509CRL crl = crlRef.get();
    if (null == crl) {
        LOG.debug("CRL garbage collected: " + crlUri);
        return refreshCrl(crlUri, issuerCertificate, validationDate);
    }
    if (validationDate.after(crl.getNextUpdate())) {
        LOG.debug("CRL no longer valid: " + crlUri);
        LOG.debug("validation date: " + validationDate);
        LOG.debug("CRL next update: " + crl.getNextUpdate());
        return refreshCrl(crlUri, issuerCertificate, validationDate);
    }
    /*
     * The Belgian PKI the nextUpdate CRL extension indicates 7 days. The
     * actual CRL refresh rate is every 3 hours. So it's a bit dangerous to
     * only base the CRL cache refresh strategy on the nextUpdate field as
     * indicated by the CRL.
     */
    Date thisUpdate = crl.getThisUpdate();
    DateTime cacheMaturityDateTime = new DateTime(thisUpdate).plusHours(this.cacheAgingHours);
    if (validationDate.after(cacheMaturityDateTime.toDate())) {
        LOG.debug("refreshing the CRL cache: " + crlUri);
        return refreshCrl(crlUri, issuerCertificate, validationDate);
    }
    LOG.debug("using cached CRL: " + crlUri);
    return crl;
}

From source file:com.cm.beer.util.DrawableManager.java

/**
 * /*w ww . j  av  a2  s .  c o  m*/
 * @param urlString
 * @return
 */
public Drawable fetchDrawable(String urlString) {
    if (mDrawableCache.containsKey(urlString)) {
        if (Logger.isLogEnabled())
            Logger.log("Returning Drawable from Cache:" + urlString);
        SoftReference<Drawable> softReference = mDrawableCache.get(urlString);
        if ((softReference == null) || (softReference.get() == null)) {
            mDrawableCache.remove(urlString);
            if (Logger.isLogEnabled())
                Logger.log("fetchDrawable():Soft Reference has been Garbage Collected:" + urlString);
        } else {
            return softReference.get();
        }
    }

    if (Logger.isLogEnabled())
        Logger.log("image url:" + urlString);
    try {
        // prevents multithreaded fetches for the same image
        mLockCache.put(urlString, urlString);
        if (Logger.isLogEnabled())
            Logger.log("Begin Downloading:" + urlString);
        InputStream is = fetch(urlString);
        if (Logger.isLogEnabled())
            Logger.log("End Downloading:" + urlString);
        Drawable drawable = Drawable.createFromStream(is, "src");
        mDrawableCache.put(urlString, new SoftReference<Drawable>(drawable));
        mLockCache.remove(urlString);
        if (Logger.isLogEnabled())
            Logger.log("got a thumbnail drawable: " + drawable.getBounds() + ", "
                    + drawable.getIntrinsicHeight() + "," + drawable.getIntrinsicWidth() + ", "
                    + drawable.getMinimumHeight() + "," + drawable.getMinimumWidth());
        return drawable;
    } catch (Throwable e) {
        Log.e(this.getClass().getName(), "fetchDrawable failed", e);
        return null;
    }
}

From source file:org.jinzora.util.DrawableManager.java

public Drawable fetchDrawable(String urlString) {
    if (drawableMap.containsKey(urlString)) {
        SoftReference<Drawable> reference = drawableMap.get(urlString);
        Drawable drawable = reference.get();
        if (drawable != null) {
            if (DBG)
                Log.d(TAG, "Using cached image");
            return drawable;
        } else {/* w  w w.  ja v a2 s .c  o  m*/
            if (DBG)
                Log.d(TAG, "Soft reference cleared.");
            drawableMap.remove(urlString);
        }
    }

    if (DBG)
        Log.d(TAG, "Fetching image");
    try {
        InputStream is = fetch(urlString);
        Drawable drawable = Drawable.createFromStream(is, "src");

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

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

From source file:com.guang.eunormia.common.cache.DefaultLocalCache.java

@Override
public V put(K key, V value) {
    SoftReference<V> result = getCache(key).put(key, new SoftReference<V>(value));
    expiryCache.put(key, -1L);// w w  w  .  j  a v a 2 s  . c  o m

    return result == null ? null : result.get();
}