com.holonplatform.core.tenancy

## Interface TenantResolver

- Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

      @FunctionalInterface
      public interface TenantResolver

  Resolver to obtain the current tenant id in a multi-tenant environment.
  Since:
    5.0.0

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `CONTEXT_KEY` Default `Context` resource reference

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <V> V` | `execute(String tenantId, Callable<V> operation)` Execute given `Callable` `operation` on behalf of given `tenantId`, binding to current thread a static `TenantResolver` context resource with default `CONTEXT_KEY` key providing the specified tenant id.
    `static void` | `execute(String tenantId, Runnable operation)` Execute given `Runnable` `operation` on behalf of given `tenantId`, binding to current thread a static `TenantResolver` context resource with default `CONTEXT_KEY` key providing the specified tenant id.
    `static Optional<TenantResolver>` | `getCurrent()` Convenience method to obtain the current `TenantResolver` made available as `Context` resource, using default `ClassLoader`.
    `Optional<String>` | `getTenantId()` Gets the current tenant id, if available
    `static TenantResolver` | `staticTenantResolver(String tenantId)` Build a static `TenantResolver`, returning always the given `tenantId` as current tenant id.

- - ### Field Detail

    - #### CONTEXT_KEY

          static final String CONTEXT_KEY

      Default `Context` resource reference

  - ### Method Detail

    - #### getTenantId

          Optional<String> getTenantId()

      Gets the current tenant id, if available
      Returns:
        Optional tenant id, an empty Optional if current tenant is not available

    - #### getCurrent

          static Optional<TenantResolver> getCurrent()

      Convenience method to obtain the current `TenantResolver` made available as `Context` resource, using default `ClassLoader`.

      See `Context.resource(String, Class)` for details about context resources availability conditions.

      Returns:
        Optional TenantResolver, empty if not available as context resource

    - #### staticTenantResolver

          static TenantResolver staticTenantResolver(String tenantId)

      Build a static `TenantResolver`, returning always the given `tenantId` as current tenant id.
      Parameters:
        `tenantId` - Static tenant id to be returned by the resolver
      Returns:
        Static TenantResolver

    - #### execute

          static void execute(String tenantId,
                              Runnable operation)
                       throws RuntimeException

      Execute given `Runnable` `operation` on behalf of given `tenantId`, binding to current thread a static `TenantResolver` context resource with default `CONTEXT_KEY` key providing the specified tenant id.
      Parameters:
        `tenantId` - Tenant id
        `operation` - Operation to execute (not null)
      Throws:
        `RuntimeException` - Exception during operation execution

    - #### execute

          static <V> V execute(String tenantId,
                               Callable<V> operation)
                        throws RuntimeException

      Execute given `Callable` `operation` on behalf of given `tenantId`, binding to current thread a static `TenantResolver` context resource with default `CONTEXT_KEY` key providing the specified tenant id.
      Type Parameters:
        `V` - Operation result type
      Parameters:
        `tenantId` - Tenant id
        `operation` - Operation to execute
      Returns:
        Operation result
      Throws:
        `RuntimeException` - Exception during operation execution

Copyright © 2017 The Holon Platform. All rights reserved.