2009-05-09 17:18:31 +02:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009 Scalable Solutions.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-09-02 09:10:21 +02:00
|
|
|
package se.scalablesolutions.akka.config
|
2009-05-09 17:18:31 +02:00
|
|
|
|
2009-11-11 22:48:49 +01:00
|
|
|
import se.scalablesolutions.akka.actor.Actor
|
|
|
|
|
import se.scalablesolutions.akka.dispatch.MessageDispatcher
|
2009-07-02 13:23:03 +02:00
|
|
|
|
2009-05-09 17:18:31 +02:00
|
|
|
/**
|
|
|
|
|
* Configuration classes - not to be used as messages.
|
|
|
|
|
*
|
|
|
|
|
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
|
|
|
|
*/
|
|
|
|
|
object ScalaConfig {
|
|
|
|
|
sealed abstract class ConfigElement
|
|
|
|
|
|
|
|
|
|
abstract class Server extends ConfigElement
|
|
|
|
|
abstract class FailOverScheme extends ConfigElement
|
|
|
|
|
abstract class Scope extends ConfigElement
|
|
|
|
|
|
|
|
|
|
case class SupervisorConfig(restartStrategy: RestartStrategy, worker: List[Server]) extends Server
|
2009-07-06 23:45:15 +02:00
|
|
|
case class Supervise(actor: Actor, lifeCycle: LifeCycle) extends Server
|
2009-05-09 17:18:31 +02:00
|
|
|
|
|
|
|
|
case class RestartStrategy(scheme: FailOverScheme, maxNrOfRetries: Int, withinTimeRange: Int) extends ConfigElement
|
|
|
|
|
|
|
|
|
|
case object AllForOne extends FailOverScheme
|
|
|
|
|
case object OneForOne extends FailOverScheme
|
|
|
|
|
|
2009-11-11 22:48:49 +01:00
|
|
|
case class LifeCycle(scope: Scope, callbacks: Option[RestartCallbacks]) extends ConfigElement
|
2009-07-07 22:11:27 +02:00
|
|
|
object LifeCycle {
|
2009-11-11 22:48:49 +01:00
|
|
|
def apply(scope: Scope) = new LifeCycle(scope, None)
|
2009-07-06 23:45:15 +02:00
|
|
|
}
|
2009-07-07 22:11:27 +02:00
|
|
|
case class RestartCallbacks(preRestart: String, postRestart: String) {
|
|
|
|
|
if (preRestart == null || postRestart == null) throw new IllegalArgumentException("Restart callback methods can't be null")
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-09 17:18:31 +02:00
|
|
|
case object Permanent extends Scope
|
|
|
|
|
case object Temporary extends Scope
|
|
|
|
|
|
2009-07-02 13:23:03 +02:00
|
|
|
case class RemoteAddress(hostname: String, port: Int)
|
|
|
|
|
|
2009-05-23 22:24:02 +02:00
|
|
|
class Component(_intf: Class[_],
|
2009-07-02 13:23:03 +02:00
|
|
|
val target: Class[_],
|
|
|
|
|
val lifeCycle: LifeCycle,
|
|
|
|
|
val timeout: Int,
|
2009-11-30 20:19:30 +01:00
|
|
|
val transactionRequired: Boolean,
|
2009-07-02 13:23:03 +02:00
|
|
|
_dispatcher: MessageDispatcher, // optional
|
|
|
|
|
_remoteAddress: RemoteAddress // optional
|
|
|
|
|
) extends Server {
|
2009-05-23 22:24:02 +02:00
|
|
|
val intf: Option[Class[_]] = if (_intf == null) None else Some(_intf)
|
2009-07-02 13:23:03 +02:00
|
|
|
val dispatcher: Option[MessageDispatcher] = if (_dispatcher == null) None else Some(_dispatcher)
|
|
|
|
|
val remoteAddress: Option[RemoteAddress] = if (_remoteAddress == null) None else Some(_remoteAddress)
|
2009-05-23 22:24:02 +02:00
|
|
|
}
|
|
|
|
|
object Component {
|
|
|
|
|
def apply(intf: Class[_], target: Class[_], lifeCycle: LifeCycle, timeout: Int) =
|
2009-11-30 20:19:30 +01:00
|
|
|
new Component(intf, target, lifeCycle, timeout, false, null, null)
|
2009-07-02 13:23:03 +02:00
|
|
|
|
2009-05-23 22:24:02 +02:00
|
|
|
def apply(target: Class[_], lifeCycle: LifeCycle, timeout: Int) =
|
2009-11-30 20:19:30 +01:00
|
|
|
new Component(null, target, lifeCycle, timeout, false, null, null)
|
2009-07-02 13:23:03 +02:00
|
|
|
|
|
|
|
|
def apply(intf: Class[_], target: Class[_], lifeCycle: LifeCycle, timeout: Int, dispatcher: MessageDispatcher) =
|
2009-11-30 20:19:30 +01:00
|
|
|
new Component(intf, target, lifeCycle, timeout, false, dispatcher, null)
|
2009-07-02 13:23:03 +02:00
|
|
|
|
|
|
|
|
def apply(target: Class[_], lifeCycle: LifeCycle, timeout: Int, dispatcher: MessageDispatcher) =
|
2009-11-30 20:19:30 +01:00
|
|
|
new Component(null, target, lifeCycle, timeout, false, dispatcher, null)
|
2009-07-02 13:23:03 +02:00
|
|
|
|
|
|
|
|
def apply(intf: Class[_], target: Class[_], lifeCycle: LifeCycle, timeout: Int, remoteAddress: RemoteAddress) =
|
2009-11-30 20:19:30 +01:00
|
|
|
new Component(intf, target, lifeCycle, timeout, false, null, remoteAddress)
|
2009-07-02 13:23:03 +02:00
|
|
|
|
|
|
|
|
def apply(target: Class[_], lifeCycle: LifeCycle, timeout: Int, remoteAddress: RemoteAddress) =
|
2009-11-30 20:19:30 +01:00
|
|
|
new Component(null, target, lifeCycle, timeout, false, null, remoteAddress)
|
2009-07-02 13:23:03 +02:00
|
|
|
|
|
|
|
|
def apply(intf: Class[_], target: Class[_], lifeCycle: LifeCycle, timeout: Int, dispatcher: MessageDispatcher, remoteAddress: RemoteAddress) =
|
2009-11-30 20:19:30 +01:00
|
|
|
new Component(intf, target, lifeCycle, timeout, false, dispatcher, remoteAddress)
|
2009-07-02 13:23:03 +02:00
|
|
|
|
|
|
|
|
def apply(target: Class[_], lifeCycle: LifeCycle, timeout: Int, dispatcher: MessageDispatcher, remoteAddress: RemoteAddress) =
|
2009-11-30 20:19:30 +01:00
|
|
|
new Component(null, target, lifeCycle, timeout, false, dispatcher, remoteAddress)
|
|
|
|
|
|
|
|
|
|
def apply(intf: Class[_], target: Class[_], lifeCycle: LifeCycle, timeout: Int, transactionRequired: Boolean) =
|
|
|
|
|
new Component(intf, target, lifeCycle, timeout, transactionRequired, null, null)
|
|
|
|
|
|
|
|
|
|
def apply(target: Class[_], lifeCycle: LifeCycle, timeout: Int, transactionRequired: Boolean) =
|
|
|
|
|
new Component(null, target, lifeCycle, timeout, transactionRequired, null, null)
|
|
|
|
|
|
|
|
|
|
def apply(intf: Class[_], target: Class[_], lifeCycle: LifeCycle, timeout: Int, transactionRequired: Boolean, dispatcher: MessageDispatcher) =
|
|
|
|
|
new Component(intf, target, lifeCycle, timeout, transactionRequired, dispatcher, null)
|
|
|
|
|
|
|
|
|
|
def apply(target: Class[_], lifeCycle: LifeCycle, timeout: Int, transactionRequired: Boolean, dispatcher: MessageDispatcher) =
|
|
|
|
|
new Component(null, target, lifeCycle, timeout, transactionRequired, dispatcher, null)
|
|
|
|
|
|
|
|
|
|
def apply(intf: Class[_], target: Class[_], lifeCycle: LifeCycle, timeout: Int, transactionRequired: Boolean, remoteAddress: RemoteAddress) =
|
|
|
|
|
new Component(intf, target, lifeCycle, timeout, transactionRequired, null, remoteAddress)
|
|
|
|
|
|
|
|
|
|
def apply(target: Class[_], lifeCycle: LifeCycle, timeout: Int, transactionRequired: Boolean, remoteAddress: RemoteAddress) =
|
|
|
|
|
new Component(null, target, lifeCycle, timeout, transactionRequired, null, remoteAddress)
|
|
|
|
|
|
|
|
|
|
def apply(intf: Class[_], target: Class[_], lifeCycle: LifeCycle, timeout: Int, transactionRequired: Boolean, dispatcher: MessageDispatcher, remoteAddress: RemoteAddress) =
|
|
|
|
|
new Component(intf, target, lifeCycle, timeout, transactionRequired, dispatcher, remoteAddress)
|
|
|
|
|
|
|
|
|
|
def apply(target: Class[_], lifeCycle: LifeCycle, timeout: Int, transactionRequired: Boolean, dispatcher: MessageDispatcher, remoteAddress: RemoteAddress) =
|
|
|
|
|
new Component(null, target, lifeCycle, timeout, transactionRequired, dispatcher, remoteAddress)
|
2009-05-23 22:24:02 +02:00
|
|
|
}
|
2009-05-09 17:18:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
|
|
|
|
*/
|
|
|
|
|
object JavaConfig {
|
2009-11-11 22:48:49 +01:00
|
|
|
import scala.reflect.BeanProperty
|
|
|
|
|
|
2009-05-09 17:18:31 +02:00
|
|
|
sealed abstract class ConfigElement
|
|
|
|
|
|
|
|
|
|
class RestartStrategy(
|
|
|
|
|
@BeanProperty val scheme: FailOverScheme,
|
|
|
|
|
@BeanProperty val maxNrOfRetries: Int,
|
|
|
|
|
@BeanProperty val withinTimeRange: Int) extends ConfigElement {
|
2009-09-02 09:10:21 +02:00
|
|
|
def transform = se.scalablesolutions.akka.config.ScalaConfig.RestartStrategy(
|
2009-05-09 17:18:31 +02:00
|
|
|
scheme.transform, maxNrOfRetries, withinTimeRange)
|
|
|
|
|
}
|
2009-07-07 22:11:27 +02:00
|
|
|
|
2009-11-11 22:48:49 +01:00
|
|
|
class LifeCycle(@BeanProperty val scope: Scope, @BeanProperty val callbacks: RestartCallbacks) extends ConfigElement {
|
|
|
|
|
def this(scope: Scope) = this(scope, null)
|
2009-07-07 22:11:27 +02:00
|
|
|
def transform = {
|
|
|
|
|
val callbackOption = if (callbacks == null) None else Some(callbacks.transform)
|
2009-11-11 22:48:49 +01:00
|
|
|
se.scalablesolutions.akka.config.ScalaConfig.LifeCycle(scope.transform, callbackOption)
|
2009-07-07 22:11:27 +02:00
|
|
|
}
|
2009-05-09 17:18:31 +02:00
|
|
|
}
|
|
|
|
|
|
2009-07-07 22:11:27 +02:00
|
|
|
class RestartCallbacks(@BeanProperty val preRestart: String, @BeanProperty val postRestart: String) {
|
2009-09-02 09:10:21 +02:00
|
|
|
def transform = se.scalablesolutions.akka.config.ScalaConfig.RestartCallbacks(preRestart, postRestart)
|
2009-07-07 22:11:27 +02:00
|
|
|
}
|
2009-07-06 23:45:15 +02:00
|
|
|
|
2009-05-09 17:18:31 +02:00
|
|
|
abstract class Scope extends ConfigElement {
|
2009-09-02 09:10:21 +02:00
|
|
|
def transform: se.scalablesolutions.akka.config.ScalaConfig.Scope
|
2009-05-09 17:18:31 +02:00
|
|
|
}
|
|
|
|
|
class Permanent extends Scope {
|
2009-09-02 09:10:21 +02:00
|
|
|
override def transform = se.scalablesolutions.akka.config.ScalaConfig.Permanent
|
2009-05-09 17:18:31 +02:00
|
|
|
}
|
|
|
|
|
class Temporary extends Scope {
|
2009-09-02 09:10:21 +02:00
|
|
|
override def transform = se.scalablesolutions.akka.config.ScalaConfig.Temporary
|
2009-05-09 17:18:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
abstract class FailOverScheme extends ConfigElement {
|
2009-09-02 09:10:21 +02:00
|
|
|
def transform: se.scalablesolutions.akka.config.ScalaConfig.FailOverScheme
|
2009-05-09 17:18:31 +02:00
|
|
|
}
|
|
|
|
|
class AllForOne extends FailOverScheme {
|
2009-09-02 09:10:21 +02:00
|
|
|
override def transform = se.scalablesolutions.akka.config.ScalaConfig.AllForOne
|
2009-05-09 17:18:31 +02:00
|
|
|
}
|
|
|
|
|
class OneForOne extends FailOverScheme {
|
2009-09-02 09:10:21 +02:00
|
|
|
override def transform = se.scalablesolutions.akka.config.ScalaConfig.OneForOne
|
2009-05-09 17:18:31 +02:00
|
|
|
}
|
|
|
|
|
|
2009-07-02 13:23:03 +02:00
|
|
|
class RemoteAddress(@BeanProperty val hostname: String, @BeanProperty val port: Int)
|
2009-07-06 23:45:15 +02:00
|
|
|
|
2009-05-09 17:18:31 +02:00
|
|
|
abstract class Server extends ConfigElement
|
2009-05-23 22:24:02 +02:00
|
|
|
class Component(@BeanProperty val intf: Class[_],
|
2009-05-09 17:18:31 +02:00
|
|
|
@BeanProperty val target: Class[_],
|
|
|
|
|
@BeanProperty val lifeCycle: LifeCycle,
|
2009-07-02 13:23:03 +02:00
|
|
|
@BeanProperty val timeout: Int,
|
2009-11-30 20:19:30 +01:00
|
|
|
@BeanProperty val transactionRequired: Boolean, // optional
|
2009-07-02 13:23:03 +02:00
|
|
|
@BeanProperty val dispatcher: MessageDispatcher, // optional
|
|
|
|
|
@BeanProperty val remoteAddress: RemoteAddress // optional
|
|
|
|
|
) extends Server {
|
|
|
|
|
|
|
|
|
|
def this(intf: Class[_], target: Class[_], lifeCycle: LifeCycle, timeout: Int) =
|
2009-11-30 20:19:30 +01:00
|
|
|
this(intf, target, lifeCycle, timeout, false, null, null)
|
2009-07-02 13:23:03 +02:00
|
|
|
|
2009-05-23 22:24:02 +02:00
|
|
|
def this(target: Class[_], lifeCycle: LifeCycle, timeout: Int) =
|
2009-11-30 20:19:30 +01:00
|
|
|
this(null, target, lifeCycle, timeout, false, null, null)
|
2009-07-02 13:23:03 +02:00
|
|
|
|
|
|
|
|
def this(intf: Class[_], target: Class[_], lifeCycle: LifeCycle, timeout: Int, remoteAddress: RemoteAddress) =
|
2009-11-30 20:19:30 +01:00
|
|
|
this(intf, target, lifeCycle, timeout, false, null, remoteAddress)
|
2009-07-02 13:23:03 +02:00
|
|
|
|
|
|
|
|
def this(target: Class[_], lifeCycle: LifeCycle, timeout: Int, remoteAddress: RemoteAddress) =
|
2009-11-30 20:19:30 +01:00
|
|
|
this(null, target, lifeCycle, timeout, false, null, remoteAddress)
|
2009-07-02 13:23:03 +02:00
|
|
|
|
|
|
|
|
def this(intf: Class[_], target: Class[_], lifeCycle: LifeCycle, timeout: Int, dispatcher: MessageDispatcher) =
|
2009-11-30 20:19:30 +01:00
|
|
|
this(intf, target, lifeCycle, timeout, false, dispatcher, null)
|
2009-07-02 13:23:03 +02:00
|
|
|
|
|
|
|
|
def this(target: Class[_], lifeCycle: LifeCycle, timeout: Int, dispatcher: MessageDispatcher) =
|
2009-11-30 20:19:30 +01:00
|
|
|
this(null, target, lifeCycle, timeout, false, dispatcher, null)
|
2009-07-02 13:23:03 +02:00
|
|
|
|
|
|
|
|
def this(target: Class[_], lifeCycle: LifeCycle, timeout: Int, dispatcher: MessageDispatcher, remoteAddress: RemoteAddress) =
|
2009-11-30 20:19:30 +01:00
|
|
|
this(null, target, lifeCycle, timeout, false, dispatcher, remoteAddress)
|
|
|
|
|
|
|
|
|
|
def this(intf: Class[_], target: Class[_], lifeCycle: LifeCycle, timeout: Int, transactionRequired: Boolean) =
|
|
|
|
|
this(intf, target, lifeCycle, timeout, transactionRequired, null, null)
|
|
|
|
|
|
|
|
|
|
def this(target: Class[_], lifeCycle: LifeCycle, timeout: Int, transactionRequired: Boolean) =
|
|
|
|
|
this(null, target, lifeCycle, timeout, transactionRequired, null, null)
|
|
|
|
|
|
|
|
|
|
def this(intf: Class[_], target: Class[_], lifeCycle: LifeCycle, timeout: Int, transactionRequired: Boolean, remoteAddress: RemoteAddress) =
|
|
|
|
|
this(intf, target, lifeCycle, timeout, transactionRequired, null, remoteAddress)
|
|
|
|
|
|
|
|
|
|
def this(target: Class[_], lifeCycle: LifeCycle, timeout: Int, transactionRequired: Boolean, remoteAddress: RemoteAddress) =
|
|
|
|
|
this(null, target, lifeCycle, timeout, transactionRequired, null, remoteAddress)
|
|
|
|
|
|
|
|
|
|
def this(intf: Class[_], target: Class[_], lifeCycle: LifeCycle, timeout: Int, transactionRequired: Boolean, dispatcher: MessageDispatcher) =
|
|
|
|
|
this(intf, target, lifeCycle, timeout, transactionRequired, dispatcher, null)
|
|
|
|
|
|
|
|
|
|
def this(target: Class[_], lifeCycle: LifeCycle, timeout: Int, transactionRequired: Boolean, dispatcher: MessageDispatcher) =
|
|
|
|
|
this(null, target, lifeCycle, timeout, transactionRequired, dispatcher, null)
|
|
|
|
|
|
|
|
|
|
def this(target: Class[_], lifeCycle: LifeCycle, timeout: Int, transactionRequired: Boolean, dispatcher: MessageDispatcher, remoteAddress: RemoteAddress) =
|
|
|
|
|
this(null, target, lifeCycle, timeout, transactionRequired, dispatcher, remoteAddress)
|
2009-07-02 13:23:03 +02:00
|
|
|
|
|
|
|
|
def transform =
|
2009-11-30 20:19:30 +01:00
|
|
|
se.scalablesolutions.akka.config.ScalaConfig.Component(
|
|
|
|
|
intf, target, lifeCycle.transform, timeout, transactionRequired, dispatcher,
|
2009-09-02 09:10:21 +02:00
|
|
|
if (remoteAddress != null) se.scalablesolutions.akka.config.ScalaConfig.RemoteAddress(remoteAddress.hostname, remoteAddress.port) else null)
|
2009-07-02 13:23:03 +02:00
|
|
|
|
2009-07-06 23:45:15 +02:00
|
|
|
def newSupervised(actor: Actor) =
|
2009-09-02 09:10:21 +02:00
|
|
|
se.scalablesolutions.akka.config.ScalaConfig.Supervise(actor, lifeCycle.transform)
|
2009-05-09 17:18:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|