Revision: 18719
          http://sourceforge.net/p/gate/code/18719
Author:   markagreenwood
Date:     2015-05-28 12:06:30 +0000 (Thu, 28 May 2015)
Log Message:
-----------
when we unload a plugin we now only empty from internal bean caches the data 
for classes we want to forget as this reduces the chances of deadlocks at a 
later point

Modified Paths:
--------------
    gate/trunk/src/main/gate/creole/AbstractResource.java
    gate/trunk/src/main/gate/creole/CreoleRegisterImpl.java
    gate/trunk/src/main/gate/util/GateClassLoader.java

Modified: gate/trunk/src/main/gate/creole/AbstractResource.java
===================================================================
--- gate/trunk/src/main/gate/creole/AbstractResource.java       2015-05-28 
09:12:09 UTC (rev 18718)
+++ gate/trunk/src/main/gate/creole/AbstractResource.java       2015-05-28 
12:06:30 UTC (rev 18719)
@@ -496,6 +496,10 @@
     return r;
   }
   
+  public static boolean forgetBeanInfo(Class<? extends Resource> c) {
+    return (beanInfoCache.remove(c) != null);
+  }
+  
   public static void flushBeanInfoCache() {
     beanInfoCache.clear();
   }

Modified: gate/trunk/src/main/gate/creole/CreoleRegisterImpl.java
===================================================================
--- gate/trunk/src/main/gate/creole/CreoleRegisterImpl.java     2015-05-28 
09:12:09 UTC (rev 18718)
+++ gate/trunk/src/main/gate/creole/CreoleRegisterImpl.java     2015-05-28 
12:06:30 UTC (rev 18719)
@@ -509,7 +509,7 @@
         }
       }
       try {
-        Gate.getClassLoader().forgetClassLoader(new 
URL(directory,"creole.xml").toExternalForm());
+        Gate.getClassLoader().forgetClassLoader(new 
URL(directory,"creole.xml").toExternalForm(), dInfo);
       }
       catch (Exception e) {
         e.printStackTrace();

Modified: gate/trunk/src/main/gate/util/GateClassLoader.java
===================================================================
--- gate/trunk/src/main/gate/util/GateClassLoader.java  2015-05-28 09:12:09 UTC 
(rev 18718)
+++ gate/trunk/src/main/gate/util/GateClassLoader.java  2015-05-28 12:06:30 UTC 
(rev 18719)
@@ -22,6 +22,9 @@
 package gate.util;
 
 import gate.Gate;
+import gate.Gate.DirectoryInfo;
+import gate.Gate.ResourceInfo;
+import gate.Resource;
 import gate.creole.AbstractResource;
 
 import java.beans.Introspector;
@@ -324,8 +327,12 @@
        gcl = childClassLoaders.remove(id);
     }
   
-    if (gcl != null && !gcl.isIsolated()) {
+    if(gcl != null && !gcl.isIsolated()) {
+      // in theory this shouldn't be needed as the Introspector uses
+      // soft references if we move to requiring Java 8 it should be
+      // safe to drop this call
       Introspector.flushCaches();
+
       AbstractResource.flushBeanInfoCache();
     }
   }
@@ -339,7 +346,47 @@
   public void forgetClassLoader(GateClassLoader classloader) {
     if(classloader != null) forgetClassLoader(classloader.getID());
   }
+  
+  
+  public void forgetClassLoader(String id, DirectoryInfo dInfo) {
 
+    if(dInfo == null) {
+      forgetClassLoader(id);
+      return;
+    }
+
+    GateClassLoader classloader = null;
+
+    synchronized(childClassLoaders) {
+      classloader = childClassLoaders.remove(id);
+    }
+
+    if(classloader != null && !classloader.isIsolated()) {
+      // now only remove those classes from the caches that the
+      // classloader was responsible for
+      for(ResourceInfo rInfo : dInfo.getResourceInfoList()) {
+        try {
+          @SuppressWarnings("unchecked")
+          Class<? extends Resource> c =
+                  (Class<? extends Resource>)classloader.loadClass(
+                          rInfo.getResourceClassName());
+          
+          if(c != null) {
+            // in theory this shouldn't be needed as the Introspector
+            // uses soft references if we move to requiring Java 8 it
+            // should be safe to drop this call
+            Introspector.flushFromCaches(c);
+
+            AbstractResource.forgetBeanInfo(c);
+          }
+        } catch(ClassNotFoundException e) {
+          // hmm not sure what to do now
+           e.printStackTrace();
+        }
+      }
+    }
+  }
+
   /**
    * Get the child classloaders in creation order. Note that you
    * shouldn't have any need to access the child classloaders. Holding

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to