import org.osgi.framework.Bundle;
/**
- *
* (Singleton) Server instance which manages a compatible cdmlib-webapp-war.
* This is done by launching a jetty instance (using jetty-runner) as an
* executed process. The choice of the external process over a more
*
* @author cmathew
* @date 23 Sep 2014
- *
*/
+public class CdmServer {
-public class CDMServer {
-
- public static final Logger logger = Logger.getLogger(CDMServer.class);
-
+ public static final Logger logger = Logger.getLogger(CdmServer.class);
private final String dataSourceName;
private final String host = "127.0.0.1";
private boolean potentiallyMissingSchema;
private boolean forceSchemaCreate = false;
-
- public CDMServer(String dataSourceName, File dataSourcesFile) throws CDMEmbeddedServerException {
+ public CdmServer(String dataSourceName, File dataSourcesFile) throws CdmEmbeddedServerException {
if(StringUtil.isBlank(dataSourceName)) {
- throw new CDMEmbeddedServerException("DataSource name is not valid");
+ throw new CdmEmbeddedServerException("DataSource name is not valid");
}
if(dataSourcesFile == null || !dataSourcesFile.exists()) {
- throw new CDMEmbeddedServerException("DataSource config file does not exist");
+ throw new CdmEmbeddedServerException("DataSource config file does not exist");
}
this.dataSourceName = dataSourceName;
Bundle bundle = Platform.getBundle("eu.etaxonomy.taxeditor.webapp");
System.out.println("war url : " + warFile.getAbsolutePath());
if(warFile == null || !warFile.exists()) {
- throw new CDMEmbeddedServerException("Cdmlib War file does not exist");
+ throw new CdmEmbeddedServerException("Cdmlib War file does not exist");
}
} catch (URISyntaxException use) {
- throw new CDMEmbeddedServerException(use);
+ throw new CdmEmbeddedServerException(use);
} catch (IOException ioe) {
- throw new CDMEmbeddedServerException(ioe);
+ throw new CdmEmbeddedServerException(ioe);
}
//TODO instead of strings, use the constants defined in eu.etaxonomy.cdm.opt.config.DataSourceConfigurer
return contextPath;
}
- private static int findFreePort() throws CDMEmbeddedServerException {
+ private static int findFreePort() throws CdmEmbeddedServerException {
ServerSocket socket = null;
try {
socket = new ServerSocket(0);
}
}
}
- throw new CDMEmbeddedServerException("Could not find a free TCP/IP port to start embedded Jetty HTTP Server on");
+ throw new CdmEmbeddedServerException("Could not find a free TCP/IP port to start embedded Jetty HTTP Server on");
}
- public void start(ICDMServerError cdmServerError) throws CDMEmbeddedServerException {
+ public void start(ICDMServerError cdmServerError) throws CdmEmbeddedServerException {
start(true, cdmServerError);
}
- public void start(boolean wait, final ICDMServerError cdmServerError) throws CDMEmbeddedServerException {
+ public void start(boolean wait, final ICDMServerError cdmServerError) throws CdmEmbeddedServerException {
if(server == null) {
- throw new CDMEmbeddedServerException("Server is already disposed");
+ throw new CdmEmbeddedServerException("Server is already disposed");
}
if(server.isStarting()) {
- throw new CDMEmbeddedServerException("Server is starting");
+ throw new CdmEmbeddedServerException("Server is starting");
}
if(server.isStarted()) {
- throw new CDMEmbeddedServerException("Server has started");
+ throw new CdmEmbeddedServerException("Server has started");
}
if(server.isRunning()) {
- throw new CDMEmbeddedServerException("Server is running");
+ throw new CdmEmbeddedServerException("Server is running");
}
if(server.isStopping()) {
- throw new CDMEmbeddedServerException("Server is currently stopping. Please re-try in about 10 seconds");
+ throw new CdmEmbeddedServerException("Server is currently stopping. Please re-try in about 10 seconds");
}
Thread serverThread = new Thread() {
- public static void stopServerViaJMX(int jmxPort) throws CDMEmbeddedServerException {
+ public static void stopServerViaJMX(int jmxPort) throws CdmEmbeddedServerException {
String JMX_URL = "service:jmx:rmi:///jndi/rmi://localhost:" + jmxPort + "/jmxrmi";
logger.warn("Shutting down Jetty instance ... ");
connection.invoke(objectName, "stop", null, null);
logger.warn("Shutdown command sent");
} catch (InstanceNotFoundException e) {
- throw new CDMEmbeddedServerException(e);
+ throw new CdmEmbeddedServerException(e);
} catch (MBeanException e) {
- throw new CDMEmbeddedServerException(e);
+ throw new CdmEmbeddedServerException(e);
} catch (ReflectionException e) {
- throw new CDMEmbeddedServerException(e);
+ throw new CdmEmbeddedServerException(e);
} catch (IOException e) {
- throw new CDMEmbeddedServerException(e);
+ throw new CdmEmbeddedServerException(e);
} catch (MalformedObjectNameException e) {
- throw new CDMEmbeddedServerException(e);
+ throw new CdmEmbeddedServerException(e);
}
}
public boolean isPotentiallyMissingSchema() {
return potentiallyMissingSchema;
}
-
-
}