Class OIFileWriter

java.lang.Object
com.nt.udc.ndk.util.OIFileWriter
All Implemented Interfaces:
StateBufferSaveable
Direct Known Subclasses:
NARXMLOIFileWriter

public class OIFileWriter extends Object implements StateBufferSaveable
This class is intended to be used as a 'plug-in' module for OI Transports to handle file output and the rotation of those files. The files will be cycled based upon the configured time parameters and/or the maximum records per file parameter of the OI node.
  • Field Details

    • MAXRECSPERFILE

      public static final String MAXRECSPERFILE
      Name (key) for the maximum records per file configuration item.
      See Also:
    • MAXRECSPERFILE_MIN

      public static final int MAXRECSPERFILE_MIN
      Minimum allowable value for the maximum records per file configuration item.
      See Also:
    • MAXRECSPERFILE_MAX

      public static final int MAXRECSPERFILE_MAX
      Maximum allowable value for the maximum records per file configuration item.
      See Also:
    • MAXRECSPERFILE_DEFAULT

      public static final int MAXRECSPERFILE_DEFAULT
      Default value for the maximum records per file configuration item.
      See Also:
    • fileWriter

      protected FileWriter fileWriter
    • m_stateManagementIfc

      protected StateManagementIfc m_stateManagementIfc
  • Constructor Details

    • OIFileWriter

      public OIFileWriter(LoggerIfc lgr, String filedir, String filename, String currext, String doneext, String timeper) throws NodeStartException
      Construct a new 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.
      Parameters:
      lgr - Reference to the log methods of the node
      filedir - Name of the output directory in which to write files
      filename - File name prefix, to be combined with a timestamp to create a unique file name
      currext - File name extension which indicates the active file
      doneext - File name extension which indicates files that have been completed
      timeper - Period of time a file remains active until it is cycled out
      Throws:
      NodeStartException
    • OIFileWriter

      public OIFileWriter(LoggerIfc lgr, String filedir, String filename, String currext, String doneext, String timeper, boolean strData) throws NodeStartException
      Construct a new 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.
      Parameters:
      lgr - Reference to the log methods of the node
      filedir - Name of the output directory in which to write files
      filename - File name prefix, to be combined with a timestamp to create a unique file name
      currext - File name extension which indicates the active file
      doneext - File name extension which indicates files that have been completed
      timeper - Period of time a file remains active until it is cycled out
      strData - 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.
      Throws:
      NodeStartException
    • OIFileWriter

      public OIFileWriter(LoggerIfc lgr, String filedir, String filename, String currext, String doneext, String timeper, boolean strData, StateManagementIfc stateMgr) throws NodeStartException
      Construct a new 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.
      Parameters:
      lgr - Reference to the log methods of the node
      filedir - Name of the output directory in which to write files
      filename - File name prefix, to be combined with a timestamp to create a unique file name
      currext - File name extension which indicates the active file
      doneext - File name extension which indicates files that have been completed
      timeper - Period of time a file remains active until it is cycled out
      strData - 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 recovery
      Throws:
      NodeStartException
    • OIFileWriter

      public OIFileWriter(LoggerIfc lgr, String filedir, String filename, String currext, String doneext, String timeper, boolean strData, StateManagementIfc stateMgr, FileRetentionThread fRThread) throws NodeStartException
      Construct a new 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.
      Parameters:
      lgr - Reference to the log methods of the node
      filedir - Name of the output directory in which to write files
      filename - File name prefix, to be combined with a timestamp to create a unique file name
      currext - File name extension which indicates the active file
      doneext - File name extension which indicates files that have been completed
      timeper - Period of time a file remains active until it is cycled out
      strData - 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 recovery
      fRThread - FileRetentionThread which is used to delete/archive older files after retention period.
      Throws:
      NodeStartException
    • OIFileWriter

      public OIFileWriter(LoggerIfc lgr, String filedir, String filename, String currext, String doneext, String timeper, boolean strData, StateManagementIfc stateMgr, int maxrecs) throws NodeStartException
      Construct a new 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.
      Parameters:
      lgr - Reference to the log methods of the node
      filedir - Name of the output directory in which to write files
      filename - File name prefix, to be combined with a timestamp to create a unique file name
      currext - File name extension which indicates the active file
      doneext - File name extension which indicates files that have been completed
      timeper - Period of time a file remains active until it is cycled out
      strData - 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 recovery
      maxrecs - Maximum number of records per file.
      Throws:
      NodeStartException
    • OIFileWriter

      public OIFileWriter(LoggerIfc lgr, String filedir, String filename, String currext, String doneext, String timeper, boolean strData, StateManagementIfc stateMgr, int maxrecs, String nodeid) throws NodeStartException
      Construct a new 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.
      Parameters:
      lgr - Reference to the log methods of the node
      filedir - Name of the output directory in which to write files
      filename - File name prefix, to be combined with a timestamp to create a unique file name
      currext - File name extension which indicates the active file
      doneext - File name extension which indicates files that have been completed
      timeper - Period of time a file remains active until it is cycled out
      strData - 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 recovery
      maxrecs - Maximum number of records per file.
      nodeId - current node id.
      Throws:
      NodeStartException
    • OIFileWriter

      public OIFileWriter(LoggerIfc lgr, String filedir, String filename, String currext, String doneext, String timeper, boolean strData, StateManagementIfc stateMgr, int maxrecs, boolean isMtCheck, int tId, boolean isOrderingCheck, String nodeid) throws NodeStartException
      Construct a new 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.
      Parameters:
      lgr - Reference to the log methods of the node
      filedir - Name of the output directory in which to write files
      filename - File name prefix, to be combined with a timestamp to create a unique file name
      currext - File name extension which indicates the active file
      doneext - File name extension which indicates files that have been completed
      timeper - Period of time a file remains active until it is cycled out
      strData - 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 recovery
      maxrecs - Maximum number of records per file.
      isMtCheck - Indicates multi threaded OIFileWriter
      tId - Current thread number
      isOrderingCheck - Indicates order required or not
      nodeId - current node id
      Throws:
      NodeStartException
    • OIFileWriter

      public OIFileWriter(LoggerIfc lgr, String filedir, String filename, String currext, String doneext, String timeper, boolean strData, StateManagementIfc stateMgr, int maxrecs, boolean isMtCheck, int tId, boolean isOrderingCheck) throws NodeStartException
      Construct a new 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.
      Parameters:
      lgr - Reference to the log methods of the node
      filedir - Name of the output directory in which to write files
      filename - File name prefix, to be combined with a timestamp to create a unique file name
      currext - File name extension which indicates the active file
      doneext - File name extension which indicates files that have been completed
      timeper - Period of time a file remains active until it is cycled out
      strData - 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 recovery
      maxrecs - Maximum number of records per file.
      isMtCheck - Indicates multi threaded OIFileWriter
      tId - Current thread number
      isOrderingCheck - Indicates order required or not
      Throws:
      NodeStartException
    • OIFileWriter

      public OIFileWriter(LoggerIfc lgr, String filedir, String filename, String currext, String doneext, String timeper, boolean strData, StateManagementIfc stateMgr, int maxrecs, FileRetentionThread fRThread) throws NodeStartException
      Construct a new 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.
      Parameters:
      lgr - Reference to the log methods of the node
      filedir - Name of the output directory in which to write files
      filename - File name prefix, to be combined with a timestamp to create a unique file name
      currext - File name extension which indicates the active file
      doneext - File name extension which indicates files that have been completed
      timeper - Period of time a file remains active until it is cycled out
      strData - 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 recovery
      maxrecs - Maximum number of records per file.
      fRThread - FileRetentionThread which is used to delete/archive older files after retention period.
      Throws:
      NodeStartException
    • OIFileWriter

      public OIFileWriter(LoggerIfc lgr, String filedir, String filename, String currext, String doneext, String timeper, boolean strData, StateManagementIfc stateMgr, int maxrecs, FileRetentionThread fRThread, String nodeid) throws NodeStartException
      Construct a new 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.
      Parameters:
      lgr - Reference to the log methods of the node
      filedir - Name of the output directory in which to write files
      filename - File name prefix, to be combined with a timestamp to create a unique file name
      currext - File name extension which indicates the active file
      doneext - File name extension which indicates files that have been completed
      timeper - Period of time a file remains active until it is cycled out
      strData - 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 recovery
      maxrecs - Maximum number of records per file.
      fRThread - FileRetentionThread which is used to delete/archive older files after retention period.
      nodeId - NodeId from which the function is called.
      Throws:
      NodeStartException
    • OIFileWriter

      public OIFileWriter(LoggerIfc lgr, String filedir, String filename, String currext, String doneext, String timeper, boolean strData, StateManagementIfc stateMgr, int maxrecs, FileRetentionThread fRThread, boolean isMtCheck, int tId, boolean isOrderingCheck, String nodeid) throws NodeStartException
      Construct a new 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.
      Parameters:
      lgr - Reference to the log methods of the node
      filedir - Name of the output directory in which to write files
      filename - File name prefix, to be combined with a timestamp to create a unique file name
      currext - File name extension which indicates the active file
      doneext - File name extension which indicates files that have been completed
      timeper - Period of time a file remains active until it is cycled out
      strData - 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 recovery
      maxrecs - Maximum number of records per file.
      fRThread - FileRetentionThread which is used to delete/archive older
      isMtCheck - Multi thread check varible
      tId - Current thread number files after retention period.
      isOrderingCheck - Indicates order required or not
      nodeid - current nodeid
      Throws:
      NodeStartException
    • OIFileWriter

      public OIFileWriter(LoggerIfc lgr, String filedir, String filename, String currext, String doneext, String timeper, boolean strData, StateManagementIfc stateMgr, int maxrecs, FileRetentionThread fRThread, boolean isMtCheck, int tId, boolean isOrderingCheck) throws NodeStartException
      Construct a new 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.
      Parameters:
      lgr - Reference to the log methods of the node
      filedir - Name of the output directory in which to write files
      filename - File name prefix, to be combined with a timestamp to create a unique file name
      currext - File name extension which indicates the active file
      doneext - File name extension which indicates files that have been completed
      timeper - Period of time a file remains active until it is cycled out
      strData - 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 recovery
      maxrecs - Maximum number of records per file.
      fRThread - FileRetentionThread which is used to delete/archive older
      isMtCheck - Multi thread check varible
      tId - Current thread number files after retention period.
      isOrderingCheck - Indicates order required or not
      Throws:
      NodeStartException
  • Method Details

    • getOutFile

      protected File getOutFile()
    • setOutFile

      protected void setOutFile(File outFile)
    • getOutDir

      protected File getOutDir()
    • getNextCycle

      protected long getNextCycle()
    • setNextCycle

      protected void setNextCycle(long nextCycle)
    • getLogger

      protected LoggerIfc getLogger()
    • getSystemTime

      protected String getSystemTime()
    • renameActiveFile

      protected String renameActiveFile(String actvName)
    • getNewFilename

      protected String getNewFilename()
    • setOriginalFileName

      public void setOriginalFileName(String filename)
    • setNextCycleTime

      protected long setNextCycleTime()
    • getTimeAmt

      protected int getTimeAmt()
    • setBufferSize

      public void setBufferSize(int bufsize)
      Sets the size of the buffer within the OutputStream.
      Parameters:
      bufsize - Size of the OutputStream buffer.
    • getBufferSize

      public int getBufferSize()
      Return the size of the OutputStream's buffer.
      Returns:
      Returns the size of the buffer within the OutputStream.
    • setOutputDirectory

      public void setOutputDirectory(String dir)
      Sets the location of the local output directory.
      Parameters:
      dir - The path to the local output directory.
    • getOutputDirectory

      public String getOutputDirectory()
      Return the location of the local output directory.
      Returns:
      Returns the path to the local output directory.
    • setFilePrefix

      public void setFilePrefix(String prefix)
      Sets the file name prefix.
      Parameters:
      prefix - The string to be prepended to the file name.
    • getFilePrefix

      public String getFilePrefix()
      Return the file name prefix.
      Returns:
      Returns the string which is prepended to the file name.
    • setActiveExtension

      public void setActiveExtension(String ext)
      Sets the active file extension.
      Parameters:
      ext - The string used for the extension of the active file.
    • getActiveExtension

      public String getActiveExtension()
      Return the extension used for the active file.
      Returns:
      Returns the string used as the extension of the active file.
    • setCompletedExtension

      public void setCompletedExtension(String ext)
      Sets the completed file extension.
      Parameters:
      ext - The string used for the extension of completed files.
    • getCompletedExtension

      public String getCompletedExtension()
      Return the extension used for completed files.
      Returns:
      Returns the string used for the extension of completed files.
    • setCycleTime

      public void setCycleTime(String period)
      Sets the cycle time period.
      Parameters:
      period - The period between cycled files.
    • getCycleTime

      public String getCycleTime()
      Return the cycle time period.
      Returns:
      Returns the period between cycled files.
    • setMaxRecsPerFile

      public void setMaxRecsPerFile(int maxRecsPerFile)
      Sets the maximum number of records per file. This value should be in the range from MAXRECSPERFILE_MIN to MAXRECSPERFILE_MAX inclusive.
      Parameters:
      maxRecsPerFile - The maximum number of records per file.
    • getMaxRecsPerFile

      public int getMaxRecsPerFile()
      Returns the maximum number of records per file.
      Returns:
      Returns the maximum number of records per file.
    • incrementRecordCount

      public void incrementRecordCount()
      Increments the record counter. If the maximum number of records per file has been reached, the state is set such that the file will be cycled. The OIFileFormatter initiates the file cycle the next time it checks if this writer is ready to cycle a file.
    • getRecordCount

      public int getRecordCount()
    • resetRecordCount

      public void resetRecordCount()
    • isOpen

      public boolean isOpen()
      Indicates whether a file is opened for output.
      Returns:
      true, if the file is opened for output.
    • setOpened

      protected void setOpened(boolean opened)
    • getFilename

      public String getFilename()
      Returns the name of the currently opened file.
      Returns:
      String Name of the currently opened file. Returns null if no file is opened.
    • open

      public boolean open() throws IOException
      Open the output file, creating it if necessary. The name and location of the file is determined thru configuration parameters at the time of the creation of the OINode.
      Returns:
      true, if it was necessary to create the file.
      Throws:
      IOException
    • write

      public void write(String str) throws IOException
      Write the given string to the active file.
      Throws:
      IOException
    • write

      public void write(NAR nar) throws IOException
      Throws:
      IOException
    • write

      public void write(byte[] bytes) throws IOException
      Write the given bytes to the active file.
      Throws:
      IOException
    • flush

      public void flush() throws IOException
      Flush the contents of the output stream buffer to the file.
      Throws:
      IOException
    • close

      public void close() throws IOException
      Close the output file.
      Throws:
      IOException
    • readyToCycle

      public boolean readyToCycle()
      Determine if we're ready to cycle the files.
      Returns:
      Return true if the files should be cycled.
    • setReadyToCycle

      public void setReadyToCycle()
      Indicate that the files should be cycled. This provides another way to have the files cycled, not solely depending on the timer. Note that this does not cycle the files immediately, but simply changes the state of the writer.
    • cycleOldFiles

      public Vector cycleOldFiles()
    • cycleFile

      public Vector cycleFile() throws IOException
      Cycle the output files, as configured by the node. Locate any files in the output directory which conform to the configured naming scheme for the OINode and tag them as having been processed.

      Returns:
      Returns a vector of string(s) representing the filename(s) that have been renamed. If more than one filename is returned, the previous file push was not successful or did not occur due to an improper shutdown.
      Throws:
      IOException
    • removeOutFile

      public boolean removeOutFile()
    • moveToReadyToCycle

      public void moveToReadyToCycle() throws IOException
      Rename all active file to rCycle files
      Throws:
      IOException
    • setMultiThreadConfiguration

      public void setMultiThreadConfiguration(boolean mtChecked, boolean mtOrderChecked)
      Sets multi threaded values
      Parameters:
      mtChecked - is multiThreading enabled or not
      mtOrderChecked - is ordering enabled or not
    • setFileLevelTransactionConfig

      public void setFileLevelTransactionConfig(boolean fileLevelTransaction)
    • getFileLevelTransactionConfig

      public boolean getFileLevelTransactionConfig()
    • shutdown

      public void shutdown()
      Shutdown the 'cycle check' thread
    • isHealthy

      public boolean isHealthy()
      This function is used to check if the writer is functional
    • saveState

      public void saveState(StateBuffer buffer)
      This function is used to store state (recovery) information into a buffer managed by the caller.

      Context information saved:

      • current output file name
      • current output file length
      • time left in cycle

      Specified by:
      saveState in interface StateBufferSaveable
      Parameters:
      buffer - Buffer used to store recovery information
    • restoreState

      public void restoreState(StateBuffer buffer) throws StateException
      This function is used to restore the writer's state based on information read from a StateBuffer.
      Specified by:
      restoreState in interface StateBufferSaveable
      Parameters:
      buffer - Buffer to read recovery information from
      Throws:
      StateException
    • saveStateNotification

      public void saveStateNotification()
    • getPosition

      public long getPosition()
    • getCurrentFileExpiryTime

      public long getCurrentFileExpiryTime()
    • getFullFilename

      public String getFullFilename()