private void removeFailedUnDeployments() throws IOException { Server server = manager.getServer(configuration.getProfileName()); List<String> remainingDeployments = new ArrayList<String>(); for (String name : failedUndeployments) { try { server.undeploy(new File(name)); } catch (Exception e) { IOException ioe = new IOException(); ioe.initCause(e); throw ioe; } } if (remainingDeployments.size() > 0) { log.severe("Failed to undeploy these artifacts: " + remainingDeployments); } failedUndeployments.clear(); }
/** * Given a server name, checks with the server manager and returns an existing instance, or * returns a newly created one. * * @param serverConfigName * @param jvmargs * @return an existing or new server instance. * @throws IOException */ private Server getServer(String serverConfigName, Collection<String> jvmargs) throws IOException { // the server instance we will work with Server server; // is there an existing server instance? try { server = this.getServerManager().getServer(serverConfigName); } catch (IllegalArgumentException e) { // server with name serverConfigName doesn't exist //try to obtain instance server = setupServer(serverConfigName, jvmargs); // setup the server manager setupServerManager(server); } return server; }
@Override public void start() throws LifecycleException { try { Server server = manager.getServer(configuration.getProfileName()); if(ServerController.isServerStarted(server)) { throw new LifecycleException( "The server is already running! " + "Managed containers does not support connecting to running server instances due to the " + "possible harmfull effect of connecting to the wrong server. Please stop server before running or " + "change to another type of container."); } manager.startServer(server.getName()); initProfileService(server); } catch (Exception e) { throw new LifecycleException("Could not start remote container", e); } }
@Override public void stop() throws LifecycleException { Server server = manager.getServer(configuration.getProfileName()); if(!server.isRunning()) { throw new LifecycleException("Can not stop server. Server is not started"); } try { removeFailedUnDeployments(); } catch (Exception e) { throw new LifecycleException("Could not clean up failed undeployments", e); } try { manager.stopServer(server.getName()); } catch (Exception e) { throw new LifecycleException("Could not stop server", e); } }