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 Details

    • getId

      Object getId()
      Returns a unique identifier for this active object.
      Returns:
      The identifier of the active object
    • addDependsOn

      ActiveObjectDependency addDependsOn(Object objectId, boolean optional)
      Adds a dependency on another active object with specified optional flag.
      Parameters:
      objectId - The identifier of the active object to depend on
      optional - True if the dependency is optional, false otherwise
      Returns:
      An ActiveObjectDependency representing 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 wait
      unit - The time unit for the specified timeout
      Throws:
      InterruptedException - if the current thread is interrupted while waiting
      ExecutionException - if an exception occurs during the execution
      TimeoutException - if the specified waiting time elapses before completion
    • getDependsOn

      ActiveObjectDependency getDependsOn(Object objectId)
      Retrieves a dependency on another active object by its identifier.
      Parameters:
      objectId - The identifier of the dependent active object
      Returns:
      An ActiveObjectDependency representing this dependency, or null if no such dependency exists
    • findDependsOn

      @Nullable ActiveObjectDependency findDependsOn(Object objectId)
      Finds a dependency on another active object by its identifier.
      Parameters:
      objectId - The identifier of the dependent active object
      Returns:
      An ActiveObjectDependency representing this dependency, or null if no such dependency exists
    • findRequiredFor

      @Nullable ActiveObjectDependency findRequiredFor(Object objectId)
      Finds a required dependency for another active object by its identifier.
      Parameters:
      objectId - The identifier of the dependent active object
      Returns:
      An ActiveObjectDependency representing 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 dependency
      filterByType - 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

      void setInstance(@Nullable T instance)
      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

      void redirectRequestAndForget(Object objectId, Object message) throws RegistryException
      Redirects a request to another active object and forgets it (does not expect response).
      Parameters:
      objectId - The identifier of the target active object
      message - The message to send
      Throws:
      RegistryException - if an error occurs during redirection
    • redirectRequest

      <R> CompletableFuture<R> redirectRequest(Object objectId, Object message) throws RegistryException
      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 object
      message - The message to send
      Returns:
      A completable future representing the eventual response
      Throws:
      RegistryException - if an error occurs during redirection