Ejemplo n.º 1
0
  public static void main(String[] args) throws InterruptedException {
    System.out.println();
    System.out.println("Untyped transactor example");
    System.out.println();

    ActorRef counter1 = Actors.actorOf(UntypedCounter.class).start();
    ActorRef counter2 = Actors.actorOf(UntypedCounter.class).start();

    counter1.sendOneWay(new Increment(counter2));

    Thread.sleep(3000);

    Future future1 = counter1.sendRequestReplyFuture("GetCount");
    Future future2 = counter2.sendRequestReplyFuture("GetCount");

    future1.await();
    if (future1.isCompleted()) {
      if (future1.result().isDefined()) {
        int result = (Integer) future1.result().get();
        System.out.println("counter 1: " + result);
      }
    }

    future2.await();
    if (future2.isCompleted()) {
      if (future2.result().isDefined()) {
        int result = (Integer) future2.result().get();
        System.out.println("counter 2: " + result);
      }
    }

    counter1.stop();
    counter2.stop();
  }
Ejemplo n.º 2
0
 @Override
 public void onReceive(Object message) throws Exception {
   if (Update.equals(message)) sensor.sendOneWay(WeatherSensor.Get, getContext());
   else if (message instanceof WeatherData) {
     final WeatherData data = (WeatherData) message;
     SwingUtilities.invokeLater(
         new Runnable() {
           public void run() {
             temperatureLabel.setText(String.valueOf(data.temperature));
             humidityLabel.setText(String.valueOf(data.humidity));
           }
         });
   }
 }