1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.kfs.sys.context;
20
21 import java.util.concurrent.Executor;
22 import java.util.concurrent.Executors;
23
24
25
26
27 public class BatchStepLauncher implements Runnable {
28 private static final String LOG_PREFIX = BatchStepLauncher.class.getName() +": ";
29 private static final String batchContainerStep = "batchContainerStep";
30
31 private static BatchStepTriggerParameters batchStepTriggerParms;
32
33
34
35
36
37
38
39
40
41
42
43 public static void main(String[] args) {
44
45
46 checkArguments(args);
47
48
49 startBatchContainer();
50
51
52
53 confirmStartUp();
54
55
56 executeSteps(args);
57
58
59 }
60
61
62
63
64 @Override
65 public void run() {
66 String[] args = new String[2];
67 args[0] = batchContainerStep;
68 args[1] = (batchStepTriggerParms != null ? batchStepTriggerParms.getJobName(): "unknown");
69
70 BatchStepRunner.main(args);
71 }
72
73
74
75
76
77
78 private static void checkArguments(String[] args) {
79 logToOut("checking arguments");
80
81 batchStepTriggerParms = new BatchStepTriggerParameters(args);
82
83 logToOut("received valid arguments");
84 }
85
86
87
88
89 private static void startBatchContainer() {
90 logToOut("starting the batch container");
91 Executor executor = Executors.newCachedThreadPool();
92
93 BatchStepLauncher batchStepLauncher = new BatchStepLauncher();
94 executor.execute(batchStepLauncher);
95 }
96
97
98
99
100 private static void confirmStartUp() {
101 logToOut("confirming batch container start up");
102
103 while (!batchStepTriggerParms.getBatchContainerDirectory().isBatchContainerRunning()) {
104 logToOut("waiting for the batch container to start up");
105 try {
106 Thread.sleep(batchStepTriggerParms.getSleepInterval());
107 }
108 catch (InterruptedException e) {
109 throw new RuntimeException("BatchStepLauncher encountered interrupt exception while trying to wait for the batch container to start up", e);
110 }
111 }
112
113 logToOut("batch container is running");
114 }
115
116
117
118
119
120
121 private static void executeSteps(String[] args) {
122 logToOut("executing step(s)");
123
124 BatchStepTrigger.main(args);
125
126 logToOut("finished executing step(s)");
127 }
128
129
130
131
132
133 private static void removeBatchContainerSemaphore() {
134 logToOut("removing batch container semaphore file");
135
136 if (batchStepTriggerParms.getBatchContainerDirectory().isBatchContainerRunning()) {
137 batchStepTriggerParms.getBatchContainerDirectory().removeBatchContainerSemaphore();
138 }
139
140 logToOut("batch container semaphore file has been removed");
141 }
142
143
144
145
146
147
148 private static void logToOut(String statement) {
149 System.out.println(LOG_PREFIX + statement);
150 }
151 }