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 goldengate.common.database.exception.GoldenGateDatabaseException;
24 import goldengate.common.logging.GgInternalLoggerFactory;
25 import openr66.commander.ClientRunner;
26 import openr66.context.ErrorCode;
27 import openr66.context.R66Result;
28 import openr66.context.task.exception.OpenR66RunnerErrorException;
29 import openr66.database.data.DbTaskRunner;
30 import openr66.protocol.configuration.Configuration;
31 import openr66.protocol.exception.OpenR66ProtocolNoConnectionException;
32 import openr66.protocol.exception.OpenR66ProtocolNotYetConnectionException;
33 import openr66.protocol.exception.OpenR66ProtocolPacketException;
34 import openr66.protocol.localhandler.LocalChannelReference;
35 import openr66.protocol.networkhandler.NetworkTransaction;
36 import openr66.protocol.test.TestRecvThroughClient;
37 import openr66.protocol.utils.R66Future;
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 public class RecvThroughClient extends AbstractTransfer {
73 protected final NetworkTransaction networkTransaction;
74 protected LocalChannelReference localChannelReference;
75 protected final RecvThroughHandler handler;
76
77
78
79
80
81
82
83
84
85
86
87 public RecvThroughClient(R66Future future, RecvThroughHandler handler, String remoteHost,
88 String filename, String rulename, String fileinfo, boolean isMD5,
89 int blocksize, long id, NetworkTransaction networkTransaction) {
90
91 super(RecvThroughClient.class,
92 future, filename, rulename, fileinfo, isMD5, remoteHost, blocksize, id, null);
93 this.networkTransaction = networkTransaction;
94 this.handler = handler;
95 }
96
97
98
99
100 public void run() {
101 if (logger == null) {
102 logger = GgInternalLoggerFactory.getLogger(RecvThroughClient.class);
103 }
104 DbTaskRunner taskRunner = this.initRequest();
105 try {
106 ClientRunner runner = new ClientRunner(networkTransaction, taskRunner, future);
107 runner.setRecvThroughHandler(handler);
108 OpenR66ProtocolNotYetConnectionException exc = null;
109 for (int i = 0; i < Configuration.RETRYNB; i++) {
110 try {
111 runner.runTransfer();
112 exc = null;
113 break;
114 } catch (OpenR66RunnerErrorException e) {
115 logger.error("Cannot Transfer", e);
116 future.setResult(new R66Result(e, null, true,
117 ErrorCode.Internal, taskRunner));
118 future.setFailure(e);
119 return;
120 } catch (OpenR66ProtocolNoConnectionException e) {
121 logger.error("Cannot Connect", e);
122 future.setResult(new R66Result(e, null, true,
123 ErrorCode.ConnectionImpossible, taskRunner));
124 future.setFailure(e);
125 return;
126 } catch (OpenR66ProtocolPacketException e) {
127 logger.error("Bad Protocol", e);
128 future.setResult(new R66Result(e, null, true,
129 ErrorCode.TransferError, taskRunner));
130 future.setFailure(e);
131 return;
132 } catch (OpenR66ProtocolNotYetConnectionException e) {
133 logger.debug("Not Yet Connected", e);
134 exc = e;
135 continue;
136 }
137 }
138 if (exc!= null) {
139 taskRunner.setLocalChannelReference(new LocalChannelReference());
140 logger.error("Cannot Connect", exc);
141 future.setResult(new R66Result(exc, null, true,
142 ErrorCode.ConnectionImpossible, taskRunner));
143 future.setFailure(exc);
144 return;
145 }
146 } finally {
147 if (taskRunner != null) {
148 if (future.isFailed() || nolog) {
149 try {
150 taskRunner.delete();
151 } catch (GoldenGateDatabaseException e) {
152 }
153 }
154 }
155 }
156 }
157
158 }