iota-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tonyfaust...@apache.org
Subject [1/2] incubator-iota git commit: [MIL5-175] - Avoiding concurrent class load - using synchronized hash map
Date Thu, 04 May 2017 02:45:37 GMT
Repository: incubator-iota
Updated Branches:
  refs/heads/master b84f86a64 -> cf172dc6e


[MIL5-175]  - Avoiding concurrent class load - using synchronized hash map


Project: http://git-wip-us.apache.org/repos/asf/incubator-iota/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-iota/commit/3f80fdb9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-iota/tree/3f80fdb9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-iota/diff/3f80fdb9

Branch: refs/heads/master
Commit: 3f80fdb9d7baa72a722960a0d28e264ef1d1adb0
Parents: b84f86a
Author: Barbara Gomes <barbaramaltagomes@gmail.com>
Authored: Thu Apr 13 11:28:29 2017 -0700
Committer: Barbara Gomes <barbaramaltagomes@gmail.com>
Committed: Thu Apr 13 11:28:29 2017 -0700

----------------------------------------------------------------------
 .../scala/org/apache/iota/fey/Ensemble.scala    | 34 ++++++++++++--------
 .../main/scala/org/apache/iota/fey/Utils.scala  |  6 +++-
 2 files changed, 26 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/3f80fdb9/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala b/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala
index 3f74cec..04308c3 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala
@@ -218,24 +218,32 @@ protected class Ensemble(val orchestrationID: String,
     * @return Props of actor based on JSON config
     */
   private def getPerformer(performerInfo: Performer, connections: Map[String, ActorRef]):
Props = {
+    var clazz:Option[Class[FeyGenericActor]] = None
 
-    val clazz = loadClazzFromJar(performerInfo.classPath, s"${performerInfo.jarLocation}/${performerInfo.jarName}",
performerInfo.jarName)
+    Utils.loadedJars.synchronized {
+      clazz = Some(loadClazzFromJar(performerInfo.classPath, s"${performerInfo.jarLocation}/${performerInfo.jarName}",
performerInfo.jarName))
+    }
 
-    val dispatcher = if(performerInfo.dispatcher != "") s"fey-custom-dispatchers.${performerInfo.dispatcher}"
else ""
+    if(clazz.isDefined) {
+      val dispatcher = if (performerInfo.dispatcher != "") s"fey-custom-dispatchers.${performerInfo.dispatcher}"
else ""
 
-    val actorProps = Props(clazz,
-      performerInfo.parameters, performerInfo.backoff, connections, performerInfo.schedule,
orchestrationName, orchestrationID, performerInfo.autoScale)
+      val actorProps = Props(clazz.get,
+        performerInfo.parameters, performerInfo.backoff, connections, performerInfo.schedule,
orchestrationName, orchestrationID, performerInfo.autoScale)
 
-    // dispatcher has higher priority than controlAware. That means that if both are defined
-    // then the custom dispatcher will be used
-    if(dispatcher != ""){
-      log.info(s"Using dispatcher: $dispatcher")
-      actorProps.withDispatcher(dispatcher)
-    }
-    else if(performerInfo.controlAware){
-      actorProps.withDispatcher(CONFIG.CONTROL_AWARE_MAILBOX)
+      // dispatcher has higher priority than controlAware. That means that if both are defined
+      // then the custom dispatcher will be used
+      if (dispatcher != "") {
+        log.info(s"Using dispatcher: $dispatcher")
+        actorProps.withDispatcher(dispatcher)
+      }
+      else if (performerInfo.controlAware) {
+        actorProps.withDispatcher(CONFIG.CONTROL_AWARE_MAILBOX)
+      } else {
+        actorProps
+      }
     }else{
-      actorProps
+      log.error(s"Could not load class for performer ${performerInfo.uid}")
+      throw new ClassNotFoundException(s"${performerInfo.jarName} -- ${performerInfo.jarLocation}")
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/3f80fdb9/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala b/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala
index 5577ea6..3bfde54 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala
@@ -42,6 +42,7 @@ protected object Utils {
     * Keeps the loaded clazz in memory
     * JARNAME,[CLASSPATH, CLASS]
     */
+
   val loadedJars: HashMap[String, (URLClassLoader, Map[String, Class[FeyGenericActor]])]
                 = HashMap.empty[String, (URLClassLoader, Map[String, Class[FeyGenericActor]])]
 
@@ -72,9 +73,11 @@ protected object Utils {
     loadedJars.get(jarName) match {
 
       case None =>
+        log.info(s"Loading Jar: $jarName")
         val urls:Array[URL] = Array(new URL(s"jar:file:$path!/"))
-        val cl: URLClassLoader = URLClassLoader.newInstance(urls)
+        val cl: URLClassLoader = URLClassLoader.newInstance(urls, getClass.getClassLoader)
         val clazz = cl.loadClass(className)
+        log.info(s"Loading Class $className with path $path")
         val feyClazz = clazz.asInstanceOf[Class[FeyGenericActor]]
         log.info(s"$path -> $className")
         loadedJars.put(jarName, (cl, Map(className -> feyClazz)))
@@ -83,6 +86,7 @@ protected object Utils {
       case Some(loadedJar) =>
         loadedJar._2.get(className) match {
           case None =>
+            log.info(s"Loading Class $className with path $path")
             val clazz = loadedJar._1.loadClass(className)
             val feyClazz = clazz.asInstanceOf[Class[FeyGenericActor]]
             loadedJars.put(jarName, (loadedJar._1, Map(className -> feyClazz) ++ loadedJar._2))


Mime
View raw message