Merge branch 'master' of git@github.com:jboner/akka
This commit is contained in:
commit
dadce028f1
5 changed files with 24 additions and 21 deletions
|
|
@ -348,8 +348,8 @@ trait Actor extends Logging with TransactionManagement {
|
|||
* <p/>
|
||||
* To be invoked from within the actor itself.
|
||||
*/
|
||||
protected[this] def startLinkRemote(actor: Actor) = {
|
||||
actor.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT)
|
||||
protected[this] def startLinkRemote(actor: Actor, hostname: String, port: Int) = {
|
||||
actor.makeRemote(hostname, port)
|
||||
actor.start
|
||||
link(actor)
|
||||
}
|
||||
|
|
@ -372,9 +372,9 @@ trait Actor extends Logging with TransactionManagement {
|
|||
* <p/>
|
||||
* To be invoked from within the actor itself.
|
||||
*/
|
||||
protected[this] def spawnRemote[T <: Actor](actorClass: Class[T]): T = {
|
||||
protected[this] def spawnRemote[T <: Actor](actorClass: Class[T], hostname: String, port: Int): T = {
|
||||
val actor = actorClass.newInstance.asInstanceOf[T]
|
||||
actor.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT)
|
||||
actor.makeRemote(hostname, port)
|
||||
actor.dispatcher = dispatcher
|
||||
actor.mailbox = mailbox
|
||||
actor.start
|
||||
|
|
@ -397,9 +397,9 @@ trait Actor extends Logging with TransactionManagement {
|
|||
* <p/>
|
||||
* To be invoked from within the actor itself.
|
||||
*/
|
||||
protected[this] def spawnLinkRemote[T <: Actor](actorClass: Class[T]): T = {
|
||||
protected[this] def spawnLinkRemote[T <: Actor](actorClass: Class[T], hostname: String, port: Int): T = {
|
||||
val actor = spawn[T](actorClass)
|
||||
actor.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT)
|
||||
actor.makeRemote(hostname, port)
|
||||
link(actor)
|
||||
actor
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,21 +23,20 @@ import org.jboss.netty.handler.codec.protobuf.{ProtobufDecoder, ProtobufEncoder}
|
|||
/**
|
||||
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
||||
*/
|
||||
class RemoteServer extends Logging {
|
||||
def start = RemoteServer.start(None)
|
||||
}
|
||||
object RemoteServer extends RemoteServer
|
||||
|
||||
/**
|
||||
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
||||
*/
|
||||
object RemoteServer extends Logging {
|
||||
class RemoteServer extends Logging {
|
||||
import Config.config
|
||||
val HOSTNAME = config.getString("akka.remote.hostname", "localhost")
|
||||
val PORT = config.getInt("akka.remote.port", 9999)
|
||||
val CONNECTION_TIMEOUT_MILLIS = config.getInt("akka.remote.connection-timeout", 1000)
|
||||
|
||||
val name = "RemoteServer@" + HOSTNAME
|
||||
|
||||
private var hostname = HOSTNAME
|
||||
private var port = PORT
|
||||
|
||||
@volatile private var isRunning = false
|
||||
@volatile private var isConfigured = false
|
||||
|
||||
|
|
@ -49,19 +48,26 @@ object RemoteServer extends Logging {
|
|||
|
||||
private val bootstrap = new ServerBootstrap(factory)
|
||||
|
||||
def name = "RemoteServer@" + hostname + ":" + port
|
||||
|
||||
def start: Unit = start(None)
|
||||
def start(loader: Option[ClassLoader]): Unit = start(HOSTNAME, PORT)
|
||||
|
||||
def start(loader: Option[ClassLoader]): Unit = start(HOSTNAME, PORT, loader)
|
||||
|
||||
def start(hostname: String, port: Int): Unit = start(hostname, port, None)
|
||||
def start(hostname: String, port: Int, loader: Option[ClassLoader]): Unit = synchronized {
|
||||
|
||||
def start(_hostname: String, _port: Int, loader: Option[ClassLoader]): Unit = synchronized {
|
||||
if (!isRunning) {
|
||||
log.info("Starting remote server at [%s:%s]", HOSTNAME, PORT)
|
||||
hostname = _hostname
|
||||
port = _port
|
||||
log.info("Starting remote server at [%s:%s]", hostname, port)
|
||||
bootstrap.setPipelineFactory(new RemoteServerPipelineFactory(name, loader))
|
||||
// FIXME make these RemoteServer options configurable
|
||||
bootstrap.setOption("child.tcpNoDelay", true)
|
||||
bootstrap.setOption("child.keepAlive", true)
|
||||
bootstrap.setOption("child.reuseAddress", true)
|
||||
bootstrap.setOption("child.connectTimeoutMillis", CONNECTION_TIMEOUT_MILLIS)
|
||||
bootstrap.bind(new InetSocketAddress(HOSTNAME, PORT))
|
||||
bootstrap.bind(new InetSocketAddress(hostname, port))
|
||||
isRunning = true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,8 +30,7 @@ class RemoteActorSpec extends TestCase {
|
|||
akka.Config.config
|
||||
new Thread(new Runnable() {
|
||||
def run = {
|
||||
val server = new RemoteServer
|
||||
server.start
|
||||
RemoteServer.start
|
||||
}
|
||||
}).start
|
||||
Thread.sleep(1000)
|
||||
|
|
|
|||
|
|
@ -25,8 +25,7 @@ class RemoteSupervisorSpec extends junit.framework.TestCase with Suite {
|
|||
akka.Config.config
|
||||
new Thread(new Runnable() {
|
||||
def run = {
|
||||
val server = new RemoteServer
|
||||
server.start
|
||||
RemoteServer.start
|
||||
}
|
||||
}).start
|
||||
Thread.sleep(1000)
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ object Kernel extends Logging {
|
|||
|
||||
// FIXME add API to shut server down gracefully
|
||||
@volatile private var hasBooted = false
|
||||
private var remoteServer: RemoteServer = _
|
||||
private var jerseySelectorThread: SelectorThread = _
|
||||
private val startTime = System.currentTimeMillis
|
||||
private var applicationLoader: Option[ClassLoader] = None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue