Package db.buffers
Class LocalManagedBufferFile
- java.lang.Object
-
- db.buffers.LocalBufferFile
-
- db.buffers.LocalManagedBufferFile
-
- All Implemented Interfaces:
BufferFile,ManagedBufferFile
public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBufferFile
LocalManagedBufferFileimplements a BufferFile as block-oriented random-access file which utilizes aBufferFileManagerto 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).
-
-
Field Summary
-
Fields inherited from class db.buffers.LocalBufferFile
BUFFER_FILE_EXTENSION, PRESAVE_FILE_EXT, PRESAVE_FILE_PREFIX, TEMP_FILE_EXT
-
-
Constructor Summary
Constructors Constructor Description LocalManagedBufferFile(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanSave()Returns true if a save file is provided for creating a new version of this buffer file.voidclose()Close the buffer file.voidcreateNewVersion(ManagedBufferFile destFile, java.lang.String fileComment, TaskMonitor monitor)Create a new buffer file version (used for check-in)booleandelete()Delete this buffer file if writable.DataBufferget(DataBuffer buf, int index)Get the specified buffer.longgetCheckinID()Returns the checkin ID corresponding to this buffer file.byte[]getForwardModMapData(int oldVersion)Returns a bit map corresponding to all buffers modified since oldVersion.InputBlockStreamgetInputBlockStream()Obtain a direct stream to read all blocks of this buffer fileInputBlockStreamgetInputBlockStream(byte[] changeMapData)Obtain a direct stream to read modified blocks of this buffer file based upon the specified changeMapBufferFilegetNextChangeDataFile(boolean getFirst)Get the next change data file which corresponds to this buffer file.OutputBlockStreamgetOutputBlockStream(int blockCount)Obtain a direct stream to write blocks to this buffer fileBufferFilegetSaveChangeDataFile()Returns a temporary change data buffer file which should be used to store a application-level ChangeSet associated with this new buffer file version.ManagedBufferFilegetSaveFile()Returns a Save file if available.LocalManagedBufferFilegetSaveFile(TaskMonitor monitor)Returns a Save file if available.voidput(DataBuffer buf, int index)Store a data buffer at the specified block index.voidsaveCompleted(boolean commit)After getting the save file, this method must be invoked to terminate the save.booleansetReadOnly()If file is open read-write, the modified contents are flushed and the file re-opened as read-only.voidsetVersionComment(java.lang.String comment)Set the comment which will be associated with this buffer file if saved.voidupdateFrom(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, finalize, getBufferFileBlock, getBufferSize, getDataBuffer, getFile, getFreeIndexes, getIndexCount, getParameter, getParameterNames, isReadOnly, peek, poke, setFreeIndexes, setParameter, toString
-
Methods inherited from class java.lang.Object
clone, equals, 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 Detail
-
LocalManagedBufferFile
public LocalManagedBufferFile(int bufferSize, BufferFileManager bfManager, long checkinId) throws java.io.IOExceptionOpen 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:
java.io.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 java.io.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:
java.io.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 java.io.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:
java.io.IOException- if an IO error occurs or a problem with the version reconstruction.
-
-
Method Detail
-
getNextChangeDataFile
public BufferFile getNextChangeDataFile(boolean getFirst) throws java.io.IOException
Description copied from interface:ManagedBufferFileGet 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:
getNextChangeDataFilein interfaceManagedBufferFile- Parameters:
getFirst- causes the iterator to reset and return the first available file.- Throws:
java.io.IOException- if an I/O error occurs
-
getCheckinID
public long getCheckinID()
Description copied from interface:ManagedBufferFileReturns 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:
getCheckinIDin interfaceManagedBufferFile
-
setVersionComment
public void setVersionComment(java.lang.String comment) throws java.io.IOExceptionDescription copied from interface:ManagedBufferFileSet 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:
setVersionCommentin interfaceManagedBufferFile- Parameters:
comment- comment text- Throws:
java.io.IOException- if an I/O error occurs
-
get
public DataBuffer get(DataBuffer buf, int index) throws java.io.IOException
Description copied from interface:BufferFileGet 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:
getin interfaceBufferFile- Overrides:
getin 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:
java.io.EOFException- if the requested buffer index is greater than the number of available buffers of the end-of-file was encountered while reading the buffer.java.io.IOException- if an I/O error occurs
-
put
public void put(DataBuffer buf, int index) throws java.io.IOException
Description copied from interface:BufferFileStore a data buffer at the specified block index.- Specified by:
putin interfaceBufferFile- Overrides:
putin classLocalBufferFile- Parameters:
buf- data bufferindex- block index- Throws:
java.io.IOException- thrown if an IO error occurs
-
setReadOnly
public boolean setReadOnly() throws java.io.IOExceptionDescription copied from interface:BufferFileIf 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:
setReadOnlyin interfaceBufferFile- Overrides:
setReadOnlyin classLocalBufferFile- Returns:
- true if successfully transitioned from read-write to read-only
- Throws:
java.io.IOException- if an I/O error occurs
-
close
public void close() throws java.io.IOExceptionDescription copied from interface:BufferFileClose 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:
closein interfaceBufferFile- Overrides:
closein classLocalBufferFile- Throws:
java.io.IOException- if an I/O error occurs
-
delete
public boolean delete()
Description copied from interface:BufferFileDelete this buffer file if writable. Once deleted, this object is immediately disposed and may no longer be used.- Specified by:
deletein interfaceBufferFile- Overrides:
deletein classLocalBufferFile- Returns:
- true if deleted, false if the file is read-only
-
getForwardModMapData
public byte[] getForwardModMapData(int oldVersion) throws java.io.IOExceptionDescription copied from interface:ManagedBufferFileReturns 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:
getForwardModMapDatain 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:
java.io.IOException- if an I/O error occurs
-
getSaveChangeDataFile
public BufferFile getSaveChangeDataFile() throws java.io.IOException
Description copied from interface:ManagedBufferFileReturns 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:
getSaveChangeDataFilein interfaceManagedBufferFile- Returns:
- change data file or null if one is not available.
- Throws:
java.io.IOException- if an I/O error occurs
-
createNewVersion
public void createNewVersion(ManagedBufferFile destFile, java.lang.String fileComment, TaskMonitor monitor) throws CancelledException, java.io.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.java.io.IOException- if the file is in an unexpected state.
-
getSaveFile
public ManagedBufferFile getSaveFile() throws java.io.IOException
Description copied from interface:ManagedBufferFileReturns 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:
getSaveFilein interfaceManagedBufferFile- Throws:
java.io.IOException- if an I/O error occurs
-
getSaveFile
public LocalManagedBufferFile getSaveFile(TaskMonitor monitor) throws java.io.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:
java.io.IOException- if an I/O error occursCancelledException- if monitor specified and pre-save cancelled
-
saveCompleted
public void saveCompleted(boolean commit) throws java.io.IOExceptionDescription copied from interface:ManagedBufferFileAfter getting the save file, this method must be invoked to terminate the save.- Specified by:
saveCompletedin 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:
java.io.IOException
-
canSave
public boolean canSave()
Description copied from interface:ManagedBufferFileReturns true if a save file is provided for creating a new version of this buffer file.- Specified by:
canSavein interfaceManagedBufferFile- See Also:
ManagedBufferFile.getSaveFile()
-
getOutputBlockStream
public OutputBlockStream getOutputBlockStream(int blockCount) throws java.io.IOException
Obtain a direct stream to write blocks to this buffer file- Overrides:
getOutputBlockStreamin classLocalBufferFile- Parameters:
blockCount- number of blocks to be transferred- Returns:
- output block stream
- Throws:
java.io.IOException
-
getInputBlockStream
public InputBlockStream getInputBlockStream() throws java.io.IOException
Obtain a direct stream to read all blocks of this buffer file- Overrides:
getInputBlockStreamin classLocalBufferFile- Returns:
- input block stream
- Throws:
java.io.IOException
-
getInputBlockStream
public InputBlockStream getInputBlockStream(byte[] changeMapData) throws java.io.IOException
Obtain a direct stream to read modified blocks of this buffer file based upon the specified changeMap- Returns:
- input block stream
- Throws:
java.io.IOException
-
updateFrom
public void updateFrom(ManagedBufferFile versionedBufferFile, int oldVersion, TaskMonitor monitor) throws java.io.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:
java.io.IOException- if an I/O error occursCancelledException- if monitor cancels operation
-
-