com.sap.cloud.account

## Interface TenantContext

-     public interface TenantContext

  `TenantContext` interface provides information about the tenant which is associated with the current `Thread`.

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `<V> V` | `execute(String id, Callable<V> callable)` This method will execute callable.call() method on behalf of the specified tenant and will return the result of the called method.
    `String` | `getAccountName()` Deprecated. replaced by `Account.getId()`
    `Collection<Tenant>` | `getSubscribedTenants()` Returns all tenants subscribed to the calling application.
    `Tenant` | `getTenant()` Returns the `Tenant` associated with the current `Thread`.
    `String` | `getTenantId()` Deprecated. replaced by `Tenant.getId()`

- - ### Method Detail

    - #### getTenantId

          @Deprecated
          String getTenantId()

      Deprecated. replaced by `Tenant.getId()`
      Returns:
        unique ID of the tenant which is associated with the current `Thread`.
      Throws:
        `TenantUnavailableException` - when there is no tenant context associated with the current `Thread`.

    - #### getAccountName

          @Deprecated
          String getAccountName()

      Deprecated. replaced by `Account.getId()`
      Returns:
        the technical representation of the account name of the current tenant which is associated with the current `Thread`.
      Throws:
        `TenantUnavailableException` - when there is no tenant context associated with the current `Thread`.

    - #### getTenant

          Tenant getTenant()

      Returns the `Tenant` associated with the current `Thread`.
      Returns:
        the current `Tenant`.
      Throws:
        `TenantUnavailableException` - when there is no tenant associated with the current thread or the current VM is not started for a particular tenant.

    - #### getSubscribedTenants

          Collection<Tenant> getSubscribedTenants()

      Returns all tenants subscribed to the calling application. Please note that a cache is used and the result will be up to date after a maximum of 5 minutes.
      Returns:
        all tenants subscribed to the calling application or empty collection if there are no subscribed tenants.

    - #### execute

          <V> V execute(String id,
                      Callable<V> callable)
                    throws TenantAlreadySetException,
                           InvalidTenantException,
                           Exception

      This method will execute callable.call() method on behalf of the specified tenant and will return the result of the called method. Tenant context will be cleared after execution of this method. Tenant identifier will be validated to ensure that the tenant exist and is allowed to be used by this application and on this VM.
      Parameters:
        `id` - the tenant Id. Tenant Id is accessible via `Tenant.getId()`. For example the tenant Id of the tenant which is assigned to the current thread can be accessed via `#getTenantId()`.
        `callable` - an instance on which call() method will be executed.
      Returns:
        the result of callable.call() execution.
      Throws:
        `TenantAlreadySetException` - if execution cannot be done with the provided tenant Id.
        `InvalidTenantException` - if there is no tenant with the given id, or if the tenant with the given id is not subscribed to the application or if the tenant id passed does not correspond to the tenant for which the current VM has been started.
        `Exception` - any exception thrown during execution of callable.call() method.

Copyright © 2018 SAP. All Rights Reserved.