org.opensubsystems.core.util
Class FileCommitUtils

java.lang.Object
  extended by org.opensubsystems.core.util.FileCommitUtils

public class FileCommitUtils
extends java.lang.Object

Class used for safe file manipulation. It simulates database transaction for file operations such as copy, move, replace or delete. The client should prepare any new or modified file to temporary location. Then the client should call prepareToCommit() method which will prepare the file fot the safe manipulation. After everything is ready, commit() method should be called, otherwise rollback() method should by called.

Version:
$Id: FileCommitUtils.java,v 1.7 2007/01/07 06:14:01 bastafidli Exp $
Author:
Julo Legeny
Code reviewer:
Miro Halas
Code reviewed:
Initial revision

Field Summary
static java.lang.String FILE_PATH_READY_TO_BE_REPLACED
          Constant for ready to replace directory name
static java.lang.String FILE_PATH_READY_TO_COPY
          Constant for ready to copy directory name
static java.lang.String FILE_PATH_READY_TO_DELETE
          Constant for ready to delete directory name
static java.lang.String FILE_PATH_READY_TO_MOVE
          Constant for ready to move directory name
static java.lang.String FILE_PATH_READY_TO_REPLACE
          Constant for ready to replace directory name
static java.lang.String FILECOMMIT_RETRY_COUNT
          Configuration setting for how many times to retry file commit or rollback operations in case of error before the commit or rollback of file manipulation operation is aborted.
static int FILECOMMIT_RETRY_COUNT_DEFAULT
          Default value for configuration setting how many times to retry file commit operations in case or error before we give up.
static int LIST_IDENTIFICATOR_COPY
          Constant for sender list identificator: copy
static int LIST_IDENTIFICATOR_DELETE
          Constant for sender list identificator: replace
static int LIST_IDENTIFICATOR_MOVE
          Constant for sender list identificator: replace
static int LIST_IDENTIFICATOR_REPLACE
          Constant for sender list identificator: replace
static int LIST_IDENTIFICATOR_TO_BE_REPLACED
          Constant for sender list identificator: to be replaced
protected  boolean m_bMovedFilesDeleteForRollback
          Flag signaling if moved files will be deleted from ready_to_move directory during rollback process.
protected  java.lang.Integer m_iReturnCode
          Error returning code
protected  int m_iStatus
          Current status of the utils (prepare commit, commit or rollback).
protected  java.util.List m_lstCopyFromFiles
          List of file names and path names that will be copied FROM (sources)
protected  java.util.List m_lstCopyToFiles
          List of file names and path names that will be copied TO (destinations)
protected  java.util.List m_lstDeleteFiles
          List of file names and path names that will be deleted
protected  java.util.List m_lstMoveFromFiles
          List of file names and path names that will be moved FROM (sources)
protected  java.util.List m_lstMoveToFiles
          List of file names and path names that will be moved TO (destinations)
protected  java.util.List m_lstReadyToBeReplacedFrom
          List of files that are ready to be replaced FROM (sources).
protected  java.util.List m_lstReadyToBeReplacedTo
          List of files that are ready to be replaced TO (destinations).
protected  java.util.List m_lstReadyToCopyFrom
          List of files that are ready to copy FROM (sources).
protected  java.util.List m_lstReadyToCopyTo
          List of files that are ready to copy TO (destinations).
protected  java.util.List m_lstReadyToDeleteFrom
          List of files that are ready to delete FROM (sources).
protected  java.util.List m_lstReadyToDeleteTo
          List of files that are ready to delete TO (destinations).
protected  java.util.List m_lstReadyToMoveFrom
          List of files that are ready to move FROM (sources).
protected  java.util.List m_lstReadyToMoveTo
          List of files that are ready to move TO (destinations).
protected  java.util.List m_lstReadyToReplaceFrom
          List of files that are ready to replace FROM (sources).
protected  java.util.List m_lstReadyToReplaceTo
          List of files that are ready to replace TO (destinations).
protected  java.util.List m_lstReplaceFromFiles
          List of file names and path names that will be replaced FROM (sources)
protected  java.util.List m_lstReplaceToFiles
          List of file names and path names that will be replaced TO (destinations)
protected static int RC_DB_ERR
          Return code for DB exception status
static java.lang.Integer RC_DB_ERR_OBJ
          Object code for for DB exception status
protected static int RC_FILE_ERR
          Return code for file exception status
static java.lang.Integer RC_FILE_ERR_OBJ
          Object code for for file exception status
static int RC_OK
          Return code for successfull status
static java.lang.Integer RC_OK_OBJ
          Object code for for successfull status
protected static int s_iFileCommitRetryCount
          How many times to retry file commit operations in case or error before we give up.
static int SENDER_COMMIT
          Constant for sender identificator: commit
static int SENDER_ROLLBACK
          Constant for sender identificator: rollback
static int SLEEP_TIME
          Constant for sleeping time duration
static int STATUS_COMMIT
          Constant for status: commit
static int STATUS_INITIAL
          Constant for initial status: no action yet
static int STATUS_PREPARE_TO_COMMIT
          Constant for status: prepare to commit
static int STATUS_ROLLBACK
          Constant for status: rollback
 
Constructor Summary
FileCommitUtils()
          Empty constructor
FileCommitUtils(java.lang.Integer iReturnCode, java.util.List lstCopyFromFiles, java.util.List lstCopyToFiles, java.util.List lstMoveFromFiles, java.util.List lstMoveToFiles, java.util.List lstReplaceFromFiles, java.util.List lstReplaceToFiles, java.util.List lstDeleteFiles, boolean bMovedFilesDeleteForRollback)
          Full constructor
 
Method Summary
 void commit()
          Method will commit files.
 int getStatus()
           
 void prepareToCommit()
          Method will prepare files to commit.
 void rollback()
          Method to rollback files.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILECOMMIT_RETRY_COUNT

public static final java.lang.String FILECOMMIT_RETRY_COUNT
Configuration setting for how many times to retry file commit or rollback operations in case of error before the commit or rollback of file manipulation operation is aborted.

See Also:
Constant Field Values

FILECOMMIT_RETRY_COUNT_DEFAULT

public static final int FILECOMMIT_RETRY_COUNT_DEFAULT
Default value for configuration setting how many times to retry file commit operations in case or error before we give up.

See Also:
Constant Field Values

SLEEP_TIME

public static final int SLEEP_TIME
Constant for sleeping time duration

See Also:
Constant Field Values

FILE_PATH_READY_TO_COPY

public static final java.lang.String FILE_PATH_READY_TO_COPY
Constant for ready to copy directory name

See Also:
Constant Field Values

FILE_PATH_READY_TO_MOVE

public static final java.lang.String FILE_PATH_READY_TO_MOVE
Constant for ready to move directory name

See Also:
Constant Field Values

FILE_PATH_READY_TO_REPLACE

public static final java.lang.String FILE_PATH_READY_TO_REPLACE
Constant for ready to replace directory name

See Also:
Constant Field Values

FILE_PATH_READY_TO_BE_REPLACED

public static final java.lang.String FILE_PATH_READY_TO_BE_REPLACED
Constant for ready to replace directory name

See Also:
Constant Field Values

FILE_PATH_READY_TO_DELETE

public static final java.lang.String FILE_PATH_READY_TO_DELETE
Constant for ready to delete directory name

See Also:
Constant Field Values

RC_OK

public static final int RC_OK
Return code for successfull status

See Also:
Constant Field Values

RC_OK_OBJ

public static final java.lang.Integer RC_OK_OBJ
Object code for for successfull status


RC_DB_ERR

protected static final int RC_DB_ERR
Return code for DB exception status

See Also:
Constant Field Values

RC_DB_ERR_OBJ

public static final java.lang.Integer RC_DB_ERR_OBJ
Object code for for DB exception status


RC_FILE_ERR

protected static final int RC_FILE_ERR
Return code for file exception status

See Also:
Constant Field Values

RC_FILE_ERR_OBJ

public static final java.lang.Integer RC_FILE_ERR_OBJ
Object code for for file exception status


STATUS_INITIAL

public static final int STATUS_INITIAL
Constant for initial status: no action yet

See Also:
Constant Field Values

STATUS_PREPARE_TO_COMMIT

public static final int STATUS_PREPARE_TO_COMMIT
Constant for status: prepare to commit

See Also:
Constant Field Values

STATUS_COMMIT

public static final int STATUS_COMMIT
Constant for status: commit

See Also:
Constant Field Values

STATUS_ROLLBACK

public static final int STATUS_ROLLBACK
Constant for status: rollback

See Also:
Constant Field Values

LIST_IDENTIFICATOR_COPY

public static final int LIST_IDENTIFICATOR_COPY
Constant for sender list identificator: copy

See Also:
Constant Field Values

LIST_IDENTIFICATOR_REPLACE

public static final int LIST_IDENTIFICATOR_REPLACE
Constant for sender list identificator: replace

See Also:
Constant Field Values

LIST_IDENTIFICATOR_TO_BE_REPLACED

public static final int LIST_IDENTIFICATOR_TO_BE_REPLACED
Constant for sender list identificator: to be replaced

See Also:
Constant Field Values

LIST_IDENTIFICATOR_MOVE

public static final int LIST_IDENTIFICATOR_MOVE
Constant for sender list identificator: replace

See Also:
Constant Field Values

LIST_IDENTIFICATOR_DELETE

public static final int LIST_IDENTIFICATOR_DELETE
Constant for sender list identificator: replace

See Also:
Constant Field Values

SENDER_COMMIT

public static final int SENDER_COMMIT
Constant for sender identificator: commit

See Also:
Constant Field Values

SENDER_ROLLBACK

public static final int SENDER_ROLLBACK
Constant for sender identificator: rollback

See Also:
Constant Field Values

m_iReturnCode

protected java.lang.Integer m_iReturnCode
Error returning code


m_lstCopyFromFiles

protected java.util.List m_lstCopyFromFiles
List of file names and path names that will be copied FROM (sources)


m_lstCopyToFiles

protected java.util.List m_lstCopyToFiles
List of file names and path names that will be copied TO (destinations)


m_lstMoveFromFiles

protected java.util.List m_lstMoveFromFiles
List of file names and path names that will be moved FROM (sources)


m_lstMoveToFiles

protected java.util.List m_lstMoveToFiles
List of file names and path names that will be moved TO (destinations)


m_lstReplaceFromFiles

protected java.util.List m_lstReplaceFromFiles
List of file names and path names that will be replaced FROM (sources)


m_lstReplaceToFiles

protected java.util.List m_lstReplaceToFiles
List of file names and path names that will be replaced TO (destinations)


m_lstDeleteFiles

protected java.util.List m_lstDeleteFiles
List of file names and path names that will be deleted


m_iStatus

protected int m_iStatus
Current status of the utils (prepare commit, commit or rollback). Status will be used for checking if there will be not called prepare to commit, commit or rollback more than once one after another. Status values: STATUS_PREPARE_TO_COMMIT = 1 STATUS_COMMIT = 2 STATUS_ROLLBACK = 3


m_bMovedFilesDeleteForRollback

protected boolean m_bMovedFilesDeleteForRollback
Flag signaling if moved files will be deleted from ready_to_move directory during rollback process. This flag will be TRUE if there will be moved files from temporary directory to the repository. If error will occured, there is not important move files back from ready_to_move directory to the temporary one.


m_lstReadyToCopyFrom

protected java.util.List m_lstReadyToCopyFrom
List of files that are ready to copy FROM (sources). a.) This list will be used for commit if everything will be ok. Files will be renamed from current 'ready_to_copy' subdirectory into their final destination. b.) This list will be used for rollback if something fails. Files will be deleted from current 'ready_to_copy' subdirectory.


m_lstReadyToCopyTo

protected java.util.List m_lstReadyToCopyTo
List of files that are ready to copy TO (destinations). This list will be used for commit if everything will be ok. Files will be renamed from current 'ready_to_copy' subdirectory into final destination. This list will stored these final destinations.


m_lstReadyToMoveFrom

protected java.util.List m_lstReadyToMoveFrom
List of files that are ready to move FROM (sources). a.) This list will be used for commit if everything will be ok. Files will be moved from current 'ready_to_move' subdirectory into their final destination. b.) This list will be used for rollback if something fails. Files will be moved back from current 'ready_to_move' subdirectory to the original directory where they were stored before.


m_lstReadyToMoveTo

protected java.util.List m_lstReadyToMoveTo
List of files that are ready to move TO (destinations). a.) This list will be used for commit if everything will be ok. Files will be moved from current 'ready_to_move' subdirectory into their final destination. This list will stored these final destinations. b.) This list will be used for rollback if something fails. Files will be moved back from current 'ready_to_move' subdirectory to the original directory where they were stored before. List will stored original destinations.


m_lstReadyToBeReplacedFrom

protected java.util.List m_lstReadyToBeReplacedFrom
List of files that are ready to be replaced FROM (sources). a.) This list will be used for commit if everything will be ok. Files will be deleted from current 'ready_to_be_replaced' subdirectory. b.) This list will be used for rollback if something fails. Files will be renamed back from current 'ready_to_be_replaced' subdirectory to their original directory where they were stored before (their destinations are stored in the list m_lstReadyToBeReplacedTo).


m_lstReadyToBeReplacedTo

protected java.util.List m_lstReadyToBeReplacedTo
List of files that are ready to be replaced TO (destinations). This list will be used for rollback if something fails. Files will be renamed back from current 'ready_to_be_replaced' subdirectory to the original directory stored in this list.


m_lstReadyToReplaceFrom

protected java.util.List m_lstReadyToReplaceFrom
List of files that are ready to replace FROM (sources). a.) This list will be used for commit if everything will be ok. Files will be renamed from current 'ready_to_replace' subdirectory into their final destination. b.) This list will be used for rollback if something fails. Files will be deleted from current 'ready_to_replace' subdirectory.


m_lstReadyToReplaceTo

protected java.util.List m_lstReadyToReplaceTo
List of files that are ready to replace TO (destinations). This list will be used for commit if everything will be ok. Files will be renamed from current 'ready_to_replace' subdirectory into their final destination. This list will stored these final destinations.


m_lstReadyToDeleteFrom

protected java.util.List m_lstReadyToDeleteFrom
List of files that are ready to delete FROM (sources). a.) This list will be used for commit if everything will be ok. Files will be deleted from current 'ready_to_delete' subdirectory. b.) This list will be used for rollback if something fails. Files will be renamed back from current 'ready_to_delete' subdirectory to the original directory where they were stored before.


m_lstReadyToDeleteTo

protected java.util.List m_lstReadyToDeleteTo
List of files that are ready to delete TO (destinations). This list will be used for rollback if something fails. Files will be renamed back from current 'ready_to_delete' subdirectory to the original directory stored in this list.


s_iFileCommitRetryCount

protected static int s_iFileCommitRetryCount
How many times to retry file commit operations in case or error before we give up.

Constructor Detail

FileCommitUtils

public FileCommitUtils()
Empty constructor


FileCommitUtils

public FileCommitUtils(java.lang.Integer iReturnCode,
                       java.util.List lstCopyFromFiles,
                       java.util.List lstCopyToFiles,
                       java.util.List lstMoveFromFiles,
                       java.util.List lstMoveToFiles,
                       java.util.List lstReplaceFromFiles,
                       java.util.List lstReplaceToFiles,
                       java.util.List lstDeleteFiles,
                       boolean bMovedFilesDeleteForRollback)
Full constructor

Parameters:
iReturnCode - - error returning code
lstCopyFromFiles - - list of file and path names that will be copied FROM (sources)
lstCopyToFiles - - list of file and path names that will be copied TO (destination)
lstMoveFromFiles - - list of file and path names that will be moved FROM (sources)
lstMoveToFiles - - list of file and path names that will be moved TO (destination)
lstReplaceFromFiles - - list of file and path names that will be replaced FROM (sources)
lstReplaceToFiles - list of file and path names that will be replaced TO (destinations)
lstDeleteFiles - - list of file and path names that will be deleted
bMovedFilesDeleteForRollback - - flag signaling if moved files will be deleted from ready_to_move directory during rollback process. This flag will be TRUE if there will be moved files from temporary directory to the repository. If error will occured, there is not important move files back from ready_to_move directory to the temporary one.
Method Detail

prepareToCommit

public void prepareToCommit()
                     throws java.io.IOException
Method will prepare files to commit. It will copy, move, replace and delete files that were send form the controller into the ready_to_XXX directory. If something fails during this operation, there will be set up list for restoring changes back.

Throws:
java.io.IOException - - error occured during file moving

commit

public void commit()
            throws OSSException
Method will commit files. It will renameTo files stored in the ready_to_XXX directory into the final destination. If something fails during this operation, it will repeat iRetryCounter times (after a sleep).

Throws:
OSSException - - error occured during files commiting

rollback

public void rollback()
              throws OSSException
Method to rollback files. It will rename back already collocated files. (renameTo) files stored in the ready_to_XXX directory into the final destination. If something fails during this operation, it will be continue and there will be memoried files that failed. RenameTo process for failed files will repeat later (after a sleep).

Throws:
OSSException - - error occured during files commiting

getStatus

public int getStatus()
Returns:
int


Copyright © 2003 - 2006 OpenSubsystems s.r.o.