use of org.jboss.remoting3.Registration in project wildfly-core by wildfly.
the class RemoteDomainConnection method connectionOpened.
@Override
public void connectionOpened(final Connection connection) throws IOException {
final Channel channel = openChannel(connection, CHANNEL_SERVICE_TYPE, configuration.getOptionMap());
if (setChannel(channel)) {
channel.receiveMessage(channelHandler.getReceiver());
channel.addCloseHandler(channelHandler);
try {
if (runningMode == RunningMode.ADMIN_ONLY) {
// Fetch the domain configuration
channelHandler.executeRequest(new FetchDomainConfigurationRequest(), null).getResult().get();
} else {
// Start the registration process
channelHandler.executeRequest(new RegisterHostControllerRequest(), null).getResult().get();
}
} catch (Exception e) {
if (e.getCause() instanceof IOException) {
throw (IOException) e.getCause();
}
throw new IOException(e);
}
// Registered
registered();
} else {
channel.closeAsync();
}
}
use of org.jboss.remoting3.Registration in project wildfly-core by wildfly.
the class AbstractChannelOpenListenerService method start.
@Override
public synchronized void start(StartContext context) throws StartException {
try {
closed = false;
RemotingLogger.ROOT_LOGGER.debugf("Registering channel listener for %s", channelName);
final ManagementChannelRegistryService registry = this.registrySupplier.get();
final Registration registration = endpointSupplier.get().registerService(channelName, this, optionMap);
// Add to global registry
registry.register(registration);
trackerService = registry.getTrackerService();
} catch (Exception e) {
throw RemotingLogger.ROOT_LOGGER.couldNotStartChanelListener(e);
}
}
use of org.jboss.remoting3.Registration in project jboss-remoting by jboss-remoting.
the class EndpointImpl method addConnectionProvider.
public Registration addConnectionProvider(final String uriScheme, final ConnectionProviderFactory providerFactory, final OptionMap optionMap) throws IOException {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(RemotingPermission.ADD_CONNECTION_PROVIDER);
}
boolean ok = false;
resourceUntick("Connection provider for " + uriScheme);
try {
final String saslProtocol = optionMap.get(RemotingOptions.SASL_PROTOCOL, RemotingOptions.DEFAULT_SASL_PROTOCOL);
final ConnectionProviderContextImpl context = new ConnectionProviderContextImpl(uriScheme, saslProtocol);
final ConnectionProvider provider = providerFactory.createInstance(context, optionMap, uriScheme);
final ProtocolRegistration protocolRegistration = new ProtocolRegistration(provider, context);
try {
if (connectionProviders.putIfAbsent(uriScheme, protocolRegistration) != null) {
safeClose(provider);
throw new DuplicateRegistrationException("URI scheme '" + uriScheme + "' is already registered to a provider");
}
// add a resource count for close
log.tracef("Adding connection provider registration named '%s': %s", uriScheme, provider);
final Registration registration = new MapRegistration<ProtocolRegistration>(connectionProviders, uriScheme, protocolRegistration) {
protected void closeAction() throws IOException {
try {
provider.closeAsync();
} finally {
super.closeAction();
}
}
};
provider.addCloseHandler((closed, exception) -> {
registration.closeAsync();
closeTick1(closed);
});
ok = true;
return registration;
} finally {
if (!ok) {
provider.close();
}
}
} finally {
if (!ok) {
closeTick1("Connection provider for " + uriScheme);
}
}
}
use of org.jboss.remoting3.Registration 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 org.jboss.remoting3.Registration 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);
}
}
Aggregations