Search in sources :

Example 1 with ManagementClientChannelStrategy

use of org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy in project wildfly-core by wildfly.

the class TransactionalProtocolClientTestCase method createClient.

/**
 * 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 ManagementClientChannelStrategy strategy = ManagementClientChannelStrategy.create(channel);
    final ManagementChannelHandler channelAssociation = new ManagementChannelHandler(strategy, clientExecutor);
    final TransactionalProtocolClient client = TransactionalProtocolHandlers.createClient(channelAssociation);
    channel.addCloseHandler(channelAssociation);
    channel.receiveMessage(channelAssociation.getReceiver());
    return client;
}
Also used : ManagementClientChannelStrategy(org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy) ManagementChannelHandler(org.jboss.as.protocol.mgmt.ManagementChannelHandler) TransactionalProtocolClient(org.jboss.as.controller.remote.TransactionalProtocolClient)

Example 2 with ManagementClientChannelStrategy

use of org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy in project wildfly-core by wildfly.

the class CLIModelControllerClient method getOrCreateChannel.

protected Channel getOrCreateChannel() throws IOException {
    Channel ch = null;
    // Strategy is checked against null by mutiple methods in locked blocks.
    // Make it non null only at the end of connection process to advertise
    // that connection is done.
    ManagementClientChannelStrategy localStrategy;
    synchronized (lock) {
        if (strategy == null) {
            final ChannelCloseHandler channelCloseHandler = new ChannelCloseHandler();
            localStrategy = ManagementClientChannelStrategy.create(channelConfig, channelAssociation, handler, saslOptions, sslContext, channelCloseHandler);
            channelCloseHandler.setOriginalStrategy(localStrategy);
        } else {
            localStrategy = strategy;
        }
        state.set(CONNECTING);
    }
    // Can't be called locked, can create dead-lock in case close occurs.
    ch = localStrategy.getChannel();
    synchronized (lock) {
        strategy = localStrategy;
        // the state is switched to MUST_CLOSE.
        if (state.get() == MUST_CLOSE) {
            close();
            lock.notifyAll();
            throw new IOException("Connection closed");
        }
        // in that case the channel close handler would change the state to LOST_CONNECTION
        if (state.get() == LOST_CONNECTION) {
            // this will clean up things up here but the closed channel is still returned
            close();
        } else {
            state.set(CONNECTED);
        }
        lock.notifyAll();
    }
    return ch;
}
Also used : ManagementClientChannelStrategy(org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy) Channel(org.jboss.remoting3.Channel) IOException(java.io.IOException)

Example 3 with ManagementClientChannelStrategy

use of org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy 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 4 with ManagementClientChannelStrategy

use of org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy in project wildfly-core by wildfly.

the class ModelControllerClientTestCase method setupTestClient.

private ModelControllerClient setupTestClient(final ModelController controller) throws IOException {
    try {
        channels.setupRemoting(new ManagementChannelInitialization() {

            @Override
            public ManagementChannelHandler startReceiving(Channel channel) {
                final ManagementClientChannelStrategy strategy = ManagementClientChannelStrategy.create(channel);
                final ManagementChannelHandler support = new ManagementChannelHandler(strategy, channels.getExecutorService());
                support.addHandlerFactory(new ModelControllerClientOperationHandler(controller, support, new ResponseAttachmentInputStreamSupport(), getClientRequestExecutor()));
                channel.receiveMessage(support.getReceiver());
                return support;
            }

            private ExecutorService getClientRequestExecutor() {
                final BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>(512);
                final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction<ThreadFactory>() {

                    public ThreadFactory run() {
                        return new JBossThreadFactory(new ThreadGroup("management-handler-thread"), Boolean.FALSE, null, "%G - %t", null, null);
                    }
                });
                ThreadPoolExecutor executor = new ThreadPoolExecutor(4, 4, 250L, TimeUnit.MILLISECONDS, workQueue, threadFactory);
                // Allow the core threads to time out as well
                executor.allowCoreThreadTimeOut(true);
                return executor;
            }
        });
        channels.startClientConnetion();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    final Channel clientChannel = channels.getClientChannel();
    return ExistingChannelModelControllerClient.createReceiving(clientChannel, channels.getExecutorService());
}
Also used : ManagementClientChannelStrategy(org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy) ModelControllerClientOperationHandler(org.jboss.as.controller.remote.ModelControllerClientOperationHandler) BlockingQueue(java.util.concurrent.BlockingQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) ManagementChannelHandler(org.jboss.as.protocol.mgmt.ManagementChannelHandler) ThreadFactory(java.util.concurrent.ThreadFactory) JBossThreadFactory(org.jboss.threads.JBossThreadFactory) JBossThreadFactory(org.jboss.threads.JBossThreadFactory) Channel(org.jboss.remoting3.Channel) ResponseAttachmentInputStreamSupport(org.jboss.as.controller.remote.ResponseAttachmentInputStreamSupport) ManagementChannelInitialization(org.jboss.as.protocol.mgmt.support.ManagementChannelInitialization) IOException(java.io.IOException) PrivilegedAction(java.security.PrivilegedAction) ExecutorService(java.util.concurrent.ExecutorService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 5 with ManagementClientChannelStrategy

use of org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy in project wildfly-core by wildfly.

the class RemoteProxyControllerProtocolTestCase method setupProxyHandlers.

private RemoteProxyController setupProxyHandlers(final ModelController proxiedController) {
    try {
        channels = new RemoteChannelPairSetup();
        channels.setupRemoting(new ManagementChannelInitialization() {

            @Override
            public ManagementChannelHandler startReceiving(Channel channel) {
                final ManagementClientChannelStrategy strategy = ManagementClientChannelStrategy.create(channel);
                final ManagementChannelHandler support = new ManagementChannelHandler(strategy, channels.getExecutorService());
                support.addHandlerFactory(new TransactionalProtocolOperationHandler(proxiedController, support, responseAttachmentSupport));
                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 ManagementClientChannelStrategy strategy = ManagementClientChannelStrategy.create(clientChannel);
    final ManagementChannelHandler support = new ManagementChannelHandler(strategy, channels.getExecutorService());
    final RemoteProxyController proxyController = RemoteProxyController.create(support, PathAddress.pathAddress(), ProxyOperationAddressTranslator.HOST);
    clientChannel.addCloseHandler(new CloseHandler<Channel>() {

        @Override
        public void handleClose(Channel closed, IOException exception) {
            support.shutdownNow();
        }
    });
    clientChannel.receiveMessage(support.getReceiver());
    return proxyController;
}
Also used : ManagementClientChannelStrategy(org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy) ManagementChannelHandler(org.jboss.as.protocol.mgmt.ManagementChannelHandler) Channel(org.jboss.remoting3.Channel) ManagementChannelInitialization(org.jboss.as.protocol.mgmt.support.ManagementChannelInitialization) IOException(java.io.IOException) IOException(java.io.IOException) RemoteChannelPairSetup(org.jboss.as.controller.support.RemoteChannelPairSetup) CloseHandler(org.jboss.remoting3.CloseHandler) RemoteProxyController(org.jboss.as.controller.remote.RemoteProxyController) TransactionalProtocolOperationHandler(org.jboss.as.controller.remote.TransactionalProtocolOperationHandler)

Aggregations

ManagementClientChannelStrategy (org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy)8 ManagementChannelHandler (org.jboss.as.protocol.mgmt.ManagementChannelHandler)7 Channel (org.jboss.remoting3.Channel)6 IOException (java.io.IOException)5 ResponseAttachmentInputStreamSupport (org.jboss.as.controller.remote.ResponseAttachmentInputStreamSupport)3 TransactionalProtocolOperationHandler (org.jboss.as.controller.remote.TransactionalProtocolOperationHandler)3 ManagementChannelInitialization (org.jboss.as.protocol.mgmt.support.ManagementChannelInitialization)3 RemoteProxyController (org.jboss.as.controller.remote.RemoteProxyController)2 RemoteChannelPairSetup (org.jboss.as.controller.support.RemoteChannelPairSetup)2 CloseHandler (org.jboss.remoting3.CloseHandler)2 InetSocketAddress (java.net.InetSocketAddress)1 URI (java.net.URI)1 PrivilegedAction (java.security.PrivilegedAction)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 ExecutorService (java.util.concurrent.ExecutorService)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 ModelControllerClientOperationHandler (org.jboss.as.controller.remote.ModelControllerClientOperationHandler)1 TransactionalProtocolClient (org.jboss.as.controller.remote.TransactionalProtocolClient)1