List of usage examples for java.lang.ref SoftReference get
public T get()
From source file:com.binroot.fatpita.BitmapManager.java
public void fetchBitmapOnThread(final String urlString, final ImageView imageView, final ProgressBar indeterminateProgressBar, final Activity act, final boolean saveToHistory) { SoftReference<Bitmap> ref = mCache.get(urlString); if (ref != null && ref.get() != null) { imageView.setImageBitmap(ref.get()); return;//from w w w . j av a2 s. c om } final Runnable progressBarShow = new Runnable() { public void run() { if (indeterminateProgressBar != null) { imageView.setVisibility(View.GONE); indeterminateProgressBar.setVisibility(View.VISIBLE); } } }; final Runnable progressBarHide = new Runnable() { public void run() { if (indeterminateProgressBar != null) { indeterminateProgressBar.setVisibility(View.GONE); imageView.setVisibility(View.VISIBLE); } } }; final Handler handler = new Handler() { @Override public void handleMessage(Message message) { if (indeterminateProgressBar != null && act != null) act.runOnUiThread(progressBarHide); imageView.setImageBitmap((Bitmap) message.obj); } }; Thread thread = new Thread() { @Override public void run() { if (indeterminateProgressBar != null && act != null) act.runOnUiThread(progressBarShow); Bitmap bitmap = fetchBitmap(urlString, saveToHistory); Message message = handler.obtainMessage(1, bitmap); handler.sendMessage(message); } }; thread.start(); }
From source file:com.guang.eunormia.common.cache.DefaultLocalCache.java
@Override public Collection<V> values() { checkAll();//w w w . ja v a 2 s . c o m Collection<V> values = new ArrayList<V>(); for (ConcurrentHashMap<K, SoftReference<V>> cache : caches) { for (SoftReference<V> sr : cache.values()) { values.add(sr.get()); } } return values; }
From source file:com.securecomcode.text.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 ww . jav a2 s.c o m MmsSmsDatabase.Reader reader = DatabaseFactory.getMmsSmsDatabase(context).readerFor(cursor, masterSecret); MessageRecord messageRecord = reader.getCurrent(); messageRecordCache.put(type + messageId, new SoftReference<MessageRecord>(messageRecord)); return messageRecord; }
From source file:com.tingtingapps.securesms.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 ww w . j av a 2 s . c om MmsSmsDatabase.Reader reader = DatabaseFactory.getMmsSmsDatabase(context).readerFor(cursor, masterSecret); MessageRecord messageRecord = reader.getCurrent(); messageRecordCache.put(type + messageId, new SoftReference<>(messageRecord)); return messageRecord; }
From source file:net.logstash.logback.composite.CompositeJsonFormatter.java
private BufferRecycler getBufferRecycler() { SoftReference<BufferRecycler> bufferRecyclerReference = recycler.get(); BufferRecycler bufferRecycler = bufferRecyclerReference.get(); if (bufferRecycler == null) { recycler.remove();//from ww w . j ava 2 s. co m return getBufferRecycler(); } return bufferRecycler; }
From source file:org.callimachusproject.repository.SparqlServiceCredentialManager.java
private synchronized SPARQLCredentialService getExistingService(Credentials credential, String serviceUrl) { if (credential == null) { SoftReference<SPARQLCredentialService> ref = services.get(serviceUrl); if (ref == null) return null; return ref.get(); } else {/*from w ww .ja va 2 s .co m*/ Map<String, SoftReference<SPARQLCredentialService>> map = protectedServices.get(credential); if (map == null) return null; SoftReference<SPARQLCredentialService> ref = map.get(serviceUrl); if (ref == null) return null; return ref.get(); } }
From source file:org.broad.igv.peaks.PeakTrackMenu.java
void openTimeSeriesPlot(TrackClickEvent trackClickEvent) { if (trackClickEvent == null) return;/*from w w w . jav a 2 s .co m*/ ReferenceFrame referenceFrame = trackClickEvent.getFrame(); if (referenceFrame == null) return; String chr = referenceFrame.getChrName(); double position = trackClickEvent.getChromosomePosition(); XYSeriesCollection data = new XYSeriesCollection(); List<Color> colors = new ArrayList(); for (SoftReference<PeakTrack> ref : PeakTrack.instances) { PeakTrack track = ref.get(); if (track != null) { Peak peak = track.getFilteredPeakNearest(chr, position); if (peak != null) { XYSeries series = new XYSeries(track.getName()); float[] scores = peak.getTimeScores(); if (scores.length == 4) { float t0 = scores[0] + 10; series.add(0, (scores[0] + 10) / t0); series.add(30, (scores[1] + 10) / t0); series.add(60, (scores[2] + 10) / t0); series.add(120, (scores[3] + 10) / t0); } data.addSeries(series); Color c = track.getName().contains("Pol") ? Color.black : track.getColor(); colors.add(c); } } } final JFreeChart chart = ChartFactory.createXYLineChart("", "Time", "Score", data, PlotOrientation.VERTICAL, true, true, false); NumberAxis axis = (NumberAxis) chart.getXYPlot().getDomainAxis(0); axis.setTickUnit(new NumberTickUnit(30)); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(400, 400)); chartPanel.setSize(new java.awt.Dimension(400, 400)); XYItemRenderer renderer = chart.getXYPlot().getRenderer(); for (int i = 0; i < colors.size(); i++) { renderer.setSeriesPaint(i, colors.get(i)); } chartPanel.setBackground(Color.white); chart.getXYPlot().setBackgroundPaint(Color.white); chart.getXYPlot().setRangeGridlinePaint(Color.black); PeakTimePlotFrame frame = new PeakTimePlotFrame(chartPanel); frame.setVisible(true); }
From source file:com.taobao.common.tedis.cache.DefaultLocalCache.java
public V remove(K key) { SoftReference<V> result = getCache(key).remove(key); expiryCache.remove(key); return result == null ? null : result.get(); }
From source file:com.cm.beer.util.ContentManager.java
/** * /*from www .j a v a 2 s. c o m*/ * @param urlString * @param imageView */ public void fetchContentOnThread(final String urlString, final Handler handler) { if (mContentCache.containsKey(urlString)) { SoftReference<String> softReference = mContentCache.get(urlString); if ((softReference == null) || (softReference.get() == null)) { mContentCache.remove(urlString); if (Logger.isLogEnabled()) Logger.log("fetchContentOnThread():Soft Reference has been Garbage Collected:" + urlString); } else { String jsonStr = softReference.get(); if (Logger.isLogEnabled()) Logger.log(urlString + "=>" + jsonStr); Message message = handler.obtainMessage(1, jsonStr); handler.sendMessage(message); return; } } Thread thread = new Thread() { @Override public void run() { while (mLockCache.containsKey(urlString)) { if (Logger.isLogEnabled()) Logger.log("URI download request in progress:" + urlString); try { Thread.sleep(1000L); } catch (InterruptedException e) { Log.e(this.getClass().getName(), e.getMessage()); } } String content = fetchContent(urlString); Message message = handler.obtainMessage(1, content); handler.sendMessage(message); } }; thread.start(); }
From source file:com.cm.beer.util.ContentManager.java
/** * //from ww w . j ava 2 s.c o m * @param urlString * @return */ public String fetchContent(String urlString) { if (mContentCache.containsKey(urlString)) { if (Logger.isLogEnabled()) Logger.log("Returning Content from Cache:" + urlString); SoftReference<String> softReference = mContentCache.get(urlString); if ((softReference == null) || (softReference.get() == null)) { mContentCache.remove(urlString); if (Logger.isLogEnabled()) Logger.log("fetchContent():Soft Reference has been Garbage Collected:" + urlString); } else { return softReference.get(); } } if (Logger.isLogEnabled()) Logger.log("url:" + urlString); try { // prevents multithreaded fetches for the same url mLockCache.put(urlString, urlString); if (Logger.isLogEnabled()) Logger.log("Begin Downloading:" + urlString); InputStream is = fetch(urlString); if (Logger.isLogEnabled()) Logger.log("End Downloading:" + urlString); String result = Util.convertStreamToString(is, "UTF-8"); mContentCache.put(urlString, new SoftReference<String>(result)); mLockCache.remove(urlString); if (Logger.isLogEnabled()) Logger.log(result); return result; } catch (Throwable e) { Log.e(this.getClass().getName(), "fetchDrawable failed", e); return null; } }