@Test public void demonstrateTheProgrammaticAPI() { // #programmatic ActorSystem system = ActorSystem.create("example"); // Get the Serialization Extension Serialization serialization = SerializationExtension.get(system); // Have something to serialize String original = "woohoo"; // Find the Serializer for it Serializer serializer = serialization.findSerializerFor(original); // Turn it into bytes byte[] bytes = serializer.toBinary(original); // Turn it back into an object, // the nulls are for the class manifest and for the classloader String back = (String) serializer.fromBinary(bytes); // Voilá! assertEquals(original, back); // #programmatic system.shutdown(); }
@Test public void serializeActorRefs() { final ActorSystem theActorSystem = ActorSystem.create("whatever"); final ActorRef theActorRef = theActorSystem.deadLetters(); // Of course this should be you // #actorref-serializer // Serialize // (beneath toBinary) final Address transportAddress = Serialization.currentTransportAddress().value(); String identifier; // If there is no transportAddress, // it means that either this Serializer isn't called // within a piece of code that sets it, // so either you need to supply your own, // or simply use the local path. if (transportAddress == null) identifier = theActorRef.path().toString(); else identifier = theActorRef.path().toStringWithAddress(transportAddress); // Then just serialize the identifier however you like // Deserialize // (beneath fromBinary) final ActorRef deserializedActorRef = theActorSystem.actorFor(identifier); // Then just use the ActorRef // #actorref-serializer theActorSystem.shutdown(); }
public static void startFrontend(Address joinAddress) { ActorSystem system = ActorSystem.create(systemName); Cluster.get(system).join(joinAddress); ActorRef frontend = system.actorOf(Props.create(Frontend.class), "frontend"); system.actorOf(Props.create(WorkProducer.class, frontend), "producer"); system.actorOf(Props.create(WorkResultConsumer.class), "consumer"); }
public void demonstrateDefaultAddress() { // this is not meant to be run, only to be compiled final ActorSystem system = ActorSystem.create(); final Address remoteAddr = new Address("", ""); // #external-address-default final Address addr = DefaultAddress.ID.get(system).getAddress(); // #external-address-default }
public static void startWorker(Address contactAddress) { ActorSystem system = ActorSystem.create(systemName); Set<ActorSelection> initialContacts = new HashSet<ActorSelection>(); initialContacts.add(system.actorSelection(contactAddress + "/user/receptionist")); ActorRef clusterClient = system.actorOf(ClusterClient.defaultProps(initialContacts), "clusterClient"); system.actorOf(Worker.props(clusterClient, Props.create(WorkExecutor.class)), "worker"); }
public static Address startBackend(Address joinAddress, String role) { Config conf = ConfigFactory.parseString("akka.cluster.roles=[" + role + "]") .withFallback(ConfigFactory.load()); ActorSystem system = ActorSystem.create(systemName, conf); Address realJoinAddress = (joinAddress == null) ? Cluster.get(system).selfAddress() : joinAddress; Cluster.get(system).join(realJoinAddress); system.actorOf( ClusterSingletonManager.defaultProps( Master.props(workTimeout), "active", PoisonPill.getInstance(), role), "master"); return realJoinAddress; }
public static void main(String[] args) { if (args.length != 6) { System.err.println("Incorrect input args"); System.exit(-1); } final String fileName = args[0]; final int minId = Integer.valueOf(args[1]); final int maxId = Integer.valueOf(args[2]); final double minAmount = Double.parseDouble(args[3]); final double maxAmount = Double.parseDouble(args[4]); final int recordsAmount = Integer.parseInt(args[5]); final ActorSystem system = ActorSystem.create("FileGeneration"); ActorRef detailsFileWriter = system.actorOf(Props.create(RandomInformationFileWriter.class), "detailsFileWriter"); system.actorOf(Props.create(Terminator.class, detailsFileWriter), "terminator"); RandomInformationFileWriter.Details details = new RandomInformationFileWriter.Details( fileName, minId, maxId, minAmount, maxAmount, recordsAmount); detailsFileWriter.tell(details, null); }
public static void main(String[] args) { ActorSystem system = ActorSystem.create("Hello"); ActorRef a = system.actorOf(Props.create(HelloWorld.class), "helloWorld"); system.actorOf(Props.create(Terminator.class, a), "terminator"); }
@BeforeClass public static void beforeClass() { system = ActorSystem.create("InitializationDocTest"); }
@Before public void setUp() { system = ActorSystem.create("MySystem", AkkaSpec.testConf()); }
@BeforeClass public static void setUp() { system = ActorSystem.create("SchedulerPatternTest", AkkaSpec.testConf()); }