added Java compat API for defining up ActiveObjects

This commit is contained in:
Jonas Boner 2009-02-16 19:50:50 +01:00
parent 0a31ad7188
commit d01a293fa7
10 changed files with 682 additions and 122 deletions

View file

@ -3,20 +3,21 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>Akka Java API</name>
<artifactId>akka-api-java</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>${akka.groupId}</groupId>
<artifactId>akka</artifactId>
<groupId>${akka.groupId}</groupId>
<version>${akka.version}</version>
</parent>
<name>Akka Java API</name>
<artifactId>api-java</artifactId>
<dependencies>
<dependency>
<groupId>com.scalablesolutions.akka</groupId>
<artifactId>kernel</artifactId>
<groupId>${akka.groupId}</groupId>
<artifactId>akka-kernel</artifactId>
<version>${akka.version}</version>
</dependency>
<dependency>
@ -48,29 +49,15 @@
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>${basedir}</directory>
<includes>
<include>derby.log</include>
<include>gps_db</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<!-- <plugin> -->
<!-- <groupId>org.apache.maven.plugins</groupId> -->
<!-- <artifactId>maven-surefire-plugin</artifactId> -->
<!-- <configuration> -->
<!-- <suiteXmlFiles> -->
<!-- <suiteXmlFile>testng.xml</suiteXmlFile> -->
<!-- </suiteXmlFiles> -->
<!-- </configuration> -->
<!-- </plugin> -->
</plugins>
<resources>
<resource>
@ -88,19 +75,6 @@
</excludes>
</resource>
</resources>
<testResources>
<testResource>
<filtering>false</filtering>
<directory>src/test/resources</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
</build>
<reporting>
<plugins></plugins>

View file

@ -0,0 +1,133 @@
/**
* Copyright (C) 2009 Scalable Solutions.
*/
package com.scalablesolutions.akka.api;
import com.google.inject.AbstractModule;
import com.google.inject.CreationException;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.spi.CloseFailedException;
import java.util.List;
import java.util.ArrayList;
import javax.annotation.Resource;
import javax.naming.Context;
import scala.actors.behavior.*;
public class Configurator {
static public Supervisor supervise(Configuration.RestartStrategy restartStrategy, List<Configuration.Component> components) {
return null;
// SupervisorFactory factory = new SupervisorFactory() {
// @Override public SupervisorConfig getSupervisorConfig() {
// new SupervisorConfig(restartStrategy, components.map(c => Worker(c.component.server, c.lifeCycle)))
// }
// }
// val supervisor = factory.newSupervisor
// supervisor ! scala.actors.behavior.Start
// supervisor
}
// private def supervise(proxy: ActiveObjectProxy): Supervisor =
// supervise(
// RestartStrategy(OneForOne, 5, 1000),
// Component(
// proxy,
// LifeCycle(Permanent, 100))
// :: Nil)
// val fooProxy = new ActiveObjectProxy(new FooImpl, 1000)
// val barProxy = new ActiveObjectProxy(new BarImpl, 1000)
// val supervisor =
// ActiveObject.supervise(
// RestartStrategy(AllForOne, 3, 100),
// Component(
// fooProxy,
// LifeCycle(Permanent, 100)) ::
// Component(
// barProxy,
// LifeCycle(Permanent, 100))
// :: Nil)
// val foo = ActiveObject.newInstance[Foo](classOf[Foo], fooProxy)
// val bar = ActiveObject.newInstance[Bar](classOf[Bar], barProxy)
// public void testResourceInjection() throws CreationException, CloseFailedException {
// Injector injector = Guice.createInjector(new AbstractModule() {
// protected void configure() {
// bind(ResourceProviderFactory.class);
// bind(MyBean.class).in(Singleton.class);
// }
// @Provides
// public Context createJndiContext() throws Exception {
// Context answer = new JndiContext();
// answer.bind("foo", new AnotherBean("Foo"));
// answer.bind("xyz", new AnotherBean("XYZ"));
// return answer;
// }
// });
// MyBean bean = injector.getInstance(MyBean.class);
// assertNotNull("Should have instantiated the bean", bean);
// assertNotNull("Should have injected a foo", bean.foo);
// assertNotNull("Should have injected a bar", bean.bar);
// assertEquals("Should have injected correct foo", "Foo", bean.foo.name);
// assertEquals("Should have injected correct bar", "XYZ", bean.bar.name);
// }
// public static class MyBean {
// @Resource
// public AnotherBean foo;
// public AnotherBean bar;
// @Resource(name = "xyz")
// public void bar(AnotherBean bar) {
// this.bar = bar;
// }
// }
// static class AnotherBean {
// public String name = "undefined";
// AnotherBean(String name) {
// this.name = name;
// }
// Injector injector = Guice.createInjector(new AbstractModule() {
// protected void configure() {
// Jsr250.bind(binder());
// bind(MyBean.class).in(Singleton.class);
// }
// });
// Injector injector = Guice.createInjector(new AbstractModule() {
// protected void configure() {
// bind(ResourceProviderFactory.class);
// bind(MyBean.class).in(Singleton.class);
// }
// @Provides
// public Context createJndiContext() throws Exception {
// Context answer = new JndiContext();
// answer.bind("foo", new AnotherBean("Foo"));
// answer.bind("xyz", new AnotherBean("XYZ"));
// return answer;
// }
// });
// MyBean bean = injector.getInstance(MyBean.class);
}