Ejemplo n.º 1
0
    public void testSchedule(
        final JavaTestKit probe,
        Props props,
        FiniteDuration startDuration,
        FiniteDuration afterRestartDuration) {
      Iterable<akka.testkit.EventFilter> filter =
          Arrays.asList(
              new akka.testkit.EventFilter[] {
                (akka.testkit.EventFilter) new ErrorFilter(ArithmeticException.class)
              });
      try {
        system.eventStream().publish(new Mute(filter));

        final ActorRef actor = system.actorOf(props);
        new Within(startDuration) {
          protected void run() {
            probe.expectMsgEquals("tick");
            probe.expectMsgEquals("tick");
            probe.expectMsgEquals("tick");
          }
        };
        actor.tell("restart", getRef());
        new Within(afterRestartDuration) {
          protected void run() {
            probe.expectMsgEquals("tick");
            probe.expectMsgEquals("tick");
          }
        };
        system.stop(actor);
      } finally {
        system.eventStream().publish(new UnMute(filter));
      }
    }
Ejemplo n.º 2
0
 @Override
 public void onReceive(Object message) throws Exception {
   if (message.equals("tick")) {
     // send another periodic tick after the specified delay
     getContext()
         .system()
         .scheduler()
         .scheduleOnce(
             Duration.create(1000, TimeUnit.MILLISECONDS),
             getSelf(),
             "tick",
             getContext().dispatcher());
     // do something useful here
     // #schedule-receive
     target.tell(message, getSelf());
     // #schedule-receive
   }
   // #schedule-receive
   else if (message.equals("restart")) {
     throw new ArithmeticException();
   }
   // #schedule-receive
   else {
     unhandled(message);
   }
 }
Ejemplo n.º 3
0
 @Override
 public void onReceive(Object message) throws Exception {
   if (message.equals("tick")) {
     // do something useful here
     // #schedule-constructor
     target.tell(message, getSelf());
     // #schedule-constructor
   }
   // #schedule-constructor
   else if (message.equals("restart")) {
     throw new ArithmeticException();
   }
   // #schedule-constructor
   else {
     unhandled(message);
   }
 }