Search in sources :

Example 41 with Channel

use of com.automatak.dnp3.Channel in project wildfly-core by wildfly.

the class TransactionalProtocolClientTestCase method startChannelServer.

@Before
public void startChannelServer() throws Exception {
    final ChannelServer.Configuration configuration = new ChannelServer.Configuration();
    configuration.setEndpointName(ENDPOINT_NAME);
    configuration.setUriScheme(URI_SCHEME);
    configuration.setBindAddress(new InetSocketAddress("127.0.0.1", PORT));
    channelServer = ChannelServer.create(configuration);
    // 
    channelServer.addChannelOpenListener(TEST_CHANNEL, new OpenListener() {

        @Override
        public void channelOpened(final Channel channel) {
            final MockController controller = new MockController();
            final ManagementClientChannelStrategy strategy = ManagementClientChannelStrategy.create(channel);
            final ManagementChannelHandler channels = new ManagementChannelHandler(strategy, remoteExecutors);
            final ManagementRequestHandlerFactory handlerFactory = new TransactionalProtocolOperationHandler(controller, channels, new ResponseAttachmentInputStreamSupport());
            channels.addHandlerFactory(handlerFactory);
            transferQueue.offer(controller);
            channel.addCloseHandler(channels);
            channel.receiveMessage(channels.getReceiver());
        }

        @Override
        public void registrationTerminated() {
        // 
        }
    });
    final ProtocolConnectionConfiguration connectionConfig = ProtocolConnectionConfiguration.create(channelServer.getEndpoint(), new URI("" + URI_SCHEME + "://127.0.0.1:" + PORT + ""));
    connectionConfig.setEndpoint(channelServer.getEndpoint());
    // 
    futureConnection = connectionConfig.getEndpoint().getConnection(connectionConfig.getUri());
}
Also used : ManagementClientChannelStrategy(org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy) ManagementChannelHandler(org.jboss.as.protocol.mgmt.ManagementChannelHandler) ProtocolConnectionConfiguration(org.jboss.as.protocol.ProtocolConnectionConfiguration) InetSocketAddress(java.net.InetSocketAddress) OpenListener(org.jboss.remoting3.OpenListener) Channel(org.jboss.remoting3.Channel) ResponseAttachmentInputStreamSupport(org.jboss.as.controller.remote.ResponseAttachmentInputStreamSupport) URI(java.net.URI) ChannelServer(org.jboss.as.controller.support.ChannelServer) ProtocolConnectionConfiguration(org.jboss.as.protocol.ProtocolConnectionConfiguration) TransactionalProtocolOperationHandler(org.jboss.as.controller.remote.TransactionalProtocolOperationHandler) ManagementRequestHandlerFactory(org.jboss.as.protocol.mgmt.ManagementRequestHandlerFactory) Before(org.junit.Before)

Example 42 with Channel

use of com.automatak.dnp3.Channel in project wildfly-core by wildfly.

the class TransactionalProtocolClientTestCase method createClient.

/**
 * Create the protocol client to talk to the remote controller.
 *
 * @return the client
 * @throws Exception
 */
TransactionalProtocolClient createClient() throws Exception {
    final Connection connection = futureConnection.get();
    final IoFuture<Channel> channelIoFuture = connection.openChannel(TEST_CHANNEL, OptionMap.EMPTY);
    return createClient(channelIoFuture.get());
}
Also used : Channel(org.jboss.remoting3.Channel) Connection(org.jboss.remoting3.Connection)

Example 43 with Channel

use of com.automatak.dnp3.Channel in project wildfly-core by wildfly.

the class TestControllerClient method executeAwaitClosed.

protected ModelNode executeAwaitClosed(final ModelNode operation) throws IOException {
    final Channel channel = getChannelAssociation().getChannel();
    final Connection connection = channel.getConnection();
    final ModelNode result = execute(operation);
    if (!ModelDescriptionConstants.SUCCESS.equals(result.get(ModelDescriptionConstants.OUTCOME).asString())) {
        return result;
    }
    try {
        connection.awaitClosed();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return result;
}
Also used : FutureManagementChannel(org.jboss.as.protocol.mgmt.FutureManagementChannel) Channel(org.jboss.remoting3.Channel) Connection(org.jboss.remoting3.Connection) ModelNode(org.jboss.dmr.ModelNode)

Example 44 with Channel

use of com.automatak.dnp3.Channel in project wildfly-core by wildfly.

the class RemoteChannelPairSetup method setupRemoting.

public void setupRemoting(final ManagementChannelInitialization initialization) throws IOException {
    // executorService = Executors.newCachedThreadPool();
    final 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);
    final 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);
    channelServer.addChannelOpenListener(TEST_CHANNEL, new OpenListener() {

        @Override
        public void registrationTerminated() {
        }

        @Override
        public void channelOpened(Channel channel) {
            serverChannel = channel;
            initialization.startReceiving(channel);
            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)

Example 45 with Channel

use of com.automatak.dnp3.Channel in project wildfly-core by wildfly.

the class DomainLifecycleUtil method executeAwaitConnectionClosed.

/**
 * Execute an operation and wait until the connection is closed. This is only useful for :reload and :shutdown operations.
 *
 * @param operation the operation to execute
 * @return the operation result
 * @throws IOException for any error
 * @throws IllegalStateException if {@link #close()} has previously been invoked on this instance.
 */
public ModelNode executeAwaitConnectionClosed(final ModelNode operation) throws IOException {
    checkClosed();
    final DomainTestClient client = internalGetOrCreateClient();
    final Channel channel = client.getChannel();
    if (null == channel) {
        throw new IllegalStateException("Didn't get a remoting channel from the DomainTestClient.");
    }
    final Connection ref = channel.getConnection();
    ModelNode result = new ModelNode();
    try {
        result = client.execute(operation);
        // IN case the operation wasn't successful, don't bother waiting
        if (!"success".equals(result.get("outcome").asString())) {
            return result;
        }
    } catch (IOException e) {
        final Throwable cause = e.getCause();
        if (!(cause instanceof ExecutionException) && !(cause instanceof CancellationException)) {
            throw e;
        }
    // else ignore, this might happen if the channel gets closed before we got the response
    }
    try {
        // Wait for the channel to close
        channel.awaitClosed();
        // Wait for the connection to be closed
        connection.awaitConnectionClosed(ref);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    return result;
}
Also used : CancellationException(java.util.concurrent.CancellationException) Channel(org.jboss.remoting3.Channel) Connection(org.jboss.remoting3.Connection) IOException(java.io.IOException) ModelNode(org.jboss.dmr.ModelNode) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

Channel (org.jboss.remoting3.Channel)41 IOException (java.io.IOException)29 Test (org.junit.Test)14 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 LivestreamServiceClient (com.google.cloud.video.livestream.v1.LivestreamServiceClient)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 ProtocolConnectionConfiguration (org.jboss.as.protocol.ProtocolConnectionConfiguration)4