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:CheckThreadViolationRepaintManager.java

private void checkThreadViolations(JComponent c) {
    if (!SwingUtilities.isEventDispatchThread() && (completeCheck || c.isShowing())) {
        boolean repaint = false;
        boolean fromSwing = false;
        boolean imageUpdate = false;
        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
        for (StackTraceElement st : stackTrace) {
            if (repaint && st.getClassName().startsWith("javax.swing.")) {
                fromSwing = true;/* www . j  a va2  s. c om*/
            }
            if (repaint && "imageUpdate".equals(st.getMethodName())) {
                imageUpdate = true;
            }
            if ("repaint".equals(st.getMethodName())) {
                repaint = true;
                fromSwing = false;
            }
        }
        if (imageUpdate) {
            // assuming it is java.awt.image.ImageObserver.imageUpdate(...)
            // image was asynchronously updated, that's ok
            return;
        }
        if (repaint && !fromSwing) {
            // no problems here, since repaint() is thread safe
            return;
        }
        // ignore the last processed component
        if (lastComponent != null && c == lastComponent.get()) {
            return;
        }
        lastComponent = new WeakReference<JComponent>(c);
        violationFound(c, stackTrace);
    }
}

From source file:com.andrew.apollo.adapters.PagerAdapter.java

/**
 * {@inheritDoc}/*  w ww .j  av  a2  s  . com*/
 */
@Override
public Object instantiateItem(final ViewGroup container, final int position) {
    final Fragment mFragment = (Fragment) super.instantiateItem(container, position);
    final WeakReference<Fragment> mWeakFragment = mFragmentArray.get(position);
    if (mWeakFragment != null) {
        mWeakFragment.clear();
    }
    mFragmentArray.put(position, new WeakReference<Fragment>(mFragment));
    return mFragment;
}

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

/**
 *  The constructor for this class/* www  .  ja v a  2 s.c  o m*/
 *
 *  @param newGroupID  The ID for this group
 *  @param channel     The signaling channel managing communications with this group
 *  @param newClient   The client to which this group instance belongs
 *  @param isJoined    Whether the group has already been joined
 */
public RespokeGroup(String newGroupID, RespokeSignalingChannel channel, RespokeClient newClient,
        Boolean isJoined) {
    groupID = newGroupID;
    signalingChannel = channel;
    clientReference = new WeakReference<RespokeClient>(newClient);
    members = new ArrayList<RespokeConnection>();
    joined = isJoined;
}

From source file:com.socialize.provider.BaseSocializeProvider.java

@Override
public void init(Context context) {
    this.context = new WeakReference<Context>(context);
}

From source file:com.joyent.manta.http.PoolStatsMBean.java

/**
 * Creates a new MBean instance backed by the passed connection manager.
 * @param connectionManager instance to get statistics from
 *///ww w  .  j a  v  a2s .c  o  m
PoolStatsMBean(final PoolingHttpClientConnectionManager connectionManager) {
    this.connectionManagerRef = new WeakReference<>(connectionManager);
    updatePoolStats();
}

From source file:ch.entwine.weblounge.common.impl.content.AbstractResourceReaderImpl.java

/**
 * Creates a new resource reader reader that will parse the XML data and store
 * it in the <code>Resource</code> object that is returned by the
 * {@link #read} method./*w w  w. j av a  2 s.  c o  m*/
 * 
 * @param rootTag
 *          name of the root tag
 * @throws ParserConfigurationException
 *           if the SAX parser setup failed
 * @throws SAXException
 *           if an error occurs while parsing
 */
public AbstractResourceReaderImpl(String rootTag) throws ParserConfigurationException, SAXException {
    if (rootTag == null)
        throw new IllegalArgumentException("Root tag name must not be null");
    this.rootTag = rootTag.toLowerCase();
    parserRef = new WeakReference<SAXParser>(parserFactory.newSAXParser());
}

From source file:com.achep.acdisplay.services.media.MediaController2KitKat.java

/**
 * {@inheritDoc}//from  w  ww .jav a2 s . co  m
 */
protected MediaController2KitKat(@NonNull Activity activity) {
    super(activity);

    SparseIntArray cachedStateSparse = sStateSparse.get();
    if (cachedStateSparse == null) {
        mStateSparse = generatePlaybackCompatSparse();
        sStateSparse = new WeakReference<>(mStateSparse);
    } else {
        mStateSparse = cachedStateSparse;
    }
}

From source file:hudson.plugins.robot.RobotBuildAction.java

/**
 * Loads new data to {@link RobotResult}.
 *//*from  w  ww. j a  va2s  .co  m*/
public synchronized void setResult(RobotResult result, BuildListener listener) {
    result.tally(this);
    try {
        getDataFile().write(result);
    } catch (IOException e) {
        e.printStackTrace(listener.fatalError("Failed to save the Robot test result"));
    }

    this.resultReference = new WeakReference<RobotResult>(result);
}

From source file:ch.entwine.weblounge.common.impl.content.page.PageReader.java

/**
 * Creates a new page data reader that will parse the XML data and store it in
 * the <code>Page</code> object that is returned by the {@link #read()} method.
 * // w w  w.  j  a va2  s .c om
 * @throws ParserConfigurationException
 *           if the SAX parser setup failed
 * @throws SAXException
 *           if an error occurs while parsing
 */
public PageReader() throws ParserConfigurationException, SAXException {
    parserRef = new WeakReference<SAXParser>(parserFactory.newSAXParser());
    pageletReader = new PageletReader();
}

From source file:org.universAAL.android.proxies.ServiceCalleeProxy.java

/**
 * Constructor for the proxy./* w  ww  .  ja v  a  2s. co  m*/
 * 
 * @param parcel
 *            The parcelable from of the grounding of the metadata.
 * @param context
 *            The Android context.
 */
public ServiceCalleeProxy(GroundingParcel parcel, Context context) {
    super(AndroidContext.THE_CONTEXT, prepareProfiles(parcel.getGrounding()));
    contextRef = new WeakReference<Context>(context);
    action = parcel.getAction();
    category = parcel.getCategory();
    replyAction = parcel.getReplyAction();
    replyCategory = parcel.getReplyCategory();
    grounding = prepareGrounding(parcel.getGrounding());
    fillTableIN(parcel.getLengthIN(), parcel.getKeysIN(), parcel.getValuesIN());
    fillTableOUT(parcel.getLengthOUT(), parcel.getKeysOUT(), parcel.getValuesOUT());
    ServiceProfile[] sps = prepareProfiles(parcel.getGrounding());
    spURI = sps[0].getURI();
    // This is for RAPI. 
    sync();
}