Interface Scope

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
AbstractScope

public interface Scope extends AutoCloseable
The lifespan of one or more variables.

Child scopes must call parent.addChild(this) at the end of their constructor and parent.removeChild(this) at the end of their close() method.

Example implementation of the close() method:

 
 public void close()
 {
   if (!closed.compareAndSet(false, true))
     return;
   parent.removeChild(this);
   children.shutdown(CLOSE_TIMEOUT);
 }
 
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addChild(Scope child)
    Adds a child scope.
    void
     
    boolean
    Determines if the scope is closed.
    void
    Removes a child scope.
  • Method Details

    • addChild

      void addChild(Scope child)
      Adds a child scope.
      Parameters:
      child - the child scope
      Throws:
      NullPointerException - if child is null
      IllegalStateException - if the scope is closed
    • removeChild

      void removeChild(Scope child)
      Removes a child scope.
      Parameters:
      child - the child scope
      Throws:
      NullPointerException - if child is null
    • isClosed

      boolean isClosed()
      Determines if the scope is closed.
      Returns:
      true if the scope is closed
    • close

      void close()
      Specified by:
      close in interface AutoCloseable