/** {@inheritDoc} */
  public synchronized void start(StartContext context) throws StartException {
    Security.addProvider(new JBossSaslProvider());

    ProtocolChannelClient<ManagementChannel> client;
    try {
      ProtocolChannelClient.Configuration<ManagementChannel> configuration =
          new ProtocolChannelClient.Configuration<ManagementChannel>();
      configuration.setEndpoint(endpointInjector.getValue());
      configuration.setUri(
          new URI(
              "remote://"
                  + hcAddressInjector.getValue().getHostName()
                  + ":"
                  + hcAddressInjector.getValue().getPort()));
      configuration.setChannelFactory(new ManagementChannelFactory());
      client = ProtocolChannelClient.create(configuration);
    } catch (Exception e) {
      throw new StartException(e);
    }

    try {
      client.connect(new ClientCallbackHandler());
      channel = client.openChannel(RemotingServices.SERVER_CHANNEL);
      channel.startReceiving();
    } catch (IOException e) {
      throw new StartException("Failed to start remote Host Controller connection", e);
    }
  }
 /**
  * Create a connection wrapper.
  *
  * @param connectionURI the connection URI
  * @param callbackHandler the callback handler
  * @return the connection wrapper
  * @throws IOException
  */
 DomainTestConnection createConnection(
     final URI connectionURI, final CallbackHandler callbackHandler) throws IOException {
   final ProtocolChannelClient.Configuration configuration =
       new ProtocolChannelClient.Configuration();
   configuration.setEndpoint(endpoint);
   configuration.setUri(connectionURI);
   final ProtocolChannelClient client = ProtocolChannelClient.create(configuration);
   return new DomainTestConnection(client, callbackHandler, executorService);
 }
Ejemplo n.º 3
0
  CLIModelControllerClient(
      final String protocol,
      CallbackHandler handler,
      String hostName,
      int connectionTimeout,
      final ConnectionCloseHandler closeHandler,
      int port,
      SSLContext sslContext)
      throws IOException {
    this.handler = handler;
    this.sslContext = sslContext;
    this.closeHandler = closeHandler;

    this.channelAssociation =
        new ManagementChannelHandler(
            new ManagementClientChannelStrategy() {
              @Override
              public Channel getChannel() throws IOException {
                return getOrCreateChannel();
              }

              @Override
              public void close() throws IOException {}
            },
            executorService,
            this);

    channelConfig = new ProtocolChannelClient.Configuration();
    try {
      channelConfig.setUri(
          new URI(protocol + "://" + formatPossibleIpv6Address(hostName) + ":" + port));
    } catch (URISyntaxException e) {
      throw new IOException("Failed to create URI", e);
    }
    channelConfig.setOptionMap(DEFAULT_OPTIONS);
    if (connectionTimeout > 0) {
      channelConfig.setConnectionTimeout(connectionTimeout);
    }
    channelConfig.setEndpoint(endpoint);
  }
  @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 ManagementChannelHandler channels =
                new ManagementChannelHandler(channel, 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 ProtocolChannelClient.Configuration connectionConfig =
        new ProtocolChannelClient.Configuration();
    connectionConfig.setEndpoint(channelServer.getEndpoint());
    connectionConfig.setUri(new URI("" + URI_SCHEME + "://127.0.0.1:" + PORT + ""));
    //
    final ProtocolChannelClient client = ProtocolChannelClient.create(connectionConfig);
    futureConnection =
        client.connect(
            new PasswordClientCallbackHandler("bob", ENDPOINT_NAME, "pass".toCharArray()));
  }
 @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 {
       // 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();
   }
 }