initial guice integration started

This commit is contained in:
Jonas Boner 2009-02-16 22:49:33 +01:00
parent d01a293fa7
commit 42cc47bf6a
4 changed files with 40 additions and 234 deletions

View file

@ -4,7 +4,7 @@
package com.scalablesolutions.akka.api
import com.scalablesolutions.akka.kernel.ActiveObject
import com.scalablesolutions.akka.kernel.{ActiveObject, ActiveObjectProxy}
import java.util.{List => JList}
@ -47,111 +47,45 @@ abstract class Server extends Configuration
class SupervisorConfig(@BeanProperty val restartStrategy: RestartStrategy, @BeanProperty val servers: JList[Server]) extends Server {
def transform = scala.actors.behavior.SupervisorConfig(restartStrategy.transform, servers.toArray.toList.asInstanceOf[List[Component]].map(_.transform))
}
class Component(@BeanProperty val serverContainer: GenericServerContainer, @BeanProperty val lifeCycle: LifeCycle) extends Server {
def transform = scala.actors.behavior.Worker(serverContainer, lifeCycle.transform)
class Component(@BeanProperty val proxy: ActiveObjectProxy, @BeanProperty val lifeCycle: LifeCycle) extends Server {
def transform = scala.actors.behavior.Worker(proxy.server, lifeCycle.transform)
}
object Configuration {
def supervise(restartStrategy: RestartStrategy, components: JList[Component]): Supervisor =
import com.google.inject.{AbstractModule, CreationException, Guice, Injector, Provides, Singleton}
import com.google.inject.spi.CloseFailedException
import com.google.inject.jsr250.{ResourceProviderFactory}
import javax.annotation.Resource
import javax.naming.Context
def supervise(restartStrategy: RestartStrategy, components: JList[Component]): Supervisor = {
val componentList = components.toArray.toList.asInstanceOf[List[Component]]
val injector = Guice.createInjector(new AbstractModule {
protected def configure = {
bind(classOf[ResourceProviderFactory[_]])
componentList.foreach(c => bind(c.getClass).in(classOf[Singleton]))
}
// @Provides
// def createJndiContext: Context = {
// val answer = new JndiContext
// answer.bind("foo", new AnotherBean("Foo"))
// answer.bind("xyz", new AnotherBean("XYZ"))
// answer
// }
})
val injectedComponents = componentList.map(c => injector.getInstance(c.getClass))
// TODO: swap 'target' in proxy before running supervise
ActiveObject.supervise(
restartStrategy.transform,
components.toArray.toList.asInstanceOf[List[Component]].map(
c => scala.actors.behavior.Worker(c.serverContainer, c.lifeCycle.transform)))
componentList.map(c => scala.actors.behavior.Worker(c.proxy.server, c.lifeCycle.transform)))
}
}
// static class SupervisorConfig extends Server {
// private final RestartStrategy restartStrategy;
// private final List<Server> servers;
// public SupervisorConfig(RestartStrategy restartStrategy, List<Server> servers) {
// this.restartStrategy = restartStrategy;
// this.servers = servers;
// }
// public RestartStrategy getRestartStrategy() {
// return restartStrategy;
// }
// public List<Server> getServer() {
// return servers;
// }
// public scala.actors.behavior.SupervisorConfig scalaVersion() {
// List<scala.actors.behavior.Server> ss = new ArrayList<scala.actors.behavior.Server>();
// for (Server s: servers) {
// ss.add(s.scalaVersion());
// }
// return new scala.actors.behavior.SupervisorConfig(restartStrategy.scalaVersion(), ss);
// }
// }
// static class Component extends Server {
// private final GenericServerContainer serverContainer;
// private final LifeCycle lifeCycle;
// public Component(GenericServerContainer serverContainer, LifeCycle lifeCycle) {
// this.serverContainer = serverContainer;
// this.lifeCycle = lifeCycle;
// }
// public GenericServerContainer getServerContainer() {
// return serverContainer;
// }
// public LifeCycle getLifeCycle() {
// return lifeCycle;
// }
// public scala.actors.behavior.Server scalaVersion() {
// return new scala.actors.behavior.Worker(serverContainer, lifeCycle.scalaVersion());
// }
// }
// static class RestartStrategy extends Configuration {
// private final FailOverScheme scheme;
// private final int maxNrOfRetries;
// private final int withinTimeRange;
// public RestartStrategy(FailOverScheme scheme, int maxNrOfRetries, int withinTimeRange) {
// this.scheme = scheme;
// this.maxNrOfRetries = maxNrOfRetries;
// this.withinTimeRange = withinTimeRange;
// }
// public FailOverScheme getFailOverScheme() {
// return scheme;
// }
// public int getMaxNrOfRetries() {
// return maxNrOfRetries;
// }
// public int getWithinTimeRange() {
// return withinTimeRange;
// }
// public scala.actors.behavior.RestartStrategy scalaVersion() {
// scala.actors.behavior.FailOverScheme fos;
// switch (scheme) {
// case AllForOne: fos = new scala.actors.behavior.AllForOne(); break;
// case OneForOne: fos = new scala.actors.behavior.OneForOne(); break;
// }
// return new scala.actors.behavior.RestartStrategy(fos, maxNrOfRetries, withinTimeRange);
// }
// }
// static class LifeCycle extends Configuration {
// private final Scope scope;
// private final int shutdownTime;
// public LifeCycle(Scope scope, int shutdownTime) {
// this.scope = scope;
// this.shutdownTime = shutdownTime;
// }
// public Scope getScope() {
// return scope;
// }
// public int getShutdownTime() {
// return shutdownTime;
// }
// public scala.actors.behavior.LifeCycle scalaVersion() {
// scala.actors.behavior.Scope s;
// switch (scope) {
// case Permanent: s = new scala.actors.behavior.Permanent(); break;
// case Transient: s = new scala.actors.behavior.Transient(); break;
// case Temporary: s = new scala.actors.behavior.Temporary(); break;
// }
// return new scala.actors.behavior.LifeCycle(s, shutdownTime);
// }
// }
// }