1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.waarp.openr66.context.task;
21
22 import org.waarp.common.logging.WaarpLogger;
23 import org.waarp.common.logging.WaarpLoggerFactory;
24 import org.waarp.openr66.context.task.exception.OpenR66RunnerErrorException;
25 import org.waarp.openr66.protocol.localhandler.packet.BusinessRequestPacket;
26 import org.waarp.openr66.protocol.utils.R66Future;
27
28
29
30
31
32
33 public class ExecBusinessTask extends AbstractExecJavaTask {
34
35
36
37
38 private static final WaarpLogger logger =
39 WaarpLoggerFactory.getLogger(ExecBusinessTask.class);
40
41 @Override
42 public final void run() {
43 if (callFromBusiness) {
44
45 String validate = "Validated";
46 if (isToValidate) {
47 logger.debug("DEBUG: {}", fullarg);
48 final String[] args = BLANK.split(fullarg);
49 final String operation = args[0];
50 int newdelay;
51 String argRule;
52 try {
53 newdelay = Integer.parseInt(args[args.length - 1]);
54 argRule = fullarg.substring(fullarg.indexOf(' ') + 1,
55 fullarg.lastIndexOf(' '));
56 } catch (final NumberFormatException e) {
57 newdelay = 0;
58 argRule = fullarg.substring(fullarg.indexOf(' ') + 1);
59 }
60 try {
61 final AbstractTask task =
62 TaskType.getTaskFromIdForBusiness(operation, argRule, newdelay,
63 session);
64 if (task != null) {
65 task.run();
66 task.getFutureCompletion().awaitOrInterruptible();
67 final R66Future future = task.getFutureCompletion();
68 if (!future.isDone() || future.isFailed()) {
69 invalid();
70 return;
71 }
72 if (future.getResult() != null &&
73 future.getResult().getOther() != null) {
74 validate = future.getResult().getOther().toString();
75 }
76 } else {
77 logger.error("ExecBusiness in error, Task invalid: " + operation);
78 invalid();
79 return;
80 }
81 } catch (final OpenR66RunnerErrorException e1) {
82 logger.error("ExecBusiness in error: " + e1);
83 invalid();
84 return;
85 }
86 final BusinessRequestPacket packet =
87 new BusinessRequestPacket(getClass().getName() + " execution ok",
88 0);
89 validate(packet);
90 return;
91 }
92 finalValidate(validate);
93 } else {
94
95 status = 2;
96 fullarg = "EXECJAVA should be used instead";
97 }
98 }
99 }