Package db.buffers
Class LocalManagedBufferFile
java.lang.Object
db.buffers.LocalBufferFile
db.buffers.LocalManagedBufferFile
- All Implemented Interfaces:
BufferFile
,ManagedBufferFile
LocalManagedBufferFile
implements a BufferFile as block-oriented
random-access file which utilizes a BufferFileManager
to
identify and facilitate versioning of buffer files. This type of
buffer file supports both save-as and save operations. The file
format used is identical to a LocalBufferFile, although additional
support is provided for associated files which facilitate versioning
(e.g., ChangeMapFile, VersionFile, and changed data files).-
Nested Class Summary
Nested classes/interfaces inherited from class db.buffers.LocalBufferFile
LocalBufferFile.InputBlockStreamFactory
-
Field Summary
Fields inherited from class db.buffers.LocalBufferFile
BUFFER_FILE_EXTENSION, PRESAVE_FILE_EXT, PRESAVE_FILE_PREFIX, TEMP_FILE_EXT
-
Constructor Summary
ConstructorDescriptionLocalManagedBufferFile
(int bufferSize, BufferFileManager bfManager, long checkinId) Open the initial version of a block file for writing.LocalManagedBufferFile
(BufferFileManager bfManager, boolean versionUpdateEnabled, int minChangeDataVer, long checkinId) Open the current version of an existing block file as read-only.LocalManagedBufferFile
(BufferFileManager bfManager, int version, int minChangeDataVer) Open an older version of an existing buffer file as read-only and NOT UPDATEABLE (bfMgr remains null). -
Method Summary
Modifier and TypeMethodDescriptionboolean
canSave()
Returns true if a save file is provided for creating a new version of this buffer file.void
close()
Close the buffer file.void
createNewVersion
(ManagedBufferFile destFile, String fileComment, TaskMonitor monitor) Create a new buffer file version (used for check-in)boolean
delete()
Delete this buffer file if writable.get
(DataBuffer buf, int index) Get the specified buffer.long
Returns the checkin ID corresponding to this buffer file.byte[]
getForwardModMapData
(int oldVersion) Returns a bit map corresponding to all buffers modified since oldVersion.Obtain a direct stream to read all blocks of this buffer filegetInputBlockStream
(byte[] changeMapData) Obtain a direct stream to read modified blocks of this buffer file based upon the specified changeMapgetNextChangeDataFile
(boolean getFirst) Get the next change data file which corresponds to this buffer file.getOutputBlockStream
(int blockCount) Obtain a direct stream to write blocks to this buffer fileReturns a temporary change data buffer file which should be used to store a application-level ChangeSet associated with this new buffer file version.Returns a Save file if available.getSaveFile
(TaskMonitor monitor) Returns a Save file if available.void
put
(DataBuffer buf, int index) Store a data buffer at the specified block index.void
saveCompleted
(boolean commit) After getting the save file, this method must be invoked to terminate the save.boolean
If file is open read-write, the modified contents are flushed and the file re-opened as read-only.void
setVersionComment
(String comment) Set the comment which will be associated with this buffer file if saved.void
updateFrom
(ManagedBufferFile versionedBufferFile, int oldVersion, TaskMonitor monitor) Create a new version of this file by updating it from a versionedBufferFile.Methods inherited from class db.buffers.LocalBufferFile
cleanupOldPreSaveFiles, clearParameters, clone, copyFile, dispose, getBufferFileBlock, getBufferSize, getDataBuffer, getFile, getFreeIndexes, getIndexCount, getParameter, getParameterNames, isReadOnly, peek, poke, setFreeIndexes, setParameter, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface db.buffers.BufferFile
clearParameters, dispose, getBufferSize, getFreeIndexes, getIndexCount, getParameter, getParameterNames, isReadOnly, setFreeIndexes, setParameter
-
Constructor Details
-
LocalManagedBufferFile
public LocalManagedBufferFile(int bufferSize, BufferFileManager bfManager, long checkinId) throws IOException Open the initial version of a block file for writing.- Parameters:
bufferSize
- user buffer sizebfManager
- buffer file version managercheckinId
- the checkinId for creating a versioned buffer file.- Throws:
IOException
- if an IO error occurs or the incorrect magicNumber was read from the file.
-
LocalManagedBufferFile
public LocalManagedBufferFile(BufferFileManager bfManager, boolean versionUpdateEnabled, int minChangeDataVer, long checkinId) throws IOException Open the current version of an existing block file as read-only.- Parameters:
bfManager
- buffer file version managerversionUpdateEnabled
- if true Save support is enabled (pre-save starts automatically).minChangeDataVer
- indicates the oldest change data buffer file to be included. A -1 indicates only the last change data buffer file is applicable.checkinId
- the checkinId for versioned buffer files which are opened for update.- Throws:
IOException
- if an IO error occurs or the incorrect magicNumber was read from the file.
-
LocalManagedBufferFile
public LocalManagedBufferFile(BufferFileManager bfManager, int version, int minChangeDataVer) throws IOException Open an older version of an existing buffer file as read-only and NOT UPDATEABLE (bfMgr remains null). Version files must exist for all versions starting with the requested version. These version files will be used in conjunction with the current buffer file to emulate an older version buffer file.- Parameters:
bfManager
- buffer file version managerversion
- version of file to be openedminChangeDataVer
- indicates the oldest change data buffer file to be included. A -1 indicates only the last change data buffer file is applicable.- Throws:
IOException
- if an IO error occurs or a problem with the version reconstruction.
-
-
Method Details
-
getNextChangeDataFile
Description copied from interface:ManagedBufferFile
Get the next change data file which corresponds to this buffer file. This method acts like an iterator which each successive invocation returning the next available file. Null is returned when no more files are available. The invoker is responsible for closing each file returned. It is highly recommended that each file be closed prior to requesting the next file.- Specified by:
getNextChangeDataFile
in interfaceManagedBufferFile
- Parameters:
getFirst
- causes the iterator to reset and return the first available file.- Throws:
IOException
- if an I/O error occurs
-
getCheckinID
public long getCheckinID()Description copied from interface:ManagedBufferFile
Returns the checkin ID corresponding to this buffer file. The returned value is only valid if this buffer file has an associated buffer file manager and is either being created (see isReadOnly) or is intended for update (see canSave).- Specified by:
getCheckinID
in interfaceManagedBufferFile
-
setVersionComment
Description copied from interface:ManagedBufferFile
Set the comment which will be associated with this buffer file if saved. The comment must be set prior to invoking close or setReadOnly.- Specified by:
setVersionComment
in interfaceManagedBufferFile
- Parameters:
comment
- comment text- Throws:
IOException
- if an I/O error occurs
-
get
Description copied from interface:BufferFile
Get the specified buffer. DataBuffer data and flags are read from the file at index and stored within the supplied DataBuffer object. If the read buffer is empty, the DataBuffer's data field will remain unchanged (which could be null).- Specified by:
get
in interfaceBufferFile
- Overrides:
get
in classLocalBufferFile
- Parameters:
buf
- a buffer whose data array will be filled-in or replaced.index
- index of buffer to be read. First user buffer is at index 0.- Throws:
IOException
- if an I/O error occurs
-
put
Description copied from interface:BufferFile
Store a data buffer at the specified block index.- Specified by:
put
in interfaceBufferFile
- Overrides:
put
in classLocalBufferFile
- Parameters:
buf
- data bufferindex
- block index- Throws:
IOException
- thrown if an IO error occurs
-
setReadOnly
Description copied from interface:BufferFile
If file is open read-write, the modified contents are flushed and the file re-opened as read-only. This is also used to commit a new version if the file had been modified for update.- Specified by:
setReadOnly
in interfaceBufferFile
- Overrides:
setReadOnly
in classLocalBufferFile
- Returns:
- true if successfully transitioned from read-write to read-only
- Throws:
IOException
- if an I/O error occurs
-
close
Description copied from interface:BufferFile
Close the buffer file. If the file was open for write access, all buffers are flushed and the file header updated. Once closed, this object is immediately disposed and may no longer be used.- Specified by:
close
in interfaceBufferFile
- Overrides:
close
in classLocalBufferFile
- Throws:
IOException
- if an I/O error occurs
-
delete
public boolean delete()Description copied from interface:BufferFile
Delete this buffer file if writable. Once deleted, this object is immediately disposed and may no longer be used.- Specified by:
delete
in interfaceBufferFile
- Overrides:
delete
in classLocalBufferFile
- Returns:
- true if deleted, false if the file is read-only
-
getForwardModMapData
Description copied from interface:ManagedBufferFile
Returns a bit map corresponding to all buffers modified since oldVersion. This identifies all buffers contained within the oldVersion which have been modified during any revision up until this file version. Buffers added since oldVersion are not identified NOTE: The bit mask may identify empty/free buffers within this file version.- Specified by:
getForwardModMapData
in interfaceManagedBufferFile
- Parameters:
oldVersion
- indicates the older version of this file for which a change map will be returned. This method may only be invoked if this file is at version 2 or higher, has an associated BufferFileManager and the oldVersion related files still exist.- Returns:
- ModMap buffer change map data
- Throws:
IOException
- if an I/O error occurs
-
getSaveChangeDataFile
Description copied from interface:ManagedBufferFile
Returns a temporary change data buffer file which should be used to store a application-level ChangeSet associated with this new buffer file version. The getSaveFile method must be successfully invoked prior to invoking this method.- Specified by:
getSaveChangeDataFile
in interfaceManagedBufferFile
- Returns:
- change data file or null if one is not available.
- Throws:
IOException
- if an I/O error occurs
-
createNewVersion
public void createNewVersion(ManagedBufferFile destFile, String fileComment, TaskMonitor monitor) throws CancelledException, IOException Create a new buffer file version (used for check-in)- Parameters:
destFile
- must be an versioned file representing an earlier version of srcFile.fileComment
- a comment for the new version.monitor
- the current monitor.- Throws:
CancelledException
- if the operation is canceled.IOException
- if the file is in an unexpected state.
-
getSaveFile
Description copied from interface:ManagedBufferFile
Returns a Save file if available. Returns null if a save can not be performed. This method may block for an extended period of time if the pre-save process has not already completed. This method does not accept a monitor since a remote TaskMonitor does not yet exist.- Specified by:
getSaveFile
in interfaceManagedBufferFile
- Throws:
IOException
- if an I/O error occurs
-
getSaveFile
public LocalManagedBufferFile getSaveFile(TaskMonitor monitor) throws IOException, CancelledException Returns a Save file if available. Returns null if a save can not be performed. This method may block for an extended period of time if the pre-save process has not already completed. This method does not accept a monitor since a remote TaskMonitor does not yet exist.- Parameters:
monitor
- optional monitor for canceling pre-save (may be null)- Throws:
IOException
- if an I/O error occursCancelledException
- if monitor specified and pre-save cancelled
-
saveCompleted
Description copied from interface:ManagedBufferFile
After getting the save file, this method must be invoked to terminate the save.- Specified by:
saveCompleted
in interfaceManagedBufferFile
- Parameters:
commit
- if true the save file will be reopened as read-only for update. If false, the save file will be deleted and the object will become invalid.- Throws:
IOException
-
canSave
public boolean canSave()Description copied from interface:ManagedBufferFile
Returns true if a save file is provided for creating a new version of this buffer file.- Specified by:
canSave
in interfaceManagedBufferFile
- See Also:
-
getOutputBlockStream
Obtain a direct stream to write blocks to this buffer file- Overrides:
getOutputBlockStream
in classLocalBufferFile
- Parameters:
blockCount
- number of blocks to be transferred- Returns:
- output block stream
- Throws:
IOException
-
getInputBlockStream
Obtain a direct stream to read all blocks of this buffer file- Overrides:
getInputBlockStream
in classLocalBufferFile
- Returns:
- input block stream
- Throws:
IOException
-
getInputBlockStream
Obtain a direct stream to read modified blocks of this buffer file based upon the specified changeMap- Returns:
- input block stream
- Throws:
IOException
-
updateFrom
public void updateFrom(ManagedBufferFile versionedBufferFile, int oldVersion, TaskMonitor monitor) throws IOException, CancelledException Create a new version of this file by updating it from a versionedBufferFile. This file must be open as read-only with versionUpdateEnabled and have been derived from an oldVersion of the versionedBufferFile (i.e., was based on a check-out of oldVersion). The save-file corresponding to this file is updated using those buffers which have been modified or added in the specified versionedBufferFile since olderVersion. When complete, this file should be closed as soon as possible.- Parameters:
versionedBufferFile
- versioned buffer fileoldVersion
- older version of versionedBufferFile from which this buffer file originated.monitor
- progress monitor- Throws:
IOException
- if an I/O error occursCancelledException
- if monitor cancels operation
-