当前位置: 首页>>代码示例>>Java>>正文


Java WampClient类代码示例

本文整理汇总了Java中ws.wamp.jawampa.WampClient的典型用法代码示例。如果您正苦于以下问题:Java WampClient类的具体用法?Java WampClient怎么用?Java WampClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


WampClient类属于ws.wamp.jawampa包,在下文中一共展示了WampClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import ws.wamp.jawampa.WampClient; //导入依赖的package包/类
public void init() throws Exception {
  WampClientBuilder builder = new WampClientBuilder();
  builder.withConnectorProvider(new NettyWampClientConnectorProvider())
      .withAuthId(config.wampUsername())
      .withAuthMethod(new Ticket(config.wampPassword()))
      .withUri(config.wampUri())
      .withRealm(config.wampRealm())
      .withInfiniteReconnects()
      .withReconnectInterval(config.wampReconnectInterval(),
          TimeUnit.SECONDS);
  client = builder.build();
  client.open();
  client.statusChanged().subscribe((WampClient.State newStatus) -> {
    if (newStatus instanceof WampClient.ConnectedState) {
      logger.info("Connected to {}",
          config.wampUri());
    } else if (newStatus instanceof WampClient.DisconnectedState) {
      logger.info("Disconnected from {}",
          config.wampUri());
    } else if (newStatus instanceof WampClient.ConnectingState) {
      logger.debug("Connecting to {}",
          config.wampUri());
    }
  });
}
 
开发者ID:semiotproject,项目名称:semiot-platform,代码行数:26,代码来源:WAMPClient.java

示例2: init

import ws.wamp.jawampa.WampClient; //导入依赖的package包/类
public Observable<WampClient.State> init(
    String wampUri, String wampRealm, int wampReconnectInterval,
    String authId, String ticket)
    throws Exception {
  WampClientBuilder builder = new WampClientBuilder();
  builder.withConnectorProvider(new PlainWampClientConnectorProvider())
      .withUri(wampUri)
      .withRealm(wampRealm)
      .withInfiniteReconnects()
      .withReconnectInterval(wampReconnectInterval,
          TimeUnit.SECONDS)
      .withAuthId(authId)
      .withAuthMethod(new Ticket(ticket));
  client = builder.build();
  client.open();
  return client.statusChanged();
}
 
开发者ID:semiotproject,项目名称:semiot-platform,代码行数:18,代码来源:WAMPClient.java

示例3: init

import ws.wamp.jawampa.WampClient; //导入依赖的package包/类
@Override
public void init() {
    try {
    WampClientBuilder builder = new WampClientBuilder();
        builder.witUri(serverURI)
                .withRealm(realm)
                .withSslContext(SslContext.newClientContext(
                        InsecureTrustManagerFactory.INSTANCE))
                .withInfiniteReconnects()
                .withReconnectInterval(5, TimeUnit.SECONDS);
        client = builder.build();
        client.statusChanged().subscribe((WampClient.Status newStatus) -> {
            if(WampClient.Status.Connected == newStatus) {
                logger.debug("Connected to WAMP router [{}]", serverURI);
            } else if(WampClient.Status.Connecting == newStatus) {
                logger.debug("Connecting to WAMP router [{}]", serverURI);
            }
        });
        client.open();
    } catch(Exception ex) {
        logger.error(ex.getMessage(), ex);
    }
}
 
开发者ID:ailabitmo,项目名称:DAAFSE,代码行数:24,代码来源:WAMPMessagePublisher.java

示例4: getOrCreateClient

import ws.wamp.jawampa.WampClient; //导入依赖的package包/类
private CompletableFuture<WampClient> getOrCreateClient(final StreamURI streamURI)
        throws ApplicationError {
    CompletableFuture<WampClient> result = new CompletableFuture<>();
    if (!clients.containsKey(streamURI.getServerURI())) {
        WampClientBuilder builder = new WampClientBuilder();
        builder.witUri(streamURI.getServerURI().toASCIIString())
                .withRealm(DEFAULT_REALM)
                .withInfiniteReconnects()
                .withReconnectInterval(5, TimeUnit.SECONDS);
        WampClient client = builder.build();
        client.statusChanged().subscribe((WampClient.Status newStatus) -> {
            logger.debug("WAMP router [{}] status: {}", 
                    streamURI.getServerURI(), newStatus);
            if(newStatus == WampClient.Status.Connected) {
                result.complete(client);
            }
        });
        client.open();
        clients.put(streamURI.getServerURI(), client);
    } else {
        result.complete(clients.get(streamURI.getServerURI()));
    }
    return result;
}
 
开发者ID:ailabitmo,项目名称:DAAFSE,代码行数:25,代码来源:WAMPMessagePublishingService.java

示例5: closeSession

import ws.wamp.jawampa.WampClient; //导入依赖的package包/类
void closeSession(Throwable disconnectReason, String optCloseMessageReason, boolean reconnectAllowed) {
    // Send goodbye message with close reason to the remote
    if (optCloseMessageReason != null) {
        GoodbyeMessage msg = new GoodbyeMessage(null, optCloseMessageReason);
        connectionController.sendMessage(msg, IWampConnectionPromise.Empty);
    }
    
    stateController.setExternalState(new WampClient.DisconnectedState(disconnectReason));
    
    int nrReconnectAttempts = reconnectAllowed ? stateController.clientConfig().totalNrReconnects() : 0;
    if (nrReconnectAttempts != 0) {
        stateController.setExternalState(new WampClient.ConnectingState());
    }
    
    clearSessionData();
    
    WaitingForDisconnectState newState = new WaitingForDisconnectState(stateController, nrReconnectAttempts);
    connectionController.close(true, newState.closePromise());
    stateController.setState(newState);
}
 
开发者ID:Matthias247,项目名称:jawampa,代码行数:21,代码来源:SessionEstablishedState.java

示例6: init

import ws.wamp.jawampa.WampClient; //导入依赖的package包/类
public Observable<WampClient.State> init() throws Exception {
  WampClientBuilder builder = new WampClientBuilder();
  builder.withUri(CONFIG.wampUri()).withRealm(CONFIG.wampRealm())
      .withInfiniteReconnects()
      .withReconnectInterval(CONFIG.wampReconnectInterval(), TimeUnit.SECONDS)
      .withConnectorProvider(new PlainWampClientConnectorProvider())
      .withAuthId(CONFIG.wampLogin())
      .withAuthMethod(new Ticket(CONFIG.wampPassword()));
  client = builder.build();
  client.open();
  return client.statusChanged();
}
 
开发者ID:semiotproject,项目名称:semiot-platform,代码行数:13,代码来源:WAMPClient.java

示例7: init

import ws.wamp.jawampa.WampClient; //导入依赖的package包/类
@PostConstruct
public void init() {
  logger.info("initializing");
  final IWampConnectorProvider provider = new NettyWampClientConnectorProvider();

  try {
    WampClientBuilder builder = new WampClientBuilder();
    builder
        .withConnectorProvider(provider)
        .withUri(config.wampUri())
        .withRealm(config.wampRealm())
        .withInfiniteReconnects()
        .withReconnectInterval(5, TimeUnit.SECONDS);
    client = builder.build();

    client.statusChanged().subscribe((WampClient.State state) -> {
      if (state instanceof WampClient.ConnectedState) {
        logger.info("connected to WAMP router [{}]", client.routerUri().toASCIIString());

        subject.onNext(client);
      } else if (state instanceof WampClient.ConnectingState) {
        logger.info("connecting to WAMP router [{}]", client.routerUri().toASCIIString());

      } else if (state instanceof WampClient.DisconnectedState) {
        logger.info("disconnected from WAMP router [{}]", client.routerUri().toASCIIString());
      }
    });

    client.open();
  } catch (Exception ex) {
    logger.warn(ex.getMessage(), ex);
  }
}
 
开发者ID:semiotproject,项目名称:semiot-platform,代码行数:34,代码来源:MessageBusService.java

示例8: start

import ws.wamp.jawampa.WampClient; //导入依赖的package包/类
public void start() {
  logger.info("Device Manager is starting...");
  try {
    WAMPClient
        .getInstance()
        .init(configuration.getAsString(Keys.WAMP_URI),
            configuration.getAsString(Keys.WAMP_REALM),
            configuration.getAsInteger(Keys.WAMP_RECONNECT),
            configuration.getAsString(Keys.WAMP_LOGIN),
            configuration.getAsString(Keys.WAMP_PASSWORD))
        .subscribe(
            (WampClient.State newState) -> {
              if (newState instanceof WampClient.ConnectedState) {
                logger.info("Connected to {}", configuration.get(Keys.WAMP_URI));
              } else if (newState instanceof WampClient.DisconnectedState) {
                logger.info("Disconnected from {}. Reason: {}",
                    configuration.get(Keys.WAMP_URI),
                    ((WampClient.DisconnectedState) newState).disconnectReason());
              } else if (newState instanceof WampClient.ConnectingState) {
                logger.info("Connecting to {}", configuration.get(Keys.WAMP_URI));
              }
            });
    logger.info("Device Proxy Service Manager started!");
  } catch (Throwable ex) {
    logger.error(ex.getMessage(), ex);
    try {
      WAMPClient.getInstance().close();
    } catch (IOException ex1) {
      logger.error(ex1.getMessage(), ex1);
    }
  }
}
 
开发者ID:semiotproject,项目名称:semiot-platform,代码行数:33,代码来源:DriverManagerImpl.java

示例9: publish

import ws.wamp.jawampa.WampClient; //导入依赖的package包/类
@Override
public void publish(final StreamURI uri, final String body) {
    try {
        WampClient client = getOrCreateClient(uri).join();
        client.publish(uri.getTopic(), body);
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
    }
}
 
开发者ID:ailabitmo,项目名称:DAAFSE,代码行数:10,代码来源:WAMPMessagePublishingService.java

示例10: register

import ws.wamp.jawampa.WampClient; //导入依赖的package包/类
@Override
public void register(final StreamURI uri) {
    if(subscriptions.containsKey(uri)) {
        logger.debug("Stream [{}] is already being read!", uri);
        return;
    }
    try {
        WampClient client = getOrCreateClient(uri).join();
        Subscription sub = client.makeSubscription(uri.getTopic(), String.class)
                .subscribe(new ObservationConsumer(uri));
        subscriptions.put(uri, sub);
    } catch (ApplicationError ex) {
        logger.error(ex.getMessage(), ex);
    }
}
 
开发者ID:ailabitmo,项目名称:DAAFSE,代码行数:16,代码来源:WAMPMessagePublishingService.java

示例11: closeIncompleteSession

import ws.wamp.jawampa.WampClient; //导入依赖的package包/类
void closeIncompleteSession(Throwable disconnectReason, String optAbortReason, boolean reconnectAllowed) {
    // Send abort to the remote
    if (optAbortReason != null) {
        AbortMessage msg = new AbortMessage(null, optAbortReason);
        connectionController.sendMessage(msg, IWampConnectionPromise.Empty);
    }
    
    int nrReconnects = reconnectAllowed ? nrReconnectAttempts : 0;
    if (nrReconnects == 0) {
        stateController.setExternalState(new WampClient.DisconnectedState(disconnectReason));
    }
    WaitingForDisconnectState newState = new WaitingForDisconnectState(stateController, nrReconnects);
    connectionController.close(true, newState.closePromise());
    stateController.setState(newState);
}
 
开发者ID:Matthias247,项目名称:jawampa,代码行数:16,代码来源:HandshakingState.java

示例12: onEnter

import ws.wamp.jawampa.WampClient; //导入依赖的package包/类
@Override
public void onEnter(ClientState lastState) {
    if (lastState instanceof InitialState) {
        stateController.setExternalState(new WampClient.ConnectingState());
    }
    
    // Check for valid number of connects
    assert (nrConnectAttempts != 0);
    // Decrease remaining number of reconnects if it's not infinite
    if (nrConnectAttempts > 0) nrConnectAttempts--;
    
    // Starts an connection attempt to the router
    connectionController =
        new QueueingConnectionController(stateController.scheduler(), new ClientConnectionListener(stateController));
    
    try {
        connectingCon =
            stateController.clientConfig().connector().connect(stateController.scheduler(), this, connectionController);
    } catch (Exception e) {
        // Catch exceptions that can happen during creating the channel
        // These are normally signs that something is wrong with our configuration
        // Therefore we don't trigger retries
        stateController.setCloseError(e);
        stateController.setExternalState(new WampClient.DisconnectedState(e));
        DisconnectedState newState = new DisconnectedState(stateController, e);
        // This is a reentrant call to setState. However it works as onEnter is the last call in setState
        stateController.setState(newState);
    }
}
 
开发者ID:Matthias247,项目名称:jawampa,代码行数:30,代码来源:ConnectingState.java

示例13: initClose

import ws.wamp.jawampa.WampClient; //导入依赖的package包/类
@Override
public void initClose() {
    reconnectSubscription.unsubscribe();
    // Current external state is Connecting
    // Move to disconnected
    stateController.setExternalState(new WampClient.DisconnectedState(null));
    // And switch the internal state also to Disconnected
    DisconnectedState newState = new DisconnectedState(stateController, null);
    stateController.setState(newState);
}
 
开发者ID:Matthias247,项目名称:jawampa,代码行数:11,代码来源:WaitingForReconnectState.java

示例14: initClose

import ws.wamp.jawampa.WampClient; //导入依赖的package包/类
@Override
public void initClose() {
    if (nrReconnectAttempts != 0) {
        // Cancelling a reconnect triggers a state transition
        nrReconnectAttempts = 0;
        stateController.setExternalState(new WampClient.DisconnectedState(null));
    }
}
 
开发者ID:Matthias247,项目名称:jawampa,代码行数:9,代码来源:WaitingForDisconnectState.java

示例15: ServerEventDispatcher

import ws.wamp.jawampa.WampClient; //导入依赖的package包/类
@Inject
public ServerEventDispatcher(WampClient wampClient,
                             ServerState serverState)
{
    this.wampClient = wampClient;
    this.serverState = serverState;

    this.setName(ServerEventDispatcher.class.getSimpleName());
    this.setDaemon(true);
    this.start();
}
 
开发者ID:udidb,项目名称:udidb,代码行数:12,代码来源:ServerEventDispatcher.java


注:本文中的ws.wamp.jawampa.WampClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。