Top Description Inners Fields Constructors Methods
org.h2.mvstore.cache

public Class FilePathCache

extends FilePathWrapper
Class Inheritance
Imports
java.io.IOException, java.nio.ByteBuffer, java.nio.channels.FileChannel, .FileLock, org.h2.store.fs.FileBase, .FilePath, .FilePathWrapper

A file with a read cache.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
FilePathCache.FileCache

A file with a read cache.

Field Summary

Modifier and TypeField and Description
public static final FilePathCache
INSTANCE

The instance.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String
getScheme()

Implements abstract org.h2.store.fs.FilePath.getScheme.

Get the scheme (prefix) for this file provider.

public FileChannel
open(String
the access mode. Supported are r, rw, rws, rwd
mode
)

Overrides org.h2.store.fs.FilePathWrapper.open.

Open a random access file object.

public static FileChannel
Inherited from org.h2.store.fs.FilePathWrapper:
canWritecreateDirectorycreateFilecreateTempFiledeleteexistsgetBasegetParentgetPathgetPrefixisAbsoluteisDirectoryisRegularFilelastModifiedmoveTonewDirectoryStreamnewInputStreamnewOutputStreamsetReadOnlysizetoRealPathunwrapunwrapwrap

Field Detail

INSTANCEback to summary
public static final FilePathCache INSTANCE

The instance.

Constructor Detail

FilePathCacheback to summary
public FilePathCache()

Method Detail

getSchemeback to summary
public String getScheme()

Implements abstract org.h2.store.fs.FilePath.getScheme.

Doc from org.h2.store.fs.FilePath.getScheme.

Get the scheme (prefix) for this file provider. This is similar to java.nio.file.spi.FileSystemProvider.getScheme.

Returns:String

the scheme

Annotations
@Override
openback to summary
public FileChannel open(String mode) throws IOException

Overrides org.h2.store.fs.FilePathWrapper.open.

Doc from org.h2.store.fs.FilePath.open.

Open a random access file object.

Parameters
mode:String

the access mode. Supported are r, rw, rws, rwd

Returns:FileChannel

the file object

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
wrapback to summary
public static FileChannel wrap(FileChannel f)
org.h2.mvstore.cache back to summary

public Class FilePathCache.FileCache

extends FileBase
Class Inheritance

A file with a read cache.

Field Summary

Modifier and TypeField and Description
private final FileChannel
private final CacheLongKeyLIRS<ByteBuffer>
private static final int

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
clearCache(ByteBuffer src, long position)

public void
force(boolean
If true then this method is required to force changes to both the file's content and metadata to be written to storage; otherwise, it need only force content changes to be written
metaData
)

Overrides org.h2.store.fs.FileBase.force.

Forces any updates to this channel's file to be written to the storage device that contains it.

private static long
getCachePos(long pos)

protected void
public FileChannel
position(long
The new position, a non-negative integer counting the number of bytes from the beginning of the file
newPosition
)

Implements abstract java.nio.channels.FileChannel.position.

Implements java.nio.channels.SeekableByteChannel.position.

Sets this channel's file position.

public long
position()

Implements abstract java.nio.channels.FileChannel.position.

Implements java.nio.channels.SeekableByteChannel.position.

Returns this channel's file position.

public int
read(ByteBuffer
The buffer into which bytes are to be transferred
dst
)

Implements abstract java.nio.channels.FileChannel.read.

Implements java.nio.channels.SeekableByteChannel.read, java.nio.channels.ReadableByteChannel.read.

Reads a sequence of bytes from this channel into the given buffer.

public synchronized int
read(ByteBuffer
The buffer into which bytes are to be transferred
dst
,
long
The file position at which the transfer is to begin; must be non-negative
position
)

Overrides org.h2.store.fs.FileBase.read.

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

public long
size()

Implements abstract java.nio.channels.FileChannel.size.

Implements java.nio.channels.SeekableByteChannel.size.

Returns the current size of this channel's file.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public synchronized FileChannel
truncate(long
The new size, a non-negative byte count
newSize
)

Implements abstract java.nio.channels.FileChannel.truncate.

Implements java.nio.channels.SeekableByteChannel.truncate.

Truncates this channel's file to the given size.

public FileLock
tryLock(long
The position at which the locked region is to start; must be non-negative
position
,
long
The size of the locked region; must be non-negative, and the sum position + size must be non-negative. A value of zero means to lock all bytes from the specified starting position to the end of the file, regardless of whether the file is subsequently extended or truncated
size
,
boolean
true to request a shared lock, false to request an exclusive lock
shared
)

Overrides org.h2.store.fs.FileBase.tryLock.

Attempts to acquire a lock on the given region of this channel's file.

public synchronized int
write(ByteBuffer
The buffer from which bytes are to be transferred
src
,
long
The file position at which the transfer is to begin; must be non-negative
position
)

Overrides org.h2.store.fs.FileBase.write.

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

public synchronized int
write(ByteBuffer
The buffer from which bytes are to be retrieved
src
)

Implements abstract java.nio.channels.FileChannel.write.

Implements java.nio.channels.SeekableByteChannel.write, java.nio.channels.WritableByteChannel.write.

Writes a sequence of bytes to this channel from the given buffer.

Inherited from org.h2.store.fs.FileBase:
lockmapreadtransferFromtransferTowrite

Field Detail

baseback to summary
private final FileChannel base
cacheback to summary
private final CacheLongKeyLIRS<ByteBuffer> cache
CACHE_BLOCK_SIZEback to summary
private static final int CACHE_BLOCK_SIZE

Constructor Detail

FileCacheback to summary
pack-priv FileCache(FileChannel base)

Method Detail

clearCacheback to summary
private void clearCache(ByteBuffer src, long position)
forceback to summary
public void force(boolean metaData) throws IOException

Overrides org.h2.store.fs.FileBase.force.

Doc from java.nio.channels.FileChannel.force.

Forces any updates to this channel's file to be written to the storage device that contains it.

If this channel's file resides on a local storage device then when this method returns it is guaranteed that all changes made to the file since this channel was created, or since this method was last invoked, will have been written to that device. This is useful for ensuring that critical information is not lost in the event of a system crash.

If the file does not reside on a local device then no such guarantee is made.

The metaData parameter can be used to limit the number of I/O operations that this method is required to perform. Passing false for this parameter indicates that only updates to the file's content need be written to storage; passing true indicates that updates to both the file's content and metadata must be written, which generally requires at least one more I/O operation. Whether this parameter actually has any effect is dependent upon the underlying operating system and is therefore unspecified.

Invoking this method may cause an I/O operation to occur even if the channel was only opened for reading. Some operating systems, for example, maintain a last-access time as part of a file's metadata, and this time is updated whenever the file is read. Whether or not this is actually done is system-dependent and is therefore unspecified.

This method is only guaranteed to force changes that were made to this channel's file via the methods defined in this class, or the methods defined by java.io.FileOutputStream or java.io.RandomAccessFile when the channel was obtained with the getChannel method. It may or may not force changes that were made by modifying the content of a mapped byte buffer obtained by invoking the map method. Invoking the force method of the mapped byte buffer will force changes made to the buffer's content to be written.

Parameters
metaData:boolean

If true then this method is required to force changes to both the file's content and metadata to be written to storage; otherwise, it need only force content changes to be written

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
getCachePosback to summary
private static long getCachePos(long pos)
implCloseChannelback to summary
protected void implCloseChannel() throws IOException

Overrides org.h2.store.fs.FileBase.implCloseChannel.

Doc from java.nio.channels.spi.AbstractInterruptibleChannel.implCloseChannel.

Closes this channel.

This method is invoked by the close method in order to perform the actual work of closing the channel. This method is only invoked if the channel has not yet been closed, and it is never invoked more than once.

An implementation of this method must arrange for any other thread that is blocked in an I/O operation upon this channel to return immediately, either by throwing an exception or by returning normally.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs while closing the channel
positionback to summary
public FileChannel position(long newPosition) throws IOException

Implements abstract java.nio.channels.FileChannel.position.

Implements java.nio.channels.SeekableByteChannel.position.

Doc from java.nio.channels.FileChannel.position.

Sets this channel's file position.

Setting the position to a value that is greater than the file's current size is legal but does not change the size of the file. A later attempt to read bytes at such a position will immediately return an end-of-file indication. A later attempt to write bytes at such a position will cause the file to 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.

Parameters
newPosition:long

The new position, a non-negative integer counting the number of bytes from the beginning of the file

Returns:FileChannel

This file channel

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
positionback to summary
public long position() throws IOException

Implements abstract java.nio.channels.FileChannel.position.

Implements java.nio.channels.SeekableByteChannel.position.

Doc from java.nio.channels.FileChannel.position.

Returns this channel's file position.

Returns:long

This channel's file position, a non-negative integer counting the number of bytes from the beginning of the file to the current position

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
readback to summary
public int read(ByteBuffer dst) throws IOException

Implements abstract java.nio.channels.FileChannel.read.

Implements java.nio.channels.SeekableByteChannel.read, java.nio.channels.ReadableByteChannel.read.

Doc from java.nio.channels.FileChannel.read.

Reads a sequence of bytes from this channel into the given buffer.

Bytes are read starting at this channel's current file position, and then the file position is updated with the number of bytes actually read. Otherwise this method behaves exactly as specified in the ReadableByteChannel interface.

Parameters
dst:ByteBuffer

Doc from java.nio.channels.ReadableByteChannel.read.

The buffer into which bytes are to be transferred

Returns:int

Doc from java.nio.channels.ReadableByteChannel.read.

The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream

Annotations
@Override
Exceptions
IOException:

Doc from java.nio.channels.ReadableByteChannel.read.

If some other I/O error occurs

readback to summary
public synchronized int read(ByteBuffer dst, long position) throws IOException

Overrides org.h2.store.fs.FileBase.read.

Doc from java.nio.channels.FileChannel.read.

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

This method works in the same manner as the read(ByteBuffer) method, except that bytes are read starting at the given file position rather than at the channel's current position. This method does not modify this channel's position. If the given position is greater than or equal to the file's current size then no bytes are read.

Parameters
dst:ByteBuffer

The buffer into which bytes are to be transferred

position:long

The file position at which the transfer is to begin; must be non-negative

Returns:int

The number of bytes read, possibly zero, or -1 if the given position is greater than or equal to the file's current size

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
sizeback to summary
public long size() throws IOException

Implements abstract java.nio.channels.FileChannel.size.

Implements java.nio.channels.SeekableByteChannel.size.

Doc from java.nio.channels.FileChannel.size.

Returns the current size of this channel's file.

Returns:long

The current size of this channel's file, measured in bytes

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
truncateback to summary
public synchronized FileChannel truncate(long newSize) throws IOException

Implements abstract java.nio.channels.FileChannel.truncate.

Implements java.nio.channels.SeekableByteChannel.truncate.

Doc from java.nio.channels.FileChannel.truncate.

Truncates this channel's file to the given size.

If the given size is less than the file's current size then the file is truncated, discarding any bytes beyond the new end of the file. If the given size is greater than or equal to the file's current size then the file is not modified. In either case, if this channel's file position is greater than the given size then it is set to that size.

Parameters
newSize:long

The new size, a non-negative byte count

Returns:FileChannel

This file channel

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
tryLockback to summary
public FileLock tryLock(long position, long size, boolean shared) throws IOException

Overrides org.h2.store.fs.FileBase.tryLock.

Doc from java.nio.channels.FileChannel.tryLock.

Attempts to acquire a lock on the given region of this channel's file.

This method does not block. An invocation always returns immediately, either having acquired a lock on the requested region or having failed to do so. If it fails to acquire a lock because an overlapping lock is held by another program then it returns null. If it fails to acquire a lock for any other reason then an appropriate exception is thrown.

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 zero-argument tryLock() 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.

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.

Parameters
position:long

The position at which the locked region is to start; must be non-negative

size:long

The size of the locked region; must be non-negative, and the sum position + size must be non-negative. A value of zero means to lock all bytes from the specified starting position to the end of the file, regardless of whether the file is subsequently extended or truncated

shared:boolean

true to request a shared lock, false to request an exclusive lock

Returns:FileLock

A lock object representing the newly-acquired lock, or null if the lock could not be acquired because another program holds an overlapping lock

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
writeback to summary
public synchronized int write(ByteBuffer src, long position) throws IOException

Overrides org.h2.store.fs.FileBase.write.

Doc from java.nio.channels.FileChannel.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 write(ByteBuffer) method, except that bytes are written starting at the given file position rather than at the channel's current position. This method does not modify this channel's position. If the given position is greater than or equal to the file's current size 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.

If the file is open in append mode, then the effect of invoking this method is unspecified.

Parameters
src:ByteBuffer

The buffer from which bytes are to be transferred

position:long

The file position at which the transfer is to begin; must be non-negative

Returns:int

The number of bytes written, possibly zero

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
writeback to summary
public synchronized int write(ByteBuffer src) throws IOException

Implements abstract java.nio.channels.FileChannel.write.

Implements java.nio.channels.SeekableByteChannel.write, java.nio.channels.WritableByteChannel.write.

Doc from java.nio.channels.FileChannel.write.

Writes a sequence of bytes to this channel from the given buffer.

Bytes are written starting at this channel's current file position unless the channel is in append mode, in which case the position is first advanced to the end of the file. The file is grown, if necessary, to accommodate the written bytes, and then the file position is updated with the number of bytes actually written. Otherwise this method behaves exactly as specified by the WritableByteChannel interface.

Parameters
src:ByteBuffer

Doc from java.nio.channels.WritableByteChannel.write.

The buffer from which bytes are to be retrieved

Returns:int

Doc from java.nio.channels.WritableByteChannel.write.

The number of bytes written, possibly zero

Annotations
@Override
Exceptions
IOException:

Doc from java.nio.channels.WritableByteChannel.write.

If some other I/O error occurs