APIdia Launch Partner
Top Description Inners Fields Constructors Methods
sun.java2d

public abstract Class ReentrantContextProvider<K extends ReentrantContext>

extends Object
Class Inheritance
Known Direct Subclasses
sun.java2d.ReentrantContextProviderCLQ, sun.java2d.ReentrantContextProviderTL
Type Parameters
<K>
ReentrantContext subclass
Imports
java.lang.ref.Reference, .SoftReference, .WeakReference

This abstract ReentrantContextProvider helper class manages the creation, storage, and retrieval of concrete ReentrantContext instances which can be subclassed to hold cached contextual data. It supports reentrancy as every call to acquire() provides a new unique context instance that must later be returned for reuse by a call to release(ctx) (typically in a try/finally block). It has a couple of abstract implementations which store references in a queue and/or thread-local storage. The Providers can be configured to hold ReentrantContext instances in memory using hard, soft or weak references. The acquire() and release() methods are used to retrieve and return the contexts. The newContext() method remains abstract in all implementations and must be provided by the module to create a new subclass of ReentrantContext with the appropriate contextual data in it. Sample Usage: - create a subclass ReentrantContextImpl to hold the thread state:
static final class ReentrantContextImpl extends ReentrantContext {
    // specific cached data
}
- create the appropriate ReentrantContextProvider:
private static final ReentrantContextProvider<ReentrantContextImpl> contextProvider =
    new ReentrantContextProviderTL<ReentrantContextImpl>(ReentrantContextProvider.REF_WEAK)
    {
        @Override
        protected ReentrantContextImpl newContext() {
            return new ReentrantContextImpl();
        }
    };
...
void someMethod() {
    ReentrantContextImpl ctx = contextProvider.acquire();
    try {
        // use the context
    } finally {
        contextProvider.release(ctx);
    }
}
See Also
ReentrantContext

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int
private final int
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte

Constructor Summary

AccessConstructor and Description
protected
ReentrantContextProvider(final int
reference type
refType
)

Create a new ReentrantContext provider using the given reference type among hard, soft or weak

Method Summary

Modifier and TypeMethod and Description
public abstract K

Returns:

ReentrantContext instance
acquire
()

Give a ReentrantContext instance for the current thread

protected final Reference<K>
getOrCreateReference(final K ctx)

protected abstract K

Returns:

new ReentrantContext instance
newContext
()

Create a new ReentrantContext instance

public abstract void
release(K
ReentrantContext instance
ctx
)

Restore the given ReentrantContext instance for reuse

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

REF_HARDback to summary
public static final int REF_HARD
REF_SOFTback to summary
public static final int REF_SOFT
REF_WEAKback to summary
public static final int REF_WEAK
refTypeback to summary
private final int refType
USAGE_CLQback to summary
pack-priv static final byte USAGE_CLQ
USAGE_TL_IN_USEback to summary
pack-priv static final byte USAGE_TL_IN_USE
USAGE_TL_INACTIVEback to summary
pack-priv static final byte USAGE_TL_INACTIVE

Constructor Detail

ReentrantContextProviderback to summary
protected ReentrantContextProvider(final int refType)

Create a new ReentrantContext provider using the given reference type among hard, soft or weak

Parameters
refType:int

reference type

Method Detail

acquireback to summary
public abstract K acquire()

Give a ReentrantContext instance for the current thread

Returns:K

ReentrantContext instance

getOrCreateReferenceback to summary
protected final Reference<K> getOrCreateReference(final K ctx)
Annotations
@SuppressWarnings:unchecked
newContextback to summary
protected abstract K newContext()

Create a new ReentrantContext instance

Returns:K

new ReentrantContext instance

releaseback to summary
public abstract void release(K ctx)

Restore the given ReentrantContext instance for reuse

Parameters
ctx:K

ReentrantContext instance

sun.java2d back to summary

pack-priv final Class ReentrantContextProvider.HardReference<V>

extends WeakReference<V>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final V

Constructor Summary

AccessConstructor and Description
pack-priv
HardReference(final V referent)

Method Summary

Modifier and TypeMethod and Description
public V
get()

Overrides java.lang.ref.Reference.get.

Returns this reference object's referent.

Field Detail

strongRefback to summary
private final V strongRef

Constructor Detail

HardReferenceback to summary
pack-priv HardReference(final V referent)

Method Detail

getback to summary
public V get()

Overrides java.lang.ref.Reference.get.

Doc from java.lang.ref.Reference.get.

Returns this reference object's referent. If this reference object has been cleared, either by the program or by the garbage collector, then this method returns null.

Annotations
@Override