private ServerState createNoResponseState(final Exception cause, final String errorMessage) { debug(ExceptionUtils.getStackTrace(cause) + errorMessage); return new ServerState(this, Status.NOT_RESPONDING, errorMessage); }
private ServerState stopInProcess() { if (isStoppable()) { if (this.cache.isReconnecting()) { this.cache.getDistributedSystem().stopReconnecting(); } // Another case of needing to use a non-daemon thread to keep the JVM alive until a clean // shutdown can be performed. If not, the JVM may exit too early causing the member to be // seen as having crashed and not cleanly departed. Thread t = new LoggingThread("ServerLauncherStopper", false, this::doStopInProcess); t.start(); try { t.join(); } catch (InterruptedException e) { // no matter, we're shutting down... } INSTANCE.compareAndSet(this, null); // note: other thread may return Status.NOT_RESPONDING now this.running.set(false); return new ServerState(this, Status.STOPPED); } else { return new ServerState(this, Status.NOT_RESPONDING); } }
this.running.set(true); return new ServerState(this, Status.ONLINE); } catch (AuthenticationRequiredException e) { failOnStart(e);
return new ServerState(this, Status.STOPPED); } catch (ConnectionFailedException handled) {
/** * Invokes the 'status' command and operation to check the status of a GemFire server (a cache * server). */ public ServerState status() { final ServerLauncher launcher = getInstance(); // if this instance is running then return local status if (isStartingOrRunning()) { debug( "Getting status from the ServerLauncher instance that actually launched the GemFire Cache Server.%n"); return new ServerState(this, isRunning() ? Status.ONLINE : Status.STARTING); } else if (isPidInProcess() && launcher != null) { return launcher.statusInProcess(); } else if (getPid() != null) { debug("Getting Server status using process ID (%1$s)%n", getPid()); return statusWithPid(); } // attempt to get status using workingDirectory else if (getWorkingDirectory() != null) { debug("Getting Server status using working directory (%1$s)%n", getWorkingDirectory()); return statusWithWorkingDirectory(); } debug("This ServerLauncher was not the instance used to launch the GemFire Cache Server, and " + "neither PID nor working directory were specified; the Server's state is unknown.%n"); return new ServerState(this, Status.NOT_RESPONDING); }
/** * Unmarshals a ServerState instance from the JSON String. * * @return a ServerState value unmarshalled from the JSON String. */ public static ServerState fromJson(final String json) { try { final GfJsonObject gfJsonObject = new GfJsonObject(json); final Status status = Status.valueOfDescription(gfJsonObject.getString(JSON_STATUS)); final List<String> jvmArguments = Arrays.asList(GfJsonArray.toStringArray(gfJsonObject.getJSONArray(JSON_JVMARGUMENTS))); return new ServerState(status, gfJsonObject.getString(JSON_STATUSMESSAGE), gfJsonObject.getLong(JSON_TIMESTAMP), gfJsonObject.getString(JSON_LOCATION), gfJsonObject.getInt(JSON_PID), gfJsonObject.getLong(JSON_UPTIME), gfJsonObject.getString(JSON_WORKINGDIRECTORY), jvmArguments, gfJsonObject.getString(JSON_CLASSPATH), gfJsonObject.getString(JSON_GEMFIREVERSION), gfJsonObject.getString(JSON_JAVAVERSION), gfJsonObject.getString(JSON_LOGFILE), gfJsonObject.getString(JSON_HOST), gfJsonObject.getString(JSON_PORT), gfJsonObject.getString(JSON_MEMBERNAME)); } catch (GfJsonException e) { throw new IllegalArgumentException("Unable to create ServerStatus from JSON: " + json, e); } }
/** * Invokes the 'stop' command and operation to stop a GemFire server (a cache server). */ public ServerState stop() { final ServerLauncher launcher = getInstance(); // if this instance is running then stop it if (isStoppable()) { return stopInProcess(); } // if in-process but difference instance of ServerLauncher else if (isPidInProcess() && launcher != null) { return launcher.stopInProcess(); } // attempt to stop using pid if provided else if (getPid() != null) { return stopWithPid(); } // attempt to stop using workingDirectory else if (getWorkingDirectory() != null) { return stopWithWorkingDirectory(); } return new ServerState(this, Status.NOT_RESPONDING); }
private ServerState stopWithPid() { try { final ProcessController controller = new ProcessControllerFactory() .createProcessController(this.controllerParameters, getPid()); controller.checkPidSupport(); controller.stop(); return new ServerState(this, Status.STOPPED); } catch (ConnectionFailedException handled) { // failed to attach to server JVM return createNoResponseState(handled, "Failed to connect to server with process id " + getPid()); } catch (IOException | MBeanInvocationFailedException | UnableToControlProcessException handled) { return createNoResponseState(handled, "Failed to communicate with server with process id " + getPid()); } }
private ServerState statusInProcess() { if (isStartingOrRunning()) { debug( "Getting status from the ServerLauncher instance that actually launched the GemFire Cache Server.%n"); return new ServerState(this, isRunning() ? Status.ONLINE : Status.STARTING); } else { return new ServerState(this, Status.NOT_RESPONDING); } }
public static ServerState fromDirectory(final String workingDirectory, final String memberName) { ServerState serverState = new ServerLauncher.Builder().setWorkingDirectory(workingDirectory) .setDisableDefaultServer(true).build().status(); if (ObjectUtils.equals(serverState.getMemberName(), memberName)) { return serverState; } return new ServerState(new ServerLauncher.Builder().build(), Status.NOT_RESPONDING); }