/** * Construct a new instance. * * @param channel the channel that is being tracked * @param messageTracker the message tracker to use * @param intMasker the function to apply to ID numbers to limit them to a specific range */ public InvocationTracker(final Channel channel, final MessageTracker messageTracker, final IntUnaryOperator intMasker) { Assert.checkNotNullParam("channel", channel); Assert.checkNotNullParam("messageTracker", messageTracker); Assert.checkNotNullParam("intMasker", intMasker); this.messageTracker = messageTracker; channel.addCloseHandler((closed, exception) -> connectionClosed(exception)); this.intMasker = intMasker; }
} catch (final IOException e) { channel.closeAsync(); channel.addCloseHandler((closed, exception) -> futureResult.setException(e));
@Override protected Channel openChannel(final Connection connection, final String serviceType, final OptionMap options) throws IOException { final Channel channel = super.openChannel(connection, serviceType, options); channel.addCloseHandler(closeHandler); return channel; }
@Override protected Channel openChannel(final Connection connection, final String serviceType, final OptionMap options) throws IOException { // This is only called as part of the connectionManager.connect() handling in getChannel() above. // So, we should hold the connectionManager lock. We want to ensure that so we know we have the right deadline. // We could synchronize again on connectionManager to ensure that, but then if there is some corner case // the analysis missed where this gets called asynchronously during connectionManager.connect() handling // we would deadlock. Better to fail than to deadlock. Use an ISE instead of an assert because if this // fails, we don't want an Error; we want something that should eventually be caught and handled. if (!Thread.holdsLock(connectionManager)) { throw new IllegalStateException(); } final Channel channel = openChannel(connection, serviceType, options, deadline); channel.addCloseHandler(closeHandler); return channel; }
@Override protected Channel openChannel(final Connection connection, final String serviceType, final OptionMap options) throws IOException { // This is only called as part of the connectionManager.connect() handling in getChannel() above. // So, we should hold the connectionManager lock. We want to ensure that so we know we have the right deadline. // We could synchronize again on connectionManager to ensure that, but then if there is some corner case // the analysis missed where this gets called asynchronously during connectionManager.connect() handling // we would deadlock. Better to fail than to deadlock. Use an ISE instead of an assert because if this // fails, we don't want an Error; we want something that should eventually be caught and handled. if (!Thread.holdsLock(connectionManager)) { throw new IllegalStateException(); } final Channel channel = openChannel(connection, serviceType, options, deadline); channel.addCloseHandler(closeHandler); return channel; }
Channel openChannel(final Connection connection) throws IOException { final IoFuture<Channel> future = connection.openChannel(DEFAULT_CHANNEL_SERVICE_TYPE, OptionMap.EMPTY); final Channel channel = future.get(); channel.addCloseHandler(new CloseHandler<Channel>() { @Override public void handleClose(final Channel old, final IOException e) { synchronized (ChannelStrategy.this) { if(ChannelStrategy.this.channel == old) { ChannelStrategy.this.channel = null; } } handler.handleChannelClosed(old, e); } }); return channel; }
@Override public void channelOpened(Channel channel) { // When the server/host is stopping we don't accept new connections // this should be using the graceful shutdown control if(closed) { log.debugf("server shutting down, closing channel %s.", channel); channel.closeAsync(); return; } final T createdChannel = createChannel(channel); channels.add(createdChannel); channel.addCloseHandler(new CloseHandler<Channel>() { public void handleClose(final Channel closed, final IOException exception) { channels.remove(createdChannel); log.tracef("Handling close for %s", createdChannel); } }); }
@Override public void channelOpened(Channel channel) { // When the server/host is stopping we don't accept new connections // this should be using the graceful shutdown control if(closed) { RemotingLogger.ROOT_LOGGER.debugf("server shutting down, closing channel %s.", channel); channel.closeAsync(); return; } final ManagementChannelShutdownHandle handle = handleChannelOpened(channel); trackerService.registerTracker(handle); handles.add(handle); channel.addCloseHandler(new CloseHandler<Channel>() { public void handleClose(final Channel closed, final IOException exception) { handles.remove(handle); handle.shutdownNow(); trackerService.unregisterTracker(handle); RemotingLogger.ROOT_LOGGER.tracef("Handling close for %s", handle); } }); }
/** * Construct a new instance. * * @param channel the channel that is being tracked * @param messageTracker the message tracker to use * @param intMasker the function to apply to ID numbers to limit them to a specific range */ public InvocationTracker(final Channel channel, final MessageTracker messageTracker, final IntUnaryOperator intMasker) { Assert.checkNotNullParam("channel", channel); Assert.checkNotNullParam("messageTracker", messageTracker); Assert.checkNotNullParam("intMasker", intMasker); this.messageTracker = messageTracker; channel.addCloseHandler((closed, exception) -> connectionClosed(exception)); this.intMasker = intMasker; }
@Override public ProxyController serverCommunicationRegistered(final String serverProcessName, final ManagementChannelHandler channelAssociation) { if(shutdown || connectionFinished) { throw HostControllerLogger.ROOT_LOGGER.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 void connectionOpened(final Connection connection) throws IOException { final Channel channel = openChannel(connection, SERVER_CHANNEL_TYPE, configuration.getOptionMap()); if(setChannel(channel)) { channel.receiveMessage(channelHandler.getReceiver()); channel.addCloseHandler(channelHandler); } else { channel.closeAsync(); } }
public void channelOpened(Channel channel) { log.debugf("Channel Opened - %s", channel); channel.addCloseHandler(new ChannelCloseHandler()); try { writeHeader(channel); channel.receiveMessage(new ClientVersionReceiver()); } catch (IOException e) { logger.failedToSendHeader(e); IoUtils.safeClose(channel); } }
@Override public void connectionOpened(final Connection connection) throws IOException { final Channel channel = openChannel(connection, SERVER_CHANNEL_TYPE, configuration.getOptionMap()); if(setChannel(channel)) { channel.receiveMessage(channelHandler.getReceiver()); channel.addCloseHandler(channelHandler); } else { channel.closeAsync(); } }
@Override public void connectionOpened(final Connection connection) throws IOException { final Channel channel = openChannel(connection, SERVER_CHANNEL_TYPE, configuration.getOptionMap()); if(setChannel(channel)) { channel.receiveMessage(channelHandler.getReceiver()); channel.addCloseHandler(channelHandler); } else { channel.closeAsync(); } }
@Override public void connectionOpened(final Connection connection) throws IOException { final Channel channel = openChannel(connection, SERVER_CHANNEL_TYPE, configuration.getOptionMap()); if(setChannel(channel)) { channel.receiveMessage(channelHandler.getReceiver()); channel.addCloseHandler(channelHandler); } else { channel.closeAsync(); } }
@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 void channelOpened(Channel channel) { final ChannelAssociation channelAssociation = new ChannelAssociation(channel); EjbLogger.ROOT_LOGGER.tracef("Welcome %s to the " + EJB_CHANNEL_NAME + " channel", channel); channel.addCloseHandler(new CloseHandler<Channel>() { @Override public void handleClose(Channel closed, IOException exception) { // do nothing EjbLogger.ROOT_LOGGER.tracef("channel %s closed", closed); } }); // send the server version and supported marshalling types to the client try { EJBRemoteConnectorService.this.sendVersionMessage(channelAssociation); } catch (IOException e) { EjbLogger.EJB3_LOGGER.closingChannel(channel, e); IoUtils.safeClose(channel); } // receive messages from the client channel.receiveMessage(new ClientVersionMessageReceiver(this.serviceContainer, channelAssociation)); }
Channel openChannel(final Connection connection) throws IOException { final IoFuture<Channel> future = connection.openChannel(DEFAULT_CHANNEL_SERVICE_TYPE, OptionMap.EMPTY); future.await(10L, TimeUnit.SECONDS); if (future.getStatus() == IoFuture.Status.WAITING) { future.cancel(); throw ProtocolLogger.ROOT_LOGGER.channelTimedOut(); } final Channel channel = future.get(); channel.addCloseHandler(new CloseHandler<Channel>() { @Override public void handleClose(final Channel old, final IOException e) { synchronized (ChannelStrategy.this) { if(ChannelStrategy.this.channel == old) { ChannelStrategy.this.handler.handleClose(old, e); ChannelStrategy.this.channel = null; } } handler.handleChannelClosed(old, e); } }); return channel; }
@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 { if (runningMode == RunningMode.ADMIN_ONLY) { // Fetch the domain configuration channelHandler.executeRequest(new FetchDomainConfigurationRequest(), null).getResult().get(); } else { // 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 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 { if (runningMode == RunningMode.ADMIN_ONLY) { // Fetch the domain configuration channelHandler.executeRequest(new FetchDomainConfigurationRequest(), null).getResult().get(); } else { // 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(); } }