1 21 22 package org.opensubsystems.core.util; 23 24 import java.io.File ; 25 import java.io.IOException ; 26 import java.util.ArrayList ; 27 import java.util.Collections ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 import java.util.Properties ; 31 import java.util.logging.Level ; 32 import java.util.logging.Logger ; 33 34 import org.opensubsystems.core.error.OSSException; 35 import org.opensubsystems.core.error.OSSInternalErrorException; 36 37 50 public class FileCommitUtils 51 { 52 54 59 public static final String FILECOMMIT_RETRY_COUNT = "oss.filecommit.retrycount"; 60 61 63 67 public static final int FILECOMMIT_RETRY_COUNT_DEFAULT = 3; 68 69 72 public static final int SLEEP_TIME = 3000; 73 74 77 public static final String FILE_PATH_READY_TO_COPY = "ready_to_copy"; 78 79 82 public static final String FILE_PATH_READY_TO_MOVE = "ready_to_move"; 83 84 87 public static final String FILE_PATH_READY_TO_REPLACE = "ready_to_replace"; 88 89 92 public static final String FILE_PATH_READY_TO_BE_REPLACED = "ready_to_be_replaced"; 93 94 97 public static final String FILE_PATH_READY_TO_DELETE = "ready_to_delete"; 98 99 102 public static final int RC_OK = 0; 103 104 107 public static final Integer RC_OK_OBJ = new Integer (RC_OK); 108 109 112 protected static final int RC_DB_ERR = 1; 113 114 117 public static final Integer RC_DB_ERR_OBJ = new Integer (RC_DB_ERR); 118 119 122 protected static final int RC_FILE_ERR = 2; 123 124 127 public static final Integer RC_FILE_ERR_OBJ = new Integer (RC_FILE_ERR); 128 129 132 public static final int STATUS_INITIAL = 0; 133 134 137 public static final int STATUS_PREPARE_TO_COMMIT = 1; 138 139 142 public static final int STATUS_COMMIT = 2; 143 144 147 public static final int STATUS_ROLLBACK = 3; 148 149 152 public static final int LIST_IDENTIFICATOR_COPY = 1; 153 154 157 public static final int LIST_IDENTIFICATOR_REPLACE = 2; 158 159 162 public static final int LIST_IDENTIFICATOR_TO_BE_REPLACED = 3; 163 164 167 public static final int LIST_IDENTIFICATOR_MOVE = 4; 168 169 172 public static final int LIST_IDENTIFICATOR_DELETE = 5; 173 174 177 public static final int SENDER_COMMIT = 1; 178 179 182 public static final int SENDER_ROLLBACK = 2; 183 184 186 189 protected Integer m_iReturnCode; 190 191 194 protected List m_lstCopyFromFiles; 195 196 199 protected List m_lstCopyToFiles; 200 201 204 protected List m_lstMoveFromFiles; 205 206 209 protected List m_lstMoveToFiles; 210 211 214 protected List m_lstReplaceFromFiles; 215 216 219 protected List m_lstReplaceToFiles; 220 221 224 protected List m_lstDeleteFiles; 225 226 236 protected int m_iStatus; 237 238 244 protected boolean m_bMovedFilesDeleteForRollback; 245 246 248 262 protected List m_lstReadyToCopyFrom; 263 264 270 protected List m_lstReadyToCopyTo; 271 272 273 289 protected List m_lstReadyToMoveFrom; 290 291 300 protected List m_lstReadyToMoveTo; 301 302 303 319 protected List m_lstReadyToBeReplacedFrom; 320 321 327 protected List m_lstReadyToBeReplacedTo; 328 329 330 344 protected List m_lstReadyToReplaceFrom; 345 346 352 protected List m_lstReadyToReplaceTo; 353 354 355 370 protected List m_lstReadyToDeleteFrom; 371 372 378 protected List m_lstReadyToDeleteTo; 379 380 382 385 private static Logger s_logger = Log.getInstance(FileCommitUtils.class); 386 387 391 protected static int s_iFileCommitRetryCount; 392 393 395 398 static 399 { 400 Properties prpSettings; 402 403 prpSettings = Config.getInstance().getPropertiesSafely(); 404 s_iFileCommitRetryCount = Config.getIntPropertyInRange( 405 prpSettings, 406 FILECOMMIT_RETRY_COUNT, 407 FILECOMMIT_RETRY_COUNT_DEFAULT, 408 "File commit retry count value", 409 0, Integer.MAX_VALUE); 411 } 412 413 416 public FileCommitUtils() 417 { 418 this(new Integer (STATUS_INITIAL), null, null, null, null, null, null, null, false); 419 } 420 421 439 public FileCommitUtils( 440 Integer iReturnCode, 441 List lstCopyFromFiles, 442 List lstCopyToFiles, 443 List lstMoveFromFiles, 444 List lstMoveToFiles, 445 List lstReplaceFromFiles, 446 List lstReplaceToFiles, 447 List lstDeleteFiles, 448 boolean bMovedFilesDeleteForRollback 449 ) 450 { 451 super(); 452 initGlobalLists(); 453 454 this.m_iReturnCode = iReturnCode; 455 this.m_lstCopyFromFiles = lstCopyFromFiles != null ? lstCopyFromFiles 456 : Collections.EMPTY_LIST; 457 this.m_lstCopyToFiles = lstCopyToFiles != null ? lstCopyToFiles 458 : Collections.EMPTY_LIST; 459 this.m_lstMoveFromFiles = lstMoveFromFiles != null ? lstMoveFromFiles 460 : Collections.EMPTY_LIST; 461 this.m_lstMoveToFiles = lstMoveToFiles != null ? lstMoveToFiles 462 : Collections.EMPTY_LIST; 463 this.m_lstReplaceFromFiles = lstReplaceFromFiles != null ? lstReplaceFromFiles 464 : Collections.EMPTY_LIST; 465 this.m_lstReplaceToFiles = lstReplaceToFiles != null ? lstReplaceToFiles 466 : Collections.EMPTY_LIST; 467 this.m_lstDeleteFiles = lstDeleteFiles != null ? lstDeleteFiles 468 : Collections.EMPTY_LIST; 469 this.m_bMovedFilesDeleteForRollback = bMovedFilesDeleteForRollback; 470 this.m_iStatus = FileCommitUtils.STATUS_INITIAL; 471 } 472 473 475 482 public void prepareToCommit( 483 ) throws IOException 484 { 485 if (this.m_iReturnCode != null) 487 { 488 StringBuffer sbTemp = new StringBuffer (); 489 StringBuffer sbTemp1 = new StringBuffer (); 490 StringBuffer sbTemp2 = new StringBuffer (); 491 492 TwoObjectStruct tosSource = null; 493 TwoObjectStruct tosDestination = null; 494 File fSourceFile = null; 495 File fSourceFileBackUp = null; 496 File fDestinationFile = null; 497 File fFinalDestinationFile = null; 498 File fDestinationFileBackUp = null; 499 File fPathTemp = null; 500 501 List lstReadyToCopyFilesFrom = new ArrayList (this.m_lstCopyToFiles.size()); 504 List lstReadyToCopyFilesTo = new ArrayList (this.m_lstCopyToFiles.size()); 505 List lstReadyToMoveFilesFrom = new ArrayList (this.m_lstMoveToFiles.size()); 506 List lstReadyToMoveFilesTo = new ArrayList (this.m_lstMoveToFiles.size()); 507 List lstReadyToMoveFilesToOriginal = new ArrayList (this.m_lstMoveToFiles.size()); 508 List lstReadyToReplaceFilesFrom = new ArrayList (this.m_lstReplaceToFiles.size()); 509 List lstReadyToReplaceFilesTo = new ArrayList (this.m_lstReplaceToFiles.size()); 510 List lstReadyToBeReplacedFilesFrom = new ArrayList (this.m_lstReplaceToFiles.size()); 511 List lstReadyToBeReplacedFilesTo = new ArrayList (this.m_lstReplaceToFiles.size()); 512 List lstReadyToDeleteFilesFrom = new ArrayList (this.m_lstDeleteFiles.size()); 513 List lstReadyToDeleteFilesTo = new ArrayList (this.m_lstDeleteFiles.size()); 514 515 Iterator itHelp1; 516 Iterator itHelp2; 517 518 assert this.m_iStatus == FileCommitUtils.STATUS_INITIAL 519 : "Cannot prepare file transaction to commit while " + 520 "there is not initial status defined (file " + 521 "transaction has been already started)."; 522 523 if (this.m_iStatus == FileCommitUtils.STATUS_INITIAL) 524 { 525 this.m_iStatus = FileCommitUtils.STATUS_PREPARE_TO_COMMIT; 526 } 527 528 try 529 { 530 if (this.m_iReturnCode == FileCommitUtils.RC_OK_OBJ) 532 { 533 initGlobalLists(); 535 536 itHelp1 = this.m_lstCopyFromFiles.iterator(); 544 itHelp2 = this.m_lstCopyToFiles.iterator(); 545 while (itHelp1.hasNext() && itHelp2.hasNext()) 546 { 547 tosSource = (TwoObjectStruct) itHelp1.next(); 549 tosDestination = (TwoObjectStruct) itHelp2.next(); 550 551 sbTemp.delete(0, sbTemp.length()); 553 if (tosSource.getFirst() != null) 555 { 556 sbTemp.append((String ) tosSource.getFirst()); 557 } 558 sbTemp.append((String ) tosSource.getSecond()); 559 fSourceFile = new File (sbTemp.toString()); 560 561 if (fSourceFile.exists()) 563 { 564 sbTemp.delete(0, sbTemp.length()); 568 sbTemp1.delete(0, sbTemp1.length()); 569 if (tosDestination.getFirst() != null) 571 { 572 sbTemp.append((String ) tosDestination.getFirst()); 573 sbTemp1.append((String ) tosDestination.getFirst()); 574 } 575 sbTemp.append(FILE_PATH_READY_TO_COPY); 576 sbTemp.append(File.separator); 577 578 fPathTemp = new File (sbTemp.toString()); 580 581 try 582 { 583 if (!fPathTemp.exists()) 585 { 586 if (!fPathTemp.mkdirs()) 588 { 589 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 592 593 throw new IOException ("Error occured during creating of '" 595 + FILE_PATH_READY_TO_COPY + "' directory."); 596 } 597 } 598 } 599 catch (Throwable thr) 600 { 601 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 603 604 throw new IOException ("Error occured during creating of '" 606 + FILE_PATH_READY_TO_COPY + "' directory. "); 607 } 608 609 sbTemp.append((String ) tosDestination.getSecond()); 610 fDestinationFile = new File (sbTemp.toString()); 612 613 sbTemp1.append((String ) tosDestination.getSecond()); 614 fFinalDestinationFile = new File (sbTemp1.toString()); 616 617 lstReadyToCopyFilesFrom.add(fDestinationFile); 623 624 lstReadyToCopyFilesTo.add(fFinalDestinationFile); 628 629 632 try 633 { 634 FileUtils.copyFile(fSourceFile, fDestinationFile); 637 638 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 642 this.m_lstReadyToCopyTo = lstReadyToCopyFilesTo; 643 } 644 catch (IOException ioExc) 645 { 646 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 648 649 throw new IOException ("Error occured during copying of the file. "); 650 } 651 catch (OSSException bfExc) 652 { 653 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 655 656 throw new IOException ("Error occured during copying of the file. "); 657 } 658 } 659 else 660 { 661 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 663 664 throw new IOException ("Source file that has to be copied does not exist."); 666 } 667 } 668 669 itHelp1 = this.m_lstMoveFromFiles.iterator(); 677 itHelp2 = this.m_lstMoveToFiles.iterator(); 678 while (itHelp1.hasNext() && itHelp2.hasNext()) 679 { 680 tosSource = (TwoObjectStruct) itHelp1.next(); 682 tosDestination = (TwoObjectStruct) itHelp2.next(); 683 684 sbTemp.delete(0, sbTemp.length()); 686 if (tosSource.getFirst() != null) 688 { 689 sbTemp.append((String ) tosSource.getFirst()); 690 } 691 sbTemp.append((String ) tosSource.getSecond()); 692 fSourceFile = new File (sbTemp.toString()); 693 694 if (fSourceFile.exists()) 696 { 697 sbTemp.delete(0, sbTemp.length()); 701 sbTemp1.delete(0, sbTemp1.length()); 702 if (tosDestination.getFirst() != null) 704 { 705 sbTemp.append((String ) tosDestination.getFirst()); 706 sbTemp1.append((String ) tosDestination.getFirst()); 707 } 708 sbTemp.append(FILE_PATH_READY_TO_MOVE); 709 sbTemp.append(File.separator); 710 711 fPathTemp = new File (sbTemp.toString()); 713 714 try 715 { 716 if (!fPathTemp.exists()) 718 { 719 if (!fPathTemp.mkdirs()) 721 { 722 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 724 725 this.m_lstReadyToMoveFrom = lstReadyToMoveFilesFrom; 728 729 throw new IOException ("Error occured during creating of '" 731 + FILE_PATH_READY_TO_MOVE + "' directory."); 732 } 733 } 734 } 735 catch (Throwable thr) 736 { 737 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 739 740 this.m_lstReadyToMoveFrom = lstReadyToMoveFilesFrom; 742 743 throw new IOException ("Error occured during creating of '" 745 + FILE_PATH_READY_TO_MOVE + "' directory. "); 746 } 747 748 sbTemp.append((String ) tosDestination.getSecond()); 749 fDestinationFile = new File (sbTemp.toString()); 751 752 sbTemp1.append((String ) tosDestination.getSecond()); 753 fFinalDestinationFile = new File (sbTemp1.toString()); 755 756 if (fFinalDestinationFile.exists()) 758 { 759 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 761 762 this.m_lstReadyToMoveFrom = lstReadyToMoveFilesFrom; 764 this.m_lstReadyToMoveTo = lstReadyToMoveFilesToOriginal; 765 766 throw new IOException ("File that has to be moved already exist in the " 768 + "destination directory."); 769 } 770 771 lstReadyToMoveFilesFrom.add(fDestinationFile); 777 778 lstReadyToMoveFilesTo.add(fFinalDestinationFile); 783 784 lstReadyToMoveFilesToOriginal.add(fSourceFile); 789 790 793 try 794 { 795 FileUtils.moveFile(fSourceFile, fDestinationFile); 797 798 this.m_lstReadyToMoveFrom = lstReadyToMoveFilesFrom; 802 this.m_lstReadyToMoveTo = lstReadyToMoveFilesTo; 803 } 804 catch (IOException ioExc) 805 { 806 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 808 809 this.m_lstReadyToMoveFrom = lstReadyToMoveFilesFrom; 811 this.m_lstReadyToMoveTo = lstReadyToMoveFilesToOriginal; 812 813 throw new IOException ("Error occured during moving of the file. "); 814 } 815 catch (OSSException bfExc) 816 { 817 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 819 820 this.m_lstReadyToMoveFrom = lstReadyToMoveFilesFrom; 822 this.m_lstReadyToMoveTo = lstReadyToMoveFilesToOriginal; 823 824 throw new IOException ("Error occured during moving of the file. "); 825 } 826 } 827 else 828 { 829 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 831 832 this.m_lstReadyToMoveFrom = lstReadyToMoveFilesFrom; 834 this.m_lstReadyToMoveTo = lstReadyToMoveFilesToOriginal; 835 836 throw new IOException ("Source file that has to be moved does not exist."); 838 } 839 } 840 841 itHelp1 = this.m_lstReplaceFromFiles.iterator(); 849 itHelp2 = this.m_lstReplaceToFiles.iterator(); 850 while (itHelp1.hasNext() && itHelp2.hasNext()) 851 { 852 tosSource = (TwoObjectStruct) itHelp1.next(); 854 tosDestination = (TwoObjectStruct) itHelp2.next(); 855 856 sbTemp.delete(0, sbTemp.length()); 858 if (tosSource.getFirst() != null) 860 { 861 sbTemp.append((String ) tosSource.getFirst()); 862 } 863 sbTemp.append((String ) tosSource.getSecond()); 864 fSourceFile = new File (sbTemp.toString()); 865 866 sbTemp.delete(0, sbTemp.length()); 868 if (tosDestination.getFirst() != null) 870 { 871 sbTemp.append((String ) tosDestination.getFirst()); 872 } 873 sbTemp.append((String ) tosDestination.getSecond()); 874 fSourceFileBackUp = new File (sbTemp.toString()); 875 876 if (fSourceFile.exists() && fSourceFileBackUp.exists()) 878 { 879 885 sbTemp.delete(0, sbTemp.length()); 886 sbTemp1.delete(0, sbTemp1.length()); 887 sbTemp2.delete(0, sbTemp2.length()); 888 if (tosDestination.getFirst() != null) 890 { 891 sbTemp.append((String ) tosDestination.getFirst()); 892 sbTemp1.append((String ) tosDestination.getFirst()); 893 sbTemp2.append((String ) tosDestination.getFirst()); 894 } 895 sbTemp.append(FILE_PATH_READY_TO_REPLACE); 896 sbTemp.append(File.separator); 897 sbTemp1.append(FILE_PATH_READY_TO_BE_REPLACED); 898 sbTemp1.append(File.separator); 899 900 fPathTemp = new File (sbTemp.toString()); 902 903 try 904 { 905 if (!fPathTemp.exists()) 907 { 908 if (!fPathTemp.mkdirs()) 910 { 911 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 913 914 this.m_lstReadyToMoveFrom = lstReadyToMoveFilesFrom; 916 this.m_lstReadyToMoveTo = lstReadyToMoveFilesToOriginal; 917 918 this.m_lstReadyToReplaceFrom = lstReadyToReplaceFilesFrom; 921 this.m_lstReadyToReplaceTo = lstReadyToReplaceFilesTo; 922 this.m_lstReadyToBeReplacedFrom = lstReadyToBeReplacedFilesFrom; 923 this.m_lstReadyToBeReplacedTo = lstReadyToBeReplacedFilesTo; 924 925 throw new IOException ( 927 "Error occured during creating of '" 928 + FILE_PATH_READY_TO_REPLACE + "' directory."); 929 } 930 } 931 } 932 catch (Throwable thr) 933 { 934 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 936 937 this.m_lstReadyToMoveFrom = lstReadyToMoveFilesFrom; 939 this.m_lstReadyToMoveTo = lstReadyToMoveFilesToOriginal; 940 941 this.m_lstReadyToReplaceFrom = lstReadyToReplaceFilesFrom; 944 this.m_lstReadyToReplaceTo = lstReadyToReplaceFilesTo; 945 this.m_lstReadyToBeReplacedFrom = lstReadyToBeReplacedFilesFrom; 946 this.m_lstReadyToBeReplacedTo = lstReadyToBeReplacedFilesTo; 947 948 IOException ioeExc = new IOException ( 950 "Error occured during creating of '" 951 + FILE_PATH_READY_TO_REPLACE + "' directory."); 952 ioeExc.initCause(thr); 953 throw ioeExc; 954 } 955 956 fPathTemp = new File (sbTemp1.toString()); 958 959 try 960 { 961 if (!fPathTemp.exists()) 963 { 964 if (!fPathTemp.mkdirs()) 966 { 967 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 969 970 this.m_lstReadyToMoveFrom = lstReadyToMoveFilesFrom; 972 this.m_lstReadyToMoveTo = lstReadyToMoveFilesToOriginal; 973 974 this.m_lstReadyToReplaceFrom = lstReadyToReplaceFilesFrom; 977 this.m_lstReadyToBeReplacedFrom = lstReadyToBeReplacedFilesFrom; 978 this.m_lstReadyToBeReplacedTo = lstReadyToBeReplacedFilesTo; 979 980 throw new IOException ( 982 "Error occured during creating of '" 983 + FILE_PATH_READY_TO_BE_REPLACED + "' directory."); 984 } 985 } 986 } 987 catch (Throwable thr) 988 { 989 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 991 992 this.m_lstReadyToMoveFrom = lstReadyToMoveFilesFrom; 994 this.m_lstReadyToMoveTo = lstReadyToMoveFilesToOriginal; 995 996 this.m_lstReadyToReplaceFrom = lstReadyToReplaceFilesFrom; 999 this.m_lstReadyToBeReplacedFrom = lstReadyToBeReplacedFilesFrom; 1000 this.m_lstReadyToBeReplacedTo = lstReadyToBeReplacedFilesTo; 1001 1002 IOException ioeExc = new IOException ( 1004 "Error occured during creating of '" 1005 + FILE_PATH_READY_TO_BE_REPLACED + "' directory."); 1006 ioeExc.initCause(thr); 1007 throw ioeExc; 1008 } 1009 1010 sbTemp.append((String ) tosSource.getSecond()); 1011 sbTemp1.append((String ) tosDestination.getSecond()); 1012 sbTemp2.append((String ) tosSource.getSecond()); 1013 1014 fDestinationFile = new File (sbTemp.toString()); 1016 1017 fFinalDestinationFile = new File (sbTemp2.toString()); 1019 1020 fDestinationFileBackUp = new File (sbTemp1.toString()); 1022 1023 lstReadyToReplaceFilesFrom.add(fDestinationFile); 1029 1030 lstReadyToReplaceFilesTo.add(fFinalDestinationFile); 1035 1036 1039 try 1040 { 1041 FileUtils.moveFile(fSourceFile, fDestinationFile); 1044 } 1045 catch (IOException ioExc) 1046 { 1047 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 1049 1050 this.m_lstReadyToMoveFrom = lstReadyToMoveFilesFrom; 1052 this.m_lstReadyToMoveTo = lstReadyToMoveFilesToOriginal; 1053 1054 this.m_lstReadyToReplaceFrom = lstReadyToReplaceFilesFrom; 1057 this.m_lstReadyToBeReplacedFrom = lstReadyToBeReplacedFilesFrom; 1058 this.m_lstReadyToBeReplacedTo = lstReadyToBeReplacedFilesTo; 1059 1060 IOException ioeExc = new IOException ( 1061 "Error occured during copying of the file."); 1062 ioeExc.initCause(ioExc); 1063 throw ioeExc; 1064 } 1065 catch (OSSException bfExc) 1066 { 1067 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 1069 1070 this.m_lstReadyToMoveFrom = lstReadyToMoveFilesFrom; 1072 this.m_lstReadyToMoveTo = lstReadyToMoveFilesToOriginal; 1073 1074 this.m_lstReadyToReplaceFrom = lstReadyToReplaceFilesFrom; 1077 this.m_lstReadyToBeReplacedFrom = lstReadyToBeReplacedFilesFrom; 1078 this.m_lstReadyToBeReplacedTo = lstReadyToBeReplacedFilesTo; 1079 1080 IOException ioeExc = new IOException ( 1081 "Error occured during copying of the file."); 1082 ioeExc.initCause(bfExc); 1083 throw ioeExc; 1084 } 1085 1086 try 1087 { 1088 if (fSourceFileBackUp.renameTo(fDestinationFileBackUp)) 1091 { 1092 1098 lstReadyToBeReplacedFilesFrom.add(fDestinationFileBackUp); 1106 1107 lstReadyToBeReplacedFilesTo.add(fSourceFileBackUp); 1111 1112 this.m_lstReadyToReplaceFrom = lstReadyToReplaceFilesFrom; 1115 this.m_lstReadyToReplaceTo = lstReadyToReplaceFilesTo; 1116 this.m_lstReadyToBeReplacedFrom = lstReadyToBeReplacedFilesFrom; 1117 this.m_lstReadyToBeReplacedTo = lstReadyToBeReplacedFilesTo; 1118 } 1119 else 1120 { 1121 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 1123 1124 this.m_lstReadyToMoveFrom = lstReadyToMoveFilesFrom; 1126 this.m_lstReadyToMoveTo = lstReadyToMoveFilesToOriginal; 1127 1128 this.m_lstReadyToReplaceFrom = lstReadyToReplaceFilesFrom; 1131 this.m_lstReadyToBeReplacedFrom = lstReadyToBeReplacedFilesFrom; 1132 this.m_lstReadyToBeReplacedTo = lstReadyToBeReplacedFilesTo; 1133 1134 throw new IOException ("Error occured during file renaming."); 1135 } 1136 } 1137 catch (Throwable thr) 1138 { 1139 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 1141 1142 this.m_lstReadyToMoveFrom = lstReadyToMoveFilesFrom; 1144 this.m_lstReadyToMoveTo = lstReadyToMoveFilesToOriginal; 1145 1146 this.m_lstReadyToReplaceFrom = lstReadyToReplaceFilesFrom; 1149 this.m_lstReadyToBeReplacedFrom = lstReadyToBeReplacedFilesFrom; 1150 this.m_lstReadyToBeReplacedTo = lstReadyToBeReplacedFilesTo; 1151 1152 IOException ioeExc = new IOException ( 1153 "Error occured during file renaming."); 1154 ioeExc.initCause(thr); 1155 throw ioeExc; 1156 } 1157 } 1158 else 1159 { 1160 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 1162 1163 this.m_lstReadyToMoveFrom = lstReadyToMoveFilesFrom; 1165 this.m_lstReadyToMoveTo = lstReadyToMoveFilesToOriginal; 1166 1167 this.m_lstReadyToReplaceFrom = lstReadyToReplaceFilesFrom; 1170 this.m_lstReadyToBeReplacedFrom = lstReadyToBeReplacedFilesFrom; 1171 this.m_lstReadyToBeReplacedTo = lstReadyToBeReplacedFilesTo; 1172 1173 throw new IOException ("Source file that has to be replaced does not exist."); 1175 } 1176 } 1177 1178 itHelp1 = this.m_lstDeleteFiles.iterator(); 1186 while (itHelp1.hasNext()) 1187 { 1188 tosSource = (TwoObjectStruct) itHelp1.next(); 1190 1191 sbTemp.delete(0, sbTemp.length()); 1193 if (tosSource.getFirst() != null) 1195 { 1196 sbTemp.append((String ) tosSource.getFirst()); 1197 } 1198 sbTemp.append((String ) tosSource.getSecond()); 1199 fSourceFile = new File (sbTemp.toString()); 1200 1201 if (fSourceFile.exists()) 1203 { 1204 1208 sbTemp.delete(0, sbTemp.length()); 1209 if (tosSource.getFirst() != null) 1211 { 1212 sbTemp.append((String ) tosSource.getFirst()); 1213 } 1214 sbTemp.append(FILE_PATH_READY_TO_DELETE); 1215 sbTemp.append(File.separator); 1216 1217 fPathTemp = new File (sbTemp.toString()); 1219 if (!fPathTemp.exists()) 1221 { 1222 try 1223 { 1224 if (!fPathTemp.mkdirs()) 1226 { 1227 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 1229 1230 this.m_lstReadyToMoveFrom = lstReadyToMoveFilesFrom; 1232 this.m_lstReadyToMoveTo = lstReadyToMoveFilesToOriginal; 1233 1234 this.m_lstReadyToReplaceFrom = lstReadyToReplaceFilesFrom; 1237 this.m_lstReadyToBeReplacedFrom = lstReadyToBeReplacedFilesFrom; 1238 this.m_lstReadyToBeReplacedTo = lstReadyToBeReplacedFilesTo; 1239 1240 this.m_lstReadyToDeleteFrom = lstReadyToDeleteFilesFrom; 1243 this.m_lstReadyToDeleteTo = lstReadyToDeleteFilesTo; 1244 1245 throw new IOException ( 1247 "Error occured during creating of '" 1248 + FILE_PATH_READY_TO_DELETE + "' directory."); 1249 } 1250 } 1251 catch (Throwable thr) 1252 { 1253 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 1255 1256 this.m_lstReadyToMoveFrom = lstReadyToMoveFilesFrom; 1258 this.m_lstReadyToMoveTo = lstReadyToMoveFilesToOriginal; 1259 1260 this.m_lstReadyToReplaceFrom = lstReadyToReplaceFilesFrom; 1263 this.m_lstReadyToBeReplacedFrom = lstReadyToBeReplacedFilesFrom; 1264 this.m_lstReadyToBeReplacedTo = lstReadyToBeReplacedFilesTo; 1265 1266 this.m_lstReadyToDeleteFrom = lstReadyToDeleteFilesFrom; 1269 this.m_lstReadyToDeleteTo = lstReadyToDeleteFilesTo; 1270 1271 IOException ioeExc = new IOException ( 1273 "Error occured during creating of '" 1274 + FILE_PATH_READY_TO_DELETE + "' directory."); 1275 ioeExc.initCause(thr); 1276 throw ioeExc; 1277 } 1278 } 1279 1280 sbTemp.append((String ) tosSource.getSecond()); 1281 1282 fSourceFileBackUp = new File (sbTemp.toString()); 1284 1285 try 1286 { 1287 if (fSourceFile.renameTo(fSourceFileBackUp)) 1290 { 1291 lstReadyToDeleteFilesFrom.add(fSourceFileBackUp); 1297 1298 lstReadyToDeleteFilesTo.add(fSourceFile); 1302 1303 this.m_lstReadyToDeleteFrom = lstReadyToDeleteFilesFrom; 1306 } 1307 else 1308 { 1309 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 1311 1312 this.m_lstReadyToMoveFrom = lstReadyToMoveFilesFrom; 1314 this.m_lstReadyToMoveTo = lstReadyToMoveFilesToOriginal; 1315 1316 this.m_lstReadyToReplaceFrom = lstReadyToReplaceFilesFrom; 1319 this.m_lstReadyToBeReplacedFrom = lstReadyToBeReplacedFilesFrom; 1320 this.m_lstReadyToBeReplacedTo = lstReadyToBeReplacedFilesTo; 1321 1322 this.m_lstReadyToDeleteFrom = lstReadyToDeleteFilesFrom; 1325 this.m_lstReadyToDeleteTo = lstReadyToDeleteFilesTo; 1326 1327 throw new IOException ("Error occured during file renaming."); 1328 } 1329 } 1330 catch (Throwable thr) 1331 { 1332 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 1334 1335 this.m_lstReadyToMoveFrom = lstReadyToMoveFilesFrom; 1337 this.m_lstReadyToMoveTo = lstReadyToMoveFilesToOriginal; 1338 1339 this.m_lstReadyToReplaceFrom = lstReadyToReplaceFilesFrom; 1342 this.m_lstReadyToBeReplacedFrom = lstReadyToBeReplacedFilesFrom; 1343 this.m_lstReadyToBeReplacedTo = lstReadyToBeReplacedFilesTo; 1344 1345 this.m_lstReadyToDeleteFrom = lstReadyToDeleteFilesFrom; 1348 this.m_lstReadyToDeleteTo = lstReadyToDeleteFilesTo; 1349 1350 IOException ioeExc = new IOException ( 1351 "Error occured during file renaming."); 1352 ioeExc.initCause(thr); 1353 throw ioeExc; 1354 } 1355 } 1356 else 1357 { 1358 1382 } 1383 } 1384 } 1385 else 1386 { 1387 if (this.m_iReturnCode == FileCommitUtils.RC_FILE_ERR_OBJ) 1389 { 1390 throw new IOException ("There was an error occured during image processing."); 1391 } 1392 } 1393 } 1394 catch (IOException ioExc) 1395 { 1396 throw ioExc; 1398 } 1399 catch (Throwable thrExc) 1400 { 1401 1404 this.m_lstReadyToCopyFrom = lstReadyToCopyFilesFrom; 1406 1407 this.m_lstReadyToMoveFrom = lstReadyToMoveFilesFrom; 1411 this.m_lstReadyToMoveTo = lstReadyToMoveFilesToOriginal; 1412 1413 this.m_lstReadyToReplaceFrom = lstReadyToReplaceFilesFrom; 1416 this.m_lstReadyToReplaceTo = lstReadyToReplaceFilesTo; 1417 this.m_lstReadyToBeReplacedFrom = lstReadyToBeReplacedFilesFrom; 1418 this.m_lstReadyToBeReplacedTo = lstReadyToBeReplacedFilesTo; 1419 1420 this.m_lstReadyToDeleteFrom = lstReadyToDeleteFilesFrom; 1422 this.m_lstReadyToDeleteTo = lstReadyToDeleteFilesTo; 1423 1424 IOException ioeExc = new IOException ( 1425 "Unspecified error has occured while preparing files to commit."); 1426 ioeExc.initCause(thrExc); 1427 throw ioeExc; 1428 } 1429 } 1430 } 1431 1432 1439 public void commit( 1440 ) throws OSSException 1441 { 1442 if (this.m_iReturnCode != null) 1444 { 1445 int iRetryCounter = 0; 1446 1447 if (this.m_iStatus == FileCommitUtils.STATUS_PREPARE_TO_COMMIT) 1448 { 1449 this.m_iStatus = FileCommitUtils.STATUS_COMMIT; 1450 } 1451 else 1452 { 1453 throw new OSSInternalErrorException("Cannot commit file transaction while " + 1454 "there is not prepare to commit status defined."); 1455 } 1456 1457 while (((this.m_lstReadyToCopyFrom.size() > 0) 1461 || (this.m_lstReadyToMoveFrom.size() > 0) 1462 || (this.m_lstReadyToReplaceFrom.size() > 0) 1463 || (this.m_lstReadyToBeReplacedFrom.size() > 0) 1464 || (this.m_lstReadyToDeleteFrom.size() > 0)) 1465 && (iRetryCounter <= s_iFileCommitRetryCount)) 1466 { 1467 if (iRetryCounter > 0) 1468 { 1469 sleep(); 1471 } 1472 1473 try 1474 { 1475 if (GlobalConstants.ERROR_CHECKING) 1476 { 1477 assert this.m_lstReadyToCopyFrom.size() == this.m_lstReadyToCopyTo.size() 1478 : "Size of the source and destination list of files that " + 1479 "will be copied has to be the same."; 1480 assert this.m_lstReadyToMoveFrom.size() == this.m_lstReadyToMoveTo.size() 1481 : "Size of the source and destination list of files that " + 1482 "will be moved has to be the same."; 1483 assert this.m_lstReadyToReplaceFrom.size() == this.m_lstReadyToReplaceTo.size() 1484 : "Size of the source and destination list of files that " + 1485 "will be replaced has to be the same."; 1486 assert this.m_lstReadyToBeReplacedFrom.size() 1487 == this.m_lstReadyToBeReplacedTo.size() 1488 : "Size of the source and destination list of files that " + 1489 "will be replaced has to be the same."; 1490 } 1491 1492 1495 doRenameFiles(this.m_lstReadyToCopyFrom, 1505 this.m_lstReadyToCopyTo, 1506 SENDER_COMMIT, 1507 LIST_IDENTIFICATOR_COPY); 1508 1509 doRenameFiles(this.m_lstReadyToMoveFrom, 1519 this.m_lstReadyToMoveTo, 1520 SENDER_COMMIT, 1521 LIST_IDENTIFICATOR_MOVE); 1522 1523 doRenameFiles(this.m_lstReadyToReplaceFrom, 1533 this.m_lstReadyToReplaceTo, 1534 SENDER_COMMIT, 1535 LIST_IDENTIFICATOR_REPLACE); 1536 1537 doDeleteFiles(this.m_lstReadyToBeReplacedFrom, 1547 SENDER_COMMIT, 1548 LIST_IDENTIFICATOR_TO_BE_REPLACED); 1549 1550 doDeleteFiles(this.m_lstReadyToDeleteFrom, 1551 SENDER_COMMIT, 1552 LIST_IDENTIFICATOR_DELETE); 1553 1554 } 1555 catch (Throwable thrExc) 1556 { 1557 s_logger.log(Level.WARNING, 1558 "An error has occured during file commit", thrExc); 1559 } 1560 finally 1561 { 1562 iRetryCounter++; 1563 } 1564 } 1565 } 1566 } 1567 1568 1577 public void rollback( 1578 ) throws OSSException 1579 { 1580 if (this.m_iReturnCode != null) 1582 { 1583 int iRetryCounter = 0; 1584 1585 if (this.m_iStatus == FileCommitUtils.STATUS_PREPARE_TO_COMMIT) 1586 { 1587 this.m_iStatus = FileCommitUtils.STATUS_ROLLBACK; 1588 } 1589 else 1590 { 1591 throw new OSSInternalErrorException( 1592 "Cannot prepare file transaction to rollback while " 1593 + "there is not prepare to commit status defined."); 1594 } 1595 1596 while (((this.m_lstReadyToBeReplacedFrom.size() > 0) 1600 || (this.m_lstReadyToMoveFrom.size() > 0) 1601 || (this.m_lstReadyToDeleteFrom.size() > 0) 1602 || (this.m_lstReadyToCopyFrom.size() > 0) 1603 || (this.m_lstReadyToReplaceFrom.size() > 0)) 1604 && (iRetryCounter <= s_iFileCommitRetryCount)) 1605 { 1606 if (iRetryCounter > 0) 1607 { 1608 sleep(); 1610 } 1611 1612 try 1613 { 1614 1620 doRenameFiles(this.m_lstReadyToBeReplacedFrom, 1625 this.m_lstReadyToBeReplacedTo, 1626 SENDER_ROLLBACK, 1627 LIST_IDENTIFICATOR_TO_BE_REPLACED); 1628 1629 doRenameFiles(this.m_lstReadyToDeleteFrom, 1634 this.m_lstReadyToDeleteTo, 1635 SENDER_ROLLBACK, 1636 LIST_IDENTIFICATOR_DELETE); 1637 1638 if (this.m_bMovedFilesDeleteForRollback) 1642 { 1643 doDeleteFiles(this.m_lstReadyToMoveFrom, 1648 SENDER_ROLLBACK, 1649 LIST_IDENTIFICATOR_MOVE); 1650 } 1651 else 1652 { 1653 doMoveFiles(this.m_lstReadyToMoveFrom, 1656 this.m_lstReadyToMoveTo, 1657 SENDER_ROLLBACK, 1658 LIST_IDENTIFICATOR_MOVE); 1659 } 1660 1661 doDeleteFiles(this.m_lstReadyToCopyFrom, 1666 SENDER_ROLLBACK, 1667 LIST_IDENTIFICATOR_COPY); 1668 1669 doDeleteFiles(this.m_lstReadyToReplaceFrom, 1674 SENDER_ROLLBACK, 1675 LIST_IDENTIFICATOR_REPLACE); 1676 } 1677 catch (Throwable thrExc) 1678 { 1679 s_logger.log(Level.WARNING, 1680 "An error has occured during file rollback", thrExc); 1681 } 1682 iRetryCounter++; 1683 } 1684 } 1685 } 1686 1687 1691 public int getStatus() 1692 { 1693 return m_iStatus; 1694 } 1695 1696 1698 1709 private void doRenameFiles( 1710 List lstSources, 1711 List lstDestinations, 1712 int iSenderIdentificator, 1713 int iListIdentificator 1714 ) 1715 { 1716 File fSourceFile; 1717 File fDestinationFile; 1718 1719 List lstSourcesCopy = new ArrayList (lstSources); 1721 List lstDestinationsCopy = new ArrayList (lstDestinations); 1722 1723 Iterator itHelp1; 1724 Iterator itHelp2; 1725 1726 int iErrorIndexPosition = 0; 1727 1728 if (GlobalConstants.ERROR_CHECKING) 1729 { 1730 assert lstSourcesCopy.size() == lstDestinationsCopy.size() 1731 : "Size of the source and destination list of files that " + 1732 "will be renamed has to be the same."; 1733 } 1734 1735 if (lstSourcesCopy.size() > 0) 1736 { 1737 1738 itHelp1 = lstSourcesCopy.iterator(); 1739 itHelp2 = lstDestinationsCopy.iterator(); 1740 while (itHelp1.hasNext() && itHelp2.hasNext()) 1741 { 1742 fSourceFile = (File ) itHelp1.next(); 1744 fDestinationFile = (File ) itHelp2.next(); 1745 1746 if (fSourceFile.exists()) 1747 { 1748 if (fDestinationFile.exists()) 1749 { 1750 s_logger.finest("Destination file " 1759 + fDestinationFile.getAbsolutePath() + 1760 " already exists, removing the source file " + 1761 fSourceFile.getAbsolutePath()); 1762 if (!fSourceFile.delete()) 1763 { 1764 iErrorIndexPosition++; 1766 s_logger.log(Level.WARNING, 1768 "Cannot delete file " + fSourceFile.getAbsolutePath() + 1769 " since the destination file already exists."); 1770 } 1771 else 1772 { 1773 removeDeletedFileFromGlobalLists(iSenderIdentificator, 1775 iListIdentificator, 1776 iErrorIndexPosition); 1777 } 1778 } 1779 else 1780 { 1781 try 1782 { 1783 if (!fSourceFile.renameTo(fDestinationFile)) 1784 { 1785 iErrorIndexPosition++; 1787 s_logger.log(Level.WARNING, 1789 "Cannot rename file from " + fSourceFile.getAbsolutePath() 1790 + " to " + fDestinationFile.getAbsolutePath()); 1791 } 1792 else 1793 { 1794 removeRenamedFileFromGlobalLists(iSenderIdentificator, 1796 iListIdentificator, 1797 iErrorIndexPosition); 1798 } 1799 } 1800 catch (Throwable thr) 1801 { 1802 iErrorIndexPosition++; 1804 s_logger.log(Level.WARNING, 1806 "Cannot rename file from " + fSourceFile.getAbsolutePath() 1807 + " to " + fDestinationFile.getAbsolutePath(), thr); 1808 } 1809 } 1810 } 1811 else 1812 { 1813 removeRenamedFileFromGlobalLists(iSenderIdentificator, 1818 iListIdentificator, 1819 iErrorIndexPosition); 1820 } 1821 } 1822 } 1823 } 1824 1825 1837 private void doMoveFiles( 1838 List lstSources, 1839 List lstDestinations, 1840 int iSenderIdentificator, 1841 int iListIdentificator 1842 ) 1843 { 1844 File fSourceFile; 1845 File fDestinationFile; 1846 1847 List lstSourcesCopy = new ArrayList (lstSources); 1849 List lstDestinationsCopy = new ArrayList (lstDestinations); 1850 1851 Iterator itHelp1; 1852 Iterator itHelp2; 1853 1854 int iErrorIndexPosition = 0; 1855 1856 if (GlobalConstants.ERROR_CHECKING) 1857 { 1858 assert lstSourcesCopy.size() == lstDestinationsCopy.size() 1859 : "Size of the source and destination list of files that " + 1860 "will be moved has to be the same."; 1861 } 1862 1863 if (lstSourcesCopy.size() > 0) 1864 { 1865 1866 itHelp1 = lstSourcesCopy.iterator(); 1867 itHelp2 = lstDestinationsCopy.iterator(); 1868 while (itHelp1.hasNext() && itHelp2.hasNext()) 1869 { 1870 fSourceFile = (File ) itHelp1.next(); 1872 fDestinationFile = (File ) itHelp2.next(); 1873 1874 if (fSourceFile.exists()) 1875 { 1876 if (fDestinationFile.exists()) 1877 { 1878 s_logger.finest("Destination file " 1887 + fDestinationFile.getAbsolutePath() + 1888 " already exists, removing the source file " + 1889 fSourceFile.getAbsolutePath()); 1890 if (!fSourceFile.delete()) 1891 { 1892 iErrorIndexPosition++; 1894 s_logger.log(Level.WARNING, 1896 "Cannot delete file " + fSourceFile.getAbsolutePath() + 1897 " since the destination file already exists."); 1898 } 1899 else 1900 { 1901 removeDeletedFileFromGlobalLists(iSenderIdentificator, 1903 iListIdentificator, 1904 iErrorIndexPosition); 1905 } 1906 } 1907 else 1908 { 1909 try 1910 { 1911 FileUtils.moveFile(fSourceFile, fDestinationFile); 1912 removeRenamedFileFromGlobalLists(iSenderIdentificator, 1914 iListIdentificator, 1915 iErrorIndexPosition); 1916 } 1917 catch (Throwable thr) 1918 { 1919 iErrorIndexPosition++; 1921 s_logger.log(Level.WARNING, 1923 "Cannot move file from " + fSourceFile.getAbsolutePath() 1924 + " to " + fDestinationFile.getAbsolutePath(), thr); 1925 } 1926 } 1927 } 1928 else 1929 { 1930 removeRenamedFileFromGlobalLists(iSenderIdentificator, 1935 iListIdentificator, 1936 iErrorIndexPosition); 1937 } 1938 } 1939 } 1940 } 1941 1942 1953 private void removeRenamedFileFromGlobalLists( 1954 int iSenderIdentificator, 1955 int iListIdentificator, 1956 int iIndexPosition 1957 ) 1958 { 1959 switch (iSenderIdentificator) 1960 { 1961 case SENDER_COMMIT: 1963 { 1964 switch (iListIdentificator) 1965 { 1966 case LIST_IDENTIFICATOR_COPY: 1967 { 1968 this.m_lstReadyToCopyFrom.remove(iIndexPosition); 1970 this.m_lstReadyToCopyTo.remove(iIndexPosition); 1971 break; 1972 } 1973 case LIST_IDENTIFICATOR_MOVE: 1974 { 1975 this.m_lstReadyToMoveFrom.remove(iIndexPosition); 1976 this.m_lstReadyToMoveTo.remove(iIndexPosition); 1977 break; 1978 } 1979 case LIST_IDENTIFICATOR_REPLACE: 1980 { 1981 this.m_lstReadyToReplaceFrom.remove(iIndexPosition); 1983 this.m_lstReadyToReplaceTo.remove(iIndexPosition); 1984 break; 1985 } 1986 default: 1987 { 1988 assert true : "List identificator is incorrectly specified."; 1989 } 1990 } 1991 break; 1992 } 1993 case SENDER_ROLLBACK: 1995 { 1996 switch (iListIdentificator) 1997 { 1998 case LIST_IDENTIFICATOR_TO_BE_REPLACED: 1999 { 2000 this.m_lstReadyToBeReplacedFrom.remove(iIndexPosition); 2002 this.m_lstReadyToBeReplacedTo.remove(iIndexPosition); 2003 break; 2004 } 2005 case LIST_IDENTIFICATOR_MOVE: 2006 { 2007 this.m_lstReadyToMoveFrom.remove(iIndexPosition); 2008 this.m_lstReadyToMoveTo.remove(iIndexPosition); 2009 break; 2010 } 2011 case LIST_IDENTIFICATOR_DELETE: 2012 { 2013 this.m_lstReadyToDeleteFrom.remove(iIndexPosition); 2015 this.m_lstReadyToDeleteTo.remove(iIndexPosition); 2016 break; 2017 } 2018 default: 2019 { 2020 assert true : "List identificator is incorrectly specified."; 2021 } 2022 } 2023 break; 2024 } 2025 default: 2026 { 2027 assert true : "Sender is incorrectly specified."; 2028 } 2029 } 2030 } 2031 2032 2040 private void doDeleteFiles( 2041 List lstSources, 2042 int iSenderIdentificator, 2043 int iListIdentificator 2044 ) 2045 { 2046 File fSourceFile; 2047 2048 List lstSourcesCopy = new ArrayList (lstSources); 2050 2051 Iterator itHelp1; 2052 int iErrorIndexPosition = 0; 2053 2054 if (lstSourcesCopy.size() > 0) 2055 { 2056 itHelp1 = lstSourcesCopy.iterator(); 2057 while (itHelp1.hasNext()) 2058 { 2059 fSourceFile = (File ) itHelp1.next(); 2061 2062 if (fSourceFile.exists()) 2063 { 2064 try 2065 { 2066 if (!fSourceFile.delete()) 2067 { 2068 iErrorIndexPosition++; 2070 s_logger.log(Level.WARNING, 2072 "Cannot delete file " + fSourceFile.getAbsolutePath()); 2073 } 2074 else 2075 { 2076 removeDeletedFileFromGlobalLists(iSenderIdentificator, 2078 iListIdentificator, 2079 iErrorIndexPosition); 2080 } 2081 } 2082 catch (Throwable thr) 2083 { 2084 iErrorIndexPosition++; 2086 s_logger.log(Level.WARNING, 2088 "Cannot delete file " + fSourceFile.getAbsolutePath(), thr); 2089 } 2090 } 2091 else 2092 { 2093 removeDeletedFileFromGlobalLists(iSenderIdentificator, 2098 iListIdentificator, 2099 iErrorIndexPosition); 2100 } 2101 } 2102 } 2103 } 2104 2105 2116 private void removeDeletedFileFromGlobalLists( 2117 int iSenderIdentificator, 2118 int iListIdentificator, 2119 int iIndexPosition 2120 ) 2121 { 2122 switch (iSenderIdentificator) 2123 { 2124 case SENDER_COMMIT: 2126 { 2127 switch (iListIdentificator) 2128 { 2129 case LIST_IDENTIFICATOR_TO_BE_REPLACED: 2130 { 2131 this.m_lstReadyToBeReplacedFrom.remove(iIndexPosition); 2133 break; 2134 } 2135 case LIST_IDENTIFICATOR_DELETE: 2136 { 2137 this.m_lstReadyToDeleteFrom.remove(iIndexPosition); 2139 break; 2140 } 2141 default: 2142 { 2143 assert true : "List identificator is incorrectly specified."; 2144 } 2145 } 2146 break; 2147 } 2148 case SENDER_ROLLBACK: 2150 { 2151 switch (iListIdentificator) 2152 { 2153 case LIST_IDENTIFICATOR_COPY: 2154 { 2155 this.m_lstReadyToCopyFrom.remove(iIndexPosition); 2157 break; 2158 } 2159 case LIST_IDENTIFICATOR_MOVE: 2160 { 2161 this.m_lstReadyToMoveFrom.remove(iIndexPosition); 2162 break; 2163 } 2164 case LIST_IDENTIFICATOR_REPLACE: 2165 { 2166 this.m_lstReadyToReplaceFrom.remove(iIndexPosition); 2168 break; 2169 } 2170 default: 2171 { 2172 assert true : "List identificator is incorrectly specified."; 2173 } 2174 } 2175 break; 2176 } 2177 default: 2178 { 2179 assert true : "Sender is incorrectly specified."; 2180 } 2181 } 2182 } 2183 2184 2187 private void initGlobalLists() 2188 { 2189 m_lstReadyToCopyFrom = Collections.EMPTY_LIST; 2190 m_lstReadyToCopyTo = Collections.EMPTY_LIST; 2191 m_lstReadyToMoveFrom = Collections.EMPTY_LIST; 2192 m_lstReadyToMoveTo = Collections.EMPTY_LIST; 2193 m_lstReadyToBeReplacedFrom = Collections.EMPTY_LIST; 2194 m_lstReadyToBeReplacedTo = Collections.EMPTY_LIST; 2195 m_lstReadyToReplaceFrom = Collections.EMPTY_LIST; 2196 m_lstReadyToReplaceTo = Collections.EMPTY_LIST; 2197 m_lstReadyToDeleteFrom = Collections.EMPTY_LIST; 2198 m_lstReadyToDeleteTo = Collections.EMPTY_LIST; 2199 } 2200 2201 2204 private void sleep() 2205 { 2206 try 2207 { 2208 Thread.sleep(SLEEP_TIME); 2209 } 2210 catch (InterruptedException iExc) 2211 { 2212 s_logger.log(Level.WARNING, "Sleep was interrupted."); 2213 } 2214 } 2215} 2216 | Popular Tags |