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.CloseableObject 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 FileTimeSourcefileTimeSourceprivate java.lang.RunnableonCloseprivate java.util.concurrent.atomic.AtomicBooleanopenprivate java.util.concurrent.atomic.AtomicIntegerregisteringCount 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 voidcheckOpen()Checks that the file system is open, throwingClosedFileSystemExceptionif it is not.voidclose()Closes the file system, runs theonClosecallback and closes all registered resources.booleanisOpen()Returns whether or not the file system is open.java.nio.file.attribute.FileTimenow()Returns the currentFileTime.<C extends java.io.Closeable>
Cregister(C resource)Registers the given resource to be closed when the file system is closed.voidunregister(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, throwingClosedFileSystemExceptionif 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.IOExceptionCloses the file system, runs theonClosecallback and closes all registered resources.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-