Exemplo 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();
  }
Exemplo n.º 2
0
  public static void main(String[] args) {
    ActorRef actorARef = Actors.actorOf(ActorA.class);

    SupervisorFactory factory =
        new SupervisorFactory(
            new SupervisorConfig(
                new OneForOneStrategy(new Class[] {IllegalArgumentException.class}, 3, 5000),
                new Supervise[] {new Supervise(actorARef, permanent())}));

    Supervisor supervisor = factory.newInstance();
    supervisor.start();

    actorARef.tell(new Message("message1 before crash"));
    actorARef.tell(new Message("message2 before crash"));

    // let actorA crash
    actorARef.tell(new CrashMessage());

    actorARef.tell(new Message("message3 after crash"));

    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
    }

    supervisor.shutdown();
  }
Exemplo n.º 3
0
  /**
   * Main method to run the program.
   *
   * @param args
   */
  public static void main(String args[]) {
    if (args.length > 0) {

      String pString = args[0];
      for (int i = 1; i < args.length; i++) {
        String fileName = args[i];
        files.add(fileName);
      }

      Pattern p = Pattern.compile(pString);
      FileCount fileCount = new FileCount(files.size());
      ActorRef colActor = akka.actor.Actors.actorOf(CollectionActor.class);
      colActor.start();
      colActor.tell(fileCount);

      for (int i = 0; i < files.size(); i++) {
        ActorRef actor = akka.actor.Actors.actorOf(ScanActor.class);
        actor.start();
        actor.tell(new Configure(files.get(i), p, colActor));
        actors.add(actor);
      }
    }
  }