Permalink
Browse files

Added service request processing

  • Loading branch information...
1 parent 789e496 commit e120304d678b6aa5e4b499b11e252fc8613d1d1b @jfim committed May 4, 2011
@@ -0,0 +1,9 @@
+package im.jeanfrancois.servicediscoverychallenge
+
+/**
+ * Document me!
+ *
+ * @author jfim
+ */
+
+case class ServiceRequestMessage(className : String, methodName : String, methodArgs : List[Object])
@@ -0,0 +1,31 @@
+package im.jeanfrancois.servicediscoverychallenge
+
+import actors.Actor
+import scala.actors.remote.RemoteActor._
+import com.google.inject.{Singleton, Inject}
+
+/**
+ * Document me!
+ *
+ * @author jfim
+ */
+
+@Singleton
+class ServiceRequestProcessor @Inject() (val serviceRegistry : ServiceRegistry) extends Actor {
+ def act() {
+ alive(1234);
+ register('ServiceRequestProcessor, this);
+ while(true) {
+ receive {
+ case ServiceRequestMessage(classname, methodName, methodArgs) => {
+ serviceRegistry.serviceList.find(service => service.getClass.getName == classname) match {
+ case Some(service) => {
+ reply(service !? ProcessServiceMethod(methodName, methodArgs));
+ }
+ case None => reply(Nil);
+ }
+ }
+ }
+ }
+ }
+}
@@ -8,10 +8,17 @@ import com.google.inject.Guice
object ServiceServer {
def main(args : Array[String]) {
val injector = Guice.createInjector(new ServiceServerModule);
+
val serviceRegistry = injector.getInstance(classOf[ServiceRegistry]);
+
serviceRegistry.serviceList.foreach(service => {
println("Starting service " + service.getClass.getName);
service.start
})
+
+ val serviceRequestProcessor = injector.getInstance(classOf[ServiceRequestProcessor]);
+ serviceRequestProcessor.start
+
+ println("Service request processor started");
}
}

0 comments on commit e120304

Please sign in to comment.