public class StreamSaver extends Task
Saves Persistit records to a DataOutputStream in the format expected by a
StreamLoader
instance.
Modifier and Type | Field and Description |
---|---|
protected int |
_cycleCount |
protected long |
_dataRecordCount |
protected DataOutputStream |
_dos |
protected String |
_filePath |
protected Exception |
_lastException |
protected Key |
_lastKey |
protected Tree |
_lastTree |
protected Volume |
_lastVolume |
protected long |
_otherRecordCount |
protected int |
_recordCount |
protected boolean |
_stop |
protected TreeSelector |
_treeSelector |
static int |
DEFAULT_BUFFER_SIZE
Size of the buffer for BufferedOutputStreams created by the File
constructors.
|
static int |
DEFAULT_CYCLE_COUNT
Default count of records to written with elided keys.
|
static int |
RECORD_TYPE_COMMENT
Record type marker for COMMENT records
|
static int |
RECORD_TYPE_COMPLETION
Record type marker for COMPLETION records
|
static int |
RECORD_TYPE_COUNT
Record type marker for FILL records
|
static int |
RECORD_TYPE_DATA
Record type marker for DATA records
|
static int |
RECORD_TYPE_END
Record type marker for END records
|
static int |
RECORD_TYPE_EXCEPTION
Record type marker for EXCEPTION records
|
static int |
RECORD_TYPE_FILL
Record type marker for FILL records
|
static int |
RECORD_TYPE_HOSTNAME
Record type marker for HOSTNAME records
|
static int |
RECORD_TYPE_KEY_FILTER
Record type marker for KEY_FILTER records
|
static int |
RECORD_TYPE_START
Record type marker for START records
|
static int |
RECORD_TYPE_TIMESTAMP
Record type marker for TIMESTAMP records
|
static int |
RECORD_TYPE_TREE_ID
Record type marker for TREE_ID records
|
static int |
RECORD_TYPE_USER
Record type marker for USER records
|
static int |
RECORD_TYPE_VOLUME_ID
Record type marker for VOLUME_ID records
|
_culledMessageCount, _description, _expirationTime, _finishTime, _maxMessageLogSize, _messageLog, _messageLogVerbosity, _messageWriter, _owner, _persistit, _startTime, _state, _suspend, _suspendedDuration, _taskId, _thread, DEFAULT_MAX_MESSAGE_LOG_SIZE, LOG_NORMAL, LOG_VERBOSE, STATE_DONE, STATE_ENDED, STATE_EXPIRED, STATE_FAILED, STATE_NAMES, STATE_NOT_STARTED, STATE_RUNNING, STATE_SUSPENDED
Constructor and Description |
---|
StreamSaver(Persistit persistit,
DataOutputStream dos)
Construct a StreamSaver from the provided DataOutputStream.
|
StreamSaver(Persistit persistit,
File file)
Construct a StreamSaver from the provided File using a default buffer
size of 64K bytes.
|
StreamSaver(Persistit persistit,
File file,
int bufferSize)
Construct a StreamSaver from the provided File using a specified buffer
size.
|
StreamSaver(Persistit persistit,
String pathName)
Construct a StreamSaver from the provided path name using a default
buffer size of 64K bytes.
|
StreamSaver(Persistit persistit,
String pathName,
int bufferSize)
Construct a StreamSaver from the provided path name using a specified
buffer size.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this StreamSaver and the underlying DataOutputStream.
|
int |
getCycleCount()
Returns the cycle count, which is the maximum number of records that will
be written with elided keys.
|
String |
getStatus()
Returns a short String message describing the current state of this
Task . |
protected void |
runTask()
Called by a newly created
Thread to perform the task. |
void |
save(Exchange exchange,
KeyFilter filter)
Save all key/value pairs in the
Tree associated with the
supplied Exchange , subject to selection by the supplied
KeyFilter . |
void |
saveAll()
Save all trees in all open volumes.
|
void |
saveTrees(String volumeName,
String[] selectedTreeNames)
Saves one or more trees in a named volume.
|
void |
saveTrees(TreeSelector treeSelector)
Saves one or more trees.
|
void |
saveTrees(Volume volume,
String[] selectedTreeNames)
Saves one or more trees in the specified
Volume . |
void |
setCycleCount(int count)
Sets the cycle count.
|
protected void |
writeComment(String comment)
Writes a COMMENT record containing an arbitrary string
|
protected void |
writeData(Exchange exchange)
Writes the key/value pair represented by the current state of an
Exchange into a DATA record. |
protected void |
writeData(Key key,
Value value)
Writes a key/value pair into a DATA record.
|
protected void |
writeException(Exception exception)
Writes an EXCEPTION record, indicating an Exception that occurred during
the save process.
|
protected void |
writeRecordCount(long dataRecordCount,
long otherRecordCount)
Writes a RECORD_COUNT record.
|
protected void |
writeTimestamp()
Writes a TIMESTAMP record containing the current system time.
|
protected void |
writeTreeInfo(Exchange exchange)
Writes a TREE_ID record for the
Tree currently associated
with the supplied Exchange . |
protected void |
writeTreeInfo(Tree tree)
Writes a TREE_ID record for the supplied
Tree . |
protected void |
writeVolumeInfo(Exchange exchange)
Writes a VOLUME_ID record for the
Volume currently
associated with the supplied Exchange . |
protected void |
writeVolumeInfo(Volume volume)
Writes a VOLUME_ID record for the supplied
Volume . |
appendMessage, cullMessages, endMessage, getMessageLogSize, getMessageLogVerbosity, getMessages, getMessageWriter, getRemainingTime, getStatusDetail, isImmediate, now, parseTreeList, poll, populateTaskStatus, postMessage, resume, run, setMaximumTime, setMessageLogVerbosity, setMessageWriter, setPersistit, setup, start, stop, suspend
public static final int RECORD_TYPE_FILL
public static final int RECORD_TYPE_DATA
public static final int RECORD_TYPE_KEY_FILTER
public static final int RECORD_TYPE_VOLUME_ID
public static final int RECORD_TYPE_TREE_ID
public static final int RECORD_TYPE_HOSTNAME
public static final int RECORD_TYPE_USER
public static final int RECORD_TYPE_COMMENT
public static final int RECORD_TYPE_COUNT
public static final int RECORD_TYPE_START
public static final int RECORD_TYPE_END
public static final int RECORD_TYPE_TIMESTAMP
public static final int RECORD_TYPE_EXCEPTION
public static final int RECORD_TYPE_COMPLETION
public static final int DEFAULT_CYCLE_COUNT
public static final int DEFAULT_BUFFER_SIZE
protected String _filePath
protected DataOutputStream _dos
protected Key _lastKey
protected Volume _lastVolume
protected Tree _lastTree
protected long _dataRecordCount
protected long _otherRecordCount
protected int _cycleCount
protected boolean _stop
protected Exception _lastException
protected int _recordCount
protected TreeSelector _treeSelector
public StreamSaver(Persistit persistit, DataOutputStream dos)
dos
- The DataOutputStreampublic StreamSaver(Persistit persistit, File file) throws FileNotFoundException
file
- The File to which data will be savedFileNotFoundException
public StreamSaver(Persistit persistit, String pathName) throws FileNotFoundException
pathName
- The path name of the file to which data will be savedFileNotFoundException
public StreamSaver(Persistit persistit, File file, int bufferSize) throws FileNotFoundException
file
- The File to which data will be savedbufferSize
- The buffer sizeFileNotFoundException
public StreamSaver(Persistit persistit, String pathName, int bufferSize) throws FileNotFoundException
pathName
- The path name of the file to which data will be savedbufferSize
- The buffer sizeFileNotFoundException
public int getCycleCount()
StreamSaver
writes the next record with a full, unelided key
value. This permits easier visual inspection of the save file.public void setCycleCount(int count)
getCycleCount()
for a description of
this property.count
- The cycle countpublic void close() throws IOException
IOException
protected void writeData(Exchange exchange) throws IOException
Exchange
into a DATA record. If the supplied
Exchange
is based on different volume or tree than the
previously written record, this method also writes VOLUME_ID and/or
TREE_ID records before the DATA record. This allows the
StreamLoader
to apply the data record to the correct volume
and tree.exchange
- The Exchange
IOException
protected void writeData(Key key, Value value) throws IOException
key
- The Key
value
- The Value
IOException
protected void writeRecordCount(long dataRecordCount, long otherRecordCount) throws IOException
IOException
protected void writeVolumeInfo(Exchange exchange) throws IOException
Volume
currently
associated with the supplied Exchange
. The information is
sufficient to recreate a new, empty Volume
having the same
path name, original size and growth parameters as the Volume
being saved.exchange
- The Exchange
IOException
protected void writeTreeInfo(Exchange exchange) throws IOException
Tree
currently associated
with the supplied Exchange
. The information is sufficient to
recreate a new, empty Tree
having the same name as the
Tree
being saved.exchange
- IOException
protected void writeVolumeInfo(Volume volume) throws IOException
Volume
. The saved
information is sufficient to recreate a new, empty Volume
having the same path name, original size and growth parameters as the
Volume
being saved.volume
- The Volume
IOException
protected void writeTreeInfo(Tree tree) throws IOException
Tree
. The saved
information is sufficient to recreate a new, empty Tree
having the same name as the Tree
being saved.tree
- The Tree
IOException
protected void writeTimestamp() throws IOException
IOException
protected void writeComment(String comment) throws IOException
comment
- The comment stringIOException
protected void writeException(Exception exception) throws IOException
exception
- The ExceptionIOException
public void save(Exchange exchange, KeyFilter filter) throws PersistitException, IOException
Tree
associated with the
supplied Exchange
, subject to selection by the supplied
KeyFilter
. If the filter
is null
then save all records.exchange
- The Exchange
filter
- The KeyFilter
PersistitException
IOException
public void saveTrees(String volumeName, String[] selectedTreeNames) throws PersistitException, IOException
volumeName
, which may either be the full path name of an
open volume, or a substring that uniquely matches one open volume.volumeName
- The volume name, or a substring that matches only one volume.selectedTreeNames
- An array names of the trees to be saved.PersistitException
IOException
public void saveTrees(Volume volume, String[] selectedTreeNames) throws PersistitException, IOException
Volume
.volume
- The Volume
selectedTreeNames
- An array names of the trees to be saved.PersistitException
IOException
public void saveTrees(TreeSelector treeSelector) throws PersistitException, IOException
treeSelector
- The TreeSelector
s to select volumes, trees, and
KeyFilters within trees.PersistitException
IOException
public void saveAll() throws PersistitException, IOException
PersistitException
IOException
protected void runTask() throws PersistitException, IOException
Task
Thread
to perform the task.runTask
in class Task
PersistitException
IOException
Copyright © 2025 Open Identity Platform Community. All rights reserved.