1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package openr66.client;
22
23 import java.sql.Timestamp;
24
25 import goldengate.common.database.data.AbstractDbData;
26 import goldengate.common.database.exception.GoldenGateDatabaseException;
27 import goldengate.common.logging.GgInternalLoggerFactory;
28 import goldengate.common.logging.GgSlf4JLoggerFactory;
29 import openr66.context.ErrorCode;
30 import openr66.context.R66Result;
31 import openr66.database.DbConstant;
32 import openr66.database.data.DbTaskRunner;
33 import openr66.protocol.exception.OpenR66DatabaseGlobalException;
34 import openr66.protocol.utils.ChannelUtils;
35 import openr66.protocol.utils.R66Future;
36
37 import org.jboss.netty.logging.InternalLoggerFactory;
38
39
40
41
42
43
44
45 public class SubmitTransfer extends AbstractTransfer {
46
47 public SubmitTransfer(R66Future future, String remoteHost,
48 String filename, String rulename, String fileinfo, boolean isMD5, int blocksize, long id,
49 Timestamp starttime) {
50 super(SubmitTransfer.class,
51 future, filename, rulename, fileinfo, isMD5, remoteHost, blocksize, id, starttime);
52 }
53
54 public void run() {
55 if (logger == null) {
56 logger = GgInternalLoggerFactory.getLogger(SubmitTransfer.class);
57 }
58 DbTaskRunner taskRunner = this.initRequest();
59 taskRunner.changeUpdatedInfo(AbstractDbData.UpdatedInfo.TOSUBMIT);
60 try {
61 taskRunner.update();
62 } catch (GoldenGateDatabaseException e) {
63 logger.debug("Cannot prepare task", e);
64 R66Result result = new R66Result(new OpenR66DatabaseGlobalException(e), null, true,
65 ErrorCode.Internal, taskRunner);
66 future.setResult(result);
67 future.setFailure(e);
68 return;
69 }
70 R66Result result = new R66Result(null,false,ErrorCode.InitOk, taskRunner);
71 future.setResult(result);
72 future.setSuccess();
73 }
74
75
76
77
78
79
80
81
82 public static void main(String[] args) {
83 InternalLoggerFactory.setDefaultFactory(new GgSlf4JLoggerFactory(null));
84 if (logger == null) {
85 logger = GgInternalLoggerFactory.getLogger(SubmitTransfer.class);
86 }
87 if (! getParams(args, true)) {
88 logger.error("Wrong initialization");
89 if (DbConstant.admin != null && DbConstant.admin.isConnected) {
90 DbConstant.admin.close();
91 }
92 ChannelUtils.stopLogger();
93 System.exit(1);
94 }
95 R66Future future = new R66Future(true);
96 SubmitTransfer transaction = new SubmitTransfer(future,
97 rhost, localFilename, rule, fileInfo, ismd5, block, DbConstant.ILLEGALVALUE, ttimestart);
98 transaction.run();
99 future.awaitUninterruptibly();
100 DbTaskRunner runner = future.getResult().runner;
101 if (future.isSuccess()) {
102 logger.warn("Prepare transfer in\n SUCCESS\n "+runner.toShortString()+
103 "<REMOTE>"+rhost+"</REMOTE>");
104 } else {
105 if (runner != null) {
106 logger.error("Prepare transfer in\n FAILURE\n "+runner.toShortString()+
107 "<REMOTE>"+rhost+"</REMOTE>", future.getCause());
108 } else {
109 logger.error("Prepare transfer in\n FAILURE\n ", future.getCause());
110 }
111 DbConstant.admin.close();
112 ChannelUtils.stopLogger();
113 System.exit(future.getResult().code.ordinal());
114 }
115 DbConstant.admin.close();
116 }
117
118 }