Package akka.actor

Examples of akka.actor.ActorRef


   * if you want to test how the Supervisor strategy is working fine
   */
  @Test
  public void testSupervisorStrategy1() throws Exception {

    ActorRef supervisorActorRef1 = _system.actorOf(new Props(
        SupervisorActor.class), "supervisor1");

    Duration timeout = Duration.parse("5 second");
    // register the BoomActor with the Supervisor
    final ActorRef child = (ActorRef) Await.result(
        ask(supervisorActorRef1, new Props(BoomActor.class), 5000),
        timeout);

    child.tell(123);

    Assert.assertFalse(child.isTerminated());
  }
View Full Code Here


  }

  @Test
  public void testSupervisorStrategy2() throws Exception {

    ActorRef supervisorActorRef2 = _system.actorOf(new Props(
        SupervisorActor.class), "supervisor2");
   
    final TestProbe probe = new TestProbe(_system);
    // register the BoomActor with the Supervisor
    final ActorRef child = (ActorRef) Await.result(
        ask(supervisorActorRef2, new Props(BoomActor.class), 5000),
        Duration.parse("5 second"));
    probe.watch(child);
    // second check
    child.tell("do something");
    probe.expectMsg(new Terminated(child));

  }
View Full Code Here

  public static void main(String[] args) throws Exception {

    ActorSystem _system = ActorSystem.create("MapReduceApp");
   
    ActorRef master = _system.actorOf(new Props(MasterActor.class),"master");
   
    master.tell("The quick brown fox tried to jump over the lazy dog and fell on the dog");
    master.tell("Dog is man's best friend");
    master.tell("Dog and Fox belong to the same family");
   
    Thread.sleep(500);
   
    master.tell(new Result(), null);
   
    Thread.sleep(500);
   
    _system.shutdown();
        System.out.println("Java done!");
View Full Code Here

        historicalEvent.creationDate = new Date();
        historicalEvent.category = category;
        historicalEvent.message = message;

        ActorSystem actorSystem = Akka.system();
        ActorRef actor = actorSystem.actorOf(new Props(HistoricalEventActor.class));
        actor.tell(historicalEvent);
    }
View Full Code Here

    }

    public void scheduleJobs()
    {
        ActorSystem actorSystem = Akka.system();
        ActorRef feedCreationActor = actorSystem.actorOf(new Props(FeedCreationActor.class));
        actorSystem.scheduler().schedule(Duration.create(0, TimeUnit.MILLISECONDS),
                                           Duration.create(1, TimeUnit.HOURS),
                                           feedCreationActor,
                                           "generate");
    }
View Full Code Here

    public void onReceive(Object message) {

        if(message instanceof String) {

            ActorRef metadataPersist = getContext().actorFor("/user/ckanMetadataPersist");
            ActorRef resourceFetcher = getContext().actorFor("/user/ckanResourceFetcher");
            ActorRef zipResourceFetcher = getContext().actorFor("/user/ckanZipResourceFetcher");

            String url = (String) message;

            try {
                String response = new Resty().text(url).toString();
                Metadata metadata = new Gson().fromJson(response, Metadata.class);

                metadataPersist.tell(metadata, getSelf());

                for(MetadataResource resource : metadata.resources) {
                    resource.metadata_name = metadata.name;

                    if(metadata.extras != null) {
                        if(metadata.extras.containsKey("encoding")) {
                            resource.encoding = metadata.extras.get("encoding");
                        }
                    }

                    if(resource.format.toLowerCase().equals("zip")) {
                        zipResourceFetcher.tell(resource, getSelf());
                    } else {
                        resourceFetcher.tell(resource, getSelf());
                    }
                }
View Full Code Here

        } else if (message instanceof List) {

            List<String> datasetList = (List<String>) message;

            ActorRef metadataFetcher = getContext().actorFor("/user/ckanMetadataFetcher");

            for (String dataset : datasetList) {
                String url = ConfigFactory.load().getString("restopengov.ckan-rest-api") + dataset;
                metadataFetcher.tell(url, getSelf());
            }

            getContext().stop(getSelf());

        } else {
View Full Code Here

import akka.actor.UntypedActor;
import akka.actor.UntypedActorFactory;

public class SubscriberMain {
  public static void main(String[] args) {
    final ActorRef logger = actorOf(Logger.class).start();
    ActorRef subscriber = actorOf(new UntypedActorFactory() {
      public UntypedActor create() {
        return new Subscriber("tcp://localhost:5555", new StringFormat(), logger);
      }
    }).start();
    subscriber.sendOneWay(Receive);
  }
View Full Code Here

import akka.japi.Procedure;

public class AsyncRequestReply {

  public static void main(String[] args) {
    ActorRef requester = actorOf(AsyncRequestActor.class).start();
    ActorRef future = actorOf(AsyncFutureActor.class).start();
    ActorRef replier = actorOf(AsyncReplyActor.class).start();
    LoggerFactory.getLogger(AsyncRequestReply.class).info("Starting up...");
    requester.sendOneWay(replier);
    future.sendOneWay(replier);
  }
View Full Code Here

import akka.actor.UntypedActor;

public class AsyncSend {

  public static void main(String[] args) {
    ActorRef actor = actorOf(AsyncSendActor.class).start();
    LoggerFactory.getLogger(AsyncSend.class).info("Starting up...");
    actor.sendOneWay("Hello, world!");
  }
View Full Code Here

TOP

Related Classes of akka.actor.ActorRef

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.