private boolean connectUsingRemoting( CommandContext cmdCtx, RemotingMBeanServerConnection rmtMBeanSvrConn) throws IOException, CliInitializationException { Connection conn = rmtMBeanSvrConn.getConnection(); Channel channel; final IoFuture<Channel> futureChannel = conn.openChannel("management", OptionMap.EMPTY); IoFuture.Status result = futureChannel.await(5, TimeUnit.SECONDS); if (result == IoFuture.Status.DONE) { channel = futureChannel.get(); } else { return false; } ModelControllerClient modelCtlrClient = ExistingChannelModelControllerClient.createReceiving(channel, createExecutor()); cmdCtx.bindClient(modelCtlrClient); return true; }
@Before public void testStart() throws IOException, URISyntaxException, InterruptedException { System.gc(); System.runFinalization(); Logger.getLogger("TEST").infof("Running test %s", name.getMethodName()); 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") .allowSaslMechanisms("SCRAM-SHA-256")) .run( new PrivilegedAction<IoFuture<Connection>>() { public IoFuture<Connection> run() { try { return endpoint.connect(new URI("remote://localhost:30123"), OptionMap.EMPTY); } catch (IOException | 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); }
/** * 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()); }