2009-07-06 23:45:15 +02:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009 Scalable Solutions.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-10-08 19:01:04 +02:00
|
|
|
package se.scalablesolutions.akka.dispatch
|
2009-07-06 23:45:15 +02:00
|
|
|
|
2009-09-02 09:10:21 +02:00
|
|
|
import actor.Actor
|
2009-07-06 23:45:15 +02:00
|
|
|
|
|
|
|
|
/**
|
2009-07-12 23:08:17 +02:00
|
|
|
* Scala API. Dispatcher factory.
|
2009-07-06 23:45:15 +02:00
|
|
|
* <p/>
|
|
|
|
|
* Example usage:
|
|
|
|
|
* <pre/>
|
|
|
|
|
* val dispatcher = Dispatchers.newEventBasedThreadPoolDispatcher
|
|
|
|
|
* .withNewThreadPoolWithBoundedBlockingQueue(100)
|
|
|
|
|
* .setCorePoolSize(16)
|
|
|
|
|
* .setMaxPoolSize(128)
|
|
|
|
|
* .setKeepAliveTimeInMillis(60000)
|
|
|
|
|
* .setRejectionPolicy(new CallerRunsPolicy)
|
|
|
|
|
* .buildThreadPool
|
|
|
|
|
* </pre>
|
|
|
|
|
* <p/>
|
|
|
|
|
*
|
|
|
|
|
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
|
|
|
|
*/
|
2009-07-12 23:08:17 +02:00
|
|
|
object Dispatchers extends DispatcherFactory
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Java API. Dispatcher factory.
|
|
|
|
|
* <p/>
|
|
|
|
|
* Example usage:
|
|
|
|
|
* <pre/>
|
|
|
|
|
* DispatcherFactory dispatcherFactory = new DispatcherFactory
|
|
|
|
|
* MessageDispatcher dispatcher = dispatcherFactory.newEventBasedThreadPoolDispatcher
|
|
|
|
|
* .withNewThreadPoolWithBoundedBlockingQueue(100)
|
|
|
|
|
* .setCorePoolSize(16)
|
|
|
|
|
* .setMaxPoolSize(128)
|
|
|
|
|
* .setKeepAliveTimeInMillis(60000)
|
|
|
|
|
* .setRejectionPolicy(new CallerRunsPolicy)
|
|
|
|
|
* .buildThreadPool
|
|
|
|
|
* </pre>
|
|
|
|
|
* <p/>
|
|
|
|
|
*
|
|
|
|
|
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
|
|
|
|
*/
|
|
|
|
|
class DispatcherFactory {
|
2009-07-06 23:45:15 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates an event based dispatcher serving multiple (millions) of actors through a thread pool.
|
|
|
|
|
* Has a fluent builder interface for configuring its semantics.
|
|
|
|
|
*/
|
2009-08-11 12:16:50 +02:00
|
|
|
def newEventBasedThreadPoolDispatcher(name: String) = new EventBasedThreadPoolDispatcher(name)
|
|
|
|
|
def newConcurrentEventBasedThreadPoolDispatcher(name: String) = new EventBasedThreadPoolDispatcher(name, true)
|
2009-07-06 23:45:15 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates an event based dispatcher serving multiple (millions) of actors through a single thread.
|
|
|
|
|
*/
|
2009-08-11 12:16:50 +02:00
|
|
|
def newEventBasedSingleThreadDispatcher(name: String) = new EventBasedSingleThreadDispatcher(name)
|
2009-07-06 23:45:15 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates an thread based dispatcher serving a single actor through the same single thread.
|
|
|
|
|
* E.g. each actor consumes its own thread.
|
|
|
|
|
*/
|
|
|
|
|
def newThreadBasedDispatcher(actor: Actor) = new ThreadBasedDispatcher(actor)
|
2009-08-11 12:16:50 +02:00
|
|
|
}
|