Example usage for java.lang.ref WeakReference WeakReference

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

Introduction

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

Prototype

public WeakReference(T referent) 

Source Link

Document

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

Usage

From source file:com.sworddance.taskcontrol.FutureListenerProcessor.java

/**
 * @param returnedFuture//w  w w .  j a  v  a 2 s .c  o  m
 */
public <P extends Future<RV>> void setReturnedFuture(P returnedFuture) {
    if (this.returnedFuture == null) {
        this.returnedFuture = new WeakReference<P>(returnedFuture);
    }
}

From source file:org.taverna.server.master.TavernaServer.java

@Override
@CallCounted//from  ww w .j  av a2 s.c  om
@PerfLogged
public ServerDescription describeService(UriInfo ui) {
    jaxrsUriInfo.set(new WeakReference<>(ui));
    return new ServerDescription(ui, resolve(interactionFeed));
}

From source file:org.openjira.jira.utils.LoadImageAsync.java

public static Bitmap getImageFromFile(String url) {
    try {//from w w w .  ja  v  a  2s  .  co m
        File root = Environment.getExternalStorageDirectory();
        if (root.canWrite()) {
            File dir = new File(root, "openjiracache");
            dir.mkdir();
            File file = new File(dir,
                    url.replace("/", "_").replace(":", "-").replace("?", "_").replace("=", "-"));
            if (file.exists() && file.length() > 0) {
                FileInputStream is = new FileInputStream(file);
                Bitmap bm = BitmapFactory.decodeStream(is);
                // Log.v(LOGTAG, "Loaded file from " +
                // file.getAbsolutePath());
                WeakReference<Bitmap> ref = new WeakReference<Bitmap>(bm);
                cachedBitmaps.put(url, ref);
                return bm;
            }
        }
    } catch (Throwable e) {
        Log.e(LOGTAG, "Could not read file " + e.getMessage());
    }
    return null;
}

From source file:org.taverna.server.master.TavernaServer.java

@Override
@CallCounted//  w w  w  .  j ava2  s  . c  o  m
@PerfLogged
@RolesAllowed(USER)
public RunList listUsersRuns(UriInfo ui) {
    jaxrsUriInfo.set(new WeakReference<>(ui));
    return new RunList(runs(), secure(ui).path("{name}"));
}

From source file:com.flexive.shared.XPathElement.java

private static XPathElement toElementImmutable(String xpath, int elemStart, int elemEnd) {
    final int indexPos = xpath.indexOf('[', elemStart);
    final XPathElement elem;
    if (indexPos == -1 || indexPos > elemEnd) {
        elem = new XPathElement(xpath.substring(elemStart, elemEnd), 1, false, true);
    } else {//from w  w  w.  ja va2s .  c om
        final int index = Integer.parseInt(xpath.substring(indexPos + 1, elemEnd - 1));
        elem = new XPathElement(xpath.substring(elemStart, indexPos), index, true);
    }
    // use canonical instances (xpath elements of nested types contain a lot of duplication)
    final WeakReference<XPathElement> ref = SHARED_ELEMENTS.get(elem);
    XPathElement cachedElem = ref != null ? ref.get() : null;
    if (ref == null || cachedElem == null) {
        SHARED_ELEMENTS.put(elem, new WeakReference<XPathElement>(elem));
        cachedElem = elem;
    }
    return cachedElem;
}

From source file:net.sf.maltcms.chromaui.charts.overlay.Peak2DOverlay.java

/**
 *
 * @return/* w  w w .j  a  v a 2 s  .  c om*/
 */
@Override
public Node createNodeDelegate() {
    Logger.getLogger(getClass().getName()).fine("Creating node delegate");
    Node node = null;
    if (nodeReference == null) {
        node = Charts.overlayNode(this, Children.create(new Peak2DOverlayChildFactory(this), true),
                getLookup());
        nodeReference = new WeakReference<>(node);
    } else {
        node = nodeReference.get();
        if (node == null) {
            node = Charts.overlayNode(this, Children.create(new Peak2DOverlayChildFactory(this), true),
                    getLookup());
            nodeReference = new WeakReference<>(node);
        }
    }
    return node;
}

From source file:com.boha.malengagolf.library.util.PagerTitleStrip22.java

void updateAdapter(PagerAdapter oldAdapter, PagerAdapter newAdapter) {
    if (oldAdapter != null) {
        oldAdapter.unregisterDataSetObserver(mPageListener);
        mWatchingAdapter = null;/*  ww  w.  j ava2 s.c  om*/
    }
    if (newAdapter != null) {
        newAdapter.registerDataSetObserver(mPageListener);
        mWatchingAdapter = new WeakReference<PagerAdapter>(newAdapter);
    }
    if (mPager != null) {
        mLastKnownCurrentPage = -1;
        mLastKnownPositionOffset = -1;
        updateText(mPager.getCurrentItem(), newAdapter);
        requestLayout();
    }
}

From source file:android.support.v7.widget.XpAppCompatCompoundDrawableHelper.java

private Drawable resolveDrawable(@DrawableRes int resId, int index) {
    if (resId != 0) {
        final Drawable d = mDrawableManager != null ? mDrawableManager.getDrawable(mView.getContext(), resId)
                : ContextCompat.getDrawable(mView.getContext(), resId);
        final ColorStateList tint = mDrawableManager != null
                ? mDrawableManager.getTintList(mView.getContext(), resId)
                : null;//from  w w w  .j ava 2 s .c om
        setInternalTint(d, tint, index);
        if (d != null) {
            DrawableUtils.fixDrawable(d);
        }
        mDrawables.put(index, new WeakReference<>(d));
        return d;
    } else {
        setInternalTint(null, null, index);
        mDrawables.put(index, new WeakReference<Drawable>(null));
        return null;
    }
}

From source file:com.alexandreroman.nrelay.NmeaRelayService.java

public void addListener(NmeaRelayListener listener) {
    clearListeners();/* www. j  a v  a2  s.  c  o m*/
    if (listener != null) {
        listenerRefs.add(new WeakReference<NmeaRelayListener>(listener));
    }
}

From source file:org.taverna.server.master.TavernaServer.java

@Override
@CallCounted//  w  ww. j  a va2 s . c o  m
@PerfLogged
@RolesAllowed(USER)
public Response submitWorkflow(Workflow workflow, UriInfo ui) throws NoUpdateException {
    jaxrsUriInfo.set(new WeakReference<>(ui));
    checkCreatePolicy(workflow);
    String name = support.buildWorkflow(workflow);
    return created(secure(ui).path("{uuid}").build(name)).build();
}