From 21c2f85c36960836963f48f17bc31bf79632f509 Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Wed, 29 Sep 2010 15:04:11 +0200 Subject: [PATCH 1/3] Changing impl of ReflectiveAccess to log to debug --- .../main/scala/util/ReflectiveAccess.scala | 21 +++---------------- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/akka-actor/src/main/scala/util/ReflectiveAccess.scala b/akka-actor/src/main/scala/util/ReflectiveAccess.scala index d0824941ce..84e3c7912c 100644 --- a/akka-actor/src/main/scala/util/ReflectiveAccess.scala +++ b/akka-actor/src/main/scala/util/ReflectiveAccess.scala @@ -255,13 +255,8 @@ object ReflectiveAccess extends Logging { ctor.setAccessible(true) Some(ctor.newInstance(args: _*).asInstanceOf[T]) } catch { - case e: java.lang.reflect.InvocationTargetException => - e.printStackTrace - log.error(e.getCause, "Could not instantiate class [%s]", clazz.getName) - None case e: Exception => - e.printStackTrace - log.error(e.getCause, "Could not instantiate class [%s]", clazz.getName) + log.debug(e, "Could not instantiate class [%s] due to [%s]", clazz.getName, e.getMessage) None } @@ -277,13 +272,8 @@ object ReflectiveAccess extends Logging { ctor.setAccessible(true) Some(ctor.newInstance(args: _*).asInstanceOf[T]) } catch { - case e: java.lang.reflect.InvocationTargetException => - e.printStackTrace - log.error(e.getCause, "Could not instantiate class [%s] due to [%s]", fqn, e.toString) - None case e: Exception => - e.printStackTrace - log.error(e.getCause, "Could not instantiate class [%s] due to [%s]", fqn, e.toString) + log.debug(e, "Could not instantiate class [%s] due to [%s]", fqn, e.getMessage) None } @@ -294,13 +284,8 @@ object ReflectiveAccess extends Logging { instance.setAccessible(true) Option(instance.get(null).asInstanceOf[T]) } catch { - case e: java.lang.reflect.InvocationTargetException => - e.printStackTrace - log.error(e.getCause, "Could not instantiate class [%s]", fqn) - None case e: Exception => - e.printStackTrace - log.error(e.getCause, "Could not instantiate class [%s]", fqn) + log.debug(e, "Could not get object [%s] due to [%s]", fqn, e.getMessage) None } From 6f11ce032da1fea6cb0e0068f98ab83a7bae913d Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Sat, 2 Oct 2010 17:32:44 +0200 Subject: [PATCH 2/3] Updating Atmosphere to 0.6.2 and switching to using SimpleBroadcaster --- akka-http/src/main/scala/AkkaBroadcaster.scala | 18 +++++++++++------- project/build/AkkaProject.scala | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/akka-http/src/main/scala/AkkaBroadcaster.scala b/akka-http/src/main/scala/AkkaBroadcaster.scala index ca5abc6f1d..8aae04bc86 100644 --- a/akka-http/src/main/scala/AkkaBroadcaster.scala +++ b/akka-http/src/main/scala/AkkaBroadcaster.scala @@ -5,23 +5,27 @@ package se.scalablesolutions.akka.comet import org.atmosphere.cpr.{AtmosphereResourceEvent, AtmosphereResource} + import se.scalablesolutions.akka.actor.Actor._ import se.scalablesolutions.akka.actor.Actor import se.scalablesolutions.akka.dispatch.Dispatchers +import org.atmosphere.jersey.util.JerseyBroadcasterUtil object AkkaBroadcaster { val broadcasterDispatcher = Dispatchers.fromConfig("akka.rest.comet-dispatcher") + + type Event = AtmosphereResourceEvent[_,_] + type Resource = AtmosphereResource[_,_] } -class AkkaBroadcaster extends org.atmosphere.jersey.JerseyBroadcaster { +class AkkaBroadcaster extends org.atmosphere.jersey.util.JerseySimpleBroadcaster { import AkkaBroadcaster._ - name = classOf[AkkaBroadcaster].getName //FIXME should be supervised - val caster = actorOf(new Actor { + lazy val caster = actorOf(new Actor { self.dispatcher = broadcasterDispatcher def receive = { - case f : Function0[_] => f() + case (r: Resource,e: Event) => JerseyBroadcasterUtil.broadcast(r,e) } }).start @@ -30,7 +34,7 @@ class AkkaBroadcaster extends org.atmosphere.jersey.JerseyBroadcaster { caster.stop } - protected override def broadcast(r : AtmosphereResource[_,_], e : AtmosphereResourceEvent[_,_]) = { - caster ! (() => super.broadcast(r,e)) + protected override def broadcast(r: Resource, e : Event) { + caster ! ((r,e)) } -} +} \ No newline at end of file diff --git a/project/build/AkkaProject.scala b/project/build/AkkaProject.scala index 3d40fe613b..bbb4cd6a88 100644 --- a/project/build/AkkaProject.scala +++ b/project/build/AkkaProject.scala @@ -91,7 +91,7 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) { // Versions // ------------------------------------------------------------------------------------------------------------------- - lazy val ATMO_VERSION = "0.6.1" + lazy val ATMO_VERSION = "0.6.2" lazy val CAMEL_VERSION = "2.4.0" lazy val CASSANDRA_VERSION = "0.6.1" lazy val DISPATCH_VERSION = "0.7.4" From d87436e2ce2c155729a6c9228d907f27be045ad1 Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Sat, 2 Oct 2010 17:38:09 +0200 Subject: [PATCH 3/3] Changing order of priority for akka.config and adding option to specify a mode --- akka-actor/src/main/scala/config/Config.scala | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/akka-actor/src/main/scala/config/Config.scala b/akka-actor/src/main/scala/config/Config.scala index 7a4ac4be48..4738920cad 100644 --- a/akka-actor/src/main/scala/config/Config.scala +++ b/akka-actor/src/main/scala/config/Config.scala @@ -41,6 +41,12 @@ object Config { } val config = { + + val confName = System.getenv("AKKA_MODE") match { + case null | "" => Option(System.getProperty("akka.mode")).map("akka." + _ + ".conf").getOrElse("akka.conf") + case s:String => "akka." + s + ".conf" + } + if (System.getProperty("akka.config", "") != "") { val configFile = System.getProperty("akka.config", "") try { @@ -52,19 +58,9 @@ object Config { "\n\tdue to: " + e.toString) } Configgy.config - } else if (getClass.getClassLoader.getResource("akka.conf") ne null) { + } else if (HOME.isDefined) { try { - Configgy.configureFromResource("akka.conf", getClass.getClassLoader) - ConfigLogger.log.info("Config loaded from the application classpath.") - } catch { - case e: ParseException => throw new ConfigurationException( - "Can't load 'akka.conf' config file from application classpath," + - "\n\tdue to: " + e.toString) - } - Configgy.config - } else if (HOME.isDefined) { - try { - val configFile = HOME.getOrElse(throwNoAkkaHomeException) + "/config/akka.conf" + val configFile = HOME.getOrElse(throwNoAkkaHomeException) + "/config/" + confName Configgy.configure(configFile) ConfigLogger.log.info( "AKKA_HOME is defined as [%s], config loaded from [%s].", @@ -73,18 +69,28 @@ object Config { } catch { case e: ParseException => throw new ConfigurationException( "AKKA_HOME is defined as [" + HOME.get + "] " + - "\n\tbut the 'akka.conf' config file can not be found at [" + HOME.get + "/config/akka.conf]," + + "\n\tbut the 'akka.conf' config file can not be found at [" + HOME.get + "/config/"+ confName + "]," + + "\n\tdue to: " + e.toString) + } + Configgy.config + } else if (getClass.getClassLoader.getResource(confName) ne null) { + try { + Configgy.configureFromResource(confName, getClass.getClassLoader) + ConfigLogger.log.info("Config [%s] loaded from the application classpath.",confName) + } catch { + case e: ParseException => throw new ConfigurationException( + "Can't load '" + confName + "' config file from application classpath," + "\n\tdue to: " + e.toString) } Configgy.config } else { ConfigLogger.log.warning( - "\nCan't load 'akka.conf'." + - "\nOne of the three ways of locating the 'akka.conf' file needs to be defined:" + + "\nCan't load '" + confName + "'." + + "\nOne of the three ways of locating the '" + confName + "' file needs to be defined:" + "\n\t1. Define the '-Dakka.config=...' system property option." + - "\n\t2. Put the 'akka.conf' file on the classpath." + + "\n\t2. Put the '" + confName + "' file on the classpath." + "\n\t3. Define 'AKKA_HOME' environment variable pointing to the root of the Akka distribution." + - "\nI have no way of finding the 'akka.conf' configuration file." + + "\nI have no way of finding the '" + confName + "' configuration file." + "\nUsing default values everywhere.") CConfig.fromString("") // default empty config } @@ -92,7 +98,7 @@ object Config { val CONFIG_VERSION = config.getString("akka.version", VERSION) if (VERSION != CONFIG_VERSION) throw new ConfigurationException( - "Akka JAR version [" + VERSION + "] is different than the provided config ('akka.conf') version [" + CONFIG_VERSION + "]") + "Akka JAR version [" + VERSION + "] is different than the provided config version [" + CONFIG_VERSION + "]") val TIME_UNIT = config.getString("akka.time-unit", "seconds")