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.fatelon.partyphotobooth.kiosk.KioskActivity.java

/**
 * Sets a handler for the key event./*from  ww  w  .  j ava2s .  c  om*/
 *
 * @param handler the handler for the key event. Pass null to clear. The reference is weakly
 *                held, so the client is responsible for holding onto a strong reference to prevent
 *                the handler from being garbage collected.
 */
public void setKeyEventHandler(KeyEventHandler handler) {
    mKeyEventHandler = new WeakReference<KeyEventHandler>(handler);
}

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

@Override
@CallCounted//from  w  w w. j av  a  2 s . c o  m
@PerfLogged
@RolesAllowed({ USER, SELF })
public TavernaServerRunREST getRunResource(String runName, UriInfo ui) throws UnknownRunException {
    jaxrsUriInfo.set(new WeakReference<>(ui));
    RunREST rr = makeRunInterface();
    rr.setRun(support.getRun(runName));
    rr.setRunName(runName);
    return rr;
}

From source file:com.digium.respokesdk.RespokeCall.java

/**
 *  Answer the call and start the process of obtaining media. This method is called automatically on the caller's
 *  side. This method must be called on the callee's side to indicate that the endpoint does wish to accept the
 *  call. //from  w  ww .  j a va 2 s .c  o m
 *
 *  @param context      An application context with which to access shared resources
 *  @param newListener  A listener to receive notifications of call-related events
 */
public void answer(final Context context, Listener newListener) {
    if (!caller) {
        listenerReference = new WeakReference<Listener>(newListener);

        getTurnServerCredentials(new Respoke.TaskCompletionListener() {
            @Override
            public void onSuccess() {
                initializePeerConnection(context);
                addLocalStreams(context);
                processRemoteSDP();
            }

            @Override
            public void onError(String errorMessage) {
                postErrorToListener(errorMessage);
            }
        });
    }
}

From source file:facebook.FacebookModule.java

protected void executeAuthorize(final Activity activity) {
    loginContext = new WeakReference<Context>(activity);
    final TiActivitySupport activitySupport = (TiActivitySupport) activity;
    int activityCode;
    if (forceDialogAuth) {
        // Single sign-on support
        activityCode = Facebook.FORCE_DIALOG_AUTH;
    } else {//from w  ww.  j  ava2  s . co m
        activityCode = activitySupport.getUniqueResultCode();
    }
    final TiActivityResultHandler resultHandler = new TiActivityResultHandler() {
        @Override
        public void onResult(Activity activity, int requestCode, int resultCode, Intent data) {
            Log.d(TAG, "onResult from Facebook login attempt. resultCode: " + resultCode, Log.DEBUG_MODE);
            facebook.authorizeCallback(requestCode, resultCode, data);
        }

        @Override
        public void onError(Activity activity, int requestCode, Exception e) {
            Log.e(TAG, e.getLocalizedMessage(), e);
        }
    };

    if (TiApplication.isUIThread()) {
        facebook.authorize(activity, activitySupport, permissions, activityCode, new LoginDialogListener(),
                resultHandler);
    } else {
        final int code = activityCode;
        TiMessenger.postOnMain(new Runnable() {
            @Override
            public void run() {
                facebook.authorize(activity, activitySupport, permissions, code, new LoginDialogListener(),
                        resultHandler);
            }
        });
    }
}

From source file:com.baidu.asynchttpclient.AsyncHttpClient.java

/**
 * Perform a HTTP GET request and track the Android Context which initiated the request.
 * //from  w  w  w .j  a v  a 2s  .  c  om
 * @param context the Android Context which initiated the request.
 * @param url the URL to send the request to.
 * @param params additional GET parameters to send with the request.
 * @param responseHandler the response handler instance that should handle the response.
 */
public WeakReference<Future<?>> get(Context context, String url, RequestParams params,
        AsyncHttpResponseHandler responseHandler) {
    return new WeakReference<Future<?>>(sendRequest(httpClient, httpContext,
            new HttpGet(getUrlWithQueryString(url, params)), null, responseHandler, context));
}

From source file:net.minecraftforge.fml.common.FMLCommonHandler.java

public void handleWorldDataLoad(SaveHandler handler, WorldInfo worldInfo, NBTTagCompound tagCompound) {
    if (getEffectiveSide() != Side.SERVER) {
        return;//  w ww. j av a2s. c om
    }
    if (handlerSet.contains(handler)) {
        return;
    }
    handlerSet.add(handler);
    handlerToCheck = new WeakReference<SaveHandler>(handler); // for confirmBackupLevelDatUse
    Map<String, NBTBase> additionalProperties = Maps.newHashMap();
    worldInfo.setAdditionalProperties(additionalProperties);
    for (ModContainer mc : Loader.instance().getModList()) {
        if (mc instanceof InjectedModContainer) {
            WorldAccessContainer wac = ((InjectedModContainer) mc).getWrappedWorldAccessContainer();
            if (wac != null) {
                wac.readData(handler, worldInfo, additionalProperties,
                        tagCompound.getCompoundTag(mc.getModId()));
            }
        }
    }
}

From source file:com.bekwam.resignator.JarsignerConfigController.java

public void setParent(ResignatorAppMainViewController parent) {

    ///*from  ww w.ja va  2  s . c o  m*/
    // Only setting parentRef if needed
    //

    if (this.parentRef == null || this.parentRef.get() != parent) {
        this.parentRef = new WeakReference<>(parent);
    }
}

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

/**
 *
 * @return/* w  ww  .ja v a2s  . c  o m*/
 */
@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 Peak1DOverlayChildFactory(this), true),
                getLookup());
        nodeReference = new WeakReference<>(node);
    } else {
        node = nodeReference.get();
        if (node == null) {
            node = Charts.overlayNode(this, Children.create(new Peak1DOverlayChildFactory(this), true),
                    getLookup());
            nodeReference = new WeakReference<>(node);
        }
    }
    return node;
}

From source file:net.sourceforge.processdash.ev.ui.EVReport.java

private void getEVModel() throws TinyCGIException {
    taskListName = settings.getTaskListName();
    if (taskListName == null)
        throw new TinyCGIException(400, "schedule name missing");
    else if (FAKE_MODEL_NAME.equals(taskListName)) {
        evModel = null;/*from  w w  w . j  ava2  s .c o  m*/
        return;
    }

    long now = System.currentTimeMillis();

    synchronized (EVReport.class) {
        if (drawingChart && (now - lastRecalcTime < MAX_DELAY) && taskListName.equals(lastTaskListName)) {
            evModel = lastEVModel.get();
            if (evModel != null)
                return;
        }
    }

    evModel = EVTaskList.openExisting(taskListName, getDataRepository(), getPSPProperties(), getObjectCache(),
            false); // change notification not required
    if (evModel == null)
        throw new TinyCGIException(404, "Not Found", "No such task/schedule");

    EVDependencyCalculator depCalc = new EVDependencyCalculator(getDataRepository(), getPSPProperties(),
            getObjectCache());
    evModel.setDependencyCalculator(depCalc);
    evModel.setTaskLabeler(new DefaultTaskLabeler(getDashboardContext()));

    if (settings.getBool(CUSTOMIZE_HIDE_BASELINE))
        evModel.disableBaselineData();

    evModel.recalc();

    synchronized (EVReport.class) {
        lastTaskListName = taskListName;
        lastRecalcTime = now;
        lastEVModel = new WeakReference<EVTaskList>(evModel);
    }
}

From source file:com.playonlinux.framework.SetupWizard.java

@Override
public void registerComponent(SetupWizardComponent setupWizardComponent) {
    components.add(new WeakReference<>(setupWizardComponent));
}