Ejemplo n.º 1
0
 @Override
 protected void doStart() throws Exception {
   session.handshake();
   BayeuxServer bayeuxServer = oort.getBayeuxServer();
   bayeuxServer.createChannelIfAbsent(forwardChannelName).getReference().addListener(this);
   bayeuxServer.createChannelIfAbsent(broadcastChannelName).getReference().addListener(this);
   bayeuxServer.createChannelIfAbsent(resultChannelName).getReference().addListener(this);
   oort.observeChannel(broadcastChannelName);
   logger.debug("Started {}", this);
 }
  public void onUpdates(List<StockPriceEmitter.Update> updates) {
    for (StockPriceEmitter.Update update : updates) {
      // Create the channel name using the stock symbol
      String channelName = "/stock/" + update.getSymbol().toLowerCase(Locale.ENGLISH);

      // Initialize the channel, making it persistent and lazy
      bayeuxServer.createChannelIfAbsent(
          channelName,
          new ConfigurableServerChannel.Initializer() {
            public void configureChannel(ConfigurableServerChannel channel) {
              channel.setPersistent(true);
              channel.setLazy(true);
            }
          });

      // Convert the Update business object to a CometD-friendly format
      Map<String, Object> data = new HashMap<String, Object>(4);
      data.put("symbol", update.getSymbol());
      data.put("oldValue", update.getOldValue());
      data.put("newValue", update.getNewValue());
      System.out.println("===========================");
      // Publish to all subscribers
      ServerChannel channel = bayeuxServer.getChannel(channelName);
      channel.publish(sender, data);
    }
  }
Ejemplo n.º 3
0
 @PostConstruct
 public void construct() throws Exception {
   counter.start();
   Oort oort = counter.getOort();
   BayeuxServer bayeuxServer = oort.getBayeuxServer();
   bayeuxServer.addListener(this);
   bayeuxServer.createChannelIfAbsent(
       CHANNEL, new ConfigurableServerChannel.Initializer.Persistent());
   oort.observeChannel(CHANNEL);
 }