From 7138505a1debc19abb7f808f0fd8c42a99392786 Mon Sep 17 00:00:00 2001 From: Michael Kober Date: Wed, 29 Sep 2010 18:51:03 +0200 Subject: [PATCH] added Java API --- .../src/main/scala/actor/TypedActor.scala | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/akka-typed-actor/src/main/scala/actor/TypedActor.scala b/akka-typed-actor/src/main/scala/actor/TypedActor.scala index 015f06289a..d71c92522f 100644 --- a/akka-typed-actor/src/main/scala/actor/TypedActor.scala +++ b/akka-typed-actor/src/main/scala/actor/TypedActor.scala @@ -379,6 +379,15 @@ final class TypedActorConfiguration { } } +/** + * Factory closure for an TypedActor, to be used with 'TypedActor.newInstance(interface, factory)'. + * + * @author michaelkober + */ +trait TypedActorFactory { + def create: TypedActor +} + /** * Factory class for creating TypedActors out of plain POJOs and/or POJOs with interfaces. * @@ -524,7 +533,50 @@ object TypedActor extends Logging { proxy.asInstanceOf[T] } + /** + * Java API. + * NOTE: Use this convenience method with care, do NOT make it possible to get a reference to the + * TypedActor instance directly, but only through its 'ActorRef' wrapper reference. + *

+ * Creates an ActorRef out of the Actor. Allows you to pass in the instance for the TypedActor. + * Only use this method when you need to pass in constructor arguments into the 'TypedActor'. + *

+ * You use it by implementing the TypedActorFactory interface. + * Example in Java: + *

+   *   MyPojo pojo = TypedActor.newInstance(MyPojo.class, new TypedActorFactory() {
+   *     public TypedActor create() {
+   *       return new MyTypedActor("service:name", 5);
+   *     }
+   *   });
+   * 
+ */ + def newInstance[T](intfClass: Class[T], factory: TypedActorFactory) : T = + newInstance(intfClass, factory.create) + /** + * Java API. + */ + def newRemoteInstance[T](intfClass: Class[T], factory: TypedActorFactory, hostname: String, port: Int) : T = + newRemoteInstance(intfClass, factory.create, hostname, port) + + /** + * Java API. + */ + def newRemoteInstance[T](intfClass: Class[T], factory: TypedActorFactory, timeout: Long, hostname: String, port: Int) : T = + newRemoteInstance(intfClass, factory.create, timeout, hostname, port) + + /** + * Java API. + */ + def newInstance[T](intfClass: Class[T], factory: TypedActorFactory, timeout: Long) : T = + newInstance(intfClass, factory.create, timeout) + + /** + * Java API. + */ + def newInstance[T](intfClass: Class[T], factory: TypedActorFactory, config: TypedActorConfiguration): T = + newInstance(intfClass, factory.create, config) /** * Create a proxy for a RemoteActorRef representing a server managed remote typed actor.