1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package openr66.context.task;
22
23 import java.sql.Timestamp;
24 import java.text.ParseException;
25 import java.text.SimpleDateFormat;
26 import java.util.Date;
27
28 import goldengate.common.logging.GgInternalLogger;
29 import goldengate.common.logging.GgInternalLoggerFactory;
30 import openr66.client.SubmitTransfer;
31 import openr66.context.R66Session;
32 import openr66.context.task.exception.OpenR66RunnerErrorException;
33 import openr66.database.DbConstant;
34 import openr66.database.data.DbTaskRunner;
35 import openr66.protocol.configuration.Configuration;
36 import openr66.protocol.utils.R66Future;
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public class TransferTask extends AbstractTask {
52
53
54
55 private static final GgInternalLogger logger = GgInternalLoggerFactory
56 .getLogger(TransferTask.class);
57
58
59
60
61
62
63
64 public TransferTask(String argRule, int delay, String argTransfer,
65 R66Session session) {
66 super(TaskType.TRANSFER, delay, argRule, argTransfer, session);
67 }
68
69
70
71
72
73
74 @Override
75 public void run() {
76 logger.info("Transfer with " + argRule + ":" + argTransfer + " and {}",
77 session);
78 String finalname = argRule;
79 finalname = getReplacedValue(finalname, argTransfer.split(" "));
80 String[] args = finalname.split(" ");
81 if (args.length < 6) {
82 futureCompletion.setFailure(
83 new OpenR66RunnerErrorException("Not enough argument in Transfer"));
84 return;
85 }
86 String filepath = null;
87 String requested = null;
88 String rule = null;
89 String information = null;
90 boolean isMD5 = false;
91 int blocksize = Configuration.configuration.BLOCKSIZE;
92 Timestamp timestart = null;
93 for (int i = 0; i < args.length; i ++) {
94 if (args[i].equalsIgnoreCase("-to")) {
95 i ++;
96 requested = args[i];
97 } else if (args[i].equalsIgnoreCase("-file")) {
98 i ++;
99 filepath = args[i];
100 } else if (args[i].equalsIgnoreCase("-rule")) {
101 i ++;
102 rule = args[i];
103 } else if (args[i].equalsIgnoreCase("-info")) {
104 i ++;
105 information = args[i];
106 i ++;
107 while (i < args.length) {
108 information += " " + args[i];
109 i ++;
110 }
111 } else if (args[i].equalsIgnoreCase("-md5")) {
112 isMD5 = true;
113 } else if (args[i].equalsIgnoreCase("-block")) {
114 i ++;
115 blocksize = Integer.parseInt(args[i]);
116 if (blocksize < 100) {
117 logger.warn("Block size is too small: " + blocksize);
118 blocksize = Configuration.configuration.BLOCKSIZE;
119 }
120 } else if (args[i].equalsIgnoreCase("-start")) {
121 i++;
122 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
123 Date date;
124 try {
125 date = dateFormat.parse(args[i]);
126 timestart = new Timestamp(date.getTime());
127 } catch (ParseException e) {
128 }
129 } else if (args[i].equalsIgnoreCase("-delay")) {
130 i++;
131 if (args[i].charAt(0) == '+') {
132 timestart = new Timestamp(System.currentTimeMillis()+
133 Long.parseLong(args[i].substring(1)));
134 } else {
135 timestart = new Timestamp(Long.parseLong(args[i]));
136 }
137 }
138 }
139 if (information == null) {
140 information = "noinfo";
141 }
142 R66Future future = new R66Future(true);
143 SubmitTransfer transaction = new SubmitTransfer(future,
144 requested, filepath, rule, information, isMD5, blocksize, DbConstant.ILLEGALVALUE,
145 timestart);
146 transaction.run();
147 future.awaitUninterruptibly();
148 futureCompletion.setResult(future.getResult());
149 DbTaskRunner runner = future.getResult().runner;
150 if (future.isSuccess()) {
151 logger.info("Prepare transfer in\n SUCCESS\n "+runner.toShortString()+
152 "\n <REMOTE>"+requested+"</REMOTE>");
153 futureCompletion.setSuccess();
154 } else {
155 if (runner != null) {
156 if (future.getCause() == null) {
157 futureCompletion.cancel();
158 } else {
159 futureCompletion.setFailure(future.getCause());
160 }
161 logger.error("Prepare transfer in\n FAILURE\n "+runner.toShortString()+
162 "\n <REMOTE>"+requested+"</REMOTE>", future.getCause());
163 } else {
164 if (future.getCause() == null) {
165 futureCompletion.cancel();
166 } else {
167 futureCompletion.setFailure(future.getCause());
168 }
169 logger.error("Prepare transfer in\n FAILURE without any runner back", future.getCause());
170 }
171 }
172 }
173
174 }