1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.waarp.openr66.client;
21
22 import org.waarp.common.database.exception.WaarpDatabaseException;
23 import org.waarp.common.logging.WaarpLoggerFactory;
24 import org.waarp.openr66.commander.ClientRunner;
25 import org.waarp.openr66.context.ErrorCode;
26 import org.waarp.openr66.context.R66Result;
27 import org.waarp.openr66.context.task.exception.OpenR66RunnerErrorException;
28 import org.waarp.openr66.database.data.DbTaskRunner;
29 import org.waarp.openr66.protocol.configuration.Configuration;
30 import org.waarp.openr66.protocol.exception.OpenR66ProtocolNoConnectionException;
31 import org.waarp.openr66.protocol.exception.OpenR66ProtocolNotYetConnectionException;
32 import org.waarp.openr66.protocol.exception.OpenR66ProtocolPacketException;
33 import org.waarp.openr66.protocol.localhandler.LocalChannelReference;
34 import org.waarp.openr66.protocol.networkhandler.NetworkTransaction;
35 import org.waarp.openr66.protocol.utils.R66Future;
36
37
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
88 public RecvThroughClient(final R66Future future,
89 final RecvThroughHandler handler,
90 final String remoteHost, final String filename,
91 final String rulename, final String fileinfo,
92 final boolean isMD5, final int blocksize,
93 final long id,
94 final NetworkTransaction networkTransaction) {
95
96 super(RecvThroughClient.class, future, filename, rulename, fileinfo, isMD5,
97 remoteHost, blocksize, id, null);
98 this.networkTransaction = networkTransaction;
99 this.handler = handler;
100 }
101
102
103
104
105
106
107 @Override
108 public void run() {
109 if (logger == null) {
110 logger = WaarpLoggerFactory.getLogger(RecvThroughClient.class);
111 }
112 final DbTaskRunner taskRunner = initRequest();
113 if (taskRunner == null) {
114
115 return;
116 }
117 try {
118 final ClientRunner runner =
119 new ClientRunner(networkTransaction, taskRunner, future);
120 runner.setRecvThroughHandler(handler);
121 OpenR66ProtocolNotYetConnectionException exc = null;
122 for (int i = 0; i < Configuration.RETRYNB; i++) {
123 try {
124 runner.runTransfer();
125 exc = null;
126 break;
127 } catch (final OpenR66RunnerErrorException e) {
128 logger.error("Cannot Transfer", e);
129 future.setResult(
130 new R66Result(e, null, true, ErrorCode.Internal, taskRunner));
131 future.setFailure(e);
132 return;
133 } catch (final OpenR66ProtocolNoConnectionException e) {
134 logger.error("Cannot Connect", e);
135 future.setResult(
136 new R66Result(e, null, true, ErrorCode.ConnectionImpossible,
137 taskRunner));
138 finalizeInErrorTransferRequest(runner, taskRunner,
139 ErrorCode.ConnectionImpossible);
140 future.setFailure(e);
141 return;
142 } catch (final OpenR66ProtocolPacketException e) {
143 logger.error("Bad Protocol", e);
144 future.setResult(new R66Result(e, null, true, ErrorCode.TransferError,
145 taskRunner));
146 future.setFailure(e);
147 return;
148 } catch (final OpenR66ProtocolNotYetConnectionException e) {
149 logger.debug("Not Yet Connected", e);
150 exc = e;
151 }
152 }
153 if (exc != null) {
154 taskRunner.setLocalChannelReference(new LocalChannelReference());
155 logger.error("Cannot Connect", exc);
156 future.setResult(
157 new R66Result(exc, null, true, ErrorCode.ConnectionImpossible,
158 taskRunner));
159 future.setFailure(exc);
160 }
161 } finally {
162 if (taskRunner != null) {
163 if (future.isFailed() || nolog) {
164 try {
165 taskRunner.delete();
166 } catch (final WaarpDatabaseException ignored) {
167
168 }
169 }
170 }
171 }
172 }
173
174 }