Package akka.actor

Examples of akka.actor.ActorSystem


import akka.agent.Agent;

public class StockApplication {

  public static void main(String[] args) throws Exception {
    ActorSystem _system = ActorSystem.create("Agent-example");
    Stock stock = new Stock("APPL", new Agent<Float>(new Float("600.45"),
        _system));

    Thread[] readerThreads = new Thread[10];
    Thread[] updateThreads = new Thread[5];
    for (int i = 0; i < 10; i++) {
      readerThreads[i] = new Thread(new StockReader(stock));
      readerThreads[i].setName("#" + i);
    }
    for (int i = 0; i < 5; i++) {
      updateThreads[i] = new Thread(new StockUpdater(stock));
      updateThreads[i].setName("#" + i);
    }
    for (int i = 0; i < 10; i++)
      readerThreads[i].start();

    for (int i = 0; i < 5; i++)
      updateThreads[i].start();

    Thread.sleep(3000);
    _system.shutdown();

  }
View Full Code Here


public class CalculatorActorSytem {

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

    ActorSystem _system = ActorSystem.create("TypedActorsExample",
        ConfigFactory.load().getConfig("TypedActorExample"));

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

    // Get access to the ActorRef
    ActorRef calActor = TypedActor.get(_system).getActorRefFor(calculator);
    // call actor with a message
    calActor.tell("Hi there",calActor);
   
    //wait for child actor to get restarted
    Thread.sleep(500);
   
    // Invoke the method and wait for result
    Timeout timeout = new Timeout(Duration.parse("5 seconds"));
      Future<Object> future = Patterns.ask(calActor, Integer.valueOf(10), timeout);
      Integer result = (Integer) Await.result(future, timeout.duration());
   
    System.out.println("Result from child actor->" + result);

    //wait before shutting down the system
    Thread.sleep(500);
   
    _system.shutdown();

  }
View Full Code Here

import scala.concurrent.stm.japi.STM;

public class Game {
  public static void main(String args[]) {

    ActorSystem _system = ActorSystem.create("Agent-example");
    Ref.View<String> turn = STM.newRef("");
    PingPong table = new PingPong(turn);

    Thread alice = new Thread(new Player("bob", table));
    Thread bob = new Thread(new Player("alice", table));

    alice.setName("alice");
    bob.setName("bob");
    alice.start(); // alice starts playing
    bob.start(); // bob starts playing
    try {
      // Wait 5 seconds
      Thread.sleep(5000);
    } catch (InterruptedException e) {
    }

    table.hit("DONE"); // cause the players to quit their threads.
    try {
      Thread.sleep(3000);
    } catch (InterruptedException e) {
    }
    _system.shutdown();
  }
View Full Code Here

*/
public class MySerializationApp {

  public static void main(String[] args) {

    ActorSystem system = ActorSystem.create("MySerializableSys",
        ConfigFactory.load().getConfig("MySerializableSys"));
   
    Serialization serialization = SerializationExtension.get(system);

    MyMessage originalMessage = new MyMessage("Munish", 36, "Bangalore");

    System.out.println("The original message is as " + originalMessage);

    // Get the Binded Serializer for it
    Serializer serializer = serialization
        .findSerializerFor(originalMessage);

    // Turn the object into bytes
    byte[] bytes = serializer.toBinary(originalMessage);

    // Turn the byte[] back into an object,
    MyMessage deSerializedMessage = (MyMessage) serializer.fromBinary(
        bytes, MyMessage.class);

    System.out.println("The de-serialized message is as " + deSerializedMessage);

    system.shutdown();
  }
View Full Code Here

public class MapReduceApplication {

  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 historicalEvent = new HistoricalEvent();
        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

        scheduleJobs();
    }

    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

            return;
        }


        Config config = ConfigFactory.load();
        ActorSystem system = ActorSystem.create("crawler", config);

        system.registerOnTermination(new Runnable() {
            public void run() {
                nodeBuilder().client(true).node().close();
            }
        });

        final Client client = new TransportClient()
                .addTransportAddress(new InetSocketTransportAddress(
                        config.getString("restopengov.elasticsearch-host"),
                        config.getInt("restopengov.elasticsearch-port")));


        if(args[0].equals("ckan")) {
            CkanActorHandler ckanHandler = new CkanActorHandler(system, client);
            ckanHandler.handle(args);
        }
        else if(args[0].equals("standalone")) {
            StandaloneActorHandler standaloneHandler = new StandaloneActorHandler(system, client);
            standaloneHandler.handle(args);
        }
        else {
            System.out.println("Command not found");
            system.shutdown();
        }

    }
View Full Code Here

import com.typesafe.akkademo.processor.service.BettingProcessor;
import com.typesafe.config.ConfigFactory;

public class BettingProcessorApplication {
    public static void main(String[] args) {
        ActorSystem system = ActorSystem.create("BettingProcessorActorSystem", ConfigFactory.load());
        ActorRef bettingProcessor = system.actorOf(new Props(BettingProcessor.class), "bettingProcessor");
    }
View Full Code Here

import akka.actor.ActorSystem;
import com.typesafe.config.ConfigFactory;

public class BettingServiceApplication {
    public static void main(String[] args) {
        ActorSystem system = ActorSystem.create("BettingServiceActorSystem", ConfigFactory.load());
        system.actorOf(new Props(BettingService.class), "bettingService");
    }
View Full Code Here

TOP

Related Classes of akka.actor.ActorSystem

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.