Revision d8a13c97
Added by Andreas Müller over 2 years ago
src/main/java/eu/etaxonomy/cdm/server/Bootloader.java | ||
---|---|---|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
9 |
|
|
10 | 9 |
package eu.etaxonomy.cdm.server; |
11 | 10 |
|
12 | 11 |
import static eu.etaxonomy.cdm.server.AssumedMemoryRequirements.KB; |
... | ... | |
75 | 74 |
import eu.etaxonomy.cdm.server.logging.LoggingConfigurator; |
76 | 75 |
import eu.etaxonomy.cdm.server.win32service.Win32Service; |
77 | 76 |
|
78 |
|
|
79 | 77 |
/** |
80 | 78 |
* A bootstrap class for starting Jetty Runner using an embedded war. |
81 | 79 |
* |
... | ... | |
158 | 156 |
|
159 | 157 |
/* end of singleton implementation */ |
160 | 158 |
|
161 |
|
|
162 |
/** |
|
163 |
* @param input |
|
164 |
* @param output |
|
165 |
* @param bufferSize |
|
166 |
* @return |
|
167 |
* @throws IOException |
|
168 |
*/ |
|
169 | 159 |
public int writeStreamTo(final InputStream input, final OutputStream output, int bufferSize) throws IOException { |
170 | 160 |
int available = Math.min(input.available(), 256 * KB); |
171 | 161 |
byte[] buffer = new byte[Math.max(bufferSize, available)]; |
... | ... | |
179 | 169 |
return answer; |
180 | 170 |
} |
181 | 171 |
|
182 |
|
|
183 |
|
|
184 | 172 |
public void parseCommandOptions(String[] args) throws ParseException { |
185 | 173 |
CommandLineParser parser = new GnuParser(); |
186 | 174 |
|
... | ... | |
195 | 183 |
} |
196 | 184 |
} |
197 | 185 |
|
198 |
|
|
199 | 186 |
/** |
200 | 187 |
* Finds the named war file either in the resources known to the class loader |
201 | 188 |
* or in a target folder if the bootloader is started from within a maven project. |
... | ... | |
311 | 298 |
public String getCdmlibServicesLastModified() { |
312 | 299 |
return cdmlibServicesLastModified; |
313 | 300 |
} |
314 |
/** |
|
315 |
* @param extractWar |
|
316 |
* @return |
|
317 |
* @throws IOException |
|
318 |
*/ |
|
301 |
|
|
319 | 302 |
private File unzip(File extractWar) throws IOException { |
320 | 303 |
UnzipUtility unzip = new UnzipUtility(); |
321 | 304 |
|
... | ... | |
325 | 308 |
return destDirectory; |
326 | 309 |
} |
327 | 310 |
|
328 |
|
|
329 |
|
|
330 | 311 |
/** |
331 | 312 |
* MAIN METHOD |
332 | 313 |
* |
... | ... | |
336 | 317 |
public static void main(String[] args) throws Exception { |
337 | 318 |
|
338 | 319 |
Bootloader bootloader = Bootloader.getBootloader(); |
339 |
|
|
340 | 320 |
bootloader.parseCommandOptions(args); |
341 |
|
|
342 | 321 |
bootloader.startServer(); |
343 | 322 |
} |
344 | 323 |
|
345 |
|
|
346 |
|
|
347 | 324 |
public void startServer() throws IOException, |
348 | 325 |
FileNotFoundException, Exception, InterruptedException { |
349 | 326 |
|
src/main/java/eu/etaxonomy/cdm/server/CommandOptions.java | ||
---|---|---|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
9 |
|
|
10 | 9 |
package eu.etaxonomy.cdm.server; |
11 | 10 |
|
12 | 11 |
import org.apache.commons.cli.Option; |
src/main/java/eu/etaxonomy/cdm/server/JvmManager.java | ||
---|---|---|
22 | 22 |
*/ |
23 | 23 |
public class JvmManager { |
24 | 24 |
|
25 |
public static final Logger logger = Logger.getLogger(JvmManager.class); |
|
26 |
|
|
25 | 27 |
// Java > 8 |
26 | 28 |
private static final String SUFFIX_META = "Metaspace"; |
27 | 29 |
|
28 |
public static final Logger logger = Logger.getLogger(JvmManager.class); |
|
29 |
|
|
30 | 30 |
public static MemoryUsage getMetaSpaceUsage(){ |
31 | 31 |
return getMemoryPoolUsage(SUFFIX_META); |
32 | 32 |
} |
... | ... | |
49 | 49 |
|
50 | 50 |
public static MemoryUsage getHeapMemoryUsage(){ |
51 | 51 |
|
52 |
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); |
|
53 |
if(memoryMXBean != null){ |
|
54 |
logger.debug("NonHeapMemoryUsage: "+memoryMXBean.getHeapMemoryUsage()); |
|
55 |
return memoryMXBean.getHeapMemoryUsage(); |
|
56 |
} |
|
57 |
return null; |
|
52 |
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); |
|
53 |
if(memoryMXBean != null){ |
|
54 |
logger.debug("NonHeapMemoryUsage: "+memoryMXBean.getHeapMemoryUsage()); |
|
55 |
return memoryMXBean.getHeapMemoryUsage(); |
|
58 | 56 |
} |
57 |
return null; |
|
58 |
} |
|
59 | 59 |
|
60 | 60 |
/** |
61 | 61 |
* |
src/main/java/eu/etaxonomy/cdm/server/OsChecker.java | ||
---|---|---|
11 | 11 |
/** |
12 | 12 |
* @author andreas |
13 | 13 |
* @date Jul 17, 2012 |
14 |
* |
|
15 | 14 |
*/ |
16 | 15 |
public class OsChecker { |
17 | 16 |
|
... | ... | |
35 | 34 |
} |
36 | 35 |
|
37 | 36 |
public boolean isLinux() { |
38 |
if (isMac()) |
|
37 |
if (isMac()) {
|
|
39 | 38 |
return false; |
39 |
} |
|
40 | 40 |
try { |
41 | 41 |
Runtime.getRuntime().exec(new String[] { "sh", "-c", "ls" }).waitFor(); |
42 | 42 |
return true; |
src/main/java/eu/etaxonomy/cdm/server/UnzipUtility.java | ||
---|---|---|
23 | 23 |
* This utility extracts files and directories of a standard zip file to |
24 | 24 |
* a destination directory. |
25 | 25 |
* @author www.codejava.net |
26 |
* |
|
27 | 26 |
*/ |
28 | 27 |
public class UnzipUtility { |
29 | 28 |
|
30 |
|
|
31 | 29 |
private static final Logger logger = Logger.getLogger(UnzipUtility.class); |
32 | 30 |
|
33 | 31 |
/** |
src/main/java/eu/etaxonomy/cdm/server/instance/CdmInstance.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2009 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
1 | 9 |
package eu.etaxonomy.cdm.server.instance; |
2 | 10 |
|
3 | 11 |
import java.lang.reflect.InvocationTargetException; |
... | ... | |
19 | 27 |
|
20 | 28 |
import com.mchange.v2.c3p0.DataSources; |
21 | 29 |
|
22 |
|
|
23 | 30 |
public class CdmInstance implements Listener { |
24 | 31 |
|
25 | 32 |
private static final Logger logger = Logger.getLogger(CdmInstance.class); |
... | ... | |
39 | 46 |
|
40 | 47 |
public List<String> getProblems() { |
41 | 48 |
if (problems == null) { |
42 |
problems = new ArrayList<String>();
|
|
49 |
problems = new ArrayList<>(); |
|
43 | 50 |
} |
44 | 51 |
return problems; |
45 | 52 |
} |
... | ... | |
52 | 59 |
return status.equals(Status.error); |
53 | 60 |
} |
54 | 61 |
|
55 |
/** |
|
56 |
* @param status |
|
57 |
* the status to set |
|
58 |
*/ |
|
59 | 62 |
public void setStatus(Status status) { |
60 | 63 |
this.status = status; |
61 | 64 |
} |
62 |
|
|
63 |
/** |
|
64 |
* @return the status |
|
65 |
*/ |
|
66 | 65 |
public Status getStatus() { |
67 | 66 |
return status; |
68 | 67 |
} |
... | ... | |
80 | 79 |
public Configuration getConfiguration() { |
81 | 80 |
return configuration; |
82 | 81 |
} |
83 |
|
|
84 |
/** |
|
85 |
* @return the configuration |
|
86 |
*/ |
|
87 | 82 |
public void setConfiguration(Configuration configuration) { |
88 | 83 |
this.configuration = configuration; |
89 | 84 |
} |
... | ... | |
94 | 89 |
public WebAppContext getWebAppContext() { |
95 | 90 |
return webAppContext; |
96 | 91 |
} |
97 |
|
|
98 |
/** |
|
99 |
* @return the webAppContext |
|
100 |
*/ |
|
101 | 92 |
public void setWebAppContext(WebAppContext webAppContext) { |
102 | 93 |
this.webAppContext = webAppContext; |
103 | 94 |
} |
... | ... | |
140 | 131 |
// never override Status.removed !!! |
141 | 132 |
setStatus(Status.stopped); |
142 | 133 |
} |
143 |
|
|
144 | 134 |
} |
145 | 135 |
|
146 | 136 |
@Override |
... | ... | |
199 | 189 |
|
200 | 190 |
public boolean bindJndiDataSource() { |
201 | 191 |
try { |
202 |
Class<DataSource> dsCass = (Class<DataSource>) Thread.currentThread().getContextClassLoader().loadClass("com.mchange.v2.c3p0.ComboPooledDataSource");
|
|
203 |
DataSource datasource = dsCass.newInstance();
|
|
204 |
dsCass.getMethod("setDriverClass", new Class[] {String.class}).invoke(datasource, new Object[] {configuration.getDriverClass()});
|
|
205 |
dsCass.getMethod("setJdbcUrl", new Class[] {String.class}).invoke(datasource, new Object[] {configuration.getDataSourceUrl()});
|
|
206 |
dsCass.getMethod("setUser", new Class[] {String.class}).invoke(datasource, new Object[] {configuration.getUsername()});
|
|
207 |
dsCass.getMethod("setPassword", new Class[] {String.class}).invoke(datasource, new Object[] {configuration.getPassword()});
|
|
192 |
Class<DataSource> datasourceClass = (Class<DataSource>) Thread.currentThread().getContextClassLoader().loadClass("com.mchange.v2.c3p0.ComboPooledDataSource");
|
|
193 |
DataSource datasource = datasourceClass.newInstance();
|
|
194 |
datasourceClass.getMethod("setDriverClass", new Class[] {String.class}).invoke(datasource, new Object[] {configuration.getDriverClass()});
|
|
195 |
datasourceClass.getMethod("setJdbcUrl", new Class[] {String.class}).invoke(datasource, new Object[] {configuration.getDataSourceUrl()});
|
|
196 |
datasourceClass.getMethod("setUser", new Class[] {String.class}).invoke(datasource, new Object[] {configuration.getUsername()});
|
|
197 |
datasourceClass.getMethod("setPassword", new Class[] {String.class}).invoke(datasource, new Object[] {configuration.getPassword()});
|
|
208 | 198 |
|
209 | 199 |
Connection connection = null; |
210 | 200 |
String sqlerror = null; |
... | ... | |
212 | 202 |
connection = datasource.getConnection(); |
213 | 203 |
connection.close(); |
214 | 204 |
} catch (SQLException e) { |
215 |
sqlerror = "Can not establish connection to data base " + configuration.getDataSourceUrl() + " [sql error code: "+ e.getSQLState() + "]";
|
|
205 |
sqlerror = "Can not establish connection to database " + configuration.getDataSourceUrl() + " [sql error code: "+ e.getSQLState() + "]"; |
|
216 | 206 |
getProblems().add(sqlerror); |
217 | 207 |
setStatus(Status.error); |
218 | 208 |
if(connection != null){ |
src/main/java/eu/etaxonomy/cdm/server/instance/Configuration.java | ||
---|---|---|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
9 |
|
|
10 | 9 |
package eu.etaxonomy.cdm.server.instance; |
11 | 10 |
|
12 | 11 |
import org.apache.log4j.Logger; |
... | ... | |
14 | 13 |
/** |
15 | 14 |
* @author a.kohlbecker |
16 | 15 |
* @date May 10, 2013 |
17 |
* |
|
18 | 16 |
*/ |
19 | 17 |
public class Configuration { |
20 | 18 |
|
21 |
public static final Logger logger = Logger.getLogger(Configuration.class);
|
|
19 |
private static final Logger logger = Logger.getLogger(Configuration.class);
|
|
22 | 20 |
|
23 | 21 |
private String instanceName; |
24 | 22 |
private String password; |
... | ... | |
41 | 39 |
public String getPassword() { |
42 | 40 |
return password; |
43 | 41 |
} |
44 |
|
|
45 | 42 |
public void setPassword(String password) { |
46 | 43 |
this.password = password; |
47 | 44 |
} |
... | ... | |
49 | 46 |
public String getUsername() { |
50 | 47 |
return username; |
51 | 48 |
} |
52 |
|
|
53 | 49 |
public void setUsername(String username) { |
54 | 50 |
this.username = username; |
55 | 51 |
} |
... | ... | |
57 | 53 |
public String getDataSourceUrl() { |
58 | 54 |
return dataSourceUrl; |
59 | 55 |
} |
60 |
|
|
61 | 56 |
public void setDataSourceUrl(String url) { |
62 | 57 |
this.dataSourceUrl = url; |
63 | 58 |
} |
... | ... | |
65 | 60 |
public String getDriverClass() { |
66 | 61 |
return driverClass; |
67 | 62 |
} |
68 |
|
|
69 | 63 |
public void setDriverClass(String driverClass) { |
70 | 64 |
this.driverClass = driverClass; |
71 | 65 |
} |
src/main/java/eu/etaxonomy/cdm/server/instance/DataSourcePropertyParser.java | ||
---|---|---|
30 | 30 |
/** |
31 | 31 |
* @author a.kohlbecker |
32 | 32 |
* @date 30.03.2010 |
33 |
* |
|
34 | 33 |
*/ |
35 | 34 |
public class DataSourcePropertyParser { |
36 | 35 |
|
... | ... | |
39 | 38 |
public static List<Configuration> parseDataSourceConfigs(File datasourcesFile){ |
40 | 39 |
|
41 | 40 |
logger.info("loading bean definition file: " + datasourcesFile.getAbsolutePath()); |
42 |
List<Configuration> configList = new ArrayList<Configuration>();
|
|
43 |
Set<String> idSet = new HashSet<String>();
|
|
41 |
List<Configuration> configList = new ArrayList<>(); |
|
42 |
Set<String> idSet = new HashSet<>(); |
|
44 | 43 |
try { |
45 | 44 |
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
46 | 45 |
Document doc = builder.parse(datasourcesFile); |
... | ... | |
80 | 79 |
} else { |
81 | 80 |
logger.error("instance with name '"+ conf.getInstanceName() + "' alreaddy exists"); |
82 | 81 |
} |
83 |
|
|
84 | 82 |
} |
85 |
|
|
86 | 83 |
} catch (SAXException e) { |
87 | 84 |
// TODO Auto-generated catch block |
88 | 85 |
e.printStackTrace(); |
... | ... | |
108 | 105 |
} |
109 | 106 |
return null; |
110 | 107 |
} |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
} |
|
108 |
} |
src/main/java/eu/etaxonomy/cdm/server/instance/InstanceManager.java | ||
---|---|---|
106 | 106 |
// instance.bindJndiDataSource(); |
107 | 107 |
if (!instance.bindJndiDataSource()) { |
108 | 108 |
// a problem with the datasource occurred skip this webapp |
109 |
logger.error("a problem with the datasource occurred -> aboarding startup of /" + instance.getName());
|
|
109 |
logger.error("a problem with the datasource occurred -> aborting startup of /" + instance.getName());
|
|
110 | 110 |
instance.setStatus(Status.error); |
111 | 111 |
} else { |
112 | 112 |
// ready for startup add to queue |
src/main/java/eu/etaxonomy/cdm/server/instance/StartupQueue.java | ||
---|---|---|
30 | 30 |
|
31 | 31 |
private final Logger logger = Logger.getLogger(InstanceManager.class); |
32 | 32 |
|
33 |
Set<CdmInstance> instancesStartingUp = new HashSet<CdmInstance>();
|
|
33 |
Set<CdmInstance> instancesStartingUp = new HashSet<>(); |
|
34 | 34 |
|
35 | 35 |
private int parallelStartUps = 1; |
36 | 36 |
|
37 |
/** |
|
38 |
* @return the parallelStartUps |
|
39 |
*/ |
|
40 | 37 |
public int getParallelStartUps() { |
41 | 38 |
return parallelStartUps; |
42 | 39 |
} |
43 |
|
|
44 |
/** |
|
45 |
* @param parallelStartUps |
|
46 |
* the parallelStartUps to set |
|
47 |
*/ |
|
48 | 40 |
public void setParallelStartUps(int parallelStartUps) { |
49 | 41 |
this.parallelStartUps = parallelStartUps; |
50 | 42 |
} |
51 | 43 |
|
52 |
/** |
|
53 |
* {@inheritDoc} |
|
54 |
*/ |
|
55 | 44 |
@Override |
56 | 45 |
public boolean add(CdmInstance e) { |
57 | 46 |
boolean result = super.add(e); |
... | ... | |
59 | 48 |
return result; |
60 | 49 |
} |
61 | 50 |
|
62 |
/** |
|
63 |
* {@inheritDoc} |
|
64 |
*/ |
|
65 | 51 |
@Override |
66 | 52 |
public void addFirst(CdmInstance e) { |
67 | 53 |
super.addFirst(e); |
68 | 54 |
registerAt(e); |
69 | 55 |
} |
70 | 56 |
|
71 |
/** |
|
72 |
* {@inheritDoc} |
|
73 |
*/ |
|
74 | 57 |
@Override |
75 | 58 |
public void addLast(CdmInstance e) { |
76 | 59 |
super.addLast(e); |
... | ... | |
89 | 72 |
startNextInstances(); |
90 | 73 |
} |
91 | 74 |
|
92 |
/** |
|
93 |
* |
|
94 |
*/ |
|
95 | 75 |
private void startNextInstances() { |
96 | 76 |
logger.debug("startNextInstances()"); |
97 | 77 |
while(instancesStartingUp.size() < parallelStartUps && !isEmpty()) { |
... | ... | |
103 | 83 |
} |
104 | 84 |
} |
105 | 85 |
|
106 |
/** |
|
107 |
* @param e |
|
108 |
*/ |
|
109 | 86 |
@SuppressWarnings("unused") |
110 | 87 |
private void registerAt(CdmInstance e) { |
111 | 88 |
new InstanceListener(e); |
... | ... | |
122 | 99 |
instance.getWebAppContext().addLifeCycleListener(this); |
123 | 100 |
} |
124 | 101 |
|
125 |
/** |
|
126 |
* {@inheritDoc} |
|
127 |
*/ |
|
128 | 102 |
@Override |
129 | 103 |
public void lifeCycleStarting(LifeCycle event) { |
130 | 104 |
// IGNORE |
131 | 105 |
} |
132 | 106 |
|
133 |
/** |
|
134 |
* {@inheritDoc} |
|
135 |
*/ |
|
136 | 107 |
@Override |
137 | 108 |
public void lifeCycleStarted(LifeCycle event) { |
138 | 109 |
notifyInstanceStartedUp(instance); |
... | ... | |
142 | 113 |
instance = null; |
143 | 114 |
} |
144 | 115 |
|
145 |
/** |
|
146 |
* {@inheritDoc} |
|
147 |
*/ |
|
148 | 116 |
@Override |
149 | 117 |
public void lifeCycleFailure(LifeCycle event, Throwable cause) { |
150 | 118 |
notifyInstanceFailed(instance); |
... | ... | |
154 | 122 |
instance = null; |
155 | 123 |
} |
156 | 124 |
|
157 |
/** |
|
158 |
* {@inheritDoc} |
|
159 |
*/ |
|
160 | 125 |
@Override |
161 | 126 |
public void lifeCycleStopping(LifeCycle event) { |
162 | 127 |
// IGNORE |
163 | 128 |
} |
164 | 129 |
|
165 |
/** |
|
166 |
* {@inheritDoc} |
|
167 |
*/ |
|
168 | 130 |
@Override |
169 | 131 |
public void lifeCycleStopped(LifeCycle event) { |
170 | 132 |
// IGNORE |
171 | 133 |
} |
172 |
|
|
173 | 134 |
} |
174 | 135 |
|
175 | 136 |
class StartupThread extends Thread{ |
... | ... | |
213 | 174 |
} finally { |
214 | 175 |
MDC.clear(); |
215 | 176 |
} |
216 |
|
|
217 | 177 |
} |
218 |
|
|
219 | 178 |
} |
220 |
|
|
221 |
} |
|
179 |
} |
src/main/java/eu/etaxonomy/cdm/server/instance/Status.java | ||
---|---|---|
3 | 3 |
import org.eclipse.jetty.util.component.LifeCycle; |
4 | 4 |
|
5 | 5 |
public enum Status{ |
6 |
|
|
6 | 7 |
/** |
7 | 8 |
* New instances are uninitialized |
8 | 9 |
*/ |
src/main/java/eu/etaxonomy/cdm/server/jsvc/ServiceWrapper.java | ||
---|---|---|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
9 |
|
|
10 | 9 |
package eu.etaxonomy.cdm.server.jsvc; |
11 | 10 |
|
12 | 11 |
import eu.etaxonomy.cdm.server.Bootloader; |
13 | 12 |
|
14 | 13 |
public class ServiceWrapper { |
15 | 14 |
|
16 |
|
|
17 | 15 |
/** |
18 | 16 |
* Method required by jsvc. jsvc is being used by the linux start up script |
19 | 17 |
* @param args |
... | ... | |
49 | 47 |
public void destroy() throws Exception { |
50 | 48 |
Bootloader.getBootloader().getServer().destroy(); |
51 | 49 |
} |
52 |
|
|
53 |
|
|
54 |
} |
|
50 |
} |
src/main/java/eu/etaxonomy/cdm/server/logging/InstanceLogWrapper.java | ||
---|---|---|
24 | 24 |
*/ |
25 | 25 |
public class InstanceLogWrapper extends HandlerWrapper { |
26 | 26 |
|
27 |
|
|
28 | 27 |
/** |
29 | 28 |
* Key under which the instance name stored in the |
30 | 29 |
* Mapped Diagnostic Context (MDC) |
... | ... | |
38 | 37 |
} |
39 | 38 |
|
40 | 39 |
@Override |
41 |
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException |
|
42 |
{ |
|
40 |
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) |
|
41 |
throws IOException, ServletException { |
|
42 |
|
|
43 | 43 |
// Collect Info for NDC/MDC |
44 | 44 |
MDC.put(CDM_INSTANCE, instanceName); |
45 |
try |
|
46 |
{ |
|
45 |
try { |
|
47 | 46 |
super.handle(target, baseRequest, request, response); |
48 | 47 |
} |
49 |
finally |
|
50 |
{ |
|
48 |
finally { |
|
51 | 49 |
// Pop info out / clear the NDC/MDC |
52 | 50 |
MDC.clear(); |
53 | 51 |
} |
54 | 52 |
} |
55 |
|
|
56 |
} |
|
53 |
} |
src/main/java/eu/etaxonomy/cdm/server/win32service/CDMServerWrapperListener.java | ||
---|---|---|
7 | 7 |
* ------------------------------------------------------------------------ |
8 | 8 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
9 | 9 |
* you may not use this file except in compliance with the License. |
10 |
* You may obtain a copy of the License at
|
|
10 |
* You may obtain a copy of the License at |
|
11 | 11 |
* http://www.apache.org/licenses/LICENSE-2.0 |
12 | 12 |
* Unless required by applicable law or agreed to in writing, software |
13 | 13 |
* distributed under the License is distributed on an "AS IS" BASIS, |
... | ... | |
16 | 16 |
* limitations under the License. |
17 | 17 |
* ======================================================================== |
18 | 18 |
*/ |
19 |
|
|
20 | 19 |
package eu.etaxonomy.cdm.server.win32service; |
21 | 20 |
|
22 | 21 |
|
... | ... | |
29 | 28 |
* @date 26.10.2010 |
30 | 29 |
* |
31 | 30 |
*/ |
32 |
public class CDMServerWrapperListener implements WrapperListener |
|
33 |
{ |
|
31 |
public class CDMServerWrapperListener implements WrapperListener { |
|
32 |
|
|
33 |
private static final Logger logger = Logger.getLogger(CDMServerWrapperListener.class); |
|
34 |
|
|
34 | 35 |
private static Server __server = null; |
35 |
|
|
36 |
public static final Logger logger = Logger.getLogger(CDMServerWrapperListener.class); |
|
37 | 36 |
|
38 |
public CDMServerWrapperListener() |
|
39 |
{ |
|
37 |
public CDMServerWrapperListener(){ |
|
40 | 38 |
} |
41 | 39 |
|
42 |
/* (non-Javadoc) |
|
43 |
* @see org.tanukisoftware.wrapper.WrapperListener#controlEvent(int) |
|
44 |
*/ |
|
45 |
public void controlEvent(int event) |
|
46 |
{ |
|
47 |
if (!WrapperManager.isControlledByNativeWrapper()) |
|
48 |
{ |
|
49 |
if ((event == WrapperManager.WRAPPER_CTRL_C_EVENT) || (event == WrapperManager.WRAPPER_CTRL_CLOSE_EVENT) || (event == WrapperManager.WRAPPER_CTRL_SHUTDOWN_EVENT)) |
|
50 |
{ |
|
40 |
@Override |
|
41 |
public void controlEvent(int event) { |
|
42 |
if (!WrapperManager.isControlledByNativeWrapper()) { |
|
43 |
if ((event == WrapperManager.WRAPPER_CTRL_C_EVENT) |
|
44 |
|| (event == WrapperManager.WRAPPER_CTRL_CLOSE_EVENT) |
|
45 |
|| (event == WrapperManager.WRAPPER_CTRL_SHUTDOWN_EVENT)){ |
|
51 | 46 |
WrapperManager.stop(0); |
52 | 47 |
} |
53 | 48 |
} |
54 |
|
|
55 | 49 |
} |
56 | 50 |
|
57 |
/* (non-Javadoc) |
|
58 |
* @see org.tanukisoftware.wrapper.WrapperListener#start(java.lang.String[]) |
|
59 |
*/ |
|
60 |
public Integer start(String[] args) |
|
61 |
{ |
|
62 |
for(int i=0; i<args.length; i++) |
|
63 |
{ |
|
51 |
@Override |
|
52 |
public Integer start(String[] args) { |
|
53 |
for(int i=0; i<args.length; i++) { |
|
64 | 54 |
logger.info("ARG[" + i + "] = " + args[i]); |
65 | 55 |
} |
66 | 56 |
try { |
... | ... | |
72 | 62 |
return null; |
73 | 63 |
} |
74 | 64 |
|
75 |
/* (non-Javadoc) |
|
76 |
* @see org.tanukisoftware.wrapper.WrapperListener#stop(int) |
|
77 |
*/ |
|
78 |
public int stop(int code) |
|
79 |
{ |
|
80 |
try |
|
81 |
{ |
|
65 |
@Override |
|
66 |
public int stop(int code) { |
|
67 |
try { |
|
82 | 68 |
logger.info("Stopping CDM Server!!!"); |
83 | 69 |
__server.stop(); |
84 | 70 |
logger.info("CDM Server Stopped!!!"); |
85 | 71 |
return code; |
86 | 72 |
} |
87 |
catch (Exception e) |
|
88 |
{ |
|
73 |
catch (Exception e) { |
|
89 | 74 |
logger.error("Stop Server Error", e); |
90 | 75 |
return -1; |
91 | 76 |
} |
92 |
|
|
93 | 77 |
} |
94 | 78 |
|
95 |
/** |
|
96 |
* @param server |
|
97 |
*/ |
|
98 |
public static void setServer(Server server) |
|
99 |
{ |
|
79 |
public static void setServer(Server server) { |
|
100 | 80 |
__server = server; |
101 | 81 |
} |
102 | 82 |
|
103 |
/** |
|
104 |
* @return |
|
105 |
*/ |
|
106 |
public static Server getServer() |
|
107 |
{ |
|
83 |
public static Server getServer() { |
|
108 | 84 |
return __server; |
109 | 85 |
} |
110 | 86 |
|
111 |
public static void main(String[] args) |
|
112 |
{ |
|
87 |
public static void main(String[] args) { |
|
113 | 88 |
String newStrArgs[] = new String[args.length + 1]; |
114 | 89 |
newStrArgs[0] = System.getProperty("jetty.home") + "etc/jetty-win32-service.xml"; |
115 |
for(int i=0; i<args.length; i++) |
|
116 |
{ |
|
90 |
for(int i=0; i<args.length; i++) { |
|
117 | 91 |
newStrArgs[i+1] = args[i]; |
118 | 92 |
} |
119 | 93 |
WrapperManager.start(new CDMServerWrapperListener(), newStrArgs); |
120 | 94 |
} |
121 |
|
|
122 |
} |
|
95 |
} |
src/main/java/eu/etaxonomy/cdm/server/win32service/Win32Service.java | ||
---|---|---|
7 | 7 |
* ------------------------------------------------------------------------ |
8 | 8 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
9 | 9 |
* you may not use this file except in compliance with the License. |
10 |
* You may obtain a copy of the License at
|
|
10 |
* You may obtain a copy of the License at |
|
11 | 11 |
* http://www.apache.org/licenses/LICENSE-2.0 |
12 | 12 |
* Unless required by applicable law or agreed to in writing, software |
13 | 13 |
* distributed under the License is distributed on an "AS IS" BASIS, |
... | ... | |
16 | 16 |
* limitations under the License. |
17 | 17 |
* ======================================================================== |
18 | 18 |
*/ |
19 |
|
|
20 | 19 |
package eu.etaxonomy.cdm.server.win32service; |
21 | 20 |
|
22 | 21 |
import org.apache.log4j.Logger; |
23 | 22 |
import org.eclipse.jetty.server.Server; |
24 | 23 |
import org.eclipse.jetty.util.component.AbstractLifeCycle; |
25 | 24 |
|
26 |
|
|
27 | 25 |
/** |
28 | 26 |
* @author a.kohlbecker |
29 | 27 |
* @date 26.10.2010 |
30 |
* |
|
31 | 28 |
*/ |
32 |
public class Win32Service extends AbstractLifeCycle implements Runnable |
|
33 |
{ |
|
34 |
public static final Logger logger = Logger.getLogger(Win32Service.class);
|
|
35 |
|
|
29 |
public class Win32Service extends AbstractLifeCycle implements Runnable {
|
|
30 |
|
|
31 |
private static final Logger logger = Logger.getLogger(Win32Service.class);
|
|
32 |
|
|
36 | 33 |
private Server server; |
37 |
|
|
38 |
public void doStart()
|
|
39 |
{ |
|
34 |
|
|
35 |
@Override
|
|
36 |
public void doStart() {
|
|
40 | 37 |
logger.info("doStart"); |
41 | 38 |
CDMServerWrapperListener.setServer(server); |
42 | 39 |
} |
43 |
|
|
44 |
public void doStop()
|
|
45 |
{ |
|
46 |
logger.info("Listener is stopping CDM Server Instance!!!");
|
|
40 |
|
|
41 |
@Override
|
|
42 |
public void doStop() {
|
|
43 |
logger.info("Listener is stopping CDM Server Instance!!!"); |
|
47 | 44 |
} |
48 |
|
|
49 |
public void run()
|
|
50 |
{ |
|
45 |
|
|
46 |
@Override
|
|
47 |
public void run() {
|
|
51 | 48 |
doStop(); |
52 |
|
|
49 |
|
|
53 | 50 |
} |
54 | 51 |
|
55 |
public void stopServer() |
|
56 |
{ |
|
57 |
try |
|
58 |
{ |
|
52 |
public void stopServer() { |
|
53 |
try { |
|
59 | 54 |
logger.info("Thread Test Stopper!!!"); |
60 | 55 |
server.stop(); |
61 | 56 |
//WrapperManager.stop(0); |
62 | 57 |
} |
63 |
catch (Exception e) |
|
64 |
{ |
|
58 |
catch (Exception e) { |
|
65 | 59 |
e.printStackTrace(); |
66 | 60 |
} |
67 | 61 |
} |
68 |
|
|
69 |
|
|
70 |
public Server getServer() |
|
71 |
{ |
|
62 |
|
|
63 |
public Server getServer() { |
|
72 | 64 |
return server; |
73 | 65 |
} |
74 | 66 |
|
75 |
public void setServer(Server server) |
|
76 |
{ |
|
67 |
public void setServer(Server server) { |
|
77 | 68 |
this.server = server; |
78 | 69 |
} |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
} |
|
70 |
} |
src/main/resources/logback.xml | ||
---|---|---|
50 | 50 |
|
51 | 51 |
<!-- ~~~~~~ "disabling" loggers unwanted at INFO level ~~~~~~ --> |
52 | 52 |
<!-- avoid vast amount of "getCitation not yet implemented" & "getProblems not yet implemented" messages --> |
53 |
<logger name="eu.etaxonomy.cdm.model.name.TaxonNameBase" level="ERROR" />
|
|
53 |
<logger name="eu.etaxonomy.cdm.model.name.TaxonName" level="ERROR" /> |
|
54 | 54 |
<logger name="eu.etaxonomy.cdm.persistence.dao.initializer" level="ERROR" /> |
55 | 55 |
<logger name="eu.etaxonomy.cdm.cache.CdmTransientEntityCacher" level="WARN" /> |
56 | 56 |
<logger name="eu.etaxonomy.cdm.remote.controller.interceptor" level="WARN" /> |
Also available in: Unified diff
cleanup