/** implementation du service Install */ @SuppressWarnings("serial") public void install(String nomLogiciel, String listImages) { if (nomLogiciel.equals("frascati")) this.logiciel= this.logicielFrascati; if (nomLogiciel.equals("nodejs")) this.logiciel= this.logicielNodejs; this.imageVirtuels.clear(); String tab[]= listImages.split(" "); for (int i = 0; i < tab.length; i++) { this.imageVirtuels.add(new VirtuelImage(tab[i],tab[i],tab[i])); } // creation de l'actor ControllerSoftwareSupervisor controllerSoftwareSupervisor = systemSoftware.actorOf(new Props(new UntypedActorFactory() { public UntypedActor create() { return new ControllerSoftwareSupervisor(imageVirtuels,logiciel,sh,new Props(WorkerInstall.class),listener); } }), "ControllerVMSupervisor"); // demarrer le déploiement controllerSoftwareSupervisor.tell(new MessageExecuteService()); }
/** implementation du service Create container */ @SuppressWarnings("serial") public void createContainer(String listImages) { System.out.println("nom des container à créer "+listImages); this.imageVirtuels.clear(); String tab[]= listImages.split(" "); for (int i = 0; i < tab.length; i++) { this.imageVirtuels.add(new VirtuelImage(tab[i],tab[i],tab[i])); } // creation de l'actor ControllerVMSupervisor controllerVmSupervisor = systemVm.actorOf(new Props(new UntypedActorFactory() { public UntypedActor create() { return new ControllerVMSupervisor(imageVirtuels,pathFabFile,sh,new Props(WorkerCreateContainer.class),listener); } }), "ControllerVMSupervisor"); // démarrer l'exécution controllerVmSupervisor.tell(new MessageExecuteService()); }
/** implementation du service Create container */ @SuppressWarnings("serial") public void startContainer(String listImages) { this.imageVirtuels.clear(); String tab[]= listImages.split(" "); for (int i = 0; i < tab.length; i++) { this.imageVirtuels.add(new VirtuelImage(tab[i],tab[i],tab[i])); } // creation de l'actor ControllerVMSupervisor controllerVmSupervisor = systemVm.actorOf(new Props(new UntypedActorFactory() { public UntypedActor create() { return new ControllerVMSupervisor(imageVirtuels,pathFabFile,sh,new Props(WorkerStartContainer.class),listener); } }), "ControllerVMSupervisor"); // démarrer l'exécution controllerVmSupervisor.tell(new MessageExecuteService()); }
/** implementation du service Create container */ @SuppressWarnings("serial") public void stopContainer(String listImages) { this.imageVirtuels.clear(); String tab[]= listImages.split(" "); for (int i = 0; i < tab.length; i++) { this.imageVirtuels.add(new VirtuelImage(tab[i],tab[i],tab[i])); } // creation de l'actor ControllerVMSupervisor controllerVmSupervisor = systemVm.actorOf(new Props(new UntypedActorFactory() { public UntypedActor create() { return new ControllerVMSupervisor(imageVirtuels,pathFabFile,sh,new Props(WorkerStopContainer.class),listener); } }), "ControllerVMSupervisor"); // démarrer l'exécution controllerVmSupervisor.tell(new MessageExecuteService()); }
/** * Attempts to register the subscriber to the specified channel. * * @return the temporary actor that delegates the event to given handler */ public <T> ActorRef subscribeEvent(final Handler<T> handler, final Class<T> channel) { ActorRef ref = system.actorOf(new Props().withCreator(new Creator<Actor>() { @Override public Actor create() throws Exception { return new UntypedActor() { @Override public void onReceive(Object message) throws Exception { if (message != null && message.getClass().equals(channel)) { handler.handle(channel.cast(message)); } else { unhandled(message); } } }; } })); eventStream().subscribe(ref, channel); return ref; }
@Test public void detach() throws Exception { ActorModel<Integer> model = new ActorModel<Integer>() { @Override protected ActorRef newActor() { return system().actorOf(Props.apply(new Creator<Actor>() { @Override public Actor create() throws Exception { return new UntypedActor() { @Override public void onReceive(Object message) throws Exception { unhandled(message); } }; } })); } }; model.detach(); Thread.sleep(100); assertThat(model.getObject(), is(nullValue())); assertThat(model.getActorRef().isTerminated(), is(true)); }
private static void RegisterActors(Binder binder) { Logger.debug("Actor Scanner Started..."); final Map<String, ActorHolder> map = new HashMap<>(); final ConfigurationBuilder configBuilder = build(); final Reflections reflections = new Reflections(configBuilder.setScanners(new SubTypesScanner())); final Set<Class<? extends UntypedActor>> actors = reflections.getSubTypesOf(UntypedActor.class); final Set<Class<? extends AbstractActor>> abstractActors = reflections.getSubTypesOf(AbstractActor.class); loopOnActors(map, actors); loopOnAbstractActors(map, abstractActors); if(!map.isEmpty()) Logger.debug("Registering actors: "); for(final String key : map.keySet()) { final ActorHolder actorHolder = map.get(key); final Class<? extends Actor> actor = actorHolder.getActor(); if(actorHolder.isSingleton()) { Logger.debug("Binding class " + actor.getSimpleName() + " to name: " + key + " Singleton Scoped."); binder.bind(ActorRef.class).annotatedWith(Names.named(key)).toProvider(new ActorRefProvider(actor, key, true)).in(Singleton.class); } else { Logger.debug("Binding class " + actor.getSimpleName() + " to name: " + key + " Request Scoped."); binder.bind(ActorRef.class).annotatedWith(Names.named(key)).toProvider(new ActorRefProvider(actor, key, false)); PropsContext.put(key, actorHolder); } } }
private static void loopOnActors(Map<String, ActorHolder> map, Set<Class<? extends UntypedActor>> actors) { for(final Class<? extends Actor> actor : actors) { if(ignore.contains(actor.getSimpleName())) continue; final String named = getNamed(actor); final boolean isSingleton = isSingleton(actor); final ActorHolder actorHolder = new ActorHolder(actor, isSingleton); if(named != null) { map.put(named, actorHolder); } else { if(map.containsKey(actor.getSimpleName())){ map.put(actor.getName(), actorHolder); final ActorHolder tempHolder = map.remove(actor.getSimpleName()); map.put(tempHolder.getActor().getName(), tempHolder); } else map.put(actor.getSimpleName(), actorHolder); } } }
@SuppressWarnings("serial") public void remoteActorCreationDemo1() { log.info("Creating a actor using remote deployment mechanism"); // create the address object that points to the remote server Address addr = new Address("akka", "ServerSys", "127.0.0.1", 2552); // creating the ServerActor on the specified remote server final ActorRef serverActor = system.actorOf(new Props(ServerActor.class) .withDeploy(new Deploy(new RemoteScope(addr)))); // create a local actor and pass the reference of the remote actor actor = system.actorOf(new Props(new UntypedActorFactory() { public UntypedActor create() { return new ClientActor(serverActor); } })); // send a message to the local client actor actor.tell("Start-RemoteActorCreationDemo1"); }
@SuppressWarnings("serial") public void remoteActorCreationDemo3() { log.info("Creating a actor with remote deployment"); // creating the ServerActor on the specified remote server final ActorRef serverActor = system.actorOf(new Props(ServerActor.class),"remoteServerActor"); // create a local actor and pass the reference of the remote actor actor = system.actorOf(new Props(new UntypedActorFactory() { public UntypedActor create() { return new ClientActor(serverActor); } })); // send a message to the local client actor actor.tell("Start-RemoteActorCreationDemo3"); }
@Test public void testFilteringActor() { ActorRef filteringActorRef = _system.actorOf(new Props( new UntypedActorFactory() { public UntypedActor create() { return new FilteringActor(testActor()); } })); // pass the reference to implicit sender testActor() otherwise // message end up in dead mailbox // first test filteringActorRef.tell("test message", super.testActor()); expectMsg("test message"); // second test filteringActorRef.tell(1, super.testActor()); expectNoMsg(); }
public ApplicationManagerSystem() { final int no_of_workers = 10; system = ActorSystem.create("LoadGeneratorApp"); final ActorRef appManager = system.actorOf( new Props(new UntypedActorFactory() { public UntypedActor create() { return new JobControllerActor(no_of_msgs); } }), "jobController"); router = system.actorOf(new Props(new UntypedActorFactory() { public UntypedActor create() { return new WorkerActor(appManager); } }).withRouter(new RoundRobinRouter(no_of_workers))); }
private static RaftActorContextImpl newFollowerContext(String id, TestActorRef<? extends UntypedActor> actor) { DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl(); configParams.setHeartBeatInterval(new FiniteDuration(100, TimeUnit.MILLISECONDS)); configParams.setElectionTimeoutFactor(100000); NonPersistentDataProvider noPersistence = new NonPersistentDataProvider(Runnable::run); ElectionTermImpl termInfo = new ElectionTermImpl(noPersistence, id, LOG); termInfo.update(1, LEADER_ID); return new RaftActorContextImpl(actor, actor.underlyingActor().getContext(), id, termInfo, -1, -1, ImmutableMap.of(LEADER_ID, ""), configParams, noPersistence, applyState -> actor.tell(applyState, actor), LOG); }
public MeteringBehavior(final UntypedActor actor) { Preconditions.checkArgument(actor != null, "actor must not be null"); this.meteredActor = actor; String actorName = actor.getSelf().path().name(); init(actorName); }
/** implementation du service Pause */ @SuppressWarnings("serial") public void pause(String listImages) { //Retrait des VM dans le fichier de configuration du repartiteur (Nginx) System.out.println("Connexion sur le serveur de repartition de charge (NGINX) pour retirer les VM dans son fichier de configuration et le signaler"); this.imageVirtuels.clear(); String tab[]= listImages.split(" "); for (int i = 0; i < tab.length; i++) { this.imageVirtuels.add(new VirtuelImage(tab[i],tab[i],tab[i])); //PB gestion des acces concurents sur le fichier a revoir(solution passer plustot la liste des VM) String commande="fab -f /home/daniel/scriptFabric/repartiteur/fabfile.py retirerServeur:namehost=172.17.0.30,username=root,passworduser=root,serveur=" +addressipport(tab[i]); sh.system(commande); } // creation de l'actor ControllerVMSupervisor controllerVmSupervisor = systemVm.actorOf(new Props(new UntypedActorFactory() { public UntypedActor create() { return new ControllerVMSupervisor(imageVirtuels,pathFabFile,sh,new Props(WorkerPauseVM.class),listener); } }), "ControllerVMSupervisor"); // démarrer l'exécution controllerVmSupervisor.tell(new MessageExecuteService()); }
@Test public void ask() throws Exception { BaseAskActorModel<Integer, String> model = new BaseAskActorModel<Integer, String>() { @Override protected ActorRef newActor() { return system().actorOf(Props.apply(new Creator<Actor>() { @Override public Actor create() throws Exception { return new UntypedActor() { @Override public void onReceive(Object message) throws Exception { if (message instanceof String) { getSender().tell(Integer.parseInt((String) message), getSelf()); } else { unhandled(message); } } }; } })); } }; assertThat(model.ask("100").get(), is(100)); model.detach(); }
@Test public void askByConstructor() throws Exception { BaseAskActorModel<Integer, String> model = new BaseAskActorModel<Integer, String>() { @Override protected ActorRef newActor() { return system().actorOf(Props.apply(new Creator<Actor>() { @Override public Actor create() throws Exception { return new UntypedActor() { @Override public void onReceive(Object message) throws Exception { if (message instanceof String) { getSender().tell(Integer.parseInt((String) message), getSelf()); } else { unhandled(message); } } }; } })); } }; assertThat(model.ask("100").get(), is(100)); model.detach(); }
@Test public void askWithScalaFuture() throws Exception { BaseAskActorModel<Integer, String> model = new BaseAskActorModel<Integer, String>() { @Override protected ActorRef newActor() { return system().actorOf(Props.apply(new Creator<Actor>() { @Override public Actor create() throws Exception { return new UntypedActor() { @Override public void onReceive(Object message) throws Exception { if (message instanceof String) { getSender().tell(Integer.parseInt((String) message), getSelf()); } else { unhandled(message); } } }; } })); } }; Future<Integer> f = model.askWithScalaFuture("100"); assertThat(Await.result(f, Duration.apply("3 sec")), is(100)); assertThat(model.getObject(), is(100)); model.detach(); }
@Test public void askUpdatesObject() throws Exception { BaseAskActorModel<Integer, String> model = new BaseAskActorModel<Integer, String>() { @Override protected ActorRef newActor() { return system().actorOf(Props.apply(new Creator<Actor>() { @Override public Actor create() throws Exception { return new UntypedActor() { @Override public void onReceive(Object message) throws Exception { if (message instanceof String) { getSender().tell(Integer.parseInt((String) message), getSelf()); } else { unhandled(message); } } }; } })); } }; model.ask("100").get(); assertThat(model.getObject(), is(100)); model.detach(); }
@Test public void tell() throws Exception { final AtomicBoolean b = new AtomicBoolean(false); TellActorModel<Integer, String> model = new TellActorModel<Integer, String>() { @Override protected ActorRef newActor() { return system().actorOf(Props.apply(new Creator<Actor>() { @Override public Actor create() throws Exception { return new UntypedActor() { @Override public void onReceive(Object message) throws Exception { if (message instanceof String) { b.set(true); } else { unhandled(message); } } }; } })); } }; model.tell("test"); Thread.sleep(100); assertThat(b.get(), is(true)); model.detach(); }
private void sendTestRequest(ActorRef ref, Class<? extends UntypedActor> handler) { TestingUtils.launchActors(system, testConfig.getName(), Collections.singletonList(new MockLauncher.ActorToLaunch("mllp-connector", handler))); TestActorRef<PIXRequestActor> actor = TestActorRef.create(system, Props.create(PIXRequestActor.class, testConfig)); Identifier fromId = new Identifier("1234", new AssigningAuthority("test-auth", "1.2.3", "ISO")); AssigningAuthority targetDomain = new AssigningAuthority("ECID", "ECID", "ECID"); actor.tell(new ResolvePatientIdentifier(ref, ref, fromId, targetDomain), ref); }
private void calculate(final int nrOfWorkers, final int nrOfElements, final int nrOfMessage) { ActorSystem system = ActorSystem.create("PiSystem"); final ActorRef listener = system.actorOf(new Props(Listener.class),"listener"); ActorRef master = system.actorOf(new Props(new UntypedActorFactory() { @Override public UntypedActor create() { return new Master(nrOfWorkers, nrOfMessage, nrOfElements, listener); } })); master.tell(new Calculate()); }
@SuppressWarnings("unchecked") private ActorRef doCreateObject() throws Exception { Props props; if (actorClass != null) { props = Props.create(new SpringCreator(ctx, Class.forName(actorClass), args)); } else if (actorBeanName != null && actorBeanClass != null) { props = SpringProps.create(actorSystem, actorBeanName, (Class<? extends UntypedActor>) Class.forName(actorBeanClass)); } else if (actorBeanClass != null) { props = SpringProps.create(actorSystem, (Class<? extends UntypedActor>) Class.forName(actorBeanClass)); } else { props = SpringProps.create(actorSystem, actorBeanName); } if (props == null) { throw new BeanCreationException("Can not create ActorRef for given parameters, actorClass=" + actorClass + ", actorBeanClass=" + actorBeanClass + ", actorBeanName=" + actorBeanName); } if (routerConfig != null) { props = props.withRouter(routerConfig); } if (deploy != null) { props = props.withDeploy(deploy); } if (mailbox != null) { props = props.withMailbox(mailbox); } if (dispatcher != null) { props = props.withDispatcher(dispatcher); } return actorSystem.actorOf(props); }
DroneValidatable(UntypedActor actor, TestActorRef<MockActor> sender, MockTrainingSet trainingSet, MockObjectiveFunction objectiveFunction) { super(); this.actor = actor; this.sender = sender; this.trainingSet = trainingSet; this.objectiveFunction = objectiveFunction; }
@SuppressWarnings("serial") public WCMapReduceServer(int no_of_reduce_workers, int no_of_map_workers) { system = ActorSystem.create("WCMapReduceApp", ConfigFactory.load() .getConfig("WCMapReduceApp")); // create the aggregate Actor aggregateActor = system.actorOf(new Props(AggregateActor.class)); // create the list of reduce Actors reduceRouter = system.actorOf(new Props(new UntypedActorFactory() { public UntypedActor create() { return new ReduceActor(aggregateActor); } }).withRouter(new RoundRobinRouter(no_of_reduce_workers))); // create the list of map Actors mapRouter = system.actorOf(new Props(new UntypedActorFactory() { public UntypedActor create() { return new MapActor(reduceRouter); } }).withRouter(new RoundRobinRouter(no_of_map_workers))); // create the overall WCMapReduce Actor that acts as the remote actor // for clients wcMapReduceActor = system.actorOf(new Props(new UntypedActorFactory() { public UntypedActor create() { return new WCMapReduceActor(aggregateActor, mapRouter); } }).withDispatcher("priorityMailBox-dispatcher"), "WCMapReduceActor"); }
@Test public void testForwardingActor() { ActorRef forwardingActorRef = _system.actorOf(new Props( new UntypedActorFactory() { public UntypedActor create() { return new ForwardingActor(testActor()); } })); // pass the reference to implicit sender testActor() otherwise // message end up in dead mailbox forwardingActorRef.tell("test message", super.testActor()); expectMsg("test message"); }
/** * 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); CuratorFramework curator = injector.getInstance(CuratorFramework.class); // Create an Akka system ActorSystem system = ActorSystem.create("DownloadSystem" + configuration.getDownloadKey()); // create the master ActorRef master = system.actorOf(new Props(new UntypedActorFactory() { public UntypedActor create() { return injector.getInstance(DownloadMaster.class); } }), "DownloadMaster" + configuration.getDownloadKey()); // 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(); curator.close(); }
@Override public UntypedActor create() { return new CompositeModuleInterpreterActor(this); }
@Override public UntypedActor create() { return new AdministratorActor(); }
@Override public UntypedActor create() { return new TopLevelInterpreterActor(this); }
@Override public UntypedActor create() { return new SimpleModuleInterpreterActor(this); }
@Override public UntypedActor create() { return new MasterInterpreterActor(firstExecutionId); }
@Override public UntypedActor create() { return new InputModuleInterpreterActor(this); }
@Override public UntypedActor create() { return new LoopModuleInterpreterActor(this); }
@Override public UntypedActor create() { return new ExecutorActor(simpleModuleExecutor); }
@Override public UntypedActor create() { return new InstanceProviderActor(this); }
public LogMessage(Class<? extends UntypedActor> source, String message) { this.source = source; this.message = message; }