use of java.lang.ref.WeakReference in project FBReaderJ by geometer.
the class CoverUtil method getCover.
public static ZLImage getCover(ZLFile file, IFormatPluginCollection collection) {
WeakReference<ZLImage> cover = ourCovers.get(file);
if (cover == NULL_IMAGE) {
return null;
} else if (cover != null) {
final ZLImage image = cover.get();
if (image != null) {
return image;
}
}
ZLImage image = null;
try {
image = collection.getPlugin(file).readCover(file);
} catch (Exception e) {
// ignore
}
ourCovers.put(file, image != null ? new WeakReference<ZLImage>(image) : NULL_IMAGE);
return image;
}
use of java.lang.ref.WeakReference in project stetho by facebook.
the class ApplicationDescriptor method onGetChildren.
@Override
protected void onGetChildren(Application element, Accumulator<Object> children) {
ElementContext context = getContext(element);
List<WeakReference<Activity>> activities = context.getActivitiesList();
// We report these in reverse order so that the newer ones show up on top
for (int i = activities.size() - 1; i >= 0; --i) {
Activity activity = activities.get(i).get();
if (activity != null) {
children.store(activity);
}
}
}
use of java.lang.ref.WeakReference in project gocd by gocd.
the class DefaultPluginJarLocationMonitor method removePluginJarChangeListener.
@Override
public void removePluginJarChangeListener(final PluginJarChangeListener listener) {
Object referenceOfListenerToBeRemoved = CollectionUtils.find(pluginJarChangeListener, new Predicate() {
@Override
public boolean evaluate(Object object) {
WeakReference<PluginJarChangeListener> listenerWeakReference = (WeakReference<PluginJarChangeListener>) object;
PluginJarChangeListener registeredListener = listenerWeakReference.get();
return registeredListener != null && registeredListener == listener;
}
});
pluginJarChangeListener.remove(referenceOfListenerToBeRemoved);
removeClearedWeakReferences();
}
use of java.lang.ref.WeakReference in project guice by google.
the class Asserts method awaitFullGc.
public static void awaitFullGc() {
// GcFinalization *should* do it, but doesn't work well in practice...
// so we put a second latch and wait for a ReferenceQueue to tell us.
ReferenceQueue<Object> queue = new ReferenceQueue<Object>();
WeakReference ref = new WeakReference<Object>(new Object(), queue);
GcFinalization.awaitFullGc();
try {
assertSame("queue didn't return ref in time", ref, queue.remove(5000));
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
use of java.lang.ref.WeakReference in project guice by google.
the class Asserts method awaitClear.
public static void awaitClear(WeakReference<?> ref) {
// GcFinalization *should* do it, but doesn't work well in practice...
// so we put a second latch and wait for a ReferenceQueue to tell us.
Object data = ref.get();
ReferenceQueue<Object> queue = null;
WeakReference extraRef = null;
if (data != null) {
queue = new ReferenceQueue<Object>();
extraRef = new WeakReference<Object>(data, queue);
data = null;
}
GcFinalization.awaitClear(ref);
if (queue != null) {
try {
assertSame("queue didn't return ref in time", extraRef, queue.remove(5000));
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
Aggregations