/**
  * Process a cluster update.
  *
  * @param context actor context
  */
 public void processClusterUpdate(ActorContext context) {
   if (!clusterService.isMainEntityNode(key)) {
     LOG.debug("[{}] No longer a global endpoint node for {}", endpointKey);
     routes.clear();
     context.stop(context.self());
   }
 }
Ejemplo n.º 2
0
    // #crRoute
    @Override
    public CustomRoute createCustomRoute(Props props, ActorContext context) {
      final ActorRef democratActor = context.actorOf(new Props(DemocratActor.class), "d");
      final ActorRef republicanActor = context.actorOf(new Props(RepublicanActor.class), "r");
      List<ActorRef> routees = Arrays.asList(new ActorRef[] {democratActor, republicanActor});

      // #crRegisterRoutees
      registerRoutees(context, routees);
      // #crRegisterRoutees

      // #crRoutingLogic
      return new CustomRoute() {
        @Override
        public Iterable<Destination> destinationsFor(ActorRef sender, Object msg) {
          switch ((Message) msg) {
            case DemocratVote:
            case DemocratCountResult:
              return Arrays.asList(new Destination[] {new Destination(sender, democratActor)});
            case RepublicanVote:
            case RepublicanCountResult:
              return Arrays.asList(new Destination[] {new Destination(sender, republicanActor)});
            default:
              throw new IllegalArgumentException("Unknown message: " + msg);
          }
        }
      };
      // #crRoutingLogic
    }
 private <T> void dispatchMsg(ActorContext context, T localMsg, BiConsumer<String, T> biConsumer) {
   for (EndpointClusterAddress address : routes.getLocalRoutes()) {
     LOG.info("Forwarding {} to local endpoint actor {}", localMsg, address);
     ThriftEndpointActorMsg<T> msg =
         new ThriftEndpointActorMsg<>(
             address.toEndpointAddress(), ActorClassifier.LOCAL, localMsg);
     context.parent().tell(msg, context.self());
   }
   for (EndpointClusterAddress address : routes.getRemoteRoutes()) {
     LOG.info("Forwarding {} to remote endpoint actor {}", localMsg, address);
     biConsumer.accept(address.getNodeId(), localMsg);
   }
 }
Ejemplo n.º 4
0
 static void done(ActorRef latencyMonitor, ActorContext context) {
   latencyMonitor.tell(Msg.DONE, context.self());
 }
Ejemplo n.º 5
0
 static void removeTarget(ActorRef latencyMonitor, ActorRef target, ActorContext context) {
   latencyMonitor.tell(new Target(target, null, false), context.self());
 }
Ejemplo n.º 6
0
 static void addTarget(
     ActorRef latencyMonitor, ActorRef target, ActorRef port, ActorContext context) {
   latencyMonitor.tell(new Target(target, port, true), context.self());
 }