public final class ThreadScope extends Object implements ContextScope
ContextScope to handle Thread-bound context resources.| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_ORDER
Default scope order
|
| Constructor and Description |
|---|
ThreadScope() |
| Modifier and Type | Method and Description |
|---|---|
<T> Optional<T> |
get(String resourceKey,
Class<T> resourceType)
Try to obtain the resource identified by given
resourceKey and with expected
resourceType. |
String |
getName()
Gets the scope name.
|
int |
getOrder()
Gets the scope order.
|
<T> Optional<T> |
put(String resourceKey,
T value)
Stores a resource reference identified by given
resourceKey. |
<T> Optional<T> |
putIfAbsent(String resourceKey,
T value)
Stores a resource reference identified by given
resourceKey, only if there is not a resource
instance already bound to given key. |
boolean |
remove(String resourceKey)
Removes the resource reference bound to the given
resourceKey from scope, if any. |
public static final int DEFAULT_ORDER
public String getName()
ContextScopegetName in interface ContextScopepublic int getOrder()
ContextScopegetOrder in interface ContextScopepublic <T> Optional<T> get(String resourceKey, Class<T> resourceType) throws TypeMismatchException
ContextScoperesourceKey and with expected
resourceType.get in interface ContextScopeT - Resource typeresourceKey - Resource key (not null)resourceType - Expected resource type (not null)TypeMismatchException - If a resource is available but the expected type is not compatible with the
resource typepublic <T> Optional<T> put(String resourceKey, T value) throws UnsupportedOperationException
ContextScoperesourceKey.put in interface ContextScopeT - Resource instance typeresourceKey - Resource key (not null)value - Resource instance. If null, if a previous resource was bound to given resource key, it
will be removed from scope.UnsupportedOperationException - If the concrete scope implementation does not support this operationpublic <T> Optional<T> putIfAbsent(String resourceKey, T value) throws UnsupportedOperationException
ContextScoperesourceKey, only if there is not a resource
instance already bound to given key.putIfAbsent in interface ContextScopeT - Resource instance typeresourceKey - Resource key (not null)value - Resource instance, if null, this method should do nothing.value has been associated to the
resource key.UnsupportedOperationException - If the concrete scope implementation does not support this operationpublic boolean remove(String resourceKey) throws UnsupportedOperationException
ContextScoperesourceKey from scope, if any.remove in interface ContextScoperesourceKey - Resource key (not null)true if a resource instance was bound to the given key and it's been removed,
false otherwise.UnsupportedOperationException - If the concrete scope implementation does not support this operationCopyright © 2019 The Holon Platform. All rights reserved.