com.holonplatform.core.internal

## Class ThreadScope

- java.lang.Object
- - com.holonplatform.core.internal.ThreadScope

- All Implemented Interfaces:
    ContextScope

      public final class ThreadScope
      extends Object
      implements ContextScope

  A `ContextScope` to handle Thread-bound context resources.
  Since:
    5.0.0

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `DEFAULT_ORDER` Default scope order

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ThreadScope()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_ORDER

          public static final int DEFAULT_ORDER

      Default scope order
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### ThreadScope

          public ThreadScope()

  - ### Method Detail

    - #### getName

          public String getName()

      Description copied from interface: `ContextScope`
      Gets the scope name. Scope name must be unique among all registered context scopes.
      Specified by:
        `getName` in interface `ContextScope`
      Returns:
        the scope name

    - #### getOrder

          public int getOrder()

      Description copied from interface: `ContextScope`
      Gets the scope order. Lower order values mean highest precedence.
      Specified by:
        `getOrder` in interface `ContextScope`
      Returns:
        the scope order

    - #### get

          public <T> Optional<T> get(String resourceKey,
                                     Class<T> resourceType)
                              throws TypeMismatchException

      Description copied from interface: `ContextScope`
      Try to obtain the resource identified by given `resourceKey` and with expected `resourceType`.
      Specified by:
        `get` in interface `ContextScope`
      Type Parameters:
        `T` - Resource type
      Parameters:
        `resourceKey` - Resource key (not null)
        `resourceType` - Expected resource type (not null)
      Returns:
        Optional resource instance, an empty Optional if resource is not available from scope according to scope resource provisioning strategy
      Throws:
        `TypeMismatchException` - If a resource is available but the expected type is not compatible with the resource type

    - #### put

          public <T> Optional<T> put(String resourceKey,
                                     T value)
                              throws UnsupportedOperationException

      Description copied from interface: `ContextScope`
      Stores a resource reference identified by given `resourceKey`.
      Specified by:
        `put` in interface `ContextScope`
      Type Parameters:
        `T` - Resource instance type
      Parameters:
        `resourceKey` - 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.
      Returns:
        Optional previous resource instance bound to given key
      Throws:
        `UnsupportedOperationException` - If the concrete scope implementation does not support this operation

    - #### putIfAbsent

          public <T> Optional<T> putIfAbsent(String resourceKey,
                                             T value)
                                      throws UnsupportedOperationException

      Description copied from interface: `ContextScope`
      Stores a resource reference identified by given `resourceKey`, only if there is not a resource instance already bound to given key.
      Specified by:
        `putIfAbsent` in interface `ContextScope`
      Type Parameters:
        `T` - Resource instance type
      Parameters:
        `resourceKey` - Resource key (not null)
        `value` - Resource instance, if `null`, this method should do nothing.
      Returns:
        Optional previous resource instance bound to given key. If there was no resource already bound to the key, an empty Optional is returned, meaning the given `value` has been associated to the resource key.
      Throws:
        `UnsupportedOperationException` - If the concrete scope implementation does not support this operation

    - #### remove

          public boolean remove(String resourceKey)
                         throws UnsupportedOperationException

      Description copied from interface: `ContextScope`
      Removes the resource reference bound to the given `resourceKey` from scope, if any.
      Specified by:
        `remove` in interface `ContextScope`
      Parameters:
        `resourceKey` - Resource key (not null)
      Returns:
        `true` if a resource instance was bound to the given key and it's been removed, `false` otherwise.
      Throws:
        `UnsupportedOperationException` - If the concrete scope implementation does not support this operation

Copyright © 2019 The Holon Platform. All rights reserved.