示例#1
0
  public void addChannelOpenListener(final String channelName, final OpenListener openListener)
      throws ServiceRegistrationException {
    endpoint.registerService(
        channelName,
        new OpenListener() {
          public void channelOpened(final Channel channel) {
            if (openListener != null) {
              openListener.channelOpened(channel);
            }
          }

          public void registrationTerminated() {
            if (openListener != null) {
              openListener.registrationTerminated();
            }
          }
        },
        OptionMap.EMPTY);
  }
  @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);
  }