|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectFactory
ReferencingFactory
AbstractAuthorityFactory
CachingAuthorityFactory
ThreadedAuthorityFactory
@ThreadSafe public abstract class ThreadedAuthorityFactory
A caching authority factory which delegates to different instances of a backing store for concurrency in multi-thread environment. This factory delays the creation of a backing store until first needed, and dispose it after some timeout. This approach allows to establish a connection to a database (for example) and keep it only for a relatively short amount of time.
Multi-threading
If two or more threads are accessing this factory in same time, then two or more instances
of the backing store may be created. The maximal amount of instances to create is specified
at ThreadedAuthorityFactory construction time. If more backing store instances are
needed, some of the threads will block until an instance become available.
| referencing/geotk-referencing (download) | View source code for this class |
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class Factory |
|---|
Factory.Availability, Factory.Organizer |
| Field Summary |
|---|
| Fields inherited from class AbstractAuthorityFactory |
|---|
nameFactory |
| Fields inherited from class ReferencingFactory |
|---|
LOGGER |
| Fields inherited from class Factory |
|---|
EMPTY_HINTS, hints |
| Constructor Summary | |
|---|---|
protected |
ThreadedAuthorityFactory(Hints userHints)
Constructs an instance using the default setting. |
protected |
ThreadedAuthorityFactory(Hints userHints,
int maxStrongReferences,
int maxBackingStores)
Constructs an instance using the given setting. |
| Method Summary | |
|---|---|
protected boolean |
canDisposeBackingStore(AbstractAuthorityFactory backingStore)
Returns true if the given backing store can be disposed now. |
protected abstract AbstractAuthorityFactory |
createBackingStore()
Creates the backing store authority factory. |
protected void |
dispose(boolean shutdown)
Releases resources immediately instead of waiting for the garbage collector. |
Map<RenderingHints.Key,?> |
getImplementationHints()
Returns the implementation hints. |
long |
getTimeout()
Returns the current timeout. |
boolean |
isActive()
Returns true if this factory contains at least one active backing store. |
void |
setTimeout(long delay)
Sets a timer for disposing the backing store after the specified amount of milliseconds of inactivity. |
| Methods inherited from class AbstractAuthorityFactory |
|---|
noSuchAuthorityCode, trimAuthority |
| Methods inherited from class ReferencingFactory |
|---|
ensureNonNull |
| Methods inherited from class Factory |
|---|
equals, hasCompatibleHints, hashCode, setOrdering, toString |
| Methods inherited from class Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
protected ThreadedAuthorityFactory(Hints userHints)
createBackingStore() method
is invoked.
userHints - An optional set of hints, or null for the default ones.
protected ThreadedAuthorityFactory(Hints userHints,
int maxStrongReferences,
int maxBackingStores)
createBackingStore() method
is invoked.
userHints - An optional set of hints, or null for the default ones.maxStrongReferences - The maximum number of objects to keep by strong reference.maxBackingStores - The maximal amount of backing stores to create. This is the
maximal amount of threads that can use this factory without blocking each other
when the requested objects are not in the cache.| Method Detail |
|---|
public Map<RenderingHints.Key,?> getImplementationHints()
CachingAuthorityFactory parent class), this method does
not set Hints.CRS_AUTHORITY_FACTORY and its friends to the backing
store. This is because the backing stores may be created and destroyed at any time, while the
implementation hints are expected to be stable. Instead, the implementation hints of a
backing store are copied straight in this ThreadedAuthorityFactory hint map.
getImplementationHints in class Factory
protected abstract AbstractAuthorityFactory createBackingStore()
throws NoSuchFactoryException,
FactoryException
createXXX(...) method is invoked. It may also be invoked again if additional
factories are needed in different threads, or if all factories have been disposed
after the timeout.
Synchronization
This method needs to be thread-safe. ThreadedAuthorityFactory does not hold a lock
when invoking this method. Subclasses are responsible to apply their own synchronization if
needed, but are encouraged to avoid doing so if possible.
In addition, implementations should not invoke availability(),
getImplementationHints(), getAuthority(),
getVendor() or any createXXX() method in order to avoid
never-ending loop. If hints are needed, use the code below instead but keep in mind
that the map may not contains the definitive set of hints at this stage:
final Hints localHints = EMPTY_HINTS.clone();
synchronized (this) {
localHints.putAll(hints);
}
createXXX(...) methods.
NoSuchFactoryException - if the backing store has not been found.
FactoryException - if the creation of backing store failed for an other reason.public boolean isActive()
true if this factory contains at least one active backing store.
A backing store is "active" if it has been created for a previous request and not
yet disposed after a period of inactivity equals to the timeout.
A return value of false typically implies that every connection to the
underlying database (if any) used by this factory have been closed. Note however
that this information is only approximative. Because of the concurrent nature of
ThreadedAuthorityFactory, we may have a small delay between the time when
the first connection is created and the time when this method returns true.
true if this factory contains at least one active backing store.public long getTimeout()
public void setTimeout(long delay)
createBackingStore() method will be invoked again.
Note that the backing store disposal can be vetoed if canDisposeBackingStore(org.geotoolkit.referencing.factory.AbstractAuthorityFactory)
returns false.
delay - The delay of inactivity (in milliseconds) before to close a backing store.protected boolean canDisposeBackingStore(AbstractAuthorityFactory backingStore)
true if the given backing store can be disposed now. This method is invoked
automatically after the amount of time specified by setTimeout(long), providing that the
factory was not used during that time. The default implementation always returns true.
Subclasses should override this method and returns false if they want to prevent the
backing store disposal under some circumstances.
backingStore - The backing store in process of being disposed.
true if the backing store can be disposed now.protected void dispose(boolean shutdown)
dispose in class CachingAuthorityFactoryshutdown - false for normal disposal, or true if
this method is invoked during the process of a JVM shutdown.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||