Esempio n. 1
0
 @Override
 public void onReceive(Object msg) throws Exception {
   if (msg.equals(Msg.TICK)) {
     if (probes.timeout()) {
       timer.cancel(); // Stop timer
       getContext().become(SPLITTING);
       getSelf().tell(Msg.DONE, getSelf()); // Start splitting
       logger.info("Latency Monitor Start Splitting");
       return;
     }
     // Send probes to all targets
     for (Pair<ActorRef, ActorRef> targetPort : targetPorts) {
       ActorRef target = targetPort.first();
       ActorRef port = targetPort.second();
       port.tell(probes.newProbe(target), getSelf());
     }
   } else if (msg instanceof Probe) {
     probes.fill((Probe) msg);
     long now = System.nanoTime();
     // TODO Temporary log here, remove or format this later
     logger.info(
         "SubOperator: "
             + ((Probe) msg).target
             + " Current latency: "
             + (now - ((Probe) msg).now) / 1000
             + "us");
   } else if (msg instanceof Target) {
     Target target = (Target) msg;
     if (target.toAdd) {
       probes.addTarget(target.target);
       targetPorts.add(new Pair<ActorRef, ActorRef>(target.target, target.port));
     } else {
       probes.removeTarget(target.target);
       for (Pair<ActorRef, ActorRef> targetPort : targetPorts) {
         if (targetPort.first().equals(target.target)) {
           targetPorts.remove(targetPort);
           break;
         }
       }
     }
   } else unhandled(msg);
 }
Esempio n. 2
0
 @Override
 public void postStop() {
   timer.cancel();
 }