Class TenantAware

  • All Implemented Interfaces:
    Runnable

    public class TenantAware
    extends Thread
    A Thread implementation that makes a thread tenant-aware by setting the tenant configuration before executing its task and clearing it afterward.

    This class ensures that any operations performed in the thread are associated with the correct tenant. It uses a tenant resolver (e.g., TenantResolver) to set and manage the tenant information during thread execution.

    By default, it will run the task inside a new transaction.

    • Constructor Detail

      • TenantAware

        public TenantAware​(Runnable task)
        Constructs a TenantAware using the current tenant.
        Parameters:
        task - the task to execute
    • Method Detail

      • tenantId

        public TenantAware tenantId​(String tenantId)
        Specify the tenant identifier
        Parameters:
        tenantId - the tenant identifier
        Returns:
        this
      • tenantHost

        public TenantAware tenantHost​(String tenantHost)
        Specify the tenant host
        Parameters:
        tenantHost - the tenant host
        Returns:
        this
      • withTransaction

        public TenantAware withTransaction​(boolean withTransaction)
        Whatever the task should run inside a new transaction
        Parameters:
        withTransaction - false to not open a transaction, else true
        Returns:
        this
      • run

        public void run()
        Specified by:
        run in interface Runnable
        Overrides:
        run in class Thread