akka.actor.UntypedActor Java Examples
The following examples show how to use
akka.actor.UntypedActor.
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: FromSearchDownloadAction.java From occurrence with Apache License 2.0 | 6 votes |
/** * 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 #2
Source File: AgentClient.java From amcgala with Educational Community License v2.0 | 4 votes |
private void createAgents(int numberOfAgents, Class<? extends UntypedActor> agentClass) { for (int i = 0; i < numberOfAgents; i++) { system.actorOf(Props.create(agentClass)); } }
Example #3
Source File: AggregationDirector.java From restcommander with Apache License 2.0 | 4 votes |
/** * Here dont need the nodeGroupMetaData.Assuming the request content has * already been ready as in the keys of the hashmap with all the target * nodes. So just need a string to have the nodeGroupType is fine. * * @param nodeGroupType * @param agentCommandType * @param dataStore * @return */ public void sendAggregationCommandToManager(String patternStr, AggregateData aggregateData) { ActorRef aggregationManager = null; try { // Start new job String directorJobUuid = UUID.randomUUID().toString(); models.utils.LogUtils.printLogNormal("!!STARTED sendAggregationCommandToManager : " + directorJobUuid + " at " + DateUtils.getNowDateTimeStr()); // Get the singleton actor system // create the master aggregationManager = ActorConfig.getActorSystem().actorOf( new Props(new UntypedActorFactory() { private static final long serialVersionUID = 1L; public UntypedActor create() { return new AggregationManager(); } }), "AggregationManager-" + UUID.randomUUID().toString()); 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); models.utils.LogUtils.printLogNormal("!!COMPLETED sendAggregationCommandToManager : " + directorJobUuid + " at " + DateUtils.getNowDateTimeStr()); } catch (Throwable ex) { models.utils.LogUtils.printLogError ("Exception in sendAggregationCommandToManager : " + ex.getLocalizedMessage()); ex.printStackTrace(); } finally { // stop the manager:agentCommandManager if (aggregationManager != null) { ActorConfig.getActorSystem().stop(aggregationManager); } aggregationManager = null; } }
Example #4
Source File: CommandManager.java From restcommander with Apache License 2.0 | 4 votes |
public UntypedActor create() { return new AssistantCommandManager(); }
Example #5
Source File: CommandDirector.java From restcommander with Apache License 2.0 | 4 votes |
/** * Here dont need the nodeGroupMetaData.Assuming the request content has * already been ready as in the keys of the hashmap with all the target * nodes. So just need a string to have the nodeGroupType is fine. * * @param nodeGroupType * @param agentCommandType * @param dataStore * @return */ public BatchResponseFromManager sendAgentCommandToManager( String nodeGroupType, String agentCommandType, Map<String, NodeGroupDataMap> dataStore) { BatchResponseFromManager agentCommandResponseFromManager = null; ActorRef agentCommandManager = null; try { //Start new job ActorConfig.runningJobCount.incrementAndGet(); String directorJobUuid = UUID.randomUUID().toString(); models.utils.LogUtils.printLogNormal("!!STARTED sendAgentCommandToManager : " + directorJobUuid + " at " + DateUtils.getNowDateTimeStr()); //20140120: double check NPE for command AgentCommandMetadata agentCommandMetadata = AgentDataProvider.agentCommandMetadatas .get(agentCommandType); if(agentCommandMetadata==null){ models.utils.LogUtils.printLogError("!!ERROR in sendAgentCommandToManager : " + directorJobUuid + " agentCommandType is NULL!! return. at " + DateUtils.getNowDateTimeStr()); return agentCommandResponseFromManager; } // Get the singleton actor system // create the master agentCommandManager = ActorConfig.getActorSystem().actorOf(new Props( new UntypedActorFactory() { private static final long serialVersionUID = 1L; public UntypedActor create() { return new CommandManager(); } }), "AgentCommandManager-" + UUID.randomUUID().toString()); final FiniteDuration duration = Duration.create( VarUtils.TIMEOUT_ASK_MANAGER_SCONDS, TimeUnit.SECONDS); // Timeout timeout = new // Timeout(FiniteDuration.parse("300 seconds")); Future<Object> future = Patterns.ask(agentCommandManager, new InitialRequestToManager(nodeGroupType, agentCommandType, directorJobUuid, dataStore), new Timeout(duration)); agentCommandResponseFromManager = (BatchResponseFromManager) Await .result(future, duration); models.utils.LogUtils.printLogNormal("GenericAgentResponseMap in future size: " + agentCommandResponseFromManager.getResponseMap().size()); models.utils.LogUtils.printLogNormal("!!COMPLETED sendAgentCommandToManager : " + directorJobUuid + " at " + DateUtils.getNowDateTimeStr()); // !!! KEY Save to files: Save command data as LOG LogProvider.saveAgentDataInLog(nodeGroupType, agentCommandType, dataStore); } catch (Throwable ex) { models.utils.LogUtils.printLogError("Exception in sendAgentCommandToManager : " + ex.getLocalizedMessage()); ex.printStackTrace(); } finally { // stop the manager:agentCommandManager if (agentCommandManager != null) { ActorConfig.getActorSystem().stop(agentCommandManager); } agentCommandManager = null; // now regard job is down; no longer a running job that requires actor system (can safe shutdown) ActorConfig.runningJobCount.decrementAndGet(); //TODO MUST ROLLBACK //ActorConfig.shutDownActorSystemWhenNoJobRunning(); } return agentCommandResponseFromManager; }