Class NarWriter

java.lang.Object
com.nt.udc.nar.NarWriter
All Implemented Interfaces:
CheckpointUserIfc, Callback, StateBufferSaveable, StateFreezable, ActionListener, EventListener

The NarWriter class is responsible for managing a single output NAR cache file.
  • Field Details

    • NARWRITE

      public static final String NARWRITE
  • Constructor Details

    • NarWriter

      public NarWriter(File outputdir, File scratchdir, ConfigIfc config, LoggerIfc logger, String nodeid, String chan, FilenameGenerator filenameGen, DCNode node, int externalId, CheckpointManager checkpointMgr, boolean fileLevelTrans)
      Creates a NarWriter object with the given parameters.
      Parameters:
      outputdir - Node output dir
      scratchdir - Node scratch dir
      config - Node config file
      logger - Node logger
      nodeid - Node's ID
      chan - Channel Value
      filenameGen - Filename generator
      fileLevelTrans - Used to indicate if the node is used in file level transaction
    • NarWriter

      public NarWriter(File outputdir, File scratchdir, ConfigIfc config, LoggerIfc logger, String nodeid, String chan, FilenameGenerator filenameGen, DCNode node, int externalId, CheckpointManager checkpointMgr, boolean isMultiThreaded, int threadCount, int currThread, boolean isOrdered, boolean fileLevelTrans)
      Creates a NarWriter object with the given parameters.
      Parameters:
      outputdir - Node output dir
      scratchdir - Node scratch dir
      config - Node config file
      logger - Node logger
      nodeid - Node's ID
      chan - Channel Value
      filenameGen - Filename generator
      isMultiThreaded - Used to signal multi threaded node.
      threadCount - Total number of threads.
      currThread - Current thread.
      isOrdered - Used to check if ordering is required.
      fileLevelTrans - Used to indicate if the node is used in file level transaction
  • Method Details

    • start

      public void start()
      Starts the NarWriter.
    • shutdown

      public void shutdown()
      Shuts down the NarWriter in a graceful manner.
    • writeNAR

      public boolean writeNAR(NAR osar)
      The writeNAR() method stores an NAR in the current cache file. When the cache file reaches the maximum number of NARs, it is renamed to the node output directory, which makes it available to the LDM and RDM.
      Parameters:
      osar - NAR to write
    • moveToArchive

      public boolean moveToArchive()
      This method renames the currently active NAR cache file to an archive file.
      Returns:
      true, if move succeeded
    • moveCacheToReadyToOut

      public boolean moveCacheToReadyToOut(boolean initNew)
    • actionPerformed

      public void actionPerformed(ActionEvent e)
      This method is called by the NarWriter timer.
      Specified by:
      actionPerformed in interface ActionListener
    • callback

      public void callback()
      This callback is used only when the saveState() call is made by this Object. The StateManager will tell this Object that the state has been saved, and then we can do post-saveState() operations.
      Specified by:
      callback in interface Callback
    • getActiveOutputFile

      public File getActiveOutputFile()
      Returns the current active output cache file.
      Returns:
      current active output file
    • getRecordCount

      public int getRecordCount()
      Returns the number of records written to the current cache file.
      Returns:
      number of records
    • getTotalRecordCount

      public int getTotalRecordCount()
      Returns the total number of records written by this writer.
      Returns:
      number of records
    • saveState

      public void saveState(StateBuffer buffer)
      Saves the state of the NarWriter to the state buffer.
      Specified by:
      saveState in interface StateBufferSaveable
      Parameters:
      buffer - State Buffer object
    • restoreState

      public void restoreState(StateBuffer buffer)
      Restores the state of the NarWriter from the state buffer.
      Specified by:
      restoreState in interface StateBufferSaveable
      Parameters:
      buffer - State Buffer object
    • freezeState

      public void freezeState(Callback freezeCallback)
      Used by another Thread to request the timer to freeze, and halt its processing.
      Specified by:
      freezeState in interface StateFreezable
      Parameters:
      freezeCallback - Notification Object. When the timer has been frozen, use this Object to notify the caller.
    • unfreezeState

      public void unfreezeState()
      Used by another Thread to request the timer to unfreeze, and resume its processing.
      Specified by:
      unfreezeState in interface StateFreezable
    • processStartOfFileData

      public boolean processStartOfFileData(String originalFileName)
    • processEndOfFileData

      public boolean processEndOfFileData()
    • processRejectFile

      public boolean processRejectFile()
    • getIdentifier

      public String getIdentifier()
      Specified by:
      getIdentifier in interface CheckpointUserIfc
    • generateEmptyCheckpointData

      public BaseCheckpointData generateEmptyCheckpointData()
      Specified by:
      generateEmptyCheckpointData in interface CheckpointUserIfc
    • getCheckpointData

      public BaseCheckpointData getCheckpointData()
      Specified by:
      getCheckpointData in interface CheckpointUserIfc
    • clearCheckpointData

      public void clearCheckpointData()
      Specified by:
      clearCheckpointData in interface CheckpointUserIfc
    • flushCheckpoint

      public void flushCheckpoint(BaseCheckpointData cp)
      Specified by:
      flushCheckpoint in interface CheckpointUserIfc
    • restoreCheckpoint

      public void restoreCheckpoint(BaseCheckpointData bcp)
      Specified by:
      restoreCheckpoint in interface CheckpointUserIfc
    • moveToReadyToOut

      public void moveToReadyToOut(boolean initNew)
    • createNewCacheFile

      public void createNewCacheFile()
    • getProcessedFileMap

      public Map getProcessedFileMap()