1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package openr66.protocol.test;
22
23 import goldengate.common.database.exception.GoldenGateDatabaseException;
24 import goldengate.common.logging.GgInternalLoggerFactory;
25 import goldengate.common.logging.GgSlf4JLoggerFactory;
26
27 import org.jboss.netty.logging.InternalLoggerFactory;
28
29 import openr66.client.ProgressBarTransfer;
30 import openr66.context.ErrorCode;
31 import openr66.context.R66Result;
32 import openr66.database.DbConstant;
33 import openr66.protocol.configuration.Configuration;
34 import openr66.protocol.networkhandler.NetworkTransaction;
35 import openr66.protocol.utils.ChannelUtils;
36 import openr66.protocol.utils.R66Future;
37
38
39
40
41
42 public class TestProgressBarTransfer extends ProgressBarTransfer {
43
44
45
46
47
48
49
50
51
52
53
54
55
56 public TestProgressBarTransfer(R66Future future, String remoteHost,
57 String filename, String rulename, String fileinfo, boolean isMD5,
58 int blocksize, long id, NetworkTransaction networkTransaction,
59 long callbackdelay) {
60 super(future, remoteHost, filename, rulename, fileinfo, isMD5,
61 blocksize, id, networkTransaction, callbackdelay);
62 }
63
64
65
66
67 @Override
68 public void callBack(int currentBlock, int blocksize) {
69 if (filesize == 0) {
70 System.err.println("Block: "+currentBlock+" BSize: "+blocksize);
71 } else {
72 System.err.println("Block: "+currentBlock+" BSize: "+blocksize+" on "+
73 (int) (Math.ceil(((double)filesize/(double)blocksize))));
74 }
75 }
76
77
78
79
80 @Override
81 public void lastCallBack(boolean success, int currentBlock, int blocksize) {
82 if (filesize == 0) {
83 System.err.println("Status: "+success+" Block: "+currentBlock+" BSize: "+blocksize);
84 } else {
85 System.err.println("Status: "+success+" Block: "+currentBlock+" BSize: "+blocksize+
86 " Size="+filesize);
87 }
88 }
89
90 public static void main(String[] args) {
91 InternalLoggerFactory.setDefaultFactory(new GgSlf4JLoggerFactory(
92 null));
93 if (logger == null) {
94 logger = GgInternalLoggerFactory.getLogger(ProgressBarTransfer.class);
95 }
96 if (! getParams(args, false)) {
97 logger.error("Wrong initialization");
98 if (DbConstant.admin != null && DbConstant.admin.isConnected) {
99 DbConstant.admin.close();
100 }
101 ChannelUtils.stopLogger();
102 System.exit(2);
103 }
104 long time1 = System.currentTimeMillis();
105 R66Future future = new R66Future(true);
106
107 Configuration.configuration.pipelineInit();
108 NetworkTransaction networkTransaction = new NetworkTransaction();
109 try {
110 TestProgressBarTransfer transaction = new TestProgressBarTransfer(future,
111 rhost, localFilename, rule, fileInfo, ismd5, block, idt,
112 networkTransaction, 100);
113 transaction.run();
114 future.awaitUninterruptibly();
115 long time2 = System.currentTimeMillis();
116 long delay = time2 - time1;
117 R66Result result = future.getResult();
118 if (future.isSuccess()) {
119 if (result.runner.getErrorInfo() == ErrorCode.Warning) {
120 logger.warn("Transfer in status:\nWARNED\n "+result.runner.toShortString()+
121 "\n <REMOTE>"+rhost+"</REMOTE>"+
122 "\n <FILEFINAL>" +
123 (result.file != null? result.file.toString()+"</FILEFINAL>" : "no file")
124 +"\n delay: "+delay);
125 } else {
126 logger.info("Transfer in status:\nSUCCESS\n "+result.runner.toShortString()+
127 "\n <REMOTE>"+rhost+"</REMOTE>"+
128 "\n <FILEFINAL>" +
129 (result.file != null? result.file.toString()+"</FILEFINAL>" : "no file")
130 +"\n delay: "+delay);
131 }
132 if (nolog) {
133
134 try {
135 result.runner.delete();
136 } catch (GoldenGateDatabaseException e) {
137 logger.warn("Cannot apply nolog to\n "+result.runner.toShortString(), e);
138 }
139 }
140 } else {
141 if (result == null || result.runner == null) {
142 logger.error("Transfer in\n FAILURE with no Id", future.getCause());
143 networkTransaction.closeAll();
144 System.exit(ErrorCode.Unknown.ordinal());
145 }
146 if (result.runner.getErrorInfo() == ErrorCode.Warning) {
147 logger.warn("Transfer is\n WARNED\n "+result.runner.toShortString()+
148 "\n <REMOTE>"+rhost+"</REMOTE>", future.getCause());
149 networkTransaction.closeAll();
150 System.exit(result.code.ordinal());
151 } else {
152 logger.error("Transfer in\n FAILURE\n "+result.runner.toShortString()+
153 "\n <REMOTE>"+rhost+"</REMOTE>", future.getCause());
154 networkTransaction.closeAll();
155 System.exit(result.code.ordinal());
156 }
157 }
158 } finally {
159 networkTransaction.closeAll();
160
161 if (future.isDone() && future.isSuccess()) {
162 System.exit(0);
163 } else {
164 System.exit(66);
165 }
166 }
167 }
168
169
170 }