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.logging.GgInternalLoggerFactory;
24 import goldengate.common.logging.GgSlf4JLoggerFactory;
25 import openr66.client.RecvThroughClient;
26 import openr66.client.RecvThroughHandler;
27 import openr66.context.ErrorCode;
28 import openr66.context.R66Result;
29 import openr66.database.DbConstant;
30 import openr66.protocol.configuration.Configuration;
31 import openr66.protocol.exception.OpenR66ProtocolBusinessException;
32 import openr66.protocol.networkhandler.NetworkTransaction;
33 import openr66.protocol.utils.R66Future;
34
35 import org.jboss.netty.buffer.ChannelBuffer;
36 import org.jboss.netty.logging.InternalLoggerFactory;
37
38
39
40
41
42
43
44 public class TestRecvThroughClient extends RecvThroughClient {
45 public static class TestRecvThroughHandler extends RecvThroughHandler {
46
47
48
49
50 @Override
51 public void writeChannelBuffer(ChannelBuffer buffer)
52 throws OpenR66ProtocolBusinessException {
53 buffer.skipBytes(buffer.readableBytes());
54
55
56
57 }
58
59 }
60
61
62
63
64
65
66
67
68
69
70 public TestRecvThroughClient(R66Future future, TestRecvThroughHandler handler,
71 String remoteHost,
72 String filename, String rulename, String fileinfo, boolean isMD5,
73 int blocksize, NetworkTransaction networkTransaction) {
74 super(future, handler, remoteHost, filename, rulename, fileinfo, isMD5, blocksize,
75 DbConstant.ILLEGALVALUE, networkTransaction);
76 }
77
78
79
80
81 public static void main(String[] args) {
82 InternalLoggerFactory.setDefaultFactory(new GgSlf4JLoggerFactory(null));
83 if (logger == null) {
84 logger = GgInternalLoggerFactory.getLogger(TestRecvThroughHandler.class);
85 }
86 if (! getParams(args, false)) {
87 logger.error("Wrong initialization");
88 if (DbConstant.admin != null && DbConstant.admin.isConnected) {
89 DbConstant.admin.close();
90 }
91 System.exit(1);
92 }
93 Configuration.configuration.pipelineInit();
94 NetworkTransaction networkTransaction = new NetworkTransaction();
95 try {
96 R66Future future = new R66Future(true);
97 TestRecvThroughHandler handler = new TestRecvThroughHandler();
98 TestRecvThroughClient transaction = new TestRecvThroughClient(future,
99 handler,
100 rhost, localFilename, rule, fileInfo, ismd5, block,
101 networkTransaction);
102 long time1 = System.currentTimeMillis();
103 transaction.run();
104 future.awaitUninterruptibly();
105
106 long time2 = System.currentTimeMillis();
107 long delay = time2 - time1;
108 R66Result result = future.getResult();
109 if (future.isSuccess()) {
110 if (result.runner.getErrorInfo() == ErrorCode.Warning) {
111 logger.warn("Warning with Id: " +
112 result.runner.getSpecialId()+" on file: " +
113 (result.file != null? result.file.toString() : "no file")
114 +" delay: "+delay);
115 } else {
116 logger.warn("Success with Id: " +
117 result.runner.getSpecialId()+" on Final file: " +
118 (result.file != null? result.file.toString() : "no file")
119 +" delay: "+delay);
120 }
121 } else {
122 if (result == null || result.runner == null) {
123 logger.warn("Transfer in Error with no Id", future.getCause());
124 networkTransaction.closeAll();
125 System.exit(1);
126 }
127 if (result.runner.getErrorInfo() == ErrorCode.Warning) {
128 logger.warn("Transfer in Warning with Id: " +
129 result.runner.getSpecialId(), future.getCause());
130 networkTransaction.closeAll();
131 System.exit(result.code.ordinal());
132 } else {
133 logger.error("Transfer in Error with Id: " +
134 result.runner.getSpecialId(), future.getCause());
135 networkTransaction.closeAll();
136 System.exit(result.code.ordinal());
137 }
138 }
139 } finally {
140 networkTransaction.closeAll();
141 }
142
143 }
144
145 }