APIdia Launch Partner
Top Description Fields Constructors Methods
sun.nio.ch

pack-priv abstract Class AsynchronousFileChannelImpl

extends AsynchronousFileChannel
Class Inheritance
Known Direct Subclasses
sun.nio.ch.SimpleAsynchronousFileChannelImpl
Imports
java.nio.ByteBuffer, java.nio.channels.*, java.util.concurrent.ExecutorService, .Future, java.util.concurrent.locks.*, java.io.FileDescriptor, .IOException, jdk.internal.access.JavaNioAccess, .SharedSecrets

Base implementation of AsynchronousFileChannel.

Field Summary

Modifier and TypeField and Description
protected volatile boolean
protected final ReadWriteLock
protected final ExecutorService
protected final FileDescriptor
private volatile FileLockTable
private static final JavaNioAccess
protected final boolean
protected final boolean

Constructor Summary

AccessConstructor and Description
protected
AsynchronousFileChannelImpl(FileDescriptor fdObj, boolean reading, boolean writing, ExecutorService executor)

Method Summary

Modifier and TypeMethod and Description
protected final FileLockImpl
addToFileLockTable(long position, long size, boolean shared)

Adds region to lock table

protected final void
begin()

Marks the beginning of an I/O operation.

protected final void
end()

Marks the end of an I/O operation.

protected final void
end(boolean completed)

Marks end of I/O operation

pack-priv final void
pack-priv final ExecutorService
pack-priv abstract <A> Future<FileLock>
implLock(long position, long size, boolean shared, A attachment, CompletionHandler<FileLock, ? super A> handler)

pack-priv abstract <A> Future<Integer>
implRead(ByteBuffer dst, long position, A attachment, CompletionHandler<Integer, ? super A> handler)

protected abstract void
implRelease(FileLockImpl fli)

Releases the given file lock.

pack-priv abstract <A> Future<Integer>
implWrite(ByteBuffer src, long position, A attachment, CompletionHandler<Integer, ? super A> handler)

pack-priv final void
public final boolean
isOpen()

Implements java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

public final Future<FileLock>
lock(long position, long size, boolean shared)

Implements abstract java.nio.channels.AsynchronousFileChannel.lock.

Acquires a lock on the given region of this channel's file.

public final <A> void
lock(long position, long size, boolean shared, A attachment, CompletionHandler<FileLock, ? super A> handler)

Implements abstract java.nio.channels.AsynchronousFileChannel.lock.

Acquires a lock on the given region of this channel's file.

public final Future<Integer>
read(ByteBuffer dst, long position)

Implements abstract java.nio.channels.AsynchronousFileChannel.read.

Reads a sequence of bytes from this channel into the given buffer, starting at the given file position.

public final <A> void
read(ByteBuffer dst, long position, A attachment, CompletionHandler<Integer, ? super A> handler)

Implements abstract java.nio.channels.AsynchronousFileChannel.read.

Reads a sequence of bytes from this channel into the given buffer, starting at the given file position.

pack-priv final void
release(FileLockImpl fli)

Invoked by FileLockImpl to release the given file lock and remove it from the lock table.

protected final void
public final Future<Integer>
write(ByteBuffer src, long position)

Implements abstract java.nio.channels.AsynchronousFileChannel.write.

Writes a sequence of bytes to this channel from the given buffer, starting at the given file position.

public final <A> void
write(ByteBuffer src, long position, A attachment, CompletionHandler<Integer, ? super A> handler)

Implements abstract java.nio.channels.AsynchronousFileChannel.write.

Writes a sequence of bytes to this channel from the given buffer, starting at the given file position.

Inherited from java.nio.channels.AsynchronousFileChannel:
forcelocklockopenopensizetruncatetryLocktryLock

Field Detail

closedback to summary
protected volatile boolean closed
closeLockback to summary
protected final ReadWriteLock closeLock
executorback to summary
protected final ExecutorService executor
fdObjback to summary
protected final FileDescriptor fdObj
fileLockTableback to summary
private volatile FileLockTable fileLockTable
NIO_ACCESSback to summary
private static final JavaNioAccess NIO_ACCESS
readingback to summary
protected final boolean reading
writingback to summary
protected final boolean writing

Constructor Detail

AsynchronousFileChannelImplback to summary
protected AsynchronousFileChannelImpl(FileDescriptor fdObj, boolean reading, boolean writing, ExecutorService executor)

Method Detail

addToFileLockTableback to summary
protected final FileLockImpl addToFileLockTable(long position, long size, boolean shared)

Adds region to lock table

beginback to summary
protected final void begin() throws IOException

Marks the beginning of an I/O operation.

Exceptions
ClosedChannelException:
If channel is closed
endback to summary
protected final void end()

Marks the end of an I/O operation.

endback to summary
protected final void end(boolean completed) throws IOException

Marks end of I/O operation

ensureFileLockTableInitializedback to summary
pack-priv final void ensureFileLockTableInitialized() throws IOException
executorback to summary
pack-priv final ExecutorService executor()
implLockback to summary
pack-priv abstract <A> Future<FileLock> implLock(long position, long size, boolean shared, A attachment, CompletionHandler<FileLock, ? super A> handler)
implReadback to summary
pack-priv abstract <A> Future<Integer> implRead(ByteBuffer dst, long position, A attachment, CompletionHandler<Integer, ? super A> handler)
implReleaseback to summary
protected abstract void implRelease(FileLockImpl fli) throws IOException

Releases the given file lock.

implWriteback to summary
pack-priv abstract <A> Future<Integer> implWrite(ByteBuffer src, long position, A attachment, CompletionHandler<Integer, ? super A> handler)
invalidateAllLocksback to summary
pack-priv final void invalidateAllLocks() throws IOException
isOpenback to summary
public final boolean isOpen()

Implements java.nio.channels.Channel.isOpen.

Doc from java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

Annotations
@Override
lockback to summary
public final Future<FileLock> lock(long position, long size, boolean shared)

Implements abstract java.nio.channels.AsynchronousFileChannel.lock.

Doc from java.nio.channels.AsynchronousFileChannel.lock.

Acquires a lock on the given region of this channel's file.

This method initiates an operation to acquire a lock on the given region of this channel's file. The method behaves in exactly the same manner as the lock(long, long, boolean, Object, CompletionHandler) method except that instead of specifying a completion handler, this method returns a Future representing the pending result. The Future's get method returns the FileLock on successful completion.

Annotations
@Override
lockback to summary
public final <A> void lock(long position, long size, boolean shared, A attachment, CompletionHandler<FileLock, ? super A> handler)

Implements abstract java.nio.channels.AsynchronousFileChannel.lock.

Doc from java.nio.channels.AsynchronousFileChannel.lock.

Acquires a lock on the given region of this channel's file.

This method initiates an operation to acquire a lock on the given region of this channel's file. The handler parameter is a completion handler that is invoked when the lock is acquired (or the operation fails). The result passed to the completion handler is the resulting FileLock.

The region specified by the position and size parameters need not be contained within, or even overlap, the actual underlying file. Lock regions are fixed in size; if a locked region initially contains the end of the file and the file grows beyond the region then the new portion of the file will not be covered by the lock. If a file is expected to grow in size and a lock on the entire file is required then a region starting at zero, and no smaller than the expected maximum size of the file, should be locked. The two-argument lock(Object, CompletionHandler) method simply locks a region of size Long#MAX_VALUE. If the position is non-negative and the size is zero, then a lock of size Long.MAX_VALUE - position is returned. If a lock that overlaps the requested region is already held by this Java virtual machine, or this method has been invoked to lock an overlapping region and that operation has not completed, then this method throws OverlappingFileLockException.

Some operating systems do not support a mechanism to acquire a file lock in an asynchronous manner. Consequently an implementation may acquire the file lock in a background thread or from a task executed by a thread in the associated thread pool. If there are many lock operations outstanding then it may consume threads in the Java virtual machine for indefinite periods.

Some operating systems do not support shared locks, in which case a request for a shared lock is automatically converted into a request for an exclusive lock. Whether the newly-acquired lock is shared or exclusive may be tested by invoking the resulting lock object's isShared method.

File locks are held on behalf of the entire Java virtual machine. They are not suitable for controlling access to a file by multiple threads within the same virtual machine.

Annotations
@Override
readback to summary
public final Future<Integer> read(ByteBuffer dst, long position)

Implements abstract java.nio.channels.AsynchronousFileChannel.read.

Doc from java.nio.channels.AsynchronousFileChannel.read.

Reads a sequence of bytes from this channel into the given buffer, starting at the given file position.

This method initiates the reading of a sequence of bytes from this channel into the given buffer, starting at the given file position. This method returns a Future representing the pending result of the operation. The Future's get method returns the number of bytes read or -1 if the given position is greater than or equal to the file's size at the time that the read is attempted.

This method works in the same manner as the AsynchronousByteChannel#read(ByteBuffer) method, except that bytes are read starting at the given file position. If the given file position is greater than the file's size at the time that the read is attempted then no bytes are read.

Annotations
@Override
readback to summary
public final <A> void read(ByteBuffer dst, long position, A attachment, CompletionHandler<Integer, ? super A> handler)

Implements abstract java.nio.channels.AsynchronousFileChannel.read.

Doc from java.nio.channels.AsynchronousFileChannel.read.

Reads a sequence of bytes from this channel into the given buffer, starting at the given file position.

This method initiates the reading of a sequence of bytes from this channel into the given buffer, starting at the given file position. The result of the read is the number of bytes read or -1 if the given position is greater than or equal to the file's size at the time that the read is attempted.

This method works in the same manner as the AsynchronousByteChannel#read(ByteBuffer, Object, CompletionHandler) method, except that bytes are read starting at the given file position. If the given file position is greater than the file's size at the time that the read is attempted then no bytes are read.

Annotations
@Override
releaseback to summary
pack-priv final void release(FileLockImpl fli) throws IOException

Invoked by FileLockImpl to release the given file lock and remove it from the lock table.

removeFromFileLockTableback to summary
protected final void removeFromFileLockTable(FileLockImpl fli)
writeback to summary
public final Future<Integer> write(ByteBuffer src, long position)

Implements abstract java.nio.channels.AsynchronousFileChannel.write.

Doc from java.nio.channels.AsynchronousFileChannel.write.

Writes a sequence of bytes to this channel from the given buffer, starting at the given file position.

This method initiates the writing of a sequence of bytes to this channel from the given buffer, starting at the given file position. The method returns a Future representing the pending result of the write operation. The Future's get method returns the number of bytes written.

This method works in the same manner as the AsynchronousByteChannel#write(ByteBuffer) method, except that bytes are written starting at the given file position. If the given position is greater than the file's size, at the time that the write is attempted, then the file will be grown to accommodate the new bytes; the values of any bytes between the previous end-of-file and the newly-written bytes are unspecified.

Annotations
@Override
writeback to summary
public final <A> void write(ByteBuffer src, long position, A attachment, CompletionHandler<Integer, ? super A> handler)

Implements abstract java.nio.channels.AsynchronousFileChannel.write.

Doc from java.nio.channels.AsynchronousFileChannel.write.

Writes a sequence of bytes to this channel from the given buffer, starting at the given file position.

This method works in the same manner as the AsynchronousByteChannel#write(ByteBuffer, Object, CompletionHandler) method, except that bytes are written starting at the given file position. If the given position is greater than the file's size, at the time that the write is attempted, then the file will be grown to accommodate the new bytes; the values of any bytes between the previous end-of-file and the newly-written bytes are unspecified.

Annotations
@Override