Search in sources :

Example 26 with Channel

use of com.google.cloud.video.livestream.v1.Channel in project jboss-remoting by jboss-remoting.

the class HeartbeatTestCase method testDefaultHeartbeat.

/**
 * Test that heartbeat can be set and can be disabled by setting it to 0
 *
 * @throws Exception
 */
@Test
public void testDefaultHeartbeat() throws Exception {
    Channel clientChannel = null;
    Channel serverChannel = null;
    Closeable streamServer = null;
    Connection connection = null;
    Registration serviceRegistration = null;
    final Endpoint endpoint = Endpoint.builder().setEndpointName("test").build();
    NetworkServerProvider networkServerProvider = endpoint.getConnectionProviderInterface("remote", NetworkServerProvider.class);
    final SecurityDomain.Builder domainBuilder = SecurityDomain.builder();
    final SimpleMapBackedSecurityRealm mainRealm = new SimpleMapBackedSecurityRealm();
    domainBuilder.addRealm("mainRealm", mainRealm).build();
    domainBuilder.setDefaultRealmName("mainRealm");
    domainBuilder.setPermissionMapper((permissionMappable, roles) -> PermissionVerifier.ALL);
    final PasswordFactory passwordFactory = PasswordFactory.getInstance("clear");
    mainRealm.setPasswordMap("bob", passwordFactory.generatePassword(new ClearPasswordSpec("pass".toCharArray())));
    final SaslServerFactory saslServerFactory = new ServiceLoaderSaslServerFactory(HeartbeatTestCase.class.getClassLoader());
    final SaslAuthenticationFactory.Builder builder = SaslAuthenticationFactory.builder();
    builder.setSecurityDomain(domainBuilder.build());
    builder.setFactory(saslServerFactory);
    builder.setMechanismConfigurationSelector(mechanismInformation -> SaslMechanismInformation.Names.SCRAM_SHA_256.equals(mechanismInformation.getMechanismName()) ? MechanismConfiguration.EMPTY : null);
    final SaslAuthenticationFactory saslAuthenticationFactory = builder.build();
    streamServer = networkServerProvider.createServer(new InetSocketAddress("localhost", 30123), OptionMap.create(Options.SSL_ENABLED, Boolean.FALSE), saslAuthenticationFactory, SSLContext.getDefault());
    final FutureResult<Channel> passer = new FutureResult<Channel>();
    serviceRegistration = endpoint.registerService("org.jboss.test", new OpenListener() {

        public void channelOpened(final Channel channel) {
            passer.setResult(channel);
        }

        public void registrationTerminated() {
        }
    }, OptionMap.EMPTY);
    IoFuture<Connection> futureConnection = AuthenticationContext.empty().with(MatchRule.ALL, AuthenticationConfiguration.empty().useName("bob").usePassword("pass").setSaslMechanismSelector(SaslMechanismSelector.NONE.addMechanism("SCRAM-SHA-256"))).run(new PrivilegedAction<IoFuture<Connection>>() {

        public IoFuture<Connection> run() {
            try {
                return endpoint.connect(new URI("remote://localhost:30123"), OptionMap.EMPTY);
            } catch (URISyntaxException e) {
                throw new RuntimeException(e);
            }
        }
    });
    connection = futureConnection.get();
    IoFuture<Channel> futureChannel = connection.openChannel("org.jboss.test", OptionMap.EMPTY);
    clientChannel = futureChannel.get();
    serverChannel = passer.getIoFuture().get();
    assertNotNull(serverChannel);
    RemoteConnectionChannel remoteClientChannel = (RemoteConnectionChannel) clientChannel;
    assertEquals(RemotingOptions.DEFAULT_HEARTBEAT_INTERVAL, Utils.getInstanceValue(remoteClientChannel.getRemoteConnection(), "heartbeatInterval"));
    RemoteWriteListener clientWriteListener = (RemoteWriteListener) Utils.getInstanceValue(remoteClientChannel.getRemoteConnection(), "writeListener");
    assertNotNull(Utils.getInstanceValue(clientWriteListener, "heartKey"));
    afterTest(clientChannel, serverChannel, connection, serviceRegistration);
    destroy(endpoint, streamServer);
}
Also used : RemoteWriteListener(org.jboss.remoting3.remote.RemoteConnection.RemoteWriteListener) InetSocketAddress(java.net.InetSocketAddress) Closeable(java.io.Closeable) ClearPasswordSpec(org.wildfly.security.password.spec.ClearPasswordSpec) IoFuture(org.xnio.IoFuture) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain) Endpoint(org.jboss.remoting3.Endpoint) FutureResult(org.xnio.FutureResult) Registration(org.jboss.remoting3.Registration) NetworkServerProvider(org.jboss.remoting3.spi.NetworkServerProvider) ServiceLoaderSaslServerFactory(org.wildfly.security.sasl.util.ServiceLoaderSaslServerFactory) SimpleMapBackedSecurityRealm(org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm) SaslServerFactory(javax.security.sasl.SaslServerFactory) ServiceLoaderSaslServerFactory(org.wildfly.security.sasl.util.ServiceLoaderSaslServerFactory) OpenListener(org.jboss.remoting3.OpenListener) Channel(org.jboss.remoting3.Channel) Connection(org.jboss.remoting3.Connection) SaslAuthenticationFactory(org.wildfly.security.auth.server.sasl.SaslAuthenticationFactory) PasswordFactory(org.wildfly.security.password.PasswordFactory) Test(org.junit.Test)

Example 27 with Channel

use of com.google.cloud.video.livestream.v1.Channel in project jboss-ejb-client by wildfly.

the class EJBClientChannel method construct.

static IoFuture<EJBClientChannel> construct(final Channel channel, final DiscoveredNodeRegistry discoveredNodeRegistry, RetryExecutorWrapper retryExecutorWrapper) {
    FutureResult<EJBClientChannel> futureResult = new FutureResult<>();
    // now perform opening negotiation: receive server greeting
    channel.receiveMessage(new Channel.Receiver() {

        public void handleError(final Channel channel, final IOException error) {
            final ClassLoader oldCL = getAndSetSafeTCCL();
            try {
                futureResult.setException(error);
            } finally {
                resetTCCL(oldCL);
            }
        }

        public void handleEnd(final Channel channel) {
            final ClassLoader oldCL = getAndSetSafeTCCL();
            try {
                futureResult.setCancelled();
            } finally {
                resetTCCL(oldCL);
            }
        }

        public void handleMessage(final Channel channel, final MessageInputStream message) {
            final ClassLoader oldCL = getAndSetSafeTCCL();
            // receive message body
            try {
                final int version = min(3, StreamUtils.readInt8(message));
                // drain the rest of the message because it's just garbage really
                while (message.read() != -1) {
                    message.skip(Long.MAX_VALUE);
                }
                // send back result
                try (MessageOutputStream out = channel.writeMessage()) {
                    out.write(version);
                    out.writeUTF("river");
                }
                // almost done; wait for initial module available report
                final EJBClientChannel ejbClientChannel = new EJBClientChannel(channel, version, discoveredNodeRegistry, futureResult, retryExecutorWrapper);
                channel.receiveMessage(new Channel.Receiver() {

                    public void handleError(final Channel channel, final IOException error) {
                        final ClassLoader oldCL = getAndSetSafeTCCL();
                        try {
                            futureResult.setException(error);
                        } finally {
                            safeClose(channel);
                            resetTCCL(oldCL);
                        }
                    }

                    public void handleEnd(final Channel channel) {
                        final ClassLoader oldCL = getAndSetSafeTCCL();
                        try {
                            futureResult.setException(new EOFException());
                        } finally {
                            safeClose(channel);
                            resetTCCL(oldCL);
                        }
                    }

                    public void handleMessage(final Channel channel, final MessageInputStream message) {
                        final ClassLoader oldCL = getAndSetSafeTCCL();
                        try {
                            ejbClientChannel.processMessage(message);
                        } finally {
                            channel.receiveMessage(this);
                            resetTCCL(oldCL);
                        }
                    }
                });
            } catch (final IOException e) {
                channel.closeAsync();
                channel.addCloseHandler((closed, exception) -> futureResult.setException(e));
            } finally {
                resetTCCL(oldCL);
            }
        }
    });
    futureResult.addCancelHandler(new Cancellable() {

        public Cancellable cancel() {
            if (futureResult.setCancelled()) {
                safeClose(channel);
            }
            return this;
        }
    });
    return futureResult.getIoFuture();
}
Also used : MessageOutputStream(org.jboss.remoting3.MessageOutputStream) MessageInputStream(org.jboss.remoting3.MessageInputStream) FutureResult(org.xnio.FutureResult) Cancellable(org.xnio.Cancellable) Channel(org.jboss.remoting3.Channel) EOFException(java.io.EOFException) IOException(java.io.IOException)

Example 28 with Channel

use of com.google.cloud.video.livestream.v1.Channel in project jboss-ejb-client by wildfly.

the class DummyServer method start.

public void start() throws Exception {
    logger.info("Starting " + this);
    // create a Remoting endpoint
    final OptionMap options = OptionMap.EMPTY;
    EndpointBuilder endpointBuilder = Endpoint.builder();
    endpointBuilder.setEndpointName(this.endpointName);
    endpointBuilder.buildXnioWorker(Xnio.getInstance()).populateFromOptions(options);
    endpoint = endpointBuilder.build();
    if (startTxServer) {
        final RemotingTransactionService remotingTransactionService = RemotingTransactionService.builder().setEndpoint(endpoint).setTransactionContext(LocalTransactionContext.getCurrent()).build();
        remotingTransactionService.register();
    }
    // add a connection provider factory for the URI scheme "remote"
    // endpoint.addConnectionProvider("remote", new RemoteConnectionProviderFactory(), OptionMap.create(Options.SSL_ENABLED, Boolean.FALSE));
    final NetworkServerProvider serverProvider = endpoint.getConnectionProviderInterface("remote", NetworkServerProvider.class);
    // set up a security realm called default with a user called test
    final SimpleMapBackedSecurityRealm realm = new SimpleMapBackedSecurityRealm();
    realm.setPasswordMap("test", ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, "test".toCharArray()));
    // set up a security domain which has realm "default"
    final SecurityDomain.Builder domainBuilder = SecurityDomain.builder();
    // add the security realm called "default" to the security domain
    domainBuilder.addRealm("default", realm).build();
    domainBuilder.setDefaultRealmName("default");
    domainBuilder.setPermissionMapper((permissionMappable, roles) -> PermissionVerifier.ALL);
    SecurityDomain testDomain = domainBuilder.build();
    // set up a SaslAuthenticationFactory (i.e. a SaslServerFactory)
    SaslAuthenticationFactory saslAuthenticationFactory = SaslAuthenticationFactory.builder().setSecurityDomain(testDomain).setMechanismConfigurationSelector(mechanismInformation -> {
        switch(mechanismInformation.getMechanismName()) {
            case "ANONYMOUS":
            case "PLAIN":
                {
                    return MechanismConfiguration.EMPTY;
                }
            default:
                return null;
        }
    }).setFactory(SaslFactories.getElytronSaslServerFactory()).build();
    final OptionMap serverOptions = OptionMap.create(Options.SASL_MECHANISMS, Sequence.of("ANONYMOUS"), Options.SASL_POLICY_NOANONYMOUS, Boolean.FALSE);
    final SocketAddress bindAddress = new InetSocketAddress(InetAddress.getByName(host), port);
    this.server = serverProvider.createServer(bindAddress, serverOptions, saslAuthenticationFactory, null);
    // set up an association to handle invocations, session creations and module/toopology listensrs
    // the association makes use of a module deployment repository as well a sa  cluster registry
    Association dummyAssociation = new DummyAssociationImpl(this, deploymentRepository, clusterRegistry);
    // set up a remoting transaction service
    RemotingTransactionService.Builder txnServiceBuilder = RemotingTransactionService.builder();
    txnServiceBuilder.setEndpoint(endpoint);
    txnServiceBuilder.setTransactionContext(LocalTransactionContext.getCurrent());
    RemotingTransactionService transactionService = txnServiceBuilder.build();
    // setup remote EJB service
    RemoteEJBService remoteEJBService = RemoteEJBService.create(dummyAssociation, transactionService, DEFAULT_CLASS_FILTER);
    remoteEJBService.serverUp();
    // Register an EJB channel open listener
    OpenListener channelOpenListener = remoteEJBService.getOpenListener();
    try {
        registration = endpoint.registerService("jboss.ejb", new OpenListener() {

            @Override
            public void channelOpened(Channel channel) {
                currentConnections.add(channel);
                channelOpenListener.channelOpened(channel);
            }

            @Override
            public void registrationTerminated() {
            }
        }, OptionMap.EMPTY);
    } catch (ServiceRegistrationException e) {
        throw new Exception(e);
    }
}
Also used : RemoteEJBService(org.jboss.ejb.protocol.remote.RemoteEJBService) SimpleMapBackedSecurityRealm(org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm) InetSocketAddress(java.net.InetSocketAddress) OpenListener(org.jboss.remoting3.OpenListener) AcceptingChannel(org.xnio.channels.AcceptingChannel) Channel(org.jboss.remoting3.Channel) EndpointBuilder(org.jboss.remoting3.EndpointBuilder) RemotingTransactionService(org.wildfly.transaction.client.provider.remoting.RemotingTransactionService) ServiceRegistrationException(org.jboss.remoting3.ServiceRegistrationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain) SaslAuthenticationFactory(org.wildfly.security.auth.server.SaslAuthenticationFactory) Association(org.jboss.ejb.server.Association) ServiceRegistrationException(org.jboss.remoting3.ServiceRegistrationException) OptionMap(org.xnio.OptionMap) NetworkServerProvider(org.jboss.remoting3.spi.NetworkServerProvider) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 29 with Channel

use of com.google.cloud.video.livestream.v1.Channel in project grpc-java by grpc.

the class ChannelzProtoUtil method toChannel.

static Channel toChannel(InternalInstrumented<ChannelStats> channel) {
    ChannelStats stats = getFuture(channel.getStats());
    Channel.Builder channelBuilder = Channel.newBuilder().setRef(toChannelRef(channel)).setData(extractChannelData(stats));
    for (InternalWithLogId subchannel : stats.subchannels) {
        channelBuilder.addSubchannelRef(toSubchannelRef(subchannel));
    }
    return channelBuilder.build();
}
Also used : ChannelStats(io.grpc.InternalChannelz.ChannelStats) Channel(io.grpc.channelz.v1.Channel) InternalWithLogId(io.grpc.InternalWithLogId)

Example 30 with Channel

use of com.google.cloud.video.livestream.v1.Channel in project ysoserial by frohoff.

the class JBoss method getChannel.

private static Channel getChannel(ConnectionProviderContextImpl context, ConnectionHandler ch, OptionMap options) throws IOException {
    Channel c;
    FutureResult<Channel> chResult = new FutureResult<Channel>(context.getExecutor());
    ch.open("jmx", chResult, options);
    IoFuture<Channel> cFuture = chResult.getIoFuture();
    Status s2 = cFuture.await();
    if (s2 == Status.FAILED) {
        System.err.println("Cannot connect");
        if (cFuture.getException() != null) {
            throw new IOException("Connect failed", cFuture.getException());
        }
    } else if (s2 != Status.DONE) {
        cFuture.cancel();
        throw new IOException("Connect timeout");
    }
    c = cFuture.get();
    return c;
}
Also used : Status(org.xnio.IoFuture.Status) FutureResult(org.xnio.FutureResult) Channel(org.jboss.remoting3.Channel) IOException(java.io.IOException)

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