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);
}
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();
}
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);
}
}
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();
}
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;
}
Aggregations