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:net.rim.ejde.internal.util.VMUtils.java

/**
 * Gets the string value of an EE property from a given EE file.
 *
 * @param eeFile/*  w w w  .  ja va 2  s  . c  om*/
 *            the ee file
 * @param property
 *            the property
 *
 * @return the string value of the property
 */
static public String getPropertyFromEEFile(final File eeFile, final String property) {
    if ((null != eeFile) && eeFile.exists() && eeFile.isFile()) {
        InputStream inputStream = null;
        Properties properties = null;
        WeakReference<Properties> propsStub = null;
        WeakReference<InputStream> streamStub = null;

        try {
            propsStub = new WeakReference<Properties>(new Properties());
            properties = propsStub.get();

            streamStub = new WeakReference<InputStream>(new FileInputStream(eeFile));
            inputStream = streamStub.get();

            properties.load(inputStream);

            final String id = properties.getProperty(property);

            return id;
        } catch (final FileNotFoundException e) {
            _log.error("", e); //$NON-NLS-1$
        } catch (final IOException e) {
            _log.error("", e); //$NON-NLS-1$
        } finally {
            if (null != properties) {
                properties.clear();
                if (propsStub != null) {
                    propsStub.clear();
                    propsStub = null;
                }
            }
            if (null != inputStream) {
                try {
                    inputStream.close();
                    if (streamStub != null) {
                        streamStub.clear();
                        streamStub = null;
                    }
                } catch (final IOException e) {
                    _log.error("", e); //$NON-NLS-1$
                }
            }
        }
    }

    return StringUtils.EMPTY;
}

From source file:com.apptentive.android.sdk.ApptentiveInternal.java

public void onActivityStarted(Activity activity) {
    if (activity != null) {
        // Set current foreground activity reference whenever a new activity is started
        currentTaskStackTopActivity = new WeakReference<Activity>(activity);
        messageManager.setCurrentForegroundActivity(activity);
    }/*  www .jav a2  s  .  c o m*/

    checkAndUpdateApptentiveConfigurations();

    syncDevice();
    syncPerson();
}

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

/**
 * Perform a HTTP PUT request and track the Android Context which initiated the request.
 * /*  w w  w  . j a v  a  2 s . co m*/
 * @param context the Android Context which initiated the request.
 * @param url the URL to send the request to.
 * @param entity a raw {@link HttpEntity} to send with the request, for example, use this to send string/json/xml
 *            payloads to a server by passing a {@link org.apache.http.entity.StringEntity}.
 * @param contentType the content type of the payload you are sending, for example application/json if sending a
 *            json payload.
 * @param responseHandler the response handler instance that should handle the response.
 */
public WeakReference<Future<?>> put(Context context, String url, HttpEntity entity, String contentType,
        AsyncHttpResponseHandler responseHandler) {
    return new WeakReference<Future<?>>(sendRequest(httpClient, httpContext,
            addEntityToRequestBase(new HttpPut(url), entity), contentType, responseHandler, context));
}

From source file:com.zuowuxuxi.asihttp.AsyncHttpClient.java

@SuppressWarnings("rawtypes")
private void sendRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest,
        String contentType, AsyncHttpResponseHandler responseHandler, Context context) {
    if (contentType != null) {
        uriRequest.addHeader("Content-Type", contentType);
    }/* w ww .  jav a2s  .  co m*/

    Future request = threadPool.submit(new AsyncHttpRequest(client, httpContext, uriRequest, responseHandler));

    if (context != null) {
        // Add request to request map
        List<WeakReference<Future>> requestList = requestMap.get(context);
        if (requestList == null) {
            requestList = new LinkedList<WeakReference<Future>>();
            requestMap.put(context, requestList);
        }

        requestList.add(new WeakReference<Future>(request));

        // TODO: Remove dead weakrefs from requestLists?
    }
}

From source file:com.apptentive.android.sdk.ApptentiveInternal.java

public void onActivityResumed(Activity activity) {
    if (activity != null) {
        // Set current foreground activity reference whenever a new activity is started
        currentTaskStackTopActivity = new WeakReference<Activity>(activity);
        messageManager.setCurrentForegroundActivity(activity);
    }/*ww  w.j av  a  2 s .  c o  m*/

}

From source file:cn.edu.zafu.corepage.base.BaseActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_base);
    Intent mNewIntent = getIntent();//from w  ww  .  j a  v  a2 s .c  o m
    //?activity
    if (null != savedInstanceState) {
        loadActivitySavedData(savedInstanceState);
        //???
        //?SaveWithActivity
    }
    mHandler = new Handler(getMainLooper());
    //handler
    mCurrentInstance = new WeakReference<BaseActivity>(this);
    //?activity
    mActivities.add(mCurrentInstance);
    //?activityactivity
    printAllActivities();
    //?activity

    init(mNewIntent);
    //?activity
    IntentFilter filter = new IntentFilter();
    filter.addAction(CoreConfig.ACTION_EXIT_APP);
    filter.addCategory(Intent.CATEGORY_DEFAULT);
    CoreConfig.getLocalBroadcastManager().registerReceiver(mExitReceiver, filter);
    //?

    //?
    AnalyticsConfig.enableEncrypt(false);
    MobclickAgent.setDebugMode(true);
    MobclickAgent.openActivityDurationTrack(false);
    MobclickAgent.updateOnlineConfig(this);
}

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

/**
 * Perform a HTTP DELETE request./*  w w w.  j a va  2s  .c o m*/
 * 
 * @param context the Android Context which initiated the request.
 * @param url the URL to send the request to.
 * @param responseHandler the response handler instance that should handle the response.
 */
public WeakReference<Future<?>> delete(Context context, String url, AsyncHttpResponseHandler responseHandler) {
    final HttpDelete delete = new HttpDelete(url);
    return new WeakReference<Future<?>>(
            sendRequest(httpClient, httpContext, delete, null, responseHandler, context));
}

From source file:net.sf.maltcms.common.charts.api.overlay.SelectionOverlay.java

/**
 *
 * @return//ww  w . jav a 2s  . c om
 */
@Override
public Node createNodeDelegate() {
    Node node = null;
    if (nodeReference == null) {
        node = overlayNode(this, Children.LEAF, getLookup());
        nodeReference = new WeakReference<>(node);
    } else {
        node = nodeReference.get();
        if (node == null) {
            node = overlayNode(this, Children.LEAF, getLookup());
            nodeReference = new WeakReference<>(node);
        }
    }
    return node;
}

From source file:org.gaeproxy.GAEProxyService.java

private void markServiceStarted() {
    sRunningInstance = new WeakReference<GAEProxyService>(this);
}

From source file:com.dpbymqn.fsm.manager.FsmManager.java

private TransitionCallback invokeTransitor(final Method m, StateListener sl) {
    final WeakReference<StateListener> slRef = new WeakReference<StateListener>(sl);
    final TransitionCallback cbk = new TransitionCallback() {
        @Override//  w ww.  j a va2  s . c o m
        public void onTransition(StatefulObject st, String fromState, String toState) {
            if (m.getParameterTypes() != null) {
                // many different types and possibilities
                switch (m.getParameterTypes().length) {
                case 0:
                    invoke(m, Modifier.isStatic(m.getModifiers()) ? null : slRef.get());
                    break;
                case 1:
                    if (String.class.equals(m.getParameterTypes()[0])) {
                        if (fromState != null) {
                            invoke(m, Modifier.isStatic(m.getModifiers()) ? null : slRef.get(), toState);
                        } else {
                            invoke(m, Modifier.isStatic(m.getModifiers()) ? null : slRef.get(), fromState);
                        }
                    } else if (StatefulObject.class.isAssignableFrom(m.getParameterTypes()[0])) {
                        invoke(m, Modifier.isStatic(m.getModifiers()) ? null : slRef.get(), st);
                    } else {
                        //                                invoke(m, Modifier.isStatic(m.getModifiers()) ? null : sl, st);
                        throw new UnsupportedOperationException("Single parameter, but not recognized:"
                                + m.getParameterTypes()[0].getSimpleName());
                    }
                    break;
                case 2:
                    if (String.class.equals(m.getParameterTypes()[0])) {
                        invoke(m, Modifier.isStatic(m.getModifiers()) ? null : slRef.get(), fromState, toState);
                    } else if (StatefulObject.class.isAssignableFrom(m.getParameterTypes()[0])) {
                        if (fromState != null) {
                            invoke(m, Modifier.isStatic(m.getModifiers()) ? null : slRef.get(), st, toState);
                        } else {
                            invoke(m, Modifier.isStatic(m.getModifiers()) ? null : slRef.get(), st, fromState);
                        }
                    }
                    break;
                case 3:
                    // format: void method( Stated st, String fromState, String toState )
                    invoke(m, Modifier.isStatic(m.getModifiers()) ? null : slRef.get(), st, fromState, toState);
                    break;
                }
            }
        }
    };
    return cbk;
}