rename CdmServerUtils, CdmServerException and CdmEmbeddedServerException
[taxeditor.git] / eu.etaxonomy.taxeditor.webapp / src / main / java / eu / etaxonomy / taxeditor / webapp / CdmServer.java
similarity index 86%
rename from eu.etaxonomy.taxeditor.webapp/src/main/java/eu/etaxonomy/taxeditor/webapp/CDMServer.java
rename to eu.etaxonomy.taxeditor.webapp/src/main/java/eu/etaxonomy/taxeditor/webapp/CdmServer.java
index 5146d0a9b83732d9bad710930beec63c121ab0ca..dca1be4673312f55f9b08b3b479d80a313712494 100644 (file)
@@ -35,7 +35,6 @@ import org.eclipse.jetty.webapp.WebAppContext;
 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
@@ -45,13 +44,10 @@ import org.osgi.framework.Bundle;
  *
  * @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";
@@ -64,14 +60,13 @@ public class CDMServer {
     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");
@@ -85,12 +80,12 @@ public class CDMServer {
             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
@@ -129,7 +124,7 @@ public class CDMServer {
         return contextPath;
     }
 
-    private static int findFreePort() throws CDMEmbeddedServerException {
+    private static int findFreePort() throws CdmEmbeddedServerException {
         ServerSocket socket = null;
         try {
             socket = new ServerSocket(0);
@@ -150,33 +145,33 @@ public class CDMServer {
                 }
             }
         }
-        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() {
@@ -247,7 +242,7 @@ public class CDMServer {
 
 
 
-    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 ... ");
 
@@ -259,15 +254,15 @@ public class CDMServer {
             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);
         }
     }
 
@@ -282,6 +277,4 @@ public class CDMServer {
     public boolean isPotentiallyMissingSchema() {
         return potentiallyMissingSchema;
     }
-
-
 }