Class DefaultCloseableService

  • All Implemented Interfaces:
    CloseableService

    class DefaultCloseableService
    extends java.lang.Object
    implements CloseableService
    Default implementation of CloseableService. This implementation stores instances of Closeable in an internal identity hash set and makes sure that the close method is invoked at most once.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Set<java.io.Closeable> closeables  
      private java.util.concurrent.atomic.AtomicBoolean closed  
      private static java.util.logging.Logger LOGGER  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(java.io.Closeable closeable)
      Register a new instance of Closeable that is to be closed when the request goes out of scope.
      void close()
      Invokes Closeable#close() method on all instances of Closeable added by the #add(Closeable) method.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOGGER

        private static final java.util.logging.Logger LOGGER
      • closed

        private final java.util.concurrent.atomic.AtomicBoolean closed
      • closeables

        private final java.util.Set<java.io.Closeable> closeables
    • Constructor Detail

      • DefaultCloseableService

        DefaultCloseableService()
    • Method Detail

      • add

        public boolean add​(java.io.Closeable closeable)
        Description copied from interface: CloseableService
        Register a new instance of Closeable that is to be closed when the request goes out of scope.

        After CloseableService.close() has been called, this method will not accept any new instance registrations and will return false instead.

        Specified by:
        add in interface CloseableService
        Parameters:
        closeable - the instance of Closeable.
        Returns:
        true if the closeable service has not been closed yet and the closeable instance was successfully registered with the service, false otherwise.
      • close

        public void close()
        Description copied from interface: CloseableService
        Invokes Closeable#close() method on all instances of Closeable added by the #add(Closeable) method. Subsequent calls of this method should not do anything.
        Specified by:
        close in interface CloseableService