Interface ContextService<C>

Type Parameters:
C - Generic type for the context.
All Known Implementing Classes:
ContextServiceImpl

public interface ContextService<C>
A service to get and enter context to run tasks with. The service is aimed to be used for the tasks which contains Cumulocity API calls. Context contains credentials to use as authorization to Cumulocity platform.
  • Method Details

    • getContext

      C getContext()
      Gets entered context
      Returns:
      entered context
      Throws:
      IllegalStateException - if not within any context
    • isInContext

      boolean isInContext()
      Returns true if context is found.
      Returns:
      true if context is found; false otherwise
    • runWithinContext

      void runWithinContext(C context, Runnable task)
      Enters context to run with Runnable task
      Parameters:
      context - the credentials to access the Cumulocity platform
      task - Runnable task
    • callWithinContext

      <V> V callWithinContext(C context, Callable<V> task)
      Enters context to run with Callable task
      Type Parameters:
      V - generic type of Callable
      Parameters:
      context - the credentials to access the Cumulocity platform
      task - Callable task
      Returns:
      the returned value from the Callable task
    • withinContext

      Runnable withinContext(C context, Runnable task)
      Enters context to run with Runnable task and returns the task with context
      Parameters:
      context - the credentials to access the Cumulocity platform
      task - Runnable task
      Returns:
      Runnable task with context
    • withinContext

      <V> Callable<V> withinContext(C context, Callable<V> task)
      Enters context to run with Callable task and returns the task with context
      Type Parameters:
      V - generic type of Callable
      Parameters:
      context - the credentials to access the Cumulocity platform
      task - Callable task
      Returns:
      Callable task with context