use of org.jboss.remoting3.CloseHandler in project wildfly-core by wildfly.
the class ServerInventoryImpl method serverCommunicationRegistered.
@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);
}
}
use of org.jboss.remoting3.CloseHandler in project wildfly-core by wildfly.
the class ExistingChannelModelControllerClient method createReceiving.
/**
* Create a model controller client which is exclusively receiving messages on an existing channel.
*
* @param channel the channel
* @param executorService an executor
* @return the created client
*/
public static ModelControllerClient createReceiving(final Channel channel, final ExecutorService executorService) {
final ManagementClientChannelStrategy strategy = ManagementClientChannelStrategy.create(channel);
final ManagementChannelHandler handler = new ManagementChannelHandler(strategy, executorService);
final ExistingChannelModelControllerClient client = new ExistingChannelModelControllerClient(handler);
handler.addHandlerFactory(client);
channel.addCloseHandler(new CloseHandler<Channel>() {
@Override
public void handleClose(Channel closed, IOException exception) {
handler.shutdown();
try {
handler.awaitCompletion(1, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} finally {
handler.shutdownNow();
}
}
});
channel.receiveMessage(handler.getReceiver());
return client;
}
use of org.jboss.remoting3.CloseHandler in project wildfly-core by wildfly.
the class RemotingModelControllerClient method getOrCreateChannel.
protected Channel getOrCreateChannel() throws IOException {
synchronized (closeable) {
if (closeable.closed) {
throw ControllerClientLogger.ROOT_LOGGER.objectIsClosed(ModelControllerClient.class.getSimpleName());
}
if (closeable.strategy == null) {
try {
closeable.endpoint = Endpoint.builder().setEndpointName("management-client").build();
final ProtocolConnectionConfiguration configuration = ProtocolConfigurationFactory.create(closeable.clientConfiguration, closeable.endpoint);
closeable.strategy = ManagementClientChannelStrategy.create(configuration, closeable.channelAssociation, closeable.clientConfiguration.getCallbackHandler(), closeable.clientConfiguration.getSaslOptions(), closeable.clientConfiguration.getSSLContext(), new CloseHandler<Channel>() {
@Override
public void handleClose(final Channel closed, final IOException exception) {
closeable.channelAssociation.handleChannelClosed(closed, exception);
}
});
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return closeable.strategy.getChannel();
}
}
use of org.jboss.remoting3.CloseHandler in project wildfly-core by wildfly.
the class AbstractChannelOpenListenerService method channelOpened.
@Override
public void channelOpened(Channel channel) {
// 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);
}
});
}
use of org.jboss.remoting3.CloseHandler in project jboss-remoting by jboss-remoting.
the class AbstractHandleableCloseable method close.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
public void close() throws IOException {
log.tracef("Closing %s synchronously", this);
boolean first = false;
synchronized (closeLock) {
switch(state) {
case OPEN:
{
first = true;
state = State.CLOSING;
break;
}
case CLOSING:
{
break;
}
case CLOSED:
return;
default:
throw new IllegalStateException();
}
}
if (first)
try {
closeAction();
} catch (IOException e) {
log.tracef(e, "Close of %s failed", this);
final Map<Key, CloseHandler<? super T>> closeHandlers;
synchronized (closeLock) {
state = State.CLOSED;
closeHandlers = this.closeHandlers;
this.closeHandlers = null;
closeLock.notifyAll();
}
if (closeHandlers != null) {
for (final CloseHandler<? super T> handler : closeHandlers.values()) {
SpiUtils.safeHandleClose(handler, (T) AbstractHandleableCloseable.this, null);
}
}
throw e;
} catch (Throwable t) {
log.errorf(t, "Close action for %s failed to execute (resource may be left in an indeterminate state)", this);
final Map<Key, CloseHandler<? super T>> closeHandlers;
synchronized (closeLock) {
state = State.CLOSED;
closeHandlers = this.closeHandlers;
this.closeHandlers = null;
closeLock.notifyAll();
}
if (closeHandlers != null) {
for (final CloseHandler<? super T> handler : closeHandlers.values()) {
SpiUtils.safeHandleClose(handler, (T) AbstractHandleableCloseable.this, null);
}
}
throw new IllegalStateException(t);
}
final IOException failure;
synchronized (closeLock) {
while (state != State.CLOSED) try {
closeLock.wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new InterruptedIOException("Interrupted while waiting for close to complete");
}
failure = this.failure;
this.failure = null;
}
if (failure != null) {
final IOException clone = clone(failure);
if (failure != clone) {
SpiUtils.glueStackTraces(failure, Thread.currentThread().getStackTrace(), 1, "asynchronous close");
}
throw clone;
}
}
Aggregations