Package akka.util

Examples of akka.util.Timeout


    } else {
      Map<String, NodeGroupDataMap> totDataStore = new HashMap<String, NodeGroupDataMap>();
      totDataStore.put(nodeGroupType, new NodeGroupDataMap(nodeGroupType));
      totDataStore.get(nodeGroupType).setNodeDataMapValid(nodeDataMapValidSafe);
      Future<Object> ackFuture = Patterns.ask(managerList.get(0), new InitialRequestToManager(nodeGroupType,
          agentCommandType, directorJobUuid, totDataStore, true, false, maxConcNum), new Timeout(Duration.create(
              15, TimeUnit.SECONDS)));
      try {
        Await.result(ackFuture,  Duration.create(
            15, TimeUnit.SECONDS));
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      managerList.get(0).tell(new endOfRequest(), null);
    }
   
    ActorRef monitor = system.actorOf(Props.create(Monitor.class, managerList, directorJobUuid, jobStatus), "ProgressMonitor" + directorJobUuid);
   
    ActorRef collector = system.actorOf(Props.create(ResponseCollector.class, jobInfo), "ResultCollector" + directorJobUuid);
   
    final FiniteDuration gatherResponseDuration = Duration.create(
        3600, TimeUnit.SECONDS);
   
    /**
     * Gather Result.
     */
    Future<Object> totResponse = Patterns.ask(collector, new gatherResponse(monitor, totJobNum), new Timeout(gatherResponseDuration));
   
    BatchResponseFromManager responseFromCollecter = null;
    try {
      responseFromCollecter = (BatchResponseFromManager) Await.result(totResponse, gatherResponseDuration);
      System.out.println("Gather Result Back! : " + responseFromCollecter.responseMap.size());
      /**
       * Slave Fail Over
       */
      int failCount = 3;
      while (responseFromCollecter.responseMap.size() < totJobNum && failCount >= 0) {
        System.out.println("Response less than request, fail over @@");
        failCount -- ;
        Map<String, NodeData> failOverMap = gatherFailOverData(nodeDataMapValidSafe, responseFromCollecter);
       
        List<Address> failOverNodeList = new ArrayList<Address>();
       
        int failOverTot = failOverMap.size();
       
        for (Address m : nodeList) {
          if (ClusterState.memberLoad.containsKey(m)) {
            failOverNodeList.add(m);
            failOverTot -= 2000;
            if (failOverTot < 0)
              break;
          }
        } 
       
       
        List<ActorRef> failOverManagerList = new ArrayList<ActorRef>();
        Queue<Integer> failOverJobQ = new ConcurrentLinkedQueue<Integer>();
       
        if (localMode || failOverNodeList.size()==0) {
          agentCommandManager =  system.actorOf(
              Props.create(LocalManager.class),"AgentCommandManager-" + UUID.randomUUID().toString()
            );
          failOverJobQ.offer(failOverManagerList.size());
          failOverManagerList.add(agentCommandManager);
          managerList.add(agentCommandManager);
          localMode = true;
        }
        else {
          for (Address m : failOverNodeList) {
            agentCommandManager = system.actorOf(
              Props.create(LocalManager.class).withDeploy(
                  new Deploy(
                       new RemoteScope(
                          m
                          )
                      )),
              "AgentCommandManager-" + UUID.randomUUID().toString()
            );
           
            failOverJobQ.offer(failOverManagerList.size());
            failOverManagerList.add(agentCommandManager);
            managerList.add(agentCommandManager);
          }
        }
        if (!localMode) {
          List<Map<String, NodeData>> failOverJobGroupList = partDataStore(failOverMap, failOverNodeList.size()==0?
              failOverMap.size():Math.min(failOverMap.size()/failOverNodeList.size()+1, 1000));
          List<ActorRef> failOverDispatcherList = new ArrayList<ActorRef>();
          int failOverRequestChunckSize = failOverJobGroupList.size()/failOverManagerList.size() + 1; // Last one do less
         
          for (int i=0; i<Math.min(3, failOverManagerList.size()) ; i++) {
            failOverDispatcherList.add(
                system.actorOf(
                    Props.create(JobDispatcher.class, failOverManagerList, failOverJobGroupList, failOverJobQ, failOverRequestChunckSize,
                        nodeGroupType, agentCommandType, directorJobUuid, maxConcNum)
                    )
                );
          }
         
          for (ActorRef failOverDispatcher : failOverDispatcherList) {
            failOverDispatcher.tell("start dispatching", null);
          }
        } else {
          Map<String, NodeGroupDataMap> failOverDataStore = new HashMap<String, NodeGroupDataMap>();
          failOverDataStore.put(nodeGroupType, new NodeGroupDataMap(nodeGroupType));
          failOverDataStore.get(nodeGroupType).setNodeDataMapValid(failOverMap);
          Future<Object> ackFuture = Patterns.ask(failOverManagerList.get(0), new InitialRequestToManager(nodeGroupType,
              agentCommandType, directorJobUuid, failOverDataStore, true, false, maxConcNum), new Timeout(Duration.create(
                  15, TimeUnit.SECONDS)));
          try {
            Await.result(ackFuture,  Duration.create(
                15, TimeUnit.SECONDS));
          } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          failOverManagerList.get(0).tell(new endOfRequest(), null);
        }
       
        jobInfo.state = State.processing;
       
       
        Future<Object> futureFailOverResponse = Patterns.ask(collector, new gatherResponse(monitor, totJobNum), new Timeout(gatherResponseDuration));
        BatchResponseFromManager failOverResponse = (BatchResponseFromManager) Await.result(futureFailOverResponse, gatherResponseDuration);
        System.out.println("FailOver Result Size" + failOverResponse.responseMap.size());
        for (Entry<String, GenericAgentResponse> e : failOverResponse.responseMap.entrySet()) {
          responseFromCollecter.responseMap.put(e.getKey(), e.getValue());
        }
      }
     
      for (Entry<String, GenericAgentResponse> e: responseFromCollecter.getResponseMap().entrySet()) {
        AgentDataProviderHelper.getInstance()
        .updateResponseFromAgentGenericResponse(nodeGroupType,
            agentCommandType, e.getValue(), dataStore);
      }
    } catch (Exception e) {
      System.out.println("Response Collector Timeout");
      responseFromCollecter = new BatchResponseFromManager();
    }
   
    jobInfo.endTime = System.currentTimeMillis();
    jobInfo.aggregationTime = (jobInfo.endTime - jobInfo.finishedNotAggregatedTime)/1000.0;
    jobInfo.state = State.gathered;
   
    System.out.println("Clear actors.");
   
    system.stop(monitor);
    system.stop(collector);
   
    for (ActorRef m : managerList) {
      system.stop(m);
    }
   
    if (localMode || nodeList.size() ==0 )
      localLoad.addAndGet( -maxConcNum);
   
    for (Address m : nodeList) {
      if (ClusterState.memberLoad.containsKey(m))
        ClusterState.memberLoad.get(m).addAndGet(-maxConcNum);
    }
   
    final FiniteDuration durationLogWorker = Duration.create(
        VarUtils.TIMEOUT_ASK_LOGWORKER_SCONDS, TimeUnit.SECONDS);
   
    ActorRef logWorker = ActorConfig.getActorSystem().actorOf(
        Props.create(LogWorker.class,
            nodeGroupType, agentCommandType, dataStore, directorJobUuid),
        "LogWorker-" + UUID.randomUUID().toString()
      );
     
    /**
     * TODO 20140515: this log worker has internally timeout; and will
     * suicide if timeout; so should no need to have external timeout
     * check/kill again
     *
     */
    Patterns.ask(logWorker, HttpWorker.MessageType.PROCESS_REQUEST,
        new Timeout(durationLogWorker));
    return responseFromCollecter;
  }
View Full Code Here


    Map<String, NodeData> partData = jobGroupList.get(i);
   
    partDataStore.get(nodeGroupType).setNodeDataMapValid(partData);
   
    Future<Object> ackFuture = Patterns.ask(manager, new InitialRequestToManager(nodeGroupType,
        agentCommandType, directorJobUuid, partDataStore, true, false, maxConcNum), new Timeout(durationManager));
    try {
      Await.result(ackFuture, durationManager);
      i++;
      while (i<jobGroupList.size() && i<(index+1)*chunckSize ) {
        ackFuture = Patterns.ask(manager, jobGroupList.get(i), new Timeout(durationManager));
        Await.result(ackFuture, durationManager);
        i++;
      }
    } catch (Exception e) {
      System.out.println("Dispatch Job Timeout.");
View Full Code Here

    ActorRef manager = slaveQ.poll();
    while (manager != null) {
      FiniteDuration duration = Duration.create(
          60, TimeUnit.SECONDS);
      streamRequestToManager streamRequest = new streamRequestToManager(0);
      Future<Object> futureResponse = Patterns.ask(manager, streamRequest, new Timeout(duration));
      System.out.println(manager.path().address().toString());
     
      try {
        BatchResponseFromManager partResponse = (BatchResponseFromManager) Await.result(futureResponse, duration);
        while (partResponse.getResponseMap().size() > 0) {
          collectResult(response, partResponse);
          streamRequest.index += partResponse.getResponseMap().size();
          futureResponse = Patterns.ask(manager, streamRequest, new Timeout(duration));
          partResponse = (BatchResponseFromManager) Await.result(futureResponse, duration);
        }
      } catch (Exception e) {
        System.out.println("Gather Response Timeout");
      }
View Full Code Here

          .path().address().toString().equals("akka://ClusterSystem"))
          && !removedNode.contains(manager.path().address()
              .toString())
          && !collectedManager.containsKey(manager)) {
        Future<Object> progress = Patterns.ask(manager,
            new querySlaveProgressMessage(), new Timeout(duration));
        System.out.println("Query "
            + manager.path().toString());
        progressList.add(progress);
        askMap.put(progress, manager);
        if (eachWorkerResponseCount.containsKey(manager.path()
View Full Code Here

      }, getContext().system().dispatcher());
     
    } else if (message instanceof collecterCheckResponse){
      FiniteDuration duration = Duration.create(
          10, TimeUnit.SECONDS);
      Future<Object> futureList = Patterns.ask(monitor, new queryMonitorForResponse(), new Timeout(duration));
      try {
        List<ActorRef> collectList = (List<ActorRef>) Await.result(futureList, duration);
        if (collectList.size() > 0) {
          for (ActorRef m : collectList) {
            slaveQ.offer(m);
View Full Code Here

      final FiniteDuration duration = Duration.create(
          VarUtils.TIMEOUT_ASK_AGGREGATION_MANAGER_SCONDS,
          TimeUnit.SECONDS);
      Future<Object> future = Patterns.ask(aggregationManager,
          new RequestToAggregationManager(patternStr,
              directorJobUuid, aggregateData), new Timeout(
              duration));

      responseFromAggregationManager = (ResponseFromAggregationManager) Await
          .result(future, duration);
View Full Code Here

  public static void main(String[] args) throws Exception {
    ActorSystem _system = ActorSystem.create("TypedActorsExample",
        ConfigFactory.load().getConfig("TypedActorExample"));

    Timeout timeout = new Timeout(Duration.parse("5 seconds"));

    CalculatorInt calculator = TypedActor.get(_system).typedActorOf(
        new TypedProps<Calculator>(CalculatorInt.class,
            Calculator.class).withDispatcher("defaultDispatcher"));

    // calling a fire and forget method
    calculator.incrementCount();

    // Invoke the method and wait for result
    Future<Integer> future = calculator.add(Integer.valueOf(14),
        Integer.valueOf(6));
    Integer result = Await.result(future, timeout.duration());

    System.out.println("Result is " + result);

    Option<Integer> counterResult = calculator.incrementAndReturn();
    System.out.println("Result is " + counterResult.get());
View Full Code Here

    final String x = Thread.currentThread().getName();

    //wait till all the messages are processed to make
    //you get the correct value, as updated to Agents are
    //async
    String result = whoseTurn.await(new Timeout(5, SECONDS));
   
    if (result == "") {
      whoseTurn.send(x);
      return true;
    }
View Full Code Here

public class CalculatorActorSytem {

  public static void main(String[] args) throws Exception {
    ActorSystem _system = ActorSystem.create("TypedActorsExample");

    Timeout timeout = new Timeout(Duration.parse("5 seconds"));

    CalculatorInt calculator = TypedActor.get(_system).typedActorOf(
        new TypedProps<Calculator>(CalculatorInt.class,
            Calculator.class));

    // calling a fire and forget method
    calculator.incrementCount();

    // Invoke the method and wait for result
    Future<Integer> future = calculator.add(Integer.valueOf(14),
        Integer.valueOf(6));
    Integer result = Await.result(future, timeout.duration());

    System.out.println("Result is " + result);

    Option<Integer> counterResult = calculator.incrementAndReturn();
    System.out.println("Result is " + counterResult.get());
View Full Code Here

        RandomTimeActor.class)
        .withRouter(new ScatterGatherFirstCompletedRouter(5, Duration
            .create(2, "seconds"))),
        "myScatterGatherFirstCompletedRouterActor");

    Timeout timeout = new Timeout(Duration.create(10, "seconds"));
    Future<Object> futureResult = akka.pattern.Patterns.ask(
        scatterGatherFirstCompletedRouter, "message", timeout);
    String result = (String) Await.result(futureResult, timeout.duration());
    System.out.println(result);

    _system.shutdown();

  }
View Full Code Here

TOP

Related Classes of akka.util.Timeout

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.