/** * Create the protocol client to talk to the remote controller. * * @param channel the remoting channel * @return the client * @throws Exception */ TransactionalProtocolClient createClient(final Channel channel) { channels.add(channel); final ManagementChannelHandler channelAssociation = new ManagementChannelHandler(channel, clientExecutor); final TransactionalProtocolClient client = TransactionalProtocolHandlers.createClient(channelAssociation); channel.addCloseHandler(channelAssociation); channel.receiveMessage(channelAssociation.getReceiver()); return client; }
@Override protected ProxyController createProxyController( final ModelController proxiedController, final PathAddress proxyNodeAddress) { try { channels = new RemoteChannelPairSetup(); channels.setupRemoting( new ManagementChannelInitialization() { @Override public ManagementChannelHandler startReceiving(Channel channel) { final ManagementChannelHandler support = new ManagementChannelHandler(channel, channels.getExecutorService()); support.addHandlerFactory( new TransactionalProtocolOperationHandler(proxiedController, support)); channel.addCloseHandler( new CloseHandler<Channel>() { @Override public void handleClose(Channel closed, IOException exception) { support.shutdownNow(); } }); channel.receiveMessage(support.getReceiver()); return support; } }); channels.startClientConnetion(); } catch (Exception e) { throw new RuntimeException(e); } final Channel clientChannel = channels.getClientChannel(); final ManagementChannelHandler support = new ManagementChannelHandler(clientChannel, channels.getExecutorService()); final RemoteProxyController proxyController = RemoteProxyController.create( support, proxyNodeAddress, ProxyOperationAddressTranslator.SERVER); clientChannel.addCloseHandler( new CloseHandler<Channel>() { @Override public void handleClose(Channel closed, IOException exception) { support.shutdownNow(); } }); clientChannel.receiveMessage(support.getReceiver()); return proxyController; }
@Override public void connectionOpened(final Connection connection) throws IOException { final Channel channel = openChannel(connection, CHANNEL_SERVICE_TYPE, configuration.getOptionMap()); if (setChannel(channel)) { channel.receiveMessage(channelHandler.getReceiver()); channel.addCloseHandler(channelHandler); try { // Start the registration process channelHandler.executeRequest(new RegisterHostControllerRequest(), null).getResult().get(); } catch (Exception e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new IOException(e); } // Registered registered(); } else { channel.closeAsync(); } }
@Override public ManagementChannelHandler startReceiving(final Channel channel) { final ManagementChannelHandler handler = new ManagementChannelHandler( ManagementClientChannelStrategy.create(channel), getExecutor()); // Assemble the request handlers for the domain channel handler.addHandlerFactory( new HostControllerRegistrationHandler( handler, domainController, operationExecutor, getExecutor(), runtimeIgnoreTransformationRegistry)); handler.addHandlerFactory(new ModelControllerClientOperationHandler(getController(), handler)); handler.addHandlerFactory( new MasterDomainControllerOperationHandlerImpl(domainController, getExecutor())); handler.addHandlerFactory(pongRequestHandler); handler.addHandlerFactory( new DomainTransactionalProtocolOperationHandler(txOperationExecutor, handler)); channel.receiveMessage(handler.getReceiver()); return handler; }
@Override public Channel.Key startReceiving(final Channel channel) { final ManagementChannelHandler handler = new ManagementChannelHandler( ManagementClientChannelStrategy.create(channel), getExecutor()); // Assemble the request handlers for the domain channel handler.addHandlerFactory( new HostControllerRegistrationHandler(handler, getController(), domainController)); handler.addHandlerFactory(new ModelControllerClientOperationHandler(getController(), handler)); handler.addHandlerFactory(new MasterDomainControllerOperationHandlerImpl(domainController)); final Channel.Key key = channel.addCloseHandler( new CloseHandler<Channel>() { @Override public void handleClose(Channel closed, IOException exception) { handler.shutdown(); boolean interrupted = false; try { if (!handler.awaitCompletion(CHANNEL_SHUTDOWN_TIMEOUT, TimeUnit.MILLISECONDS)) { ROOT_LOGGER.gracefulManagementChannelHandlerShutdownTimedOut( CHANNEL_SHUTDOWN_TIMEOUT); } } catch (InterruptedException e) { interrupted = true; ROOT_LOGGER.serviceShutdownIncomplete(e); } catch (Exception e) { ROOT_LOGGER.serviceShutdownIncomplete(e); } finally { handler.shutdownNow(); if (interrupted) { Thread.currentThread().interrupt(); } } } }); channel.receiveMessage(handler.getReceiver()); return key; }