diff --git a/akka.iws b/akka.iws index 5a75486cb0..4ff0203169 100644 --- a/akka.iws +++ b/akka.iws @@ -2,25 +2,23 @@ - + + + - - - + - - + + + - - - + + - - - - - - + + + + @@ -40,7 +38,46 @@ - + + + + + + + - - + + - + - - + + - + + + + + + + + + + + + + + + + + + + @@ -132,16 +187,45 @@ - + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -150,52 +234,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -261,256 +300,6 @@ - + @@ -1233,11 +1192,11 @@ - + - + - + @@ -1295,116 +1254,116 @@ - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + + + + + + + + + + + + + + + + + - + + + + + + + + diff --git a/api-java/src/test/java/se/scalablesolutions/akka/api/ActiveObjectGuiceConfiguratorTest.java b/api-java/src/test/java/se/scalablesolutions/akka/api/ActiveObjectGuiceConfiguratorTest.java index 9918cc15ae..0419097865 100755 --- a/api-java/src/test/java/se/scalablesolutions/akka/api/ActiveObjectGuiceConfiguratorTest.java +++ b/api-java/src/test/java/se/scalablesolutions/akka/api/ActiveObjectGuiceConfiguratorTest.java @@ -49,21 +49,21 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase { public void testGuiceActiveObjectInjection() { messageLog = ""; - Foo foo = conf.getActiveObject("foo"); - Bar bar = conf.getActiveObject("bar"); + Foo foo = conf.getActiveObject(Foo.class); + Bar bar = conf.getActiveObject(Bar.class); assertTrue(foo.getBar().toString().equals(bar.toString())); } public void testGuiceExternalDependencyInjection() { messageLog = ""; - Bar bar = conf.getActiveObject("bar"); + Bar bar = conf.getActiveObject(Bar.class); Ext ext = conf.getExternalDependency(Ext.class); assertTrue(bar.getExt().toString().equals(ext.toString())); } public void testLookupNonSupervisedInstance() { try { - String str = conf.getActiveObject("string"); + String str = conf.getActiveObject(String.class); fail("exception should have been thrown"); } catch (Exception e) { assertEquals("Class string has not been put under supervision (by passing in the config to the supervise() method", e.getMessage()); @@ -72,7 +72,7 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase { public void testActiveObjectInvocation() throws InterruptedException { messageLog = ""; - Foo foo = conf.getActiveObject("foo"); + Foo foo = conf.getActiveObject(Foo.class); messageLog += foo.foo("foo "); foo.bar("bar "); messageLog += "before_bar "; @@ -82,8 +82,8 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase { public void testActiveObjectInvocationsInvocation() throws InterruptedException { messageLog = ""; - Foo foo = conf.getActiveObject("foo"); - Bar bar = conf.getActiveObject("bar"); + Foo foo = conf.getActiveObject(Foo.class); + Bar bar = conf.getActiveObject(Bar.class); messageLog += foo.foo("foo "); foo.bar("bar "); messageLog += "before_bar "; @@ -94,7 +94,7 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase { public void testForcedTimeout() { messageLog = ""; - Foo foo = conf.getActiveObject("foo"); + Foo foo = conf.getActiveObject(Foo.class); try { foo.longRunning(); fail("exception should have been thrown"); @@ -104,7 +104,7 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase { public void testForcedException() { messageLog = ""; - Foo foo = conf.getActiveObject("foo"); + Foo foo = conf.getActiveObject(Foo.class); try { foo.throwsException(); fail("exception should have been thrown"); diff --git a/api-java/src/test/java/se/scalablesolutions/akka/api/InMemoryStateTest.java b/api-java/src/test/java/se/scalablesolutions/akka/api/InMemoryStateTest.java index 57db86c34d..488ab3e375 100755 --- a/api-java/src/test/java/se/scalablesolutions/akka/api/InMemoryStateTest.java +++ b/api-java/src/test/java/se/scalablesolutions/akka/api/InMemoryStateTest.java @@ -32,7 +32,7 @@ public class InMemoryStateTest extends TestCase { } public void testShouldNotRollbackStateForStatefulServerInCaseOfSuccess() { - InMemStateful stateful = conf.getActiveObject("inmem-stateful"); + InMemStateful stateful = conf.getActiveObject(InMemStateful.class); stateful.setState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactional stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // to trigger commit @@ -40,9 +40,9 @@ public class InMemoryStateTest extends TestCase { } public void testShouldRollbackStateForStatefulServerInCaseOfFailure() { - InMemStateful stateful = conf.getActiveObject("inmem-stateful"); + InMemStateful stateful = conf.getActiveObject(InMemStateful.class); stateful.setState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state - InMemFailer failer = conf.getActiveObject("inmem-failer"); + InMemFailer failer = conf.getActiveObject(InMemFailer.class); try { stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactional method fail("should have thrown an exception"); diff --git a/api-java/src/test/java/se/scalablesolutions/akka/api/JerseyFoo.java b/api-java/src/test/java/se/scalablesolutions/akka/api/JerseyFoo.java index 597273bd4f..7b92f1c8a2 100644 --- a/api-java/src/test/java/se/scalablesolutions/akka/api/JerseyFoo.java +++ b/api-java/src/test/java/se/scalablesolutions/akka/api/JerseyFoo.java @@ -1,5 +1,12 @@ package se.scalablesolutions.akka.api; +import javax.ws.rs.Path; +import javax.ws.rs.GET; +import javax.ws.rs.Produces; + +@Path("/foo") public interface JerseyFoo { + @GET + @Produces({"application/json"}) public String foo(); } diff --git a/api-java/src/test/java/se/scalablesolutions/akka/api/JerseyFooImpl.java b/api-java/src/test/java/se/scalablesolutions/akka/api/JerseyFooImpl.java index 93dfb27384..51e176eb89 100644 --- a/api-java/src/test/java/se/scalablesolutions/akka/api/JerseyFooImpl.java +++ b/api-java/src/test/java/se/scalablesolutions/akka/api/JerseyFooImpl.java @@ -4,10 +4,10 @@ import javax.ws.rs.Path; import javax.ws.rs.GET; import javax.ws.rs.Produces; -@Path("/foo") +//@Path("/foo") public class JerseyFooImpl implements JerseyFoo { - @GET - @Produces({"application/json"}) + //@GET + //@Produces({"application/json"}) public String foo() { return "hello foo"; } diff --git a/api-java/src/test/java/se/scalablesolutions/akka/api/PersistentStateTest.java b/api-java/src/test/java/se/scalablesolutions/akka/api/PersistentStateTest.java index 2e36bca2fa..21197a885a 100755 --- a/api-java/src/test/java/se/scalablesolutions/akka/api/PersistentStateTest.java +++ b/api-java/src/test/java/se/scalablesolutions/akka/api/PersistentStateTest.java @@ -42,7 +42,7 @@ public class PersistentStateTest extends TestCase { } public void testShouldNotRollbackStateForStatefulServerInCaseOfSuccess() { - PersistentStateful stateful = conf.getActiveObject("persistent-stateful"); + PersistentStateful stateful = conf.getActiveObject(PersistentStateful.class); stateful.setState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactional stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // to trigger commit @@ -50,9 +50,9 @@ public class PersistentStateTest extends TestCase { } public void testShouldRollbackStateForStatefulServerInCaseOfFailure() { - PersistentStateful stateful = conf.getActiveObject("persistent-stateful"); + PersistentStateful stateful = conf.getActiveObject(PersistentStateful.class); stateful.setState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state - PersistentFailer failer = conf.getActiveObject("persistent-failer"); + PersistentFailer failer = conf.getActiveObject(PersistentFailer.class); try { stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactional method fail("should have thrown an exception"); diff --git a/api-java/src/test/java/se/scalablesolutions/akka/api/RestTest.java b/api-java/src/test/java/se/scalablesolutions/akka/api/RestTest.java index d465bf41e8..7687d1744c 100644 --- a/api-java/src/test/java/se/scalablesolutions/akka/api/RestTest.java +++ b/api-java/src/test/java/se/scalablesolutions/akka/api/RestTest.java @@ -8,8 +8,12 @@ import com.sun.jersey.api.container.grizzly.GrizzlyWebContainerFactory; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.WebResource; import com.sun.grizzly.http.SelectorThread; +import com.sun.grizzly.http.servlet.ServletAdapter; +import com.sun.grizzly.tcp.Adapter; +import com.sun.grizzly.standalone.StaticStreamAlgorithm; import javax.ws.rs.core.UriBuilder; +import javax.servlet.Servlet; import org.junit.*; import static org.junit.Assert.*; @@ -19,19 +23,33 @@ import java.io.IOException; import java.net.URI; import junit.framework.TestSuite; +import se.scalablesolutions.akka.kernel.config.ActiveObjectGuiceConfiguratorForJava; +import se.scalablesolutions.akka.kernel.config.JavaConfig; public class RestTest extends TestSuite { - private static URI URI = UriBuilder.fromUri("http://localhost/").port(9998).build(); + private static int PORT = 9998; + private static URI URI = UriBuilder.fromUri("http://localhost/").port(PORT).build(); private static SelectorThread selector = null; + private static ActiveObjectGuiceConfiguratorForJava conf = new ActiveObjectGuiceConfiguratorForJava(); @BeforeClass public static void initialize() throws IOException { + conf.configureActiveObjects( + new JavaConfig.RestartStrategy(new JavaConfig.AllForOne(), 3, 5000), + new JavaConfig.Component[] { + new JavaConfig.Component( + "jersey-foo", + JerseyFoo.class, + JerseyFooImpl.class, + new JavaConfig.LifeCycle(new JavaConfig.Permanent(), 1000), 10000000) + }).inject().supervise(); selector = startJersey(); } @AfterClass public static void cleanup() throws IOException { + conf.stop(); selector.stopEndpoint(); System.exit(0); } @@ -46,10 +64,27 @@ public class RestTest extends TestSuite { selector.stopEndpoint(); } - private static SelectorThread startJersey() throws IOException { - Map initParams = new java.util.HashMap(); - initParams.put("com.sun.jersey.config.property.packages", "se.scalablesolutions.akka.api"); - //return GrizzlyWebContainerFactory.create(URI, initParams); - return GrizzlyWebContainerFactory.create(URI, se.scalablesolutions.akka.kernel.jersey.AkkaServlet.class); + private static SelectorThread startJersey() { + try { + ServletAdapter adapter = new ServletAdapter(); + Servlet servlet = se.scalablesolutions.akka.kernel.jersey.AkkaServlet.class.newInstance(); + adapter.setServletInstance(servlet); + adapter.setContextPath(URI.getPath()); + return createGrizzlySelector(adapter, URI, PORT); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static SelectorThread createGrizzlySelector(Adapter adapter, URI uri, int port) throws IOException, InstantiationException { + final String scheme = uri.getScheme(); + if (!scheme.equalsIgnoreCase("http")) + throw new IllegalArgumentException("The URI scheme, of the URI " + uri + ", must be equal (ignoring case) to 'http'"); + final SelectorThread selectorThread = new SelectorThread(); + selectorThread.setAlgorithmClassName(StaticStreamAlgorithm.class.getName()); + selectorThread.setPort(port); + selectorThread.setAdapter(adapter); + selectorThread.listen(); + return selectorThread; } } diff --git a/kernel/akka-kernel.iml b/kernel/akka-kernel.iml index 41bc3a9fb4..2af3d27ef6 100644 --- a/kernel/akka-kernel.iml +++ b/kernel/akka-kernel.iml @@ -135,6 +135,15 @@ + + + + + + + + + diff --git a/kernel/src/main/scala/ActiveObject.scala b/kernel/src/main/scala/ActiveObject.scala index 8d651fc141..dc62d0e98a 100755 --- a/kernel/src/main/scala/ActiveObject.scala +++ b/kernel/src/main/scala/ActiveObject.scala @@ -84,12 +84,13 @@ object ActiveObject { /** * @author Jonas Bonér */ -// FIXME: use interface for ActiveObjectGuiceConfigurator + +// FIXME: STM that allows concurrent updates, detects collision, rolls back and restarts class ActiveObjectProxy(val intf: Class[_], val target: Class[_], val timeout: Int) extends InvocationHandler { import ActiveObject.threadBoundTx private[this] var activeTx: Option[Transaction] = None - private[this] var targetInstance: AnyRef = _ + private[akka] var targetInstance: AnyRef = _ private[akka] def setTargetInstance(instance: AnyRef) = { targetInstance = instance diff --git a/kernel/src/main/scala/config/ActiveObjectConfigurator.scala b/kernel/src/main/scala/config/ActiveObjectConfigurator.scala index 4455788cd4..93b115b758 100644 --- a/kernel/src/main/scala/config/ActiveObjectConfigurator.scala +++ b/kernel/src/main/scala/config/ActiveObjectConfigurator.scala @@ -29,12 +29,21 @@ trait ActiveObjectConfigurator { * @param clazz the class for the active object * @return the active object for the class */ - def getActiveObject(clazz: Class[_]): AnyRef + def getActiveObject[T](clazz: Class[T]): T + def getActiveObjectProxy(clazz: Class[_]): ActiveObjectProxy + def getExternalDependency[T](clazz: Class[T]): T + + def getComponentInterfaces: List[Class[_]] + def configureActiveObjects(restartStrategy: RestartStrategy, components: List[Component]): ActiveObjectConfigurator + def inject: ActiveObjectConfigurator + def supervise: ActiveObjectConfigurator + def reset + def stop } diff --git a/kernel/src/main/scala/config/ActiveObjectGuiceConfigurator.scala b/kernel/src/main/scala/config/ActiveObjectGuiceConfigurator.scala index c7f4ea5d46..1463cb7630 100644 --- a/kernel/src/main/scala/config/ActiveObjectGuiceConfigurator.scala +++ b/kernel/src/main/scala/config/ActiveObjectGuiceConfigurator.scala @@ -45,9 +45,8 @@ class ActiveObjectGuiceConfigurator extends ActiveObjectConfigurator with CamelC * @param clazz the class for the active object * @return the active object for the class */ - override def getActiveObject(clazz: Class[_]): AnyRef = synchronized { - //def getActiveObject[T](name: String): T = synchronized { - log.debug("Looking up active object [%s]", clazz.getName) + override def getActiveObject[T](clazz: Class[T]): T = synchronized { + log.debug("Creating new active object [%s]", clazz.getName) if (injector == null) throw new IllegalStateException("inject() and/or supervise() must be called before invoking getActiveObject(clazz)") val activeObjectOption: Option[Tuple3[Class[_], Class[_], ActiveObjectProxy]] = activeObjectRegistry.get(clazz) if (activeObjectOption.isDefined) { @@ -58,7 +57,7 @@ class ActiveObjectGuiceConfigurator extends ActiveObjectConfigurator with CamelC val target = implClass.newInstance injector.injectMembers(target) activeObjectProxy.setTargetInstance(target.asInstanceOf[AnyRef]) - activeObjectFactory.newInstance(intfClass, activeObjectProxy).asInstanceOf[AnyRef] + activeObjectFactory.newInstance(intfClass, activeObjectProxy).asInstanceOf[T] } else throw new IllegalStateException("Class [" + clazz.getName + "] has not been put under supervision (by passing in the config to the 'supervise') method") } @@ -74,6 +73,8 @@ class ActiveObjectGuiceConfigurator extends ActiveObjectConfigurator with CamelC injector.getInstance(clazz).asInstanceOf[T] } + override def getComponentInterfaces: List[Class[_]] = components.map(_.intf) + override def getRoutingEndpoint(uri: String): Endpoint = synchronized { camelContext.getEndpoint(uri) } @@ -91,9 +92,9 @@ class ActiveObjectGuiceConfigurator extends ActiveObjectConfigurator with CamelC this.components = components.toArray.toList.asInstanceOf[List[Component]] bindings = for (c <- this.components) yield new DependencyBinding(c.intf, c.target) // build up the Guice interface class -> impl class bindings - val arrayList = new java.util.ArrayList[DependencyBinding]() - for (b <- bindings) arrayList.add(b) - modules.add(new ActiveObjectGuiceModule(arrayList)) + val deps = new java.util.ArrayList[DependencyBinding](bindings.size) + for (b <- bindings) deps.add(b) + modules.add(new ActiveObjectGuiceModule(deps)) this } diff --git a/kernel/src/main/scala/config/ActiveObjectGuiceConfiguratorForJava.scala b/kernel/src/main/scala/config/ActiveObjectGuiceConfiguratorForJava.scala index 83c4debe4a..2ad74931f2 100644 --- a/kernel/src/main/scala/config/ActiveObjectGuiceConfiguratorForJava.scala +++ b/kernel/src/main/scala/config/ActiveObjectGuiceConfiguratorForJava.scala @@ -10,7 +10,7 @@ import akka.kernel.{Supervisor, ActiveObjectProxy, ActiveObjectFactory} import com.google.inject._ import com.google.inject.jsr250.ResourceProviderFactory -import java.util.{ArrayList, HashMap, Collection} +import java.util._ import org.apache.camel.impl.{JndiRegistry, DefaultCamelContext} import org.apache.camel.{Endpoint, Routes} @@ -18,138 +18,62 @@ import org.apache.camel.{Endpoint, Routes} * @author Jonas Bonér */ class ActiveObjectGuiceConfiguratorForJava { - private var modules = new ArrayList[Module] - private var injector: Injector = _ - private var supervisor: Supervisor = _ - private var restartStrategy: RestartStrategy = _ - private var components: List[Component] = _ - private var bindings: List[DependencyBinding] = Nil - private var configRegistry = new HashMap[Class[_], Component] // TODO is configRegistry needed? - private var activeObjectRegistry = new HashMap[String, Tuple2[Class[_], ActiveObjectProxy]] - private var activeObjectFactory = new ActiveObjectFactory - //private var camelContext = new DefaultCamelContext(); - - def getExternalDependency[T](clazz: Class[T]): T = synchronized { - injector.getInstance(clazz).asInstanceOf[T] - } -/* - def getRoutingEndpoint(uri: String): Endpoint = synchronized { - camelContext.getEndpoint(uri) - } - - def getRoutingEndpoints: Collection[Endpoint] = synchronized { - camelContext.getEndpoints - } - - def getRoutingEndpoints(uri: String): Collection[Endpoint] = synchronized { - camelContext.getEndpoints(uri) - } -*/ + val INSTANCE = new ActiveObjectGuiceConfigurator + /** * Returns the active abject that has been put under supervision for the class specified. * * @param clazz the class for the active object * @return the active object for the class */ - def getActiveObject[T](name: String): T = synchronized { - if (injector == null) throw new IllegalStateException("inject() and supervise() must be called before invoking newInstance(clazz)") - if (activeObjectRegistry.containsKey(name)) { - val activeObjectTuple = activeObjectRegistry.get(name) - val clazz = activeObjectTuple._1 - val activeObjectProxy = activeObjectTuple._2 - activeObjectProxy.setTargetInstance(injector.getInstance(clazz).asInstanceOf[AnyRef]) - //val target = clazz.newInstance - //injector.injectMembers(target) - //activeObjectProxy.setTargetInstance(target.asInstanceOf[AnyRef]) - activeObjectFactory.newInstance(clazz, activeObjectProxy).asInstanceOf[T] - } else throw new IllegalStateException("Class " + name + " has not been put under supervision (by passing in the config to the supervise() method") - } + def getActiveObject[T](clazz: Class[T]): T = INSTANCE.getActiveObject(clazz) - def configureActiveObjects(restartStrategy: RestartStrategy, components: Array[Component]): ActiveObjectGuiceConfiguratorForJava = synchronized { - this.restartStrategy = restartStrategy - this.components = components.toArray.toList.asInstanceOf[List[Component]] - bindings = for (c <- this.components) yield { - new DependencyBinding(c.intf, c.target) - } - val arrayList = new ArrayList[DependencyBinding]() - for (b <- bindings) arrayList.add(b) - modules.add(new ActiveObjectGuiceModule(arrayList)) + def configureActiveObjects( + restartStrategy: RestartStrategy, components: Array[Component]): + ActiveObjectGuiceConfiguratorForJava = { + INSTANCE.configureActiveObjects( + restartStrategy.transform, + components.toList.asInstanceOf[scala.List[Component]].map(_.transform)) this } - def inject(): ActiveObjectGuiceConfiguratorForJava = synchronized { - if (injector != null) throw new IllegalStateException("inject() has already been called on this configurator") - injector = Guice.createInjector(modules) + def inject(): ActiveObjectGuiceConfiguratorForJava = { + INSTANCE.inject this } - def supervise: ActiveObjectGuiceConfiguratorForJava = synchronized { - if (injector == null) inject() - injector = Guice.createInjector(modules) - val workers = new java.util.ArrayList[se.scalablesolutions.akka.kernel.config.ScalaConfig.Worker] - for (c <- components) { - val activeObjectProxy = new ActiveObjectProxy(c.intf, c.target, c.timeout) - workers.add(c.newWorker(activeObjectProxy)) - activeObjectRegistry.put(c.name, (c.intf, activeObjectProxy)) -// camelContext.getRegistry.asInstanceOf[JndiRegistry].bind(c.intf.getName, activeObjectProxy) - } - supervisor = activeObjectFactory.supervise(restartStrategy.transform, workers) -// camelContext.start + def supervise: ActiveObjectGuiceConfiguratorForJava = { + INSTANCE.supervise this } - - /** - * Add additional services to be wired in. - *
-   * ActiveObjectGuiceModule.addExternalGuiceModule(new AbstractModule {
-   *   protected void configure() {
-   *     bind(Foo.class).to(FooImpl.class).in(Scopes.SINGLETON);
-   *     bind(BarImpl.class);
-   *     link(Bar.class).to(BarImpl.class);
-   *     bindConstant(named("port")).to(8080);
-   *   }})
-   * 
- */ - def addExternalGuiceModule(module: Module): ActiveObjectGuiceConfiguratorForJava = synchronized { - modules.add(module) + def addExternalGuiceModule(module: Module): ActiveObjectGuiceConfiguratorForJava = { + INSTANCE.addExternalGuiceModule(module) this } - /** - * Add Camel routes for the active objects. - *
-   * activeObjectGuiceModule.addRoutes(new RouteBuilder() {
-   *   def configure = {
-   *     from("akka:actor1").to("akka:actor2")
-   *     from("akka:actor2").process(new Processor() {
-   *       def process(e: Exchange) = {
-   *         println("Received exchange: " + e.getIn())
-   *       }
-   *     })
-   *   }
-   * }).inject().supervise();
-   * 
- * - def addRoutes(routes: Routes): ActiveObjectGuiceConfiguratorForJava = synchronized { - camelContext.addRoutes(routes) + def addRoutes(routes: Routes): ActiveObjectGuiceConfiguratorForJava = { + INSTANCE.addRoutes(routes) this } - */ - def getGuiceModules = modules - - def reset = synchronized { - modules = new ArrayList[Module] - configRegistry = new HashMap[Class[_], Component] - activeObjectRegistry = new HashMap[String, Tuple2[Class[_], ActiveObjectProxy]] - injector = null - restartStrategy = null - //camelContext = new DefaultCamelContext + def getComponentInterfaces: List[Class[_]] = { + val al = new ArrayList[Class[_]] + for (c <- INSTANCE.getComponentInterfaces) al.add(c) + al } - def stop = synchronized { - //camelContext.stop - supervisor.stop - } + def getExternalDependency[T](clazz: Class[T]): T = INSTANCE.getExternalDependency(clazz) + + def getRoutingEndpoint(uri: String): Endpoint = INSTANCE.getRoutingEndpoint(uri) + + def getRoutingEndpoints: java.util.Collection[Endpoint] = INSTANCE.getRoutingEndpoints + + def getRoutingEndpoints(uri: String): java.util.Collection[Endpoint] = INSTANCE.getRoutingEndpoints(uri) + + def getGuiceModules: List[Module] = INSTANCE.getGuiceModules + + def reset = INSTANCE.reset + + def stop = INSTANCE.stop } diff --git a/kernel/src/main/scala/config/CamelConfigurator.scala b/kernel/src/main/scala/config/CamelConfigurator.scala index 5f2f6bf0aa..9cebafed9b 100644 --- a/kernel/src/main/scala/config/CamelConfigurator.scala +++ b/kernel/src/main/scala/config/CamelConfigurator.scala @@ -29,7 +29,6 @@ trait CamelConfigurator { def getRoutingEndpoint(uri: String): Endpoint - // F def getRoutingEndpoints: java.util.Collection[Endpoint] def getRoutingEndpoints(uri: String): java.util.Collection[Endpoint] diff --git a/kernel/src/main/scala/config/Config.scala b/kernel/src/main/scala/config/Config.scala index aa71471799..0b5b593f53 100644 --- a/kernel/src/main/scala/config/Config.scala +++ b/kernel/src/main/scala/config/Config.scala @@ -86,6 +86,8 @@ object JavaConfig { @BeanProperty val target: Class[_], @BeanProperty val lifeCycle: LifeCycle, @BeanProperty val timeout: Int) extends Server { + def transform = se.scalablesolutions.akka.kernel.config.ScalaConfig.Component( + name, intf, target, lifeCycle.transform, timeout) def newWorker(proxy: ActiveObjectProxy) = se.scalablesolutions.akka.kernel.config.ScalaConfig.Worker(proxy.server, lifeCycle.transform) } diff --git a/kernel/src/main/scala/jersey/ActiveObjectComponentProvider.scala b/kernel/src/main/scala/jersey/ActiveObjectComponentProvider.scala index 039aa19ec0..6ef9560a55 100644 --- a/kernel/src/main/scala/jersey/ActiveObjectComponentProvider.scala +++ b/kernel/src/main/scala/jersey/ActiveObjectComponentProvider.scala @@ -4,18 +4,21 @@ package se.scalablesolutions.akka.kernel.jersey +import com.sun.jersey.core.spi.component.ioc.{IoCManagedComponentProvider, IoCFullyManagedComponentProvider, IoCInstantiatedComponentProvider, IoCComponentProvider} import kernel.Logging import config.ActiveObjectConfigurator -import com.sun.jersey.core.spi.component.ioc.IoCComponentProvider import com.sun.jersey.core.spi.component.ComponentProvider import java.lang.reflect.{Constructor, InvocationTargetException} class ActiveObjectComponentProvider(val clazz: Class[_], val configurator: ActiveObjectConfigurator) - extends IoCComponentProvider with Logging { + extends IoCManagedComponentProvider with Logging { - override def getInstance: AnyRef = { + override def getInstance: AnyRef = configurator.getActiveObject(clazz).asInstanceOf[AnyRef] + + override def getInjectableInstance(obj: AnyRef): AnyRef = { + obj.asInstanceOf[ActiveObjectProxy].targetInstance } } \ No newline at end of file diff --git a/kernel/src/main/scala/jersey/ActiveObjectComponentProviderFactory.scala b/kernel/src/main/scala/jersey/ActiveObjectComponentProviderFactory.scala index 898af47028..a97f42a123 100644 --- a/kernel/src/main/scala/jersey/ActiveObjectComponentProviderFactory.scala +++ b/kernel/src/main/scala/jersey/ActiveObjectComponentProviderFactory.scala @@ -11,9 +11,7 @@ import config.ActiveObjectConfigurator class ActiveObjectComponentProviderFactory(val configurator: ActiveObjectConfigurator) extends IoCComponentProviderFactory { - override def getComponentProvider(clazz: Class[_]): ActiveObjectComponentProvider = { - new ActiveObjectComponentProvider(clazz, configurator) - } + override def getComponentProvider(clazz: Class[_]): ActiveObjectComponentProvider = getComponentProvider(null, clazz) override def getComponentProvider(context: ComponentContext, clazz: Class[_]): ActiveObjectComponentProvider = { new ActiveObjectComponentProvider(clazz, configurator) diff --git a/kernel/src/main/scala/jersey/AkkaServlet.scala b/kernel/src/main/scala/jersey/AkkaServlet.scala index 5795434277..efc3a5f6a5 100644 --- a/kernel/src/main/scala/jersey/AkkaServlet.scala +++ b/kernel/src/main/scala/jersey/AkkaServlet.scala @@ -4,16 +4,23 @@ package se.scalablesolutions.akka.kernel.jersey -import com.sun.jersey.api.core.ResourceConfig +import com.sun.jersey.api.core.{DefaultResourceConfig, ResourceConfig} import com.sun.jersey.spi.container.servlet.ServletContainer import com.sun.jersey.spi.container.WebApplication - import config.ActiveObjectConfigurator - +import java.util.{HashSet, ArrayList} class AkkaServlet extends ServletContainer { override def initiate(rc: ResourceConfig, wa: WebApplication) = { - val configurator = ActiveObjectConfigurator.getConfiguratorFor(getServletContext) - wa.initiate(rc, new ActiveObjectComponentProviderFactory(configurator)); + val configurator = ActiveObjectConfigurator.getConfiguratorFor(getServletContext); + val set = new HashSet[Class[_]] + for (c <- configurator.getComponentInterfaces) { + println("========== " + c) + set.add(c) + } + + wa.initiate( + new DefaultResourceConfig(set), + new ActiveObjectComponentProviderFactory(configurator)); } } \ No newline at end of file