Java Code Examples for akka.actor.ActorRef#isTerminated()

The following examples show how to use akka.actor.ActorRef#isTerminated() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AggregationManager.java    From restcommander with Apache License 2.0 6 votes vote down vote up
/**
 * Potential bug: this assumes when cancel; all initial request to each node
 * has been sent out by asst manager to each op worker.
 * 
 * For those op worker who has receive this cancel first PRIOR to the asst
 * manager's request message; the reply back could
 * 
 * This way prevent memory leak by sending cancel to OP worker in order to
 * stop http worker; rather than directly stopping OP worker without
 * stopping http worker If not; this did not really stop the ASST manager..
 * 
 * will rely on the global ASK manager timeout for if .
 */
private void cancelRequestAndCancelWorkers() {

	for (ActorRef worker : workers) {
		if (worker == null) {
			models.utils.LogUtils.printLogError("worker is gone. null ptr: ");
		} else if (!worker.isTerminated()) {
			// just stop should be fine. since no next layer
			getContext().stop(worker);
		}
	}

	 models.utils.LogUtils.printLogError
			 ("--DEBUG--aggregationManager sending cancelPendingRequest at time: "
					+ DateUtils.getNowDateTimeStr());
}
 
Example 2
Source File: FromSearchDownloadAction.java    From occurrence with Apache License 2.0 6 votes vote down vote up
/**
 * This method it's mirror of the 'main' method, is kept for clarity in parameters usage.
 */
public static void run(WorkflowConfiguration workflowConfiguration, DownloadJobConfiguration configuration) {
  final Injector injector = createInjector(workflowConfiguration, configuration);
  try (CuratorFramework curatorDownload = injector.getInstance(Key.get(CuratorFramework.class, Names.named("Downloads")));
       CuratorFramework curatorIndices = injector.getInstance(Key.get(CuratorFramework.class, Names.named("Indices")))) {

    // Create an Akka system
    ActorSystem system = ActorSystem.create("DownloadSystem" + configuration.getDownloadKey());

    // create the master
    ActorRef master = system.actorOf(new Props(new UntypedActorFactory() {
      /**
       *
       */
      private static final long serialVersionUID = 1L;

      public UntypedActor create() {
        return injector.getInstance(DownloadMaster.class);
      }
    }), "DownloadMaster" + configuration.getDownloadKey());

    Mutex readMutex = injector.getInstance(Mutex.class);
    readMutex.acquire();
    // start the calculation
    master.tell(new DownloadMaster.Start());
    while (!master.isTerminated()) {
      try {
        Thread.sleep(SLEEP_TIME_BEFORE_TERMINATION);
      } catch (InterruptedException ie) {
        LOG.error("Thread interrupted", ie);
      }
    }
    system.shutdown();
    readMutex.release();
  }
}
 
Example 3
Source File: ExecutionManager.java    From parallec with Apache License 2.0 5 votes vote down vote up
/**
 * Cancel request and workers.
 */
@SuppressWarnings("deprecation")
private void cancelRequestAndWorkers() {

    for (ActorRef worker : workers.values()) {
        if (worker != null && !worker.isTerminated()) {
            worker.tell(OperationWorkerMsgType.CANCEL, getSelf());
        }
    }

    logger.info("ExecutionManager sending cancelPendingRequest at time: "
            + PcDateUtils.getNowDateTimeStr());
}
 
Example 4
Source File: ExecutionManager.java    From parallec with Apache License 2.0 5 votes vote down vote up
/**
 * Cancel request and worker on host.
 *
 * @param targetHosts
 *            the target hosts
 */
@SuppressWarnings("deprecation")
private void cancelRequestAndWorkerOnHost(List<String> targetHosts) {

    List<String> validTargetHosts = new ArrayList<String>(workers.keySet());
    validTargetHosts.retainAll(targetHosts);
    logger.info("targetHosts for cancel: Total: {}"
            + " Valid in current manager with worker threads: {}",
            targetHosts.size(), validTargetHosts.size());

    for (String targetHost : validTargetHosts) {

        ActorRef worker = workers.get(targetHost);

        if (worker != null && !worker.isTerminated()) {
            worker.tell(OperationWorkerMsgType.CANCEL, getSelf());
            logger.info("Submitted CANCEL request on Host {}", targetHost);
        } else {
            logger.info(
                    "Did NOT Submitted "
                            + "CANCEL request on Host {} as worker on this host is null or already killed",
                    targetHost);
        }

    }

}
 
Example 5
Source File: CommandManager.java    From restcommander with Apache License 2.0 5 votes vote down vote up
/**
 * Potential bug: this assumes when cancel; all initial request to each node
 * has been sent out by asst manager to each op worker.
 * 
 * For those op worker who has receive this cancel first PRIOR to the asst
 * manager's request message; the reply back could
 * 
 * This way prevent memory leak by sending cancel to OP worker in order to
 * stop http worker; rather than directly stopping OP worker without
 * stopping http worker If not; this did not really stop the ASST manager..
 * 
 * will rely on the global ASK manager timeout for if .
 */
private void cancelRequestAndCancelWorkers() {

	for (ActorRef worker : workers) {
		if (worker == null) {
			models.utils.LogUtils.printLogError("worker is gone. null ptr: ");
		} else if (!worker.isTerminated()) {
			worker.tell(OperationWorker.MessageType.CANCEL, getSelf());
		}
	}

	 models.utils.LogUtils.printLogError
			 ("--DEBUG--AgentCommandManager sending cancelPendingRequest at time: "
					+ DateUtils.getNowDateTimeStr());
}
 
Example 6
Source File: ParallelTaskManager.java    From parallec with Apache License 2.0 4 votes vote down vote up
/**
 * Send parallel task to execution manager.
 *
 * @param task
 *            the parallel task
 * @return the batch response from manager
 */
@SuppressWarnings("deprecation")
public ResponseFromManager sendTaskToExecutionManager(ParallelTask task) {

    ResponseFromManager commandResponseFromManager = null;
    ActorRef executionManager = null;
    try {
        // Start new job
        logger.info("!!STARTED sendAgentCommandToManager : "
                + task.getTaskId() + " at "
                + PcDateUtils.getNowDateTimeStr());

        executionManager = ActorConfig.createAndGetActorSystem().actorOf(
                Props.create(ExecutionManager.class, task),
                "ExecutionManager-" + task.getTaskId());

        final FiniteDuration duration = Duration.create(task.getConfig()
                .getTimeoutAskManagerSec(), TimeUnit.SECONDS);
        // Timeout timeout = new
        // Timeout(FiniteDuration.parse("300 seconds"));
        Future<Object> future = Patterns.ask(executionManager,
                new InitialRequestToManager(task), new Timeout(duration));

        // set ref
        task.executionManager = executionManager;

        commandResponseFromManager = (ResponseFromManager) Await.result(
                future, duration);

        logger.info("!!COMPLETED sendTaskToExecutionManager : "
                + task.getTaskId() + " at "
                + PcDateUtils.getNowDateTimeStr()
                + "  \t\t  GenericResponseMap in future size: "
                + commandResponseFromManager.getResponseCount());

    } catch (Exception ex) {
        logger.error("Exception in sendTaskToExecutionManager {} details {}: ",
                ex, ex);

    } finally {
        // stop the manager
        if (executionManager != null && !executionManager.isTerminated()) {
            ActorConfig.createAndGetActorSystem().stop(executionManager);
        }

        if (task.getConfig().isAutoSaveLogToLocal()) {
            task.saveLogToLocal();
        }

    }

    return commandResponseFromManager;

}