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); } }
public ServerState(final ServerLauncher launcher, final Status status, final String errorMessage) { this(status, // status errorMessage, // statusMessage System.currentTimeMillis(), // timestamp getServerLocation(launcher), // serverLocation null, // pid 0L, // uptime launcher.getWorkingDirectory(), // workingDirectory ManagementFactory.getRuntimeMXBean().getInputArguments(), // jvmArguments null, // classpath GemFireVersion.getGemFireVersion(), // gemfireVersion System.getProperty("java.version"), // javaVersion null, // logFile getServerBindAddressAsString(launcher), // host launcher.getServerPortAsString(), // port null);// memberName }
public ServerState(final ServerLauncher launcher, final Status status) { this(status, launcher.statusMessage, System.currentTimeMillis(), launcher.getId(), identifyPid(), ManagementFactory.getRuntimeMXBean().getUptime(), launcher.getWorkingDirectory(), ManagementFactory.getRuntimeMXBean().getInputArguments(), System.getProperty("java.class.path"), GemFireVersion.getGemFireVersion(), System.getProperty("java.version"), getServerLogFileCanonicalPath(launcher), getServerBindAddressAsString(launcher), getServerPortAsString(launcher), launcher.getMemberName()); }
this.running.set(true); return new ServerState(this, Status.ONLINE); } catch (AuthenticationRequiredException e) { failOnStart(e);
serverState = ServerLauncher.ServerState.fromJson(serverProxy.status()); serverProxy.shutDownMember(); } else { if (AbstractLauncher.Status.ONLINE.equals(serverState.getStatus())) { getGfsh().logInfo( String.format(CliStrings.STOP_SERVER__STOPPING_SERVER_MESSAGE, serverState.getWorkingDirectory(), serverState.getServiceLocation(), serverState.getMemberName(), serverState.getPid(), serverState.getLogFile()), null); while (serverState.isVmWithProcessIdRunning()) { Gfsh.print("."); if (stopWatch.elapsedTimeMillis() > WAITING_FOR_STOP_TO_MAKE_PID_GO_AWAY_TIMEOUT_MILLIS) { return ResultModel.createError(serverState.toString());
ServerLauncher.ServerState.fromJson(serverProxy.status()).toString()); } else { return ResultModel.createError((CliStrings if (status.getStatus().equals(AbstractLauncher.Status.NOT_RESPONDING) || status.getStatus().equals(AbstractLauncher.Status.STOPPED)) { return ResultModel.createError(status.toString()); return ResultModel.createInfo(status.toString());
return new ServerState(this, Status.STOPPED); } catch (ConnectionFailedException handled) {
return ServerState.fromJson(statusJson); } 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 statusWithPid() { try { final ProcessController controller = new ProcessControllerFactory() .createProcessController(this.controllerParameters, getPid()); controller.checkPidSupport(); final String statusJson = controller.status(); return ServerState.fromJson(statusJson); } 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 | InterruptedException | TimeoutException handled) { return createNoResponseState(handled, "Failed to communicate with server with process id " + getPid()); } }
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 createNoResponseState(final Exception cause, final String errorMessage) { debug(ExceptionUtils.getStackTrace(cause) + errorMessage); return new ServerState(this, Status.NOT_RESPONDING, errorMessage); }
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); }