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 Summary
Modifier and TypeMethodDescription<V> V
callWithinContext
(C context, Callable<V> task) Enters context to run with Callable taskGets entered contextboolean
Returnstrue
if context is found.void
runWithinContext
(C context, Runnable task) Enters context to run with Runnable taskwithinContext
(C context, Runnable task) Enters context to run with Runnable task and returns the task with context<V> Callable<V>
withinContext
(C context, Callable<V> task) Enters context to run with Callable task and returns the task with context
-
Method Details
-
getContext
C getContext()Gets entered context- Returns:
- entered context
- Throws:
IllegalStateException
- if not within any context
-
isInContext
boolean isInContext()Returnstrue
if context is found.- Returns:
true
if context is found;false
otherwise
-
runWithinContext
Enters context to run with Runnable task- Parameters:
context
- the credentials to access the Cumulocity platformtask
- Runnable task
-
callWithinContext
Enters context to run with Callable task- Type Parameters:
V
- generic type of Callable- Parameters:
context
- the credentials to access the Cumulocity platformtask
- Callable task- Returns:
- the returned value from the Callable task
-
withinContext
Enters context to run with Runnable task and returns the task with context- Parameters:
context
- the credentials to access the Cumulocity platformtask
- Runnable task- Returns:
- Runnable task with context
-
withinContext
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 platformtask
- Callable task- Returns:
- Callable task with context
-