Class ConcurrentChildScopes

java.lang.Object
io.github.cowwoc.pouch10.core.ConcurrentChildScopes

public final class ConcurrentChildScopes extends Object
Manages child scopes.

This class is thread-safe.

Preconditions that apply to all methods:

  • Parent scope is not closed.
  • Child scope implementations of close() are idempotent.
  • Constructor Details

    • ConcurrentChildScopes

      public ConcurrentChildScopes()
      Creates a new ConcurrentChildScopes.
  • Method Details

    • add

      public void add(Scope child)
      Adds a child scope.
      Parameters:
      child - the child scope
      Throws:
      NullPointerException - if child is null
      IllegalArgumentException - if child was already added to this scope
      IllegalStateException - if shutdown has been requested
    • remove

      public boolean remove(Scope child)
      Removes a child scope.
      Parameters:
      child - the child scope
      Returns:
      true on success; false if the scope was not found
      Throws:
      NullPointerException - if child is null
    • shutdown

      public boolean shutdown(Duration timeout)
      Initiates a graceful shutdown of child scopes.
      Parameters:
      timeout - the amount of time to wait for the children to shut down on their own before invoking close() on them
      Returns:
      true if all the children shut down gracefully, false if a shutdown is already in progress or a timeout occurred
      Throws:
      WrappedCheckedException - if the thread is interrupted or a child scope threw an exception while shutting down