1 package org.columba.core.command; 17 18 import org.columba.api.command.ICommand; 19 import org.columba.api.command.ICommandReference; 20 import org.columba.api.command.IWorkerStatusController; 21 import org.columba.core.base.Lock; 22 23 31 public abstract class Command implements ICommand { 32 33 38 public static final int NORMAL_OPERATION = 1; 39 40 44 public static final int DAEMON_PRIORITY = -10; 45 46 49 public static final int NORMAL_PRIORITY = 0; 50 51 54 public static final int REALTIME_PRIORITY = 10; 55 56 59 public static final int DEFINETLY_NEXT_OPERATION_PRIORITY = 20; 60 61 64 public static final int FIRST_EXECUTION = 0; 65 66 protected int priority; 67 68 protected int commandType; 69 70 protected boolean synchronize; 71 72 protected int timeStamp; 73 74 protected Lock[] folderLocks; 75 76 private ICommandReference reference; 77 78 79 public Command(ICommandReference theReference) { 80 this.reference = theReference; 81 82 commandType = NORMAL_OPERATION; 83 priority = NORMAL_PRIORITY; 84 85 } 86 87 public void process(Worker worker) throws Exception { 88 setTimeStamp(worker.getTimeStamp()); 89 execute(worker); 90 } 91 92 95 public void updateGUI() throws Exception { 96 } 98 99 102 public abstract void execute(IWorkerStatusController worker) 103 throws Exception ; 104 105 public boolean canBeProcessed() { 106 107 boolean success = reference.tryToGetLock(this); 108 if (!success) { 109 releaseAllFolderLocks(); 110 } 111 return success; 112 113 } 114 115 public void releaseAllFolderLocks() { 116 117 reference.releaseLock(this); 118 119 } 120 121 122 123 public int getCommandType() { 124 return commandType; 125 } 126 127 public int getPriority() { 128 return priority; 129 } 130 131 public void incPriority() { 132 priority++; 133 } 134 135 public boolean isSynchronize() { 136 return synchronize; 137 } 138 139 public void setSynchronize(boolean isSynchronize) { 140 this.synchronize = isSynchronize; 141 } 142 143 public void setPriority(int thePriority) { 144 this.priority = thePriority; 145 } 146 147 152 public int getTimeStamp() { 153 return timeStamp; 154 } 155 156 162 public void setTimeStamp(int theTimeStamp) { 163 this.timeStamp = theTimeStamp; 164 } 165 166 169 public ICommandReference getReference() { 170 return reference; 171 } 172 173 public void finish() throws Exception { 174 updateGUI(); 175 } 176 } | Popular Tags |