@Override public ServerStatus stopServer(final String serverName, final int gracefulTimeout, final boolean blocking) { final ManagedServer server = servers.get(serverName); if(server == null) { return ServerStatus.STOPPED; } server.stop(); if(blocking) { server.awaitState(ManagedServer.InternalState.STOPPED); } return server.getState(); }
public void handleClose(final Channel closed, final IOException exception) { final boolean shuttingDown = shutdown || connectionFinished; // Unregister right away if(server.callbackUnregistered(client, shuttingDown)) { domainController.unregisterRunningServer(server.getServerName()); } } });
/** * Notification that the server process finished. */ synchronized void processFinished() { final InternalState required = this.requiredState; final InternalState state = this.internalState; // If the server was not stopped if(required == InternalState.STOPPED && state == InternalState.PROCESS_STOPPING) { finishTransition(InternalState.PROCESS_STOPPING, InternalState.PROCESS_STOPPED); } else { this.requiredState = InternalState.STOPPED; if ( !(internalSetState(getTransitionTask(InternalState.PROCESS_STOPPING), internalState, InternalState.PROCESS_STOPPING) && internalSetState(getTransitionTask(InternalState.PROCESS_REMOVING), internalState, InternalState.PROCESS_REMOVING) && internalSetState(getTransitionTask(InternalState.STOPPED), internalState, InternalState.STOPPED)) ){ this.requiredState = InternalState.FAILED; internalSetState(null, internalState, InternalState.PROCESS_STOPPED); } } }
/** * Notification that the server process finished. */ protected synchronized void processFinished() { final InternalState required = this.requiredState; final InternalState state = this.internalState; // If the server was not stopped if(required == InternalState.STOPPED && state == InternalState.PROCESS_STOPPING) { finishTransition(InternalState.PROCESS_STOPPING, InternalState.PROCESS_STOPPED); } else { this.requiredState = InternalState.FAILED; internalSetState(null, state, InternalState.PROCESS_STOPPED); } }
@Override public void reconnectServer(final String serverName, final ModelNode domainModel, final byte[] authKey, final boolean running, final boolean stopping) { if(shutdown || connectionFinished) { throw HostControllerMessages.MESSAGES.hostAlreadyShutdown(); } ManagedServer existing = servers.get(serverName); if(existing != null) { ROOT_LOGGER.existingServerWithState(serverName, existing.getState()); return; } final ManagedServer server = createManagedServer(serverName, domainModel, authKey); if ((existing = servers.putIfAbsent(serverName, server)) != null) { ROOT_LOGGER.existingServerWithState(serverName, existing.getState()); return; } if(running) { if(!stopping) { server.reconnectServerProcess(); // Register the server proxy at the domain controller domainController.registerRunningServer(server.getProxyController()); } else { server.setServerProcessStopping(); } } else { server.removeServerProcess(); } synchronized (shutdownCondition) { shutdownCondition.notifyAll(); } }
@Override public ProxyController serverCommunicationRegistered(final String serverProcessName, final ManagementChannelHandler channelAssociation) { if(shutdown || connectionFinished) { throw HostControllerMessages.MESSAGES.hostAlreadyShutdown(); } final String serverName = ManagedServer.getServerName(serverProcessName); final ManagedServer server = servers.get(serverName); if(server == null) { ROOT_LOGGER.noServerAvailable(serverName); return null; } try { final TransactionalProtocolClient client = server.channelRegistered(channelAssociation); final Channel channel = channelAssociation.getChannel(); channel.addCloseHandler(new CloseHandler<Channel>() { public void handleClose(final Channel closed, final IOException exception) { final boolean shuttingDown = shutdown || connectionFinished; // Unregister right away if(server.callbackUnregistered(client, shuttingDown)) { domainController.unregisterRunningServer(server.getServerName()); } } }); return server.getProxyController(); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public ServerStatus startServer(final String serverName, final ModelNode domainModel, final boolean blocking) { if(shutdown || connectionFinished) { throw HostControllerMessages.MESSAGES.hostAlreadyShutdown(); } ManagedServer server = servers.get(serverName); if(server == null) { // Create a new authKey final byte[] authKey = new byte[16]; new Random(new SecureRandom().nextLong()).nextBytes(authKey); // Create the managed server final ManagedServer newServer = createManagedServer(serverName, domainModel, authKey); server = servers.putIfAbsent(serverName, newServer); if(server == null) { server = newServer; } } server.start(); synchronized (shutdownCondition) { shutdownCondition.notifyAll(); } if(blocking) { // Block until the server started message server.awaitState(ManagedServer.InternalState.SERVER_STARTED); } else { // Wait until the server opens the mgmt connection server.awaitState(ManagedServer.InternalState.SERVER_STARTING); } return server.getState(); }
@Override public boolean serverReconnected(String serverProcessName, ManagementChannelHandler channelHandler) { final String serverName = ManagedServer.getServerName(serverProcessName); final ManagedServer server = servers.get(serverName); // Register the new communication channel serverCommunicationRegistered(serverProcessName, channelHandler); // Mark the server as started serverStarted(serverProcessName); // Register the server proxy at the domain controller domainController.registerRunningServer(server.getProxyController()); // If the server requires a reload, means we are out of sync return server.isRequiresReload() == false; }
@Override public void serverProcessStarted(final String serverProcessName) { final String serverName = ManagedServer.getServerName(serverProcessName); final ManagedServer server = servers.get(serverName); if(server == null) { ROOT_LOGGER.noServerAvailable(serverName); return; } server.processStarted(); synchronized (shutdownCondition) { shutdownCondition.notifyAll(); } }
@Override public void serverStartFailed(final String serverProcessName) { final String serverName = ManagedServer.getServerName(serverProcessName); final ManagedServer server = servers.get(serverName); if(server == null) { ROOT_LOGGER.noServerAvailable(serverName); return; } server.serverStartFailed(); synchronized (shutdownCondition) { shutdownCondition.notifyAll(); } }
@Override public void serverProcessAdded(final String serverProcessName) { final String serverName = ManagedServer.getServerName(serverProcessName); final ManagedServer server = servers.get(serverName); if(server == null) { ROOT_LOGGER.noServerAvailable(serverName); return; } server.processAdded(); synchronized (shutdownCondition) { shutdownCondition.notifyAll(); } }
@Override public void serverProcessRemoved(final String serverProcessName) { final String serverName = ManagedServer.getServerName(serverProcessName); final ManagedServer server = servers.remove(serverName); if(server == null) { ROOT_LOGGER.noServerAvailable(serverName); return; } server.processRemoved(); synchronized (shutdownCondition) { shutdownCondition.notifyAll(); } }
@Override public void serverStarted(String serverProcessName) { final String serverName = ManagedServer.getServerName(serverProcessName); final ManagedServer server = servers.get(serverName); if(server == null) { ROOT_LOGGER.noServerAvailable(serverName); return; } server.serverStarted(null); synchronized (shutdownCondition) { shutdownCondition.notifyAll(); } }
@Override public void serverProcessStopped(final String serverProcessName) { final String serverName = ManagedServer.getServerName(serverProcessName); final ManagedServer server = servers.get(serverName); if(server == null) { ROOT_LOGGER.noServerAvailable(serverName); return; } // always un-register in case the process exits domainController.unregisterRunningServer(server.getServerName()); server.processFinished(); synchronized (shutdownCondition) { shutdownCondition.notifyAll(); } }
@Override public void operationFailed(final String serverProcessName, final ProcessMessageHandler.OperationType type) { final String serverName = ManagedServer.getServerName(serverProcessName); final ManagedServer server = servers.get(serverName); if(server == null) { ROOT_LOGGER.noServerAvailable(serverName); return; } switch (type) { case ADD: server.transitionFailed(ManagedServer.InternalState.PROCESS_ADDING); break; case START: server.transitionFailed(ManagedServer.InternalState.PROCESS_STARTING); break; case STOP: server.transitionFailed(ManagedServer.InternalState.PROCESS_STOPPING); break; case SEND_STDIN: case RECONNECT: server.transitionFailed(ManagedServer.InternalState.SERVER_STARTING); break; case REMOVE: server.transitionFailed(ManagedServer.InternalState.PROCESS_REMOVING); break; } }
/** * Notification that the process was added */ void processAdded() { finishTransition(InternalState.PROCESS_ADDING, InternalState.PROCESS_ADDED); }
@Override public String getServerProcessName(String serverName) { return ManagedServer.getServerProcessName(serverName); }
if (server != null) { try { int blockingTimeoutValue = blockingTimeout.getProxyBlockingTimeout(server.getAddress(), server.getProxyController()); BlockingQueueOperationListener<TransactionalProtocolClient.Operation> listener = new BlockingQueueOperationListener<>(); AsyncFuture<OperationResponse> future = server.suspend(timeoutInSeconds, listener);
if (server != null) { try { int blockingTimeoutValue = blockingTimeout.getProxyBlockingTimeout(server.getAddress(), server.getProxyController()); BlockingQueueOperationListener<TransactionalProtocolClient.Operation> listener = new BlockingQueueOperationListener<>(); AsyncFuture<OperationResponse> future = server.resume(listener);