Search in sources :

Example 1 with CloseHandler

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);
    }
}
Also used : TransactionalProtocolClient(org.jboss.as.controller.remote.TransactionalProtocolClient) Channel(org.jboss.remoting3.Channel) IOException(java.io.IOException)

Example 2 with CloseHandler

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;
}
Also used : ManagementClientChannelStrategy(org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy) ManagementChannelHandler(org.jboss.as.protocol.mgmt.ManagementChannelHandler) Channel(org.jboss.remoting3.Channel) IOException(java.io.IOException)

Example 3 with CloseHandler

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();
    }
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) ProtocolConnectionConfiguration(org.jboss.as.protocol.ProtocolConnectionConfiguration) Channel(org.jboss.remoting3.Channel) CloseHandler(org.jboss.remoting3.CloseHandler) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException)

Example 4 with CloseHandler

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);
        }
    });
}
Also used : ManagementChannelShutdownHandle(org.jboss.as.protocol.mgmt.support.ManagementChannelShutdownHandle) Channel(org.jboss.remoting3.Channel) IOException(java.io.IOException)

Example 5 with CloseHandler

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;
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) CloseHandler(org.jboss.remoting3.CloseHandler) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException)

Aggregations

IOException (java.io.IOException)10 Channel (org.jboss.remoting3.Channel)7 CloseHandler (org.jboss.remoting3.CloseHandler)4 ManagementChannelHandler (org.jboss.as.protocol.mgmt.ManagementChannelHandler)3 ManagementClientChannelStrategy (org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy)3 InterruptedIOException (java.io.InterruptedIOException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 RemoteProxyController (org.jboss.as.controller.remote.RemoteProxyController)2 TransactionalProtocolOperationHandler (org.jboss.as.controller.remote.TransactionalProtocolOperationHandler)2 RemoteChannelPairSetup (org.jboss.as.controller.support.RemoteChannelPairSetup)2 ManagementChannelInitialization (org.jboss.as.protocol.mgmt.support.ManagementChannelInitialization)2 Test (org.junit.Test)2 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)1 ResponseAttachmentInputStreamSupport (org.jboss.as.controller.remote.ResponseAttachmentInputStreamSupport)1 TransactionalProtocolClient (org.jboss.as.controller.remote.TransactionalProtocolClient)1 ProtocolConnectionConfiguration (org.jboss.as.protocol.ProtocolConnectionConfiguration)1 ManagementChannelShutdownHandle (org.jboss.as.protocol.mgmt.support.ManagementChannelShutdownHandle)1 Connection (org.jboss.remoting3.Connection)1