Пример #1
0
 @Override
 public void notifyObservers() {
   System.out.println();
   for (IObserver observer : observers) {
     observer.update(desc);
   }
 }
Пример #2
0
  /**
   * 从指定队列接收消息,然后通过观察者对象处理
   *
   * @param queueName
   * @param observer
   * @throws Exception
   */
  public void receive(String queueName, IObserver observer) throws Exception {
    try {
      this.init();

      // 指定队列
      channel.queueDeclare(queueName, true, false, false, null);

      // 绑定队列到指定的交换机
      // channel.queueBind(queueName, mqExchangeName, queueName);
      // log.info("Bind queue {} to {} success! ", queueName, mqExchangeName);

      QueueingConsumer consumer = new QueueingConsumer(channel);
      channel.basicConsume(queueName, true, consumer);

      while (true) {
        // 阻塞,直到接收到一条消息
        QueueingConsumer.Delivery delivery = consumer.nextDelivery();
        String message = new String(delivery.getBody());
        log.info("Received a message: " + message);

        observer.update(message);
      }

    } finally {
      this.destory();
    }
  }
Пример #3
0
 /* (non-Javadoc)
  * @see ome.formats.importer.IObservable#notifyObservers(ome.formats.importer.ImportEvent)
  */
 public void notifyObservers(ImportEvent event) {
   for (IObserver observer : observers) {
     observer.update(this, event);
   }
 }
Пример #4
0
 @Override
 public void onStateChange(T content) {
   for (IObserver<T> observer : observers) {
     observer.update(content);
   }
 }
Пример #5
0
 public void notifyObservers() {
   for (int i = 0; i < observers.size(); i++) {
     IObserver observer = observers.get(i);
     observer.update();
   }
 }