Akka has landed
authorChristos KK Loverdos <loverdos@gmail.com>
Tue, 29 Nov 2011 12:11:18 +0000 (14:11 +0200)
committerChristos KK Loverdos <loverdos@gmail.com>
Tue, 29 Nov 2011 12:11:18 +0000 (14:11 +0200)
13 files changed:
logic/pom.xml
logic/src/main/scala/gr/grnet/aquarium/messaging/amqp/rabbitmq/v091/RabbitMQConfigurations.scala
logic/src/main/scala/gr/grnet/aquarium/processor/actor/AquariumActor.scala [new file with mode: 0644]
logic/src/main/scala/gr/grnet/aquarium/processor/actor/AquariumActorFactory.scala [new file with mode: 0644]
logic/src/main/scala/gr/grnet/aquarium/processor/actor/AquariumActorRoles.scala [new file with mode: 0644]
logic/src/main/scala/gr/grnet/aquarium/processor/actor/AquariumDispatcher.scala [new file with mode: 0644]
logic/src/main/scala/gr/grnet/aquarium/processor/actor/DefaultAquariumActorFactory.scala [new file with mode: 0644]
logic/src/main/scala/gr/grnet/aquarium/processor/actor/ReflectiveAquariumActor.scala [new file with mode: 0644]
logic/src/main/scala/gr/grnet/aquarium/processor/actor/ResourceEventProcessor.scala [new file with mode: 0644]
logic/src/main/scala/gr/grnet/aquarium/util/package.scala
logic/src/main/scala/gr/grnet/aquarium/util/xstream/XStreamHelpers.scala
logic/src/test/resources/akka.conf [new file with mode: 0644]
project/build/Aquarium.scala

index 654b51c..4c67427 100644 (file)
         http://kenai.com/projects/crontab-parser/sources/maven-repo/content/
       </url>
     </repository>
+
+    <repository>
+      <id>akka</id>
+      <name>Akka</name>
+      <url>http://akka.io/repository/</url>
+    </repository>
+
+    <repository>
+      <id>typesafe-releases</id>
+      <name>Typesafe releases</name>
+      <url>http://repo.typesafe.com/typesafe/releases</url>
+    </repository>
   </repositories>
 
   <dependencies>
       <!--<artifactId>casbah-core_2.9.1</artifactId>-->
       <!--<version>2.1.5-1</version>-->
     <!--</dependency>-->
+
+    <dependency>
+      <groupId>se.scalablesolutions.akka</groupId>
+      <artifactId>akka-actor</artifactId>
+      <version>1.3-RC1</version>
+    </dependency>
+
+    <dependency>
+      <groupId>se.scalablesolutions.akka</groupId>
+      <artifactId>akka-remote</artifactId>
+      <version>1.3-RC1</version>
+    </dependency>
+
+    <dependency>
+      <groupId>se.scalablesolutions.akka</groupId>
+      <artifactId>akka-testkit</artifactId>
+      <version>1.3-RC1</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 </project>
index e6f15d7..f96d3e5 100644 (file)
@@ -41,7 +41,7 @@ package v091
 import confmodel.RabbitMQConfigurationsModel
 import gr.grnet.aquarium.util.xstream.XStreamHelpers
 import com.ckkloverdos.maybe.{Failed, NoVal, Just, Maybe}
-import gr.grnet.aquarium.util.{Loggable, shortClassNameOf}
+import gr.grnet.aquarium.util.{Loggable, shortNameOfClass}
 import com.ckkloverdos.resource.{StreamResource, StreamResourceContext}
 import com.thoughtworks.xstream.XStream
 
@@ -78,7 +78,7 @@ object RabbitMQConfigurations extends Loggable {
         val confsModelErrors = confsModel.validateConfModel
 
         if(confsModelErrors.size > 0) {
-          val errorMsg = "%s has %s error(s)".format(shortClassNameOf(confsModel.getClass))
+          val errorMsg = "%s has %s error(s)".format(shortNameOfClass(confsModel.getClass))
           logger.error(errorMsg)
           for(error <- confsModelErrors) {
             logger.error(error)
diff --git a/logic/src/main/scala/gr/grnet/aquarium/processor/actor/AquariumActor.scala b/logic/src/main/scala/gr/grnet/aquarium/processor/actor/AquariumActor.scala
new file mode 100644 (file)
index 0000000..7e04b0c
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.processor.actor
+
+import AquariumActorRoles.AquariumActorRole
+import akka.actor.Actor
+
+/**
+ * Parent of all Aquarium actors.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+trait AquariumActor extends Actor {
+  def role: AquariumActorRole
+}
\ No newline at end of file
diff --git a/logic/src/main/scala/gr/grnet/aquarium/processor/actor/AquariumActorFactory.scala b/logic/src/main/scala/gr/grnet/aquarium/processor/actor/AquariumActorFactory.scala
new file mode 100644 (file)
index 0000000..c725912
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.processor.actor
+
+import akka.actor.ActorRef
+
+/**
+ * 
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+trait AquariumActorFactory {
+  def makeDispatcher: ActorRef
+  def makeResourceEventProcessor: ActorRef
+}
+
+object AquariumActorFactory {
+  @volatile private var _factory: AquariumActorFactory = DefaultAquariumActorFactory
+
+  def set(factory: AquariumActorFactory) = {
+    _factory = factory
+  }
+
+  def get = _factory
+}
\ No newline at end of file
diff --git a/logic/src/main/scala/gr/grnet/aquarium/processor/actor/AquariumActorRoles.scala b/logic/src/main/scala/gr/grnet/aquarium/processor/actor/AquariumActorRoles.scala
new file mode 100644 (file)
index 0000000..b96713a
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.processor.actor
+
+/**
+ * 
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+object AquariumActorRoles {
+  sealed abstract class AquariumActorRole(val role: String)
+
+  /**
+   * The generic router/dispatcher.
+   */
+  case object Dispatcher extends AquariumActorRole("Dispatcher")
+
+
+  /**
+   * Processes user-related resource events.
+   */
+  case object ResourceProcessor extends AquariumActorRole("ResourceProcessor")
+}
\ No newline at end of file
diff --git a/logic/src/main/scala/gr/grnet/aquarium/processor/actor/AquariumDispatcher.scala b/logic/src/main/scala/gr/grnet/aquarium/processor/actor/AquariumDispatcher.scala
new file mode 100644 (file)
index 0000000..6ee76ce
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.processor.actor
+
+import gr.grnet.aquarium.logic.events.ResourceEvent
+import akka.actor.ActorRef
+
+/**
+ * 
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+class AquariumDispatcher extends AquariumActor {
+  def role = AquariumActorRoles.Dispatcher
+
+  def resourceEventProcessor: ActorRef =
+    AquariumActorFactory.get.makeResourceEventProcessor
+
+  protected def receive = {
+    case message: ResourceEvent =>
+      // Dispatch to resource processor
+      resourceEventProcessor ! message
+  }
+}
\ No newline at end of file
diff --git a/logic/src/main/scala/gr/grnet/aquarium/processor/actor/DefaultAquariumActorFactory.scala b/logic/src/main/scala/gr/grnet/aquarium/processor/actor/DefaultAquariumActorFactory.scala
new file mode 100644 (file)
index 0000000..ce2aa69
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.processor.actor
+
+import akka.actor.Actor
+import Actor.actorOf
+
+/**
+ * The simplest of all actor factory implementation.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+object DefaultAquariumActorFactory extends AquariumActorFactory {
+  def makeDispatcher = {
+    val actor = actorOf[AquariumDispatcher]
+    actor.start
+    actor
+  }
+
+  def makeResourceEventProcessor = {
+    val actor = actorOf[ResourceEventProcessor]
+    actor.start()
+    actor
+  }
+}
\ No newline at end of file
diff --git a/logic/src/main/scala/gr/grnet/aquarium/processor/actor/ReflectiveAquariumActor.scala b/logic/src/main/scala/gr/grnet/aquarium/processor/actor/ReflectiveAquariumActor.scala
new file mode 100644 (file)
index 0000000..439e639
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium
+package processor
+package actor
+
+import akka.actor.Actor
+import com.ckkloverdos.maybe.{Failed, NoVal, Just, Maybe}
+import util.{Loggable, shortNameOfClass}
+
+/**
+ * An actor who dispatches to particular methods based on the type of the received message.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+trait ReflectiveAquariumActor extends Actor with Loggable {
+  private val messageMethodMap: Map[Class[_ <: AnyRef], java.lang.reflect.Method] = {
+    val classMethodPairs = for(knownMessageType <- knownMessageTypes) yield {
+      require(knownMessageType ne null, "Null in knownMessageTypes of %s".format(this.getClass))
+      val methodName = "on%s".format(shortNameOfClass(knownMessageType))
+      // For each class MethodClass we expect a method with the following signature:
+      // def onMethodClass(message: MethodClass): Unit
+      Maybe(this.getClass.getMethod(methodName, knownMessageType)) match {
+        case Just(method) =>
+          method.setAccessible(true)
+          (knownMessageType, method)
+        case NoVal =>
+          throw new Exception("Reflective actor %s does not know how to process message %s".format(this.getClass, knownMessageType))
+        case Failed(e, m) =>
+          throw new Exception("Reflective actor %s does not know how to process message %s".format(this.getClass, knownMessageType), e)
+      }
+    }
+
+    Map(classMethodPairs: _*)
+  }
+
+  def knownMessageTypes: List[Class[_ <: AnyRef]]
+
+  protected def receive: Receive  = {
+    case null =>
+      receiveNull
+    case message: AnyRef =>
+      messageMethodMap.get(message.getClass) match {
+        case Some(reflectiveMethod) =>
+          reflectiveMethod.invoke(this, message)
+        case None =>
+          receiveUnknown(message)
+      }
+    case message =>
+      // For the Anys....
+      receiveUnknown(message)
+  }
+
+  def receiveNull: Unit = {}
+
+  def receiveUnknown(message: Any): Unit = {
+    logger.warn("Received unknown message: %s".format(message))
+  }
+}
\ No newline at end of file
diff --git a/logic/src/main/scala/gr/grnet/aquarium/processor/actor/ResourceEventProcessor.scala b/logic/src/main/scala/gr/grnet/aquarium/processor/actor/ResourceEventProcessor.scala
new file mode 100644 (file)
index 0000000..4b3114d
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.processor.actor
+
+import gr.grnet.aquarium.logic.events.ResourceEvent
+
+/**
+ * 
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+class ResourceEventProcessor extends AquariumActor with ReflectiveAquariumActor {
+  def role = AquariumActorRoles.ResourceProcessor
+
+  def knownMessageTypes = List(classOf[ResourceEvent])
+
+  def onResourceEvent(re: ResourceEvent): Unit = {
+    println("Received %s".format(re))
+  }
+}
\ No newline at end of file
index c540613..a18195d 100644 (file)
@@ -48,11 +48,34 @@ package object util {
     }
   }
 
-  def shortClassNameOf(theClass: Class[_]): String = {
+  /**
+   * Compute the class name excluding any leading packages.
+   *
+   * This is basically the name after the last dot.
+   */
+  def shortNameOfClass(theClass: Class[_]): String = {
     val cname = theClass.getName
     cname.substring(cname.lastIndexOf(".") + 1)
   }
 
+  /**
+   * For the class of the provided object, compute the class name excluding any leading packages.
+   *
+   * This is basically the name after the last dot.
+   *
+   * The `null` value is mapped to string `"null"`.
+   */
+  def shortClassNameOf(anyRef: AnyRef): String = {
+    anyRef match {
+      case null =>
+        "<null>"
+      case clz: Class[_] =>
+        shortNameOfClass(clz)
+      case obj =>
+        shortNameOfClass(obj.getClass)
+    }
+  }
+
   def safeToStringOrNull(obj: AnyRef): String = obj match {
     case null => null
     case _ => obj.toString
index 59da36c..696d481 100644 (file)
@@ -55,7 +55,7 @@ object XStreamHelpers {
 
   def prepareXStreamAlias[T : Manifest](xs: XStream): XStream = {
     val theClass = manifest[T].erasure
-    xs.alias(shortClassNameOf(theClass), theClass)
+    xs.alias(shortNameOfClass(theClass), theClass)
     xs
   }
   
diff --git a/logic/src/test/resources/akka.conf b/logic/src/test/resources/akka.conf
new file mode 100644 (file)
index 0000000..3bb8ad8
--- /dev/null
@@ -0,0 +1,177 @@
+####################
+# Akka Config File #
+####################
+
+# This file has all the default settings, so all these could be removed with no visible effect.
+# Modify as needed.
+
+akka {
+  version = "1.3-RC1"   # Akka version, checked against the runtime version of Akka.
+
+  enabled-modules = ["remote", "http"]       # Comma separated list of the enabled modules. Options: ["remote", "camel", "http"]
+
+  time-unit = "seconds"      # Time unit for all timeout properties throughout the config
+
+  event-handlers = ["akka.event.EventHandler$DefaultListener"] # event handlers to register at boot time (EventHandler$DefaultListener logs to STDOUT)
+  event-handler-level = "DEBUG" # Options: ERROR, WARNING, INFO, DEBUG
+
+  # These boot classes are loaded (and created) automatically when the Akka Microkernel boots up
+  #     Can be used to bootstrap your application(s)
+  #     Should be the FQN (Fully Qualified Name) of the boot class which needs to have a default constructor
+  # boot = ["sample.camel.Boot",
+  #         "sample.rest.java.Boot",
+  #         "sample.rest.scala.Boot",
+  #         "sample.security.Boot"]
+  boot = []
+
+  actor {
+    timeout = 5                        # Default timeout for Future based invocations
+                                       #    - Actor:        ? and ask
+                                       #    - UntypedActor: ask
+                                       #    - TypedActor:   methods with non-void return type
+    serialize-messages = off           # Does a deep clone of (non-primitive) messages to ensure immutability
+    throughput = 5                     # Default throughput for all ExecutorBasedEventDrivenDispatcher, set to 1 for complete fairness
+    throughput-deadline-time = -1      # Default throughput deadline for all ExecutorBasedEventDrivenDispatcher, set to 0 or negative for no deadline
+    dispatcher-shutdown-timeout = 1    # Using the akka.time-unit, how long dispatchers by default will wait for new actors until they shut down
+
+    default-dispatcher {
+      type = "GlobalExecutorBasedEventDriven" # Must be one of the following, all "Global*" are non-configurable
+                                              #   - ExecutorBasedEventDriven
+                                              #   - ExecutorBasedEventDrivenWorkStealing
+                                              #   - GlobalExecutorBasedEventDriven
+      keep-alive-time = 60             # Keep alive time for threads
+      core-pool-size-factor = 1.0      # No of core threads ... ceil(available processors * factor)
+      max-pool-size-factor  = 4.0      # Max no of threads ... ceil(available processors * factor)
+      executor-bounds = -1             # Makes the Executor bounded, -1 is unbounded
+      task-queue-size = -1             # Specifies the bounded capacity of the task queue (< 1 == unbounded)
+      task-queue-type = "linked"       # Specifies which type of task queue will be used, can be "array" or "linked" (default)
+      allow-core-timeout = on          # Allow core threads to time out
+      rejection-policy = "sane"        # sane, abort, caller-runs, discard-oldest, discard
+      throughput = 5                   # Throughput for ExecutorBasedEventDrivenDispatcher, set to 1 for complete fairness
+      throughput-deadline-time = -1    # Throughput deadline for ExecutorBasedEventDrivenDispatcher, set to 0 or negative for no deadline
+      mailbox-capacity = -1            # If negative (or zero) then an unbounded mailbox is used (default)
+                                       # If positive then a bounded mailbox is used and the capacity is set using the property
+                                       # NOTE: setting a mailbox to 'blocking' can be a bit dangerous,
+                                       #       could lead to deadlock, use with care
+                                       #
+                                       # The following are only used for ExecutorBasedEventDriven
+                                       # and only if mailbox-capacity > 0
+      mailbox-push-timeout-time = 10   # Specifies the timeout to add a new message to a mailbox that is full - negative number means infinite timeout
+                                       #       (in unit defined by the time-unit property)
+    }
+
+    debug {
+      receive = "false"       # enable function of Actor.loggable(), which is
+                              # to log any received message at DEBUG level
+      autoreceive = "false"   # enable DEBUG logging of all AutoReceiveMessages
+                              # (Kill, PoisonPill and the like)
+      lifecycle = "false"     # enable DEBUG logging of actor lifecycle changes
+    }
+
+    mailbox {
+        mongodb {
+            # Any specified collection name will be used as a prefix for collections that use durable mongo mailboxes
+            uri = "mongodb://localhost/akka.mailbox"   # Follow Mongo URI Spec - http://www.mongodb.org/display/DOCS/Connections
+            # Configurable timeouts for certain ops
+            timeout {
+                read = 3000 # number of milliseconds to wait for a read to succeed before timing out the future
+                write = 3000 # number of milliseconds to wait for a write to succeed before timing out the future
+            }
+        }
+      }
+    }
+
+  stm {
+    fair             = on     # Should global transactions be fair or non-fair (non fair yield better performance)
+    max-retries      = 1000
+    timeout          = 5      # Default timeout for blocking transactions and transaction set (in unit defined by
+                              #     the time-unit property)
+    write-skew       = true
+    blocking-allowed = false
+    interruptible    = false
+    speculative      = true
+    quick-release    = true
+    propagation      = "requires"
+    trace-level      = "none"
+  }
+
+  http {
+    hostname = "localhost"
+    port = 9998
+
+    #If you are using akka.http.AkkaRestServlet
+    filters = ["akka.security.AkkaSecurityFilterFactory"] # List with all jersey filters to use
+    # resource-packages = ["sample.rest.scala",
+    #                      "sample.rest.java",
+    #                      "sample.security"] # List with all resource packages for your Jersey services
+    resource-packages = []
+
+    # The authentication service to use. Need to be overridden (sample now)
+    # authenticator = "sample.security.BasicAuthenticationService"
+    authenticator = "N/A"
+
+    # Uncomment if you are using the KerberosAuthenticationActor
+    # kerberos {
+    #   servicePrincipal = "HTTP/localhost@EXAMPLE.COM"
+    #   keyTabLocation   = "URL to keytab"
+    #   kerberosDebug    = "true"
+    #   realm            = "EXAMPLE.COM"
+    # }
+    kerberos {
+      servicePrincipal = "N/A"
+      keyTabLocation   = "N/A"
+      kerberosDebug    = "N/A"
+      realm            = ""
+    }
+
+    #If you are using akka.http.AkkaMistServlet
+    mist-dispatcher {
+      #type = "GlobalExecutorBasedEventDriven" # Uncomment if you want to use a different dispatcher than the default one for Comet
+    }
+    connection-close = true                 # toggles the addition of the "Connection" response header with a "close" value
+    root-actor-id = "_httproot"             # the id of the actor to use as the root endpoint
+    root-actor-builtin = true               # toggles the use of the built-in root endpoint base class
+    timeout = 1000                          # the default timeout for all async requests (in ms)
+    expired-header-name = "Async-Timeout"   # the name of the response header to use when an async request expires
+    expired-header-value = "expired"        # the value of the response header to use when an async request expires
+  }
+
+  remote {
+
+    # secure-cookie = "050E0A0D0D06010A00000900040D060F0C09060B" # generate your own with '$AKKA_HOME/scripts/generate_config_with_secure_cookie.sh' or using 'Crypt.generateSecureCookie'
+    secure-cookie = ""
+
+    layer = "akka.remote.netty.NettyRemoteSupport"
+
+    server {
+      hostname = "localhost"       # The hostname or IP that clients should connect to
+      port = 2552                  # The port clients should connect to. Default is 2552 (AKKA)
+      message-frame-size = 1048576 # Increase this if you want to be able to send messages with large payloads
+      connection-timeout = 100     # Number in time-unit
+      require-cookie = off         # Should the remote server require that it peers share the same secure-cookie (defined in the 'remote' section)?
+      untrusted-mode = off         # Enable untrusted mode for full security of server managed actors, allows untrusted clients to connect.
+      backlog = 4096               # Sets the size of the connection backlog
+      execution-pool-keepalive = 60# Length in akka.time-unit how long core threads will be kept alive if idling
+      execution-pool-size      = 16# Size of the core pool of the remote execution unit
+      max-channel-memory-size  = 0 # Maximum channel size, 0 for off
+      max-total-memory-size    = 0 # Maximum total size of all channels, 0 for off
+    }
+
+    client {
+      buffering {
+        retry-message-send-on-failure = off # Buffer outbound messages when send failed, if off you'll get an exception instead
+        capacity = -1                      # If negative (or zero) then an unbounded mailbox is used (default)
+                                           # If positive then a bounded mailbox is used and the capacity is set using the property
+      }
+      reconnect-delay = 5                  # Number in time-unit
+      read-timeout = 120                   # Number in time-unit
+      message-frame-size = 1048576         # Size in bytes
+      reap-futures-delay = 5               # Number in time-unit
+      reconnection-time-window = 600 # Maximum time window that a client should try to reconnect for
+    }
+  }
+
+  test {
+    timefactor = "1.0"    # factor by which to scale timeouts during tests, e.g. to account for shared build system load
+  }
+}
\ No newline at end of file
index 98d289d..bb53693 100644 (file)
@@ -44,6 +44,8 @@ class Aquarium(info: ProjectInfo) extends ParentProject(info) {
        //val repo3 = "jboss" at "http://repository.jboss.org/nexus/content/groups/public/"
        //val repo4 = "sonatype" at "http://oss.sonatype.org/content/groups/public/"
        //val repo5 = "jcrontab" at "http://kenai.com/projects/crontab-parser/sources/maven-repo/content/"
+       // val repo6 = "typsafe" at "http://repo.typesafe.com/typesafe/releases/"
+       // val repo7 = "akka" at "http://akka.io/repository/"
 
        val lib_slf4j     = "org.slf4j"      % "slf4j-api"            % "1.6.1"   withSources()
        val lib_h2        = "com.h2database" % "h2"                   % "1.3.160" withSources()
@@ -63,8 +65,9 @@ class Aquarium(info: ProjectInfo) extends ParentProject(info) {
                val lib_jcrontab  = "com.kenai.crontab-parser" % "crontab-parser" % "1.0.1" withSources()
                val lib_xstream   = "com.thoughtworks.xstream" % "xstream"     % "1.4.1" withSources()
                val lib_rabbit    = "com.rabbitmq"   % "amqp-client"       % "2.7.0" withSources()
-//    val lib_mongo     = "org.mongodb"    % "mongo-java-driver" % "2.7.2" withSources()
-    val lib_casbah    = "com.mongodb.casbah" % "casbah-core_2.9.1"  % "2.1.5-1" withSources()
+               val lib_mongo     = "org.mongodb"    % "mongo-java-driver" % "2.7.2" withSources()
+       //val lib_casbah    = "com.mongodb.casbah" % "casbah-core_2.9.1"  % "2.1.5-1" withSources()
+       val lib_akka = "se.scalablesolutions.akka" % "akka-actor" % "1.3-RC1" withSources()
 
                val lib_converter      = "com.ckkloverdos" % "converter_2.9.1"      % "0.3.0" withSources()
                val lib_streamresource = "com.ckkloverdos" % "streamresource_2.9.1" % "0.2.0" withSources()