Package org.apache.cassandra.io.util
Class ChannelProxy
- java.lang.Object
-
- org.apache.cassandra.utils.concurrent.SharedCloseableImpl
-
- org.apache.cassandra.io.util.ChannelProxy
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,SharedCloseable
public final class ChannelProxy extends SharedCloseableImpl
A proxy of a FileChannel that: - implements reference counting - exports only thread safe FileChannel operations - wraps IO exceptions into runtime exceptions Tested by RandomAccessReaderTest.
-
-
Constructor Summary
Constructors Constructor Description ChannelProxy(java.io.File file)
ChannelProxy(java.lang.String path)
ChannelProxy(java.lang.String filePath, java.nio.channels.FileChannel channel)
ChannelProxy(ChannelProxy copy)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
filePath()
int
getFileDescriptor()
java.nio.MappedByteBuffer
map(java.nio.channels.FileChannel.MapMode mode, long position, long size)
ChannelProxy
newChannel()
sharedCopy()
can not be used if thread will be interruped, as the backing channel will be closed.static java.nio.channels.FileChannel
openChannel(java.io.File file)
int
read(java.nio.ByteBuffer buffer, long position)
ChannelProxy
sharedCopy()
long
size()
java.lang.String
toString()
long
transferTo(long position, long count, java.nio.channels.WritableByteChannel target)
-
Methods inherited from class org.apache.cassandra.utils.concurrent.SharedCloseableImpl
addTo, close, close, isCleanedUp
-
-
-
-
Constructor Detail
-
ChannelProxy
public ChannelProxy(java.lang.String path)
-
ChannelProxy
public ChannelProxy(java.io.File file)
-
ChannelProxy
public ChannelProxy(java.lang.String filePath, java.nio.channels.FileChannel channel)
-
ChannelProxy
public ChannelProxy(ChannelProxy copy)
-
-
Method Detail
-
openChannel
public static java.nio.channels.FileChannel openChannel(java.io.File file)
-
newChannel
public final ChannelProxy newChannel()
sharedCopy()
can not be used if thread will be interruped, as the backing channel will be closed.- Returns:
- a new channel instance
-
sharedCopy
public ChannelProxy sharedCopy()
- Returns:
- a new instance of the object representing the same state and backed by the same underlying resources. Coordinates with the original (and other instances) when the underlying resource should be closed. Throws an exception if the shared resource has already been closed.
-
filePath
public java.lang.String filePath()
-
read
public int read(java.nio.ByteBuffer buffer, long position)
-
transferTo
public long transferTo(long position, long count, java.nio.channels.WritableByteChannel target)
-
map
public java.nio.MappedByteBuffer map(java.nio.channels.FileChannel.MapMode mode, long position, long size)
-
size
public long size()
-
getFileDescriptor
public int getFileDescriptor()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-