add extension mechanism

- type is encoded in key, allowing proper typing in Scala & Java
- test cases for Scala & Java are included to ensure that the API makes
  sense and does not break
This commit is contained in:
Roland 2011-11-17 23:15:19 +01:00
parent 7999c4c195
commit 69ce6aa9d6
7 changed files with 166 additions and 8 deletions

View file

@ -0,0 +1,33 @@
/**
* Copyright (C) 2009-2011 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.actor;
import org.junit.Test;
import static org.junit.Assert.*;
public class JavaExtension {
static class TestExtension implements Extension<TestExtension> {
private ActorSystemImpl system;
public static ExtensionKey<TestExtension> key = new ExtensionKey<TestExtension>() {};
public ExtensionKey<TestExtension> init(ActorSystemImpl system) {
this.system = system;
return key;
}
public ActorSystemImpl getSystem() {
return system;
}
}
private ActorSystem system = ActorSystem.create("JavaExtension", ActorSystemSpec.javaconfig());
@Test
public void mustBeAccessible() {
final ActorSystemImpl s = system.extension(TestExtension.key).getSystem();
assertSame(s, system);
}
}