Package com.github.devmix.process.acto
Interface ActiveObjectContext<T>
- Type Parameters:
T- The type of instance held by the active object
public interface ActiveObjectContext<T>
Represents the context of an active object, providing methods to manage dependencies,
lifecycle, and message handling.
- Author:
- Sergey Grachev
-
Method Summary
Modifier and TypeMethodDescriptionaddDependsOn(Object objectId, boolean optional) Adds a dependency on another active object with specified optional flag.voidawaitEmptyQueue(long timeout, TimeUnit unit) Waits until the message queue of this active object becomes empty.findDependsOn(Object objectId) Finds a dependency on another active object by its identifier.findRequiredFor(Object objectId) Finds a required dependency for another active object by its identifier.voidforEachDependency(java.util.function.Consumer<ActiveObjectDependency> fn, ActiveObjectDependency.Type filterByType) Applies a function to each dependency, optionally filtering by type.getDependsOn(Object objectId) Retrieves a dependency on another active object by its identifier.getId()Returns a unique identifier for this active object.longReturns the current idle timeout for this active object.Returns the current instance held by this active object.<O> OReturns the options associated with this active object context.Returns the current status of this active object.longReturns the current wait messages timeout for this active object.<R> CompletableFuture<R> redirectRequest(Object objectId, Object message) Redirects a request to another active object and returns a future for its response.voidredirectRequestAndForget(Object objectId, Object message) Redirects a request to another active object and forgets it (does not expect response).voidsetIdleTimeout(long idleTimeout) Sets a new idle timeout for this active object.voidsetInstance(T instance) Sets a new instance for this active object.voidsetWaitMessagesTimeout(long waitMessagesTimeout) Sets a new wait messages timeout for this active object.
-
Method Details
-
getId
Object getId()Returns a unique identifier for this active object.- Returns:
- The identifier of the active object
-
addDependsOn
Adds a dependency on another active object with specified optional flag.- Parameters:
objectId- The identifier of the active object to depend onoptional- True if the dependency is optional, false otherwise- Returns:
- An
ActiveObjectDependencyrepresenting this dependency
-
awaitEmptyQueue
void awaitEmptyQueue(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException Waits until the message queue of this active object becomes empty.- Parameters:
timeout- The maximum time to waitunit- The time unit for the specified timeout- Throws:
InterruptedException- if the current thread is interrupted while waitingExecutionException- if an exception occurs during the executionTimeoutException- if the specified waiting time elapses before completion
-
getDependsOn
Retrieves a dependency on another active object by its identifier.- Parameters:
objectId- The identifier of the dependent active object- Returns:
- An
ActiveObjectDependencyrepresenting this dependency, or null if no such dependency exists
-
findDependsOn
Finds a dependency on another active object by its identifier.- Parameters:
objectId- The identifier of the dependent active object- Returns:
- An
ActiveObjectDependencyrepresenting this dependency, or null if no such dependency exists
-
findRequiredFor
Finds a required dependency for another active object by its identifier.- Parameters:
objectId- The identifier of the dependent active object- Returns:
- An
ActiveObjectDependencyrepresenting this required dependency, or null if no such dependency exists
-
forEachDependency
void forEachDependency(java.util.function.Consumer<ActiveObjectDependency> fn, @Nullable ActiveObjectDependency.Type filterByType) Applies a function to each dependency, optionally filtering by type.- Parameters:
fn- The consumer function to apply to each dependencyfilterByType- The type of dependencies to include, or null if no filtering should be applied
-
getIdleTimeout
long getIdleTimeout()Returns the current idle timeout for this active object.- Returns:
- The idle timeout in milliseconds
-
setInstance
Sets a new instance for this active object.- Parameters:
instance- The new instance, or null to clear the instance
-
getInstance
T getInstance()Returns the current instance held by this active object.- Returns:
- The instance, or null if no instance is currently set
-
getOptions
<O> O getOptions()Returns the options associated with this active object context.- Type Parameters:
O- The type of options- Returns:
- The options
-
setIdleTimeout
void setIdleTimeout(long idleTimeout) Sets a new idle timeout for this active object.- Parameters:
idleTimeout- The new idle timeout in milliseconds
-
getStatus
ActiveObjectStatus getStatus()Returns the current status of this active object.- Returns:
- The status of the active object
-
getWaitMessagesTimeout
long getWaitMessagesTimeout()Returns the current wait messages timeout for this active object.- Returns:
- The wait messages timeout in milliseconds
-
setWaitMessagesTimeout
void setWaitMessagesTimeout(long waitMessagesTimeout) Sets a new wait messages timeout for this active object.- Parameters:
waitMessagesTimeout- The new wait messages timeout in milliseconds
-
redirectRequestAndForget
Redirects a request to another active object and forgets it (does not expect response).- Parameters:
objectId- The identifier of the target active objectmessage- The message to send- Throws:
RegistryException- if an error occurs during redirection
-
redirectRequest
Redirects a request to another active object and returns a future for its response.- Type Parameters:
R- The type of the response- Parameters:
objectId- The identifier of the target active objectmessage- The message to send- Returns:
- A completable future representing the eventual response
- Throws:
RegistryException- if an error occurs during redirection
-