This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ometer.akka | |
import akka.actor.Actor | |
import akka.dispatch.ExecutionContext | |
import akka.actor.ActorRef | |
import akka.dispatch.Promise | |
import akka.dispatch.Future | |
import akka.dispatch.DefaultPromise | |
class Example extends SafeActor { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.actor._ | |
import akka.pattern.ask | |
import akka.util._ | |
import akka.util.duration._ | |
import scala.util.control.Exception._ | |
/** | |
* To test, execute this code and use this command in a shell: "telnet localhost 8080" | |
* At the prompt, type in numbers and press enter, and they will be accumulated, returning | |
* the total value each time. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package perf | |
import akka.actor.ActorSystem | |
import akka.actor.Actor | |
import akka.actor.Props | |
import scala.concurrent.forkjoin.ThreadLocalRandom | |
import akka.routing.ConsistentHashingRouter | |
import akka.routing.ConsistentHashingRouter.ConsistentHashableEnvelope | |
import scala.util.Random | |
import akka.routing.Broadcast |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab( 'com.typesafe.akka:akka-actor_2.10:2.3.2' ) | |
@Grab( 'com.typesafe:config:1.2.0' ) | |
import akka.actor.UntypedActor | |
import akka.japi.Procedure | |
import akka.actor.ActorSystem | |
import akka.actor.Props | |
import com.typesafe.config.ConfigFactory | |
class PingPongActor extends UntypedActor { | |
static final String PING = 'PING' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.routing.ConsistentHashingRouter | |
import akka.routing.ConsistentHashingRouter.ConsistentHashMapping | |
import akka.actor.Actor | |
import akka.pattern.ask | |
case class Entry(key: String, value: String) | |
class Cache extends Actor { | |
var cache = Map.empty[String, String] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
akka.actor.deployment { | |
/statsService/workerRouter { | |
router = round-robin | |
nr-of-instances = 100 | |
cluster { | |
enabled = on | |
routees-path = "/user/statsWorker" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.cluster.Cluster | |
import akka.cluster.ClusterEvent._ | |
val clusterListener = system.actorOf(Props(new Actor with ActorLogging { | |
def receive = { | |
case state: CurrentClusterState ⇒ | |
log.info("Current members: {}", state.members) | |
case MemberUp(member) ⇒ | |
log.info("Member is up: {}", member) | |
// send a message to the "world" actor running at the member node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case object BackendRegistration | |
case class Job(text: String) | |
class Frontend extends Actor { | |
var backends = IndexedSeq.empty[ActorRef] | |
var jobCounter = 0 | |
def receive = { | |
case job: Job if backends.isEmpty => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example | |
import java.util.concurrent.ConcurrentHashMap | |
import java.util.concurrent.ConcurrentLinkedQueue | |
import com.typesafe.config.Config | |
import com.typesafe.config.ConfigFactory | |
import akka.actor.Actor | |
import akka.actor.ActorContext | |
import akka.actor.ActorRef | |
import akka.actor.ActorSystem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Welcome to Scala version 2.10.0-RC5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_07). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> system=ActorSystem("repl",ConfigFactory.parseString("pinned{type=PinnedDispatcher;executor=thread-pool-executor}").withFallback(config)) | |
[DEBUG] [12/09/2012 21:23:23.535] [run-main] [EventStream(akka://repl)] logger log1-Logging$DefaultLogger started | |
[DEBUG] [12/09/2012 21:23:23.535] [run-main] [EventStream(akka://repl)] Default Loggers started | |
system: akka.actor.ActorSystem = akka://repl | |
scala> case class Add(x: Int) |