@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);
 }
  public static void main(String[] args) {

    if (args.length != 6) {
      System.err.println("Incorrect input args");
      System.exit(-1);
    }

    final String fileName = args[0];
    final int minId = Integer.valueOf(args[1]);
    final int maxId = Integer.valueOf(args[2]);
    final double minAmount = Double.parseDouble(args[3]);
    final double maxAmount = Double.parseDouble(args[4]);
    final int recordsAmount = Integer.parseInt(args[5]);

    final ActorSystem system = ActorSystem.create("FileGeneration");
    ActorRef detailsFileWriter =
        system.actorOf(Props.create(RandomInformationFileWriter.class), "detailsFileWriter");
    system.actorOf(Props.create(Terminator.class, detailsFileWriter), "terminator");

    RandomInformationFileWriter.Details details =
        new RandomInformationFileWriter.Details(
            fileName, minId, maxId, minAmount, maxAmount, recordsAmount);
    detailsFileWriter.tell(details, null);
  }
 Probe(ActorRef target, long id) {
   this.target = target;
   this.id = id;
   this.now = System.nanoTime(); // The time unit is ns
 }