Package com.google.common.jimfs
Class FileSystemState
- java.lang.Object
-
- com.google.common.jimfs.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
-
Constructor Summary
Constructors Constructor Description FileSystemState(FileTimeSource fileTimeSource, java.lang.Runnable onClose)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkOpen()
Checks that the file system is open, throwingClosedFileSystemException
if it is not.void
close()
Closes the file system, runs theonClose
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 currentFileTime
.<C extends java.io.Closeable>
Cregister(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.
-
-
-
Field Detail
-
resources
private final java.util.Set<java.io.Closeable> resources
-
fileTimeSource
private final FileTimeSource fileTimeSource
-
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, throwingClosedFileSystemException
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 currentFileTime
.
-
close
public void close() throws java.io.IOException
Closes the file system, runs theonClose
callback and closes all registered resources.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
-