Added ScalaDoc for akka-patterns

This commit is contained in:
Viktor Klang 2010-05-06 22:27:59 +02:00
parent 3ce843eff7
commit a56ac7b664
4 changed files with 31 additions and 6 deletions

View file

@ -10,8 +10,7 @@ import se.scalablesolutions.akka.actor.Actor._
object Patterns {
type PF[A, B] = PartialFunction[A, B]
/**
* Creates a new PartialFunction whose isDefinedAt is a combination
/** Creates a new PartialFunction whose isDefinedAt is a combination
* of the two parameters, and whose apply is first to call filter.apply and then filtered.apply
*/
def filter[A, B](filter: PF[A, Unit], filtered: PF[A, B]): PF[A, B] = {
@ -20,19 +19,21 @@ object Patterns {
filtered(a)
}
/**
* Interceptor is a filter(x,y) where x.isDefinedAt is considered to be always true
/** Interceptor is a filter(x,y) where x.isDefinedAt is considered to be always true
*/
def intercept[A, B](interceptor: (A) => Unit, interceptee: PF[A, B]): PF[A, B] =
filter({case a if a.isInstanceOf[A] => interceptor(a)}, interceptee)
//FIXME 2.8, use default params with CyclicIterator
/** Creates a LoadBalancer from the thunk-supplied InfiniteIterator
*/
def loadBalancerActor(actors: => InfiniteIterator[ActorID]): ActorID =
newActor(() => new Actor with LoadBalancer {
start
val seq = actors
})
/** Creates a Dispatcher given a routing and a message-transforming function
*/
def dispatcherActor(routing: PF[Any, ActorID], msgTransformer: (Any) => Any): ActorID =
newActor(() => new Actor with Dispatcher {
start
@ -40,11 +41,16 @@ object Patterns {
def routes = routing
})
/** Creates a Dispatcher given a routing
*/
def dispatcherActor(routing: PF[Any, ActorID]): ActorID = newActor(() => new Actor with Dispatcher {
start
def routes = routing
})
/** Creates an actor that pipes all incoming messages to
* both another actor and through the supplied function
*/
def loggerActor(actorToLog: ActorID, logger: (Any) => Unit): ActorID =
dispatcherActor({case _ => actorToLog}, logger)
}