Search in sources :

Example 6 with Channel

use of com.google.cloud.video.livestream.v1.Channel 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 7 with Channel

use of com.google.cloud.video.livestream.v1.Channel 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 8 with Channel

use of com.google.cloud.video.livestream.v1.Channel 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 9 with Channel

use of com.google.cloud.video.livestream.v1.Channel 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 10 with Channel

use of com.google.cloud.video.livestream.v1.Channel in project wildfly-core by wildfly.

the class RemoteChannelPairSetup method setupRemoting.

public void setupRemoting(final ManagementMessageHandler handler) throws IOException {
    // executorService = new ThreadPoolExecutor(16, 16, 1L, TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>());
    ThreadFactory threadFactory = new JBossThreadFactory(new ThreadGroup("Remoting"), Boolean.FALSE, null, "Remoting %f thread %t", null, null);
    executorService = new QueueExecutor(EXECUTOR_MAX_THREADS / 4 + 1, EXECUTOR_MAX_THREADS, EXECUTOR_KEEP_ALIVE_TIME, TimeUnit.MILLISECONDS, 500, threadFactory, true, null);
    ChannelServer.Configuration configuration = new ChannelServer.Configuration();
    configuration.setEndpointName(ENDPOINT_NAME);
    configuration.setUriScheme(URI_SCHEME);
    configuration.setBindAddress(new InetSocketAddress("127.0.0.1", PORT));
    configuration.setExecutor(executorService);
    channelServer = ChannelServer.create(configuration);
    final Channel.Receiver receiver = ManagementChannelReceiver.createDelegating(handler);
    this.registration = channelServer.addChannelOpenListener(TEST_CHANNEL, new OpenListener() {

        @Override
        public void registrationTerminated() {
        }

        @Override
        public void channelOpened(Channel channel) {
            serverChannel = channel;
            serverChannel.receiveMessage(receiver);
            clientConnectedLatch.countDown();
        }
    });
}
Also used : JBossThreadFactory(org.jboss.threads.JBossThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) JBossThreadFactory(org.jboss.threads.JBossThreadFactory) ProtocolConnectionConfiguration(org.jboss.as.protocol.ProtocolConnectionConfiguration) QueueExecutor(org.jboss.threads.QueueExecutor) InetSocketAddress(java.net.InetSocketAddress) OpenListener(org.jboss.remoting3.OpenListener) Channel(org.jboss.remoting3.Channel)

Aggregations

Channel (org.jboss.remoting3.Channel)41 IOException (java.io.IOException)29 Test (org.junit.Test)14 LivestreamServiceClient (com.google.cloud.video.livestream.v1.LivestreamServiceClient)13 Connection (org.jboss.remoting3.Connection)12 MessageInputStream (org.jboss.remoting3.MessageInputStream)12 CountDownLatch (java.util.concurrent.CountDownLatch)10 OpenListener (org.jboss.remoting3.OpenListener)10 MessageOutputStream (org.jboss.remoting3.MessageOutputStream)9 InetSocketAddress (java.net.InetSocketAddress)8 URI (java.net.URI)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 IoFuture (org.xnio.IoFuture)7 Channel (com.google.cloud.video.livestream.v1.Channel)6 URISyntaxException (java.net.URISyntaxException)6 ManagementClientChannelStrategy (org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy)6 FutureResult (org.xnio.FutureResult)6 ManagementChannelHandler (org.jboss.as.protocol.mgmt.ManagementChannelHandler)5 Endpoint (org.jboss.remoting3.Endpoint)5 Event (com.google.cloud.video.livestream.v1.Event)4