saker.util Documentation TaskDoc JavaDoc Packages
public class WeakReferencedToken<Timplements Token
Token implementation that is initialized with a weak and a strong reference.

This base token implementation can be used when the server stores the passed objects using a reference, and the token is returned to the client to store.

The weak reference used during the construction of the object should be stored in a collection on the server, and an instance of this token should be returned to the client. Once the client releases all references to this token, the server will be able to garbage collect the strongly referenced object, as there are only weak references pointing to it.

It may be useful to extend this class and provide additional functions to the client to manually uninstall the token reference from the server.

TThe type of the referenced object.
Fields
protected final T
The strong reference to the object.
protected final WeakReference<extends T>
The weak reference to the object.
Constructors
public
WeakReferencedToken(WeakReference<extends T> objectWeakRef)
Constructs a new token with the given weak reference.
protected final T objectStrongRef
The strong reference to the object.
protected final WeakReference<extends T> objectWeakRef
The weak reference to the object.
public WeakReferencedToken(WeakReference<extends T> objectWeakRef) throws NullPointerException
Constructs a new token with the given weak reference.

The strong reference of this token is initialized by referent of the argument.

objectWeakRefThe reference.
NullPointerExceptionIf the argument is null.