public class OIFileWriter extends java.lang.Object implements StateBufferSaveable
Modifier and Type | Field and Description |
---|---|
protected java.io.FileWriter |
fileWriter |
protected StateManagementIfc |
m_stateManagementIfc |
static java.lang.String |
MAXRECSPERFILE
Name (key) for the maximum records per file configuration item.
|
static int |
MAXRECSPERFILE_DEFAULT
Default value for the maximum records per file configuration item.
|
static int |
MAXRECSPERFILE_MAX
Maximum allowable value for the maximum records per file configuration item.
|
static int |
MAXRECSPERFILE_MIN
Minimum allowable value for the maximum records per file configuration item.
|
Constructor and Description |
---|
OIFileWriter(LoggerIfc lgr,
java.lang.String filedir,
java.lang.String filename,
java.lang.String currext,
java.lang.String doneext,
java.lang.String timeper)
Construct a new
OIFileWriter to be used within an
OITransport object. |
OIFileWriter(LoggerIfc lgr,
java.lang.String filedir,
java.lang.String filename,
java.lang.String currext,
java.lang.String doneext,
java.lang.String timeper,
boolean strData)
Construct a new
OIFileWriter to be used within an
OITransport object. |
OIFileWriter(LoggerIfc lgr,
java.lang.String filedir,
java.lang.String filename,
java.lang.String currext,
java.lang.String doneext,
java.lang.String timeper,
boolean strData,
StateManagementIfc stateMgr)
Construct a new
OIFileWriter to be used within an
OITransport object. |
OIFileWriter(LoggerIfc lgr,
java.lang.String filedir,
java.lang.String filename,
java.lang.String currext,
java.lang.String doneext,
java.lang.String timeper,
boolean strData,
StateManagementIfc stateMgr,
FileRetentionThread fRThread)
Construct a new
OIFileWriter to be used within an
OITransport object. |
OIFileWriter(LoggerIfc lgr,
java.lang.String filedir,
java.lang.String filename,
java.lang.String currext,
java.lang.String doneext,
java.lang.String timeper,
boolean strData,
StateManagementIfc stateMgr,
int maxrecs)
Construct a new
OIFileWriter to be used within an
OITransport object. |
OIFileWriter(LoggerIfc lgr,
java.lang.String filedir,
java.lang.String filename,
java.lang.String currext,
java.lang.String doneext,
java.lang.String timeper,
boolean strData,
StateManagementIfc stateMgr,
int maxrecs,
boolean isMtCheck,
int tId,
boolean isOrderingCheck)
Construct a new
OIFileWriter to be used within an
OITransport object. |
OIFileWriter(LoggerIfc lgr,
java.lang.String filedir,
java.lang.String filename,
java.lang.String currext,
java.lang.String doneext,
java.lang.String timeper,
boolean strData,
StateManagementIfc stateMgr,
int maxrecs,
FileRetentionThread fRThread)
Construct a new
OIFileWriter to be used within an
OITransport object. |
OIFileWriter(LoggerIfc lgr,
java.lang.String filedir,
java.lang.String filename,
java.lang.String currext,
java.lang.String doneext,
java.lang.String timeper,
boolean strData,
StateManagementIfc stateMgr,
int maxrecs,
FileRetentionThread fRThread,
boolean isMtCheck,
int tId,
boolean isOrderingCheck)
Construct a new
OIFileWriter to be used within an
OITransport object. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the output file.
|
java.util.Vector |
cycleFile()
Cycle the output files, as configured by the node.
|
void |
flush()
Flush the contents of the output stream buffer to the file.
|
java.lang.String |
getActiveExtension()
Return the extension used for the active file.
|
int |
getBufferSize()
Return the size of the OutputStream's buffer.
|
java.lang.String |
getCompletedExtension()
Return the extension used for completed files.
|
long |
getCurrentFileExpiryTime() |
java.lang.String |
getCycleTime()
Return the cycle time period.
|
boolean |
getFileLevelTransactionConfig() |
java.lang.String |
getFilename()
Returns the name of the currently opened file.
|
java.lang.String |
getFilePrefix()
Return the file name prefix.
|
java.lang.String |
getFullFilename() |
protected LoggerIfc |
getLogger() |
int |
getMaxRecsPerFile()
Returns the maximum number of records per file.
|
protected java.lang.String |
getNewFilename() |
protected long |
getNextCycle() |
protected java.io.File |
getOutDir() |
protected java.io.File |
getOutFile() |
java.lang.String |
getOutputDirectory()
Return the location of the local output directory.
|
long |
getPosition() |
int |
getRecordCount() |
protected java.lang.String |
getSystemTime() |
protected int |
getTimeAmt() |
void |
incrementRecordCount()
Increments the record counter.
|
boolean |
isHealthy()
This function is used to check if the writer is functional
|
boolean |
isOpen()
Indicates whether a file is opened for output.
|
void |
moveToReadyToCycle()
Rename all active file to rCycle files
|
boolean |
open()
Open the output file, creating it if necessary.
|
boolean |
readyToCycle()
Determine if we're ready to cycle the files.
|
boolean |
removeOutFile() |
protected java.lang.String |
renameActiveFile(java.lang.String actvName) |
void |
resetRecordCount() |
void |
restoreState(StateBuffer buffer)
This function is used to restore the writer's state
based on information read from a StateBuffer.
|
void |
saveState(StateBuffer buffer)
This function is used to store state (recovery) information into
a buffer managed by the caller.
|
void |
saveStateNotification() |
void |
setActiveExtension(java.lang.String ext)
Sets the active file extension.
|
void |
setBufferSize(int bufsize)
Sets the size of the buffer within the OutputStream.
|
void |
setCompletedExtension(java.lang.String ext)
Sets the completed file extension.
|
void |
setCycleTime(java.lang.String period)
Sets the cycle time period.
|
void |
setFileLevelTransactionConfig(boolean fileLevelTransaction) |
void |
setFilePrefix(java.lang.String prefix)
Sets the file name prefix.
|
void |
setMaxRecsPerFile(int maxRecsPerFile)
Sets the maximum number of records per file.
|
void |
setMultiThreadConfiguration(boolean mtChecked,
boolean mtOrderChecked)
Sets multi threaded values
|
protected void |
setNextCycle(long nextCycle) |
protected long |
setNextCycleTime() |
protected void |
setOpened(boolean opened) |
void |
setOriginalFileName(java.lang.String filename) |
protected void |
setOutFile(java.io.File outFile) |
void |
setOutputDirectory(java.lang.String dir)
Sets the location of the local output directory.
|
void |
setReadyToCycle()
Indicate that the files should be cycled.
|
void |
shutdown()
Shutdown the 'cycle check' thread
|
void |
write(byte[] bytes)
Write the given bytes to the active file.
|
void |
write(NAR nar) |
void |
write(java.lang.String str)
Write the given string to the active file.
|
public static final java.lang.String MAXRECSPERFILE
public static final int MAXRECSPERFILE_MIN
public static final int MAXRECSPERFILE_MAX
public static final int MAXRECSPERFILE_DEFAULT
protected java.io.FileWriter fileWriter
protected StateManagementIfc m_stateManagementIfc
public OIFileWriter(LoggerIfc lgr, java.lang.String filedir, java.lang.String filename, java.lang.String currext, java.lang.String doneext, java.lang.String timeper) throws NodeStartException
OIFileWriter
to be used within an
OITransport
object. Files will be created based
upon the provided configuration parameters.
Additionally, a simple Thread() is started to periodically check
the time period to determine if the output file is ready to be
cycled. When the OITransport() is being shutdown, the shutdown()
method of this file writer should be called to stop this thread.lgr
- Reference to the log methods of the nodefiledir
- Name of the output directory in which to write filesfilename
- File name prefix, to be combined with a timestamp
to create a unique file namecurrext
- File name extension which indicates the active filedoneext
- File name extension which indicates files that have
been completedtimeper
- Period of time a file remains active until it is
cycled outNodeStartException
public OIFileWriter(LoggerIfc lgr, java.lang.String filedir, java.lang.String filename, java.lang.String currext, java.lang.String doneext, java.lang.String timeper, boolean strData) throws NodeStartException
OIFileWriter
to be used within an
OITransport
object. Files will be created based
upon the provided configuration parameters. The writer can be
configured to write the incoming data as Strings or as an array
of bytes.
Additionally, a simple Thread() is started to periodically check
the time period to determine if the output file is ready to be
cycled. When the OITransport() is being shutdown, the shutdown()
method of this file writer should be called to stop this thread.lgr
- Reference to the log methods of the nodefiledir
- Name of the output directory in which to write filesfilename
- File name prefix, to be combined with a timestamp
to create a unique file namecurrext
- File name extension which indicates the active filedoneext
- File name extension which indicates files that have
been completedtimeper
- Period of time a file remains active until it is
cycled outstrData
- A value of true indicates this file writer will
write the incoming data to the file as Strings.
The default is to write the data as an array of
bytes.NodeStartException
public OIFileWriter(LoggerIfc lgr, java.lang.String filedir, java.lang.String filename, java.lang.String currext, java.lang.String doneext, java.lang.String timeper, boolean strData, StateManagementIfc stateMgr) throws NodeStartException
OIFileWriter
to be used within an
OITransport
object. Files will be created based
upon the provided configuration parameters. The writer can be
configured to write the incoming data as Strings or as an array
of bytes.
Additionally, a simple Thread() is started to periodically check
the time period to determine if the output file is ready to be
cycled. When the OITransport() is being shutdown, the shutdown()
method of this file writer should be called to stop this thread.lgr
- Reference to the log methods of the nodefiledir
- Name of the output directory in which to write filesfilename
- File name prefix, to be combined with a timestamp
to create a unique file namecurrext
- File name extension which indicates the active filedoneext
- File name extension which indicates files that have
been completedtimeper
- Period of time a file remains active until it is
cycled outstrData
- A value of true indicates this file writer will
write the incoming data to the file as Strings.
The default is to write the data as an array of
bytes.stateMgr
- An interface used to manage state recoveryNodeStartException
public OIFileWriter(LoggerIfc lgr, java.lang.String filedir, java.lang.String filename, java.lang.String currext, java.lang.String doneext, java.lang.String timeper, boolean strData, StateManagementIfc stateMgr, FileRetentionThread fRThread) throws NodeStartException
OIFileWriter
to be used within an
OITransport
object. Files will be created based
upon the provided configuration parameters. The writer can be
configured to write the incoming data as Strings or as an array
of bytes.
Additionally, a simple Thread() is started to periodically check
the time period to determine if the output file is ready to be
cycled. When the OITransport() is being shutdown, the shutdown()
method of this file writer should be called to stop this thread.lgr
- Reference to the log methods of the nodefiledir
- Name of the output directory in which to write filesfilename
- File name prefix, to be combined with a timestamp
to create a unique file namecurrext
- File name extension which indicates the active filedoneext
- File name extension which indicates files that have
been completedtimeper
- Period of time a file remains active until it is
cycled outstrData
- A value of true indicates this file writer will
write the incoming data to the file as Strings.
The default is to write the data as an array of
bytes.stateMgr
- An interface used to manage state recoveryfRThread
- FileRetentionThread which is used to delete/archive older
files after retention period.NodeStartException
public OIFileWriter(LoggerIfc lgr, java.lang.String filedir, java.lang.String filename, java.lang.String currext, java.lang.String doneext, java.lang.String timeper, boolean strData, StateManagementIfc stateMgr, int maxrecs) throws NodeStartException
OIFileWriter
to be used within an
OITransport
object. Files will be created based
upon the provided configuration parameters. The writer can be
configured to write the incoming data as Strings or as an array
of bytes.
Additionally, a simple Thread() is started to periodically check
the time period to determine if the output file is ready to be
cycled. When the OITransport() is being shutdown, the shutdown()
method of this file writer should be called to stop this thread.lgr
- Reference to the log methods of the nodefiledir
- Name of the output directory in which to write filesfilename
- File name prefix, to be combined with a timestamp
to create a unique file namecurrext
- File name extension which indicates the active filedoneext
- File name extension which indicates files that have
been completedtimeper
- Period of time a file remains active until it is
cycled outstrData
- A value of true indicates this file writer will
write the incoming data to the file as Strings.
The default is to write the data as an array of
bytes.stateMgr
- An interface used to manage state recoverymaxrecs
- Maximum number of records per file.NodeStartException
public OIFileWriter(LoggerIfc lgr, java.lang.String filedir, java.lang.String filename, java.lang.String currext, java.lang.String doneext, java.lang.String timeper, boolean strData, StateManagementIfc stateMgr, int maxrecs, boolean isMtCheck, int tId, boolean isOrderingCheck) throws NodeStartException
OIFileWriter
to be used within an
OITransport
object. Files will be created based
upon the provided configuration parameters. The writer can be
configured to write the incoming data as Strings or as an array
of bytes.
Additionally, a simple Thread() is started to periodically check
the time period to determine if the output file is ready to be
cycled. When the OITransport() is being shutdown, the shutdown()
method of this file writer should be called to stop this thread.lgr
- Reference to the log methods of the nodefiledir
- Name of the output directory in which to write filesfilename
- File name prefix, to be combined with a timestamp
to create a unique file namecurrext
- File name extension which indicates the active filedoneext
- File name extension which indicates files that have
been completedtimeper
- Period of time a file remains active until it is
cycled outstrData
- A value of true indicates this file writer will
write the incoming data to the file as Strings.
The default is to write the data as an array of
bytes.stateMgr
- An interface used to manage state recoverymaxrecs
- Maximum number of records per file.isMtCheck
- Indicates multi threaded OIFileWritertId
- Current thread numberisOrderingCheck
- Indicates order required or notNodeStartException
public OIFileWriter(LoggerIfc lgr, java.lang.String filedir, java.lang.String filename, java.lang.String currext, java.lang.String doneext, java.lang.String timeper, boolean strData, StateManagementIfc stateMgr, int maxrecs, FileRetentionThread fRThread) throws NodeStartException
OIFileWriter
to be used within an
OITransport
object. Files will be created based
upon the provided configuration parameters. The writer can be
configured to write the incoming data as Strings or as an array
of bytes.
Additionally, a simple Thread() is started to periodically check
the time period to determine if the output file is ready to be
cycled. When the OITransport() is being shutdown, the shutdown()
method of this file writer should be called to stop this thread.lgr
- Reference to the log methods of the nodefiledir
- Name of the output directory in which to write filesfilename
- File name prefix, to be combined with a timestamp
to create a unique file namecurrext
- File name extension which indicates the active filedoneext
- File name extension which indicates files that have
been completedtimeper
- Period of time a file remains active until it is
cycled outstrData
- A value of true indicates this file writer will
write the incoming data to the file as Strings.
The default is to write the data as an array of
bytes.stateMgr
- An interface used to manage state recoverymaxrecs
- Maximum number of records per file.fRThread
- FileRetentionThread which is used to delete/archive older
files after retention period.NodeStartException
public OIFileWriter(LoggerIfc lgr, java.lang.String filedir, java.lang.String filename, java.lang.String currext, java.lang.String doneext, java.lang.String timeper, boolean strData, StateManagementIfc stateMgr, int maxrecs, FileRetentionThread fRThread, boolean isMtCheck, int tId, boolean isOrderingCheck) throws NodeStartException
OIFileWriter
to be used within an
OITransport
object. Files will be created based
upon the provided configuration parameters. The writer can be
configured to write the incoming data as Strings or as an array
of bytes.
Additionally, a simple Thread() is started to periodically check
the time period to determine if the output file is ready to be
cycled. When the OITransport() is being shutdown, the shutdown()
method of this file writer should be called to stop this thread.lgr
- Reference to the log methods of the nodefiledir
- Name of the output directory in which to write filesfilename
- File name prefix, to be combined with a timestamp
to create a unique file namecurrext
- File name extension which indicates the active filedoneext
- File name extension which indicates files that have
been completedtimeper
- Period of time a file remains active until it is
cycled outstrData
- A value of true indicates this file writer will
write the incoming data to the file as Strings.
The default is to write the data as an array of
bytes.stateMgr
- An interface used to manage state recoverymaxrecs
- Maximum number of records per file.fRThread
- FileRetentionThread which is used to delete/archive olderisMtCheck
- Multi thread check varibletId
- Current thread number
files after retention period.isOrderingCheck
- Indicates order required or notNodeStartException
protected java.io.File getOutFile()
protected void setOutFile(java.io.File outFile)
protected java.io.File getOutDir()
protected long getNextCycle()
protected void setNextCycle(long nextCycle)
protected LoggerIfc getLogger()
protected java.lang.String getSystemTime()
protected java.lang.String renameActiveFile(java.lang.String actvName)
protected java.lang.String getNewFilename()
public void setOriginalFileName(java.lang.String filename)
protected long setNextCycleTime()
protected int getTimeAmt()
public void setBufferSize(int bufsize)
bufsize
- Size of the OutputStream buffer.public int getBufferSize()
public void setOutputDirectory(java.lang.String dir)
dir
- The path to the local output directory.public java.lang.String getOutputDirectory()
public void setFilePrefix(java.lang.String prefix)
prefix
- The string to be prepended to the file name.public java.lang.String getFilePrefix()
public void setActiveExtension(java.lang.String ext)
ext
- The string used for the extension of the active file.public java.lang.String getActiveExtension()
public void setCompletedExtension(java.lang.String ext)
ext
- The string used for the extension of completed files.public java.lang.String getCompletedExtension()
public void setCycleTime(java.lang.String period)
period
- The period between cycled files.public java.lang.String getCycleTime()
public void setMaxRecsPerFile(int maxRecsPerFile)
MAXRECSPERFILE_MIN
to MAXRECSPERFILE_MAX
inclusive.maxRecsPerFile
- The maximum number of records per file.public int getMaxRecsPerFile()
public void incrementRecordCount()
OIFileFormatter
initiates the file cycle the next time
it checks if this writer is ready to cycle a file.public int getRecordCount()
public void resetRecordCount()
public boolean isOpen()
true
, if the file is opened for output.protected void setOpened(boolean opened)
public java.lang.String getFilename()
public boolean open() throws java.io.IOException
true
, if it was necessary to create the file.java.io.IOException
public void write(java.lang.String str) throws java.io.IOException
java.io.IOException
public void write(NAR nar) throws java.io.IOException
java.io.IOException
public void write(byte[] bytes) throws java.io.IOException
java.io.IOException
public void flush() throws java.io.IOException
java.io.IOException
public void close() throws java.io.IOException
java.io.IOException
public boolean readyToCycle()
true
if the files should be cycled.public void setReadyToCycle()
public java.util.Vector cycleFile() throws java.io.IOException
OINode
and tag
them as having been processed.java.io.IOException
public boolean removeOutFile()
public void moveToReadyToCycle() throws java.io.IOException
java.io.IOException
public void setMultiThreadConfiguration(boolean mtChecked, boolean mtOrderChecked)
mtChecked
- is multiThreading enabled or notmtOrderChecked
- is ordering enabled or notpublic void setFileLevelTransactionConfig(boolean fileLevelTransaction)
public boolean getFileLevelTransactionConfig()
public void shutdown()
public boolean isHealthy()
public void saveState(StateBuffer buffer)
Context information saved:
saveState
in interface StateBufferSaveable
buffer
- Buffer used to store recovery informationpublic void restoreState(StateBuffer buffer) throws StateException
restoreState
in interface StateBufferSaveable
buffer
- Buffer to read recovery information fromStateException
public void saveStateNotification()
public long getPosition()
public long getCurrentFileExpiryTime()
public java.lang.String getFullFilename()