net.sf.xbus.technical.file
Class FileSender

java.lang.Object
  extended by net.sf.xbus.technical.file.FileBase
      extended by net.sf.xbus.technical.file.FileSender
All Implemented Interfaces:
TAResource, Sender, TextSender
Direct Known Subclasses:
FileByteArrayListSender, FileLineWriterSender, FileStreamSender

public class FileSender
extends FileBase
implements Sender, TAResource, TextSender

FileSender manages writing a text file on a mounted file system.

Configuration:

Chapter Section Key Content
System Interface Filename File path name on the mounted-system
System Interface ConflictResolution Three actions must be possible when a file already exists
append, overwrite or error
System Interface Encoding Specified character encoding of the interface (Optional)


Field Summary
protected  java.lang.String[] mBackupFilename
          Path name for the backup copy Array for broadcasting
protected  FileSenderConfiguration mConfiguration
           
protected  java.lang.String[] mTempFilename
          Path name of the temporary file to be write Array for broadcasting
protected  boolean senderExecuted
          Indicates wether execute has been called, used in commit and rollback
 
Constructor Summary
FileSender(XBUSSystem system)
          Constructs a FileSender object giving all necessary data from the standard configuration, checking file permissions and registering current resource by the TAManager.
 
Method Summary
 void close()
          Is not implemented for file system
 void commit()
          Implemented method commit from TAResource interface.
 java.lang.String execute(java.lang.String function, java.lang.String callData)
          Implemented method execute from TextSender sends the given string callData to the neighbor-system.
 java.lang.String getType()
          A Sender can send data either as a String or as an Object to the neighboring system.
 void open()
          Is not implemented for file system
protected  void prepareWriteFile(java.lang.String fileName, int fileNo)
           
protected  java.io.BufferedWriter prepareWriter(java.lang.String fileName, int fileNo)
           
 void rollback()
          Implemented method rollback from TAResource ignores all changes have made since the beginning of the process (transaction).
 
Methods inherited from class net.sf.xbus.technical.file.FileBase
copyFile, deleteFile, getEncoding, getFileLength, getLastByteOfFile, renameFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mConfiguration

protected FileSenderConfiguration mConfiguration

mTempFilename

protected java.lang.String[] mTempFilename
Path name of the temporary file to be write Array for broadcasting


mBackupFilename

protected java.lang.String[] mBackupFilename
Path name for the backup copy Array for broadcasting


senderExecuted

protected boolean senderExecuted
Indicates wether execute has been called, used in commit and rollback

Constructor Detail

FileSender

public FileSender(XBUSSystem system)
           throws XException
Constructs a FileSender object giving all necessary data from the standard configuration, checking file permissions and registering current resource by the TAManager.

Parameters:
system - destination of the message
Throws:
XException - if an error occurs
Method Detail

execute

public java.lang.String execute(java.lang.String function,
                                java.lang.String callData)
                         throws XException
Implemented method execute from TextSender sends the given string callData to the neighbor-system. Three actions must be taking into account when a file already exists:

Append append new data to the existing file
Overwrite overwrite existing file with the new data
Error throw XException

Specified by:
execute in interface TextSender
Parameters:
function - Name of the interface
callData - String to be written
Returns:
the response of the neighbor system
Throws:
XException - if any error occurs

prepareWriter

protected java.io.BufferedWriter prepareWriter(java.lang.String fileName,
                                               int fileNo)
                                        throws XException
Throws:
XException

prepareWriteFile

protected void prepareWriteFile(java.lang.String fileName,
                                int fileNo)
                         throws XException
Throws:
XException

commit

public void commit()
            throws XException
Implemented method commit from TAResource interface. The purpose of commit actions is to remove any backup information that had been created during process (tansaction).

Undepending on the ConflictResolution, the following acts commit all actions.

  1. remove resorce from the TAManager
  2. rename temporary file to the current file
  3. delete backup copy if exist

Specified by:
commit in interface TAResource
Throws:
XException - if any error occurs
See Also:
TAResource.commit()

rollback

public void rollback()
              throws XException
Implemented method rollback from TAResource ignores all changes have made since the beginning of the process (transaction).

Undepending on the ConflictResolution, the following acts roll back all modifications that have been made in the file system associated with this FileSender:

  1. remove resorce from the TAManager
  2. delete temp file
  3. if backup copy exist, then rename it to the original file

Specified by:
rollback in interface TAResource
Throws:
XException - if any error occurs
See Also:
TAResource.rollback()

open

public void open()
Is not implemented for file system

Specified by:
open in interface TAResource

close

public void close()
Is not implemented for file system

Specified by:
close in interface TAResource

getType

public java.lang.String getType()
Description copied from interface: Sender
A Sender can send data either as a String or as an Object to the neighboring system.
When working with Strings the Sender must fulfill two preconditions: When working with Objects the Sender must also fulfill two preconditions:

Specified by:
getType in interface Sender