Class FileSystemState

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    final class FileSystemState
    extends java.lang.Object
    implements java.io.Closeable
    Object that manages the open/closed state of a file system, ensuring that all open resources are closed when the file system is closed and that file system methods throw an exception when the file system has been closed.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private FileTimeSource fileTimeSource  
      private java.lang.Runnable onClose  
      private java.util.concurrent.atomic.AtomicBoolean open  
      private java.util.concurrent.atomic.AtomicInteger registering
      Count of resources currently in the process of being registered.
      private java.util.Set<java.io.Closeable> resources  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void checkOpen()
      Checks that the file system is open, throwing ClosedFileSystemException if it is not.
      void close()
      Closes the file system, runs the onClose callback and closes all registered resources.
      boolean isOpen()
      Returns whether or not the file system is open.
      java.nio.file.attribute.FileTime now()
      Returns the current FileTime.
      <C extends java.io.Closeable>
      C
      register​(C resource)
      Registers the given resource to be closed when the file system is closed.
      void unregister​(java.io.Closeable resource)
      Unregisters the given resource.
      • Methods inherited from class java.lang.Object

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

      • resources

        private final java.util.Set<java.io.Closeable> resources
      • onClose

        private final java.lang.Runnable onClose
      • open

        private final java.util.concurrent.atomic.AtomicBoolean open
      • registering

        private final java.util.concurrent.atomic.AtomicInteger registering
        Count of resources currently in the process of being registered.
    • Constructor Detail

      • FileSystemState

        FileSystemState​(FileTimeSource fileTimeSource,
                        java.lang.Runnable onClose)
    • Method Detail

      • isOpen

        public boolean isOpen()
        Returns whether or not the file system is open.
      • checkOpen

        public void checkOpen()
        Checks that the file system is open, throwing ClosedFileSystemException if it is not.
      • register

        @CanIgnoreReturnValue
        public <C extends java.io.Closeable> C register​(C resource)
        Registers the given resource to be closed when the file system is closed. Should be called when the resource is opened.
      • unregister

        public void unregister​(java.io.Closeable resource)
        Unregisters the given resource. Should be called when the resource is closed.
      • now

        public java.nio.file.attribute.FileTime now()
        Returns the current FileTime.
      • close

        public void close()
                   throws java.io.IOException
        Closes the file system, runs the onClose callback and closes all registered resources.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException