Package com.nt.udc.nar
Class NarWriter
java.lang.Object
com.nt.udc.nar.NarWriter
- All Implemented Interfaces:
CheckpointUserIfc
,Callback
,StateBufferSaveable
,StateFreezable
,ActionListener
,EventListener
public class NarWriter
extends Object
implements ActionListener, StateBufferSaveable, StateFreezable, Callback, CheckpointUserIfc
The NarWriter class is responsible for managing a single output NAR cache
file.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionNarWriter
(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.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. -
Method Summary
Modifier and TypeMethodDescriptionvoid
This method is called by the NarWriter timer.void
callback()
This callback is used only when the saveState() call is made by this Object.void
void
void
void
freezeState
(Callback freezeCallback) Used by another Thread to request the timer to freeze, and halt its processing.Returns the current active output cache file.int
Returns the number of records written to the current cache file.int
Returns the total number of records written by this writer.boolean
moveCacheToReadyToOut
(boolean initNew) boolean
This method renames the currently active NAR cache file to an archive file.void
moveToReadyToOut
(boolean initNew) boolean
boolean
boolean
processStartOfFileData
(String originalFileName) void
void
restoreState
(StateBuffer buffer) Restores the state of the NarWriter from the state buffer.void
saveState
(StateBuffer buffer) Saves the state of the NarWriter to the state buffer.void
shutdown()
Shuts down the NarWriter in a graceful manner.void
start()
Starts the NarWriter.void
Used by another Thread to request the timer to unfreeze, and resume its processing.boolean
The writeNAR() method stores an NAR in the current cache file.
-
Field Details
-
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 dirscratchdir
- Node scratch dirconfig
- Node config filelogger
- Node loggernodeid
- Node's IDchan
- Channel ValuefilenameGen
- Filename generatorfileLevelTrans
- 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 dirscratchdir
- Node scratch dirconfig
- Node config filelogger
- Node loggernodeid
- Node's IDchan
- Channel ValuefilenameGen
- Filename generatorisMultiThreaded
- 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
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
This method is called by the NarWriter timer.- Specified by:
actionPerformed
in interfaceActionListener
-
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. -
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
Saves the state of the NarWriter to the state buffer.- Specified by:
saveState
in interfaceStateBufferSaveable
- Parameters:
buffer
- State Buffer object
-
restoreState
Restores the state of the NarWriter from the state buffer.- Specified by:
restoreState
in interfaceStateBufferSaveable
- Parameters:
buffer
- State Buffer object
-
freezeState
Used by another Thread to request the timer to freeze, and halt its processing.- Specified by:
freezeState
in interfaceStateFreezable
- 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 interfaceStateFreezable
-
processStartOfFileData
-
processEndOfFileData
public boolean processEndOfFileData() -
processRejectFile
public boolean processRejectFile() -
getIdentifier
- Specified by:
getIdentifier
in interfaceCheckpointUserIfc
-
generateEmptyCheckpointData
- Specified by:
generateEmptyCheckpointData
in interfaceCheckpointUserIfc
-
getCheckpointData
- Specified by:
getCheckpointData
in interfaceCheckpointUserIfc
-
clearCheckpointData
public void clearCheckpointData()- Specified by:
clearCheckpointData
in interfaceCheckpointUserIfc
-
flushCheckpoint
- Specified by:
flushCheckpoint
in interfaceCheckpointUserIfc
-
restoreCheckpoint
- Specified by:
restoreCheckpoint
in interfaceCheckpointUserIfc
-
moveToReadyToOut
public void moveToReadyToOut(boolean initNew) -
createNewCacheFile
public void createNewCacheFile() -
getProcessedFileMap
-