/
AbstractForker.java
251 lines (197 loc) · 5.44 KB
/
AbstractForker.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.maven;
import java.io.File;
import java.util.List;
import java.util.Map;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* AbstractForker
*
* Base class for forking jetty.
*/
public abstract class AbstractForker extends AbstractLifeCycle
{
private static final Logger LOG = LoggerFactory.getLogger(AbstractForker.class);
protected Map<String, String> env;
protected String jvmArgs;
protected boolean exitVm;
protected boolean stopAtShutdown;
protected List<File> jettyXmlFiles;
protected Map<String, String> jettyProperties;
protected int stopPort;
protected String stopKey;
protected File jettyOutputFile;
protected boolean waitForChild;
protected int maxChildStartChecks = 10; //check up to 10 times for child to start
protected long maxChildStartCheckMs = 200; //wait 200ms between checks
protected File tokenFile;
protected File workDir;
protected Map<String, String> systemProperties;
protected abstract ProcessBuilder createCommand();
protected abstract void redeployWebApp() throws Exception;
public File getWorkDir()
{
return workDir;
}
public void setWorkDir(File workDir)
{
this.workDir = workDir;
}
/**
* @return the systemProperties
*/
public Map<String, String> getSystemProperties()
{
return systemProperties;
}
/**
* Set the systemProperties to set.
* @param systemProperties the systemProperties to set
*/
public void setSystemProperties(Map<String, String> systemProperties)
{
this.systemProperties = systemProperties;
}
public Map<String, String> getEnv()
{
return env;
}
public void setEnv(Map<String, String> env)
{
this.env = env;
}
public String getJvmArgs()
{
return jvmArgs;
}
public void setJvmArgs(String jvmArgs)
{
this.jvmArgs = jvmArgs;
}
public boolean isExitVm()
{
return exitVm;
}
public void setExitVm(boolean exitVm)
{
this.exitVm = exitVm;
}
public boolean isStopAtShutdown()
{
return stopAtShutdown;
}
public void setStopAtShutdown(boolean stopAtShutdown)
{
this.stopAtShutdown = stopAtShutdown;
}
public List<File> getJettyXmlFiles()
{
return jettyXmlFiles;
}
public void setJettyXmlFiles(List<File> jettyXmlFiles)
{
this.jettyXmlFiles = jettyXmlFiles;
}
public Map<String, String> getJettyProperties()
{
return jettyProperties;
}
public void setJettyProperties(Map<String, String> jettyProperties)
{
this.jettyProperties = jettyProperties;
}
public int getStopPort()
{
return stopPort;
}
public void setStopPort(int stopPort)
{
this.stopPort = stopPort;
}
public String getStopKey()
{
return stopKey;
}
public void setStopKey(String stopKey)
{
this.stopKey = stopKey;
}
public File getJettyOutputFile()
{
return jettyOutputFile;
}
public void setJettyOutputFile(File jettyOutputFile)
{
this.jettyOutputFile = jettyOutputFile;
}
public boolean isWaitForChild()
{
return waitForChild;
}
public void setWaitForChild(boolean waitForChild)
{
this.waitForChild = waitForChild;
}
public int getMaxChildtartChecks()
{
return maxChildStartChecks;
}
public void setMaxChildStartChecks(int maxChildStartChecks)
{
this.maxChildStartChecks = maxChildStartChecks;
}
public long getMaxChildStartCheckMs()
{
return maxChildStartCheckMs;
}
public void setMaxChildStartCheckMs(long maxChildStartCheckMs)
{
this.maxChildStartCheckMs = maxChildStartCheckMs;
}
public File getTokenFile()
{
return tokenFile;
}
public void setTokenFile(File tokenFile)
{
this.tokenFile = tokenFile;
}
public void doStart()
throws Exception
{
super.doStart();
//Create the command to fork
ProcessBuilder command = createCommand();
Process process = command.start();
if (waitForChild)
{
//keep executing until the child dies
process.waitFor();
}
else
{
//just wait until the child has started successfully
int attempts = maxChildStartChecks;
while (!tokenFile.exists() && attempts > 0)
{
Thread.sleep(maxChildStartCheckMs);
--attempts;
}
if (attempts <= 0)
LOG.info("Couldn't verify success of child startup");
}
}
}