karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ioca...@apache.org
Subject svn commit: r1164621 - in /karaf/cellar/branches/cellar-2.2.x: ./ core/src/main/java/org/apache/karaf/cellar/core/utils/ hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/ hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/ hazel...
Date Fri, 02 Sep 2011 16:44:16 GMT
Author: iocanel
Date: Fri Sep  2 16:44:16 2011
New Revision: 1164621

URL: http://svn.apache.org/viewvc?rev=1164621&view=rev
Log:
Merged from trunk
[KARAF-842] Added a combined class loader which delegates class loading to bundles that have
registered themselves to the class loader. Added a bundle listener that register/unregisters
bundles that import hazelcast or cellar packages to the comined class loader. [from revision
1164523]

Added:
    karaf/cellar/branches/cellar-2.2.x/core/src/main/java/org/apache/karaf/cellar/core/utils/
      - copied from r1164523, karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/utils/
    karaf/cellar/branches/cellar-2.2.x/core/src/main/java/org/apache/karaf/cellar/core/utils/CombinedClassLoader.java
      - copied unchanged from r1164523, karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/utils/CombinedClassLoader.java
    karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/CellarExtender.java
      - copied unchanged from r1164523, karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/CellarExtender.java
    karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastBundleListener.java
      - copied unchanged from r1164523, karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastBundleListener.java
Modified:
    karaf/cellar/branches/cellar-2.2.x/   (props changed)
    karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastClusterManager.java
    karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastEventTransportFactory.java
    karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java
    karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/QueueConsumer.java
    karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastServiceFactory.java
    karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/resources/META-INF/spring/beans.xml

Propchange: karaf/cellar/branches/cellar-2.2.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Sep  2 16:44:16 2011
@@ -1 +1 @@
-/karaf/cellar/trunk:1101991,1102000,1103447,1103456,1125012,1125040,1131478,1142446,1149693,1150108,1160898,1161074,1161494,1161515,1161766,1162249,1162252,1162321,1162327,1162356-1162357,1162390,1162397,1162399,1164077
+/karaf/cellar/trunk:1101991,1102000,1103447,1103456,1125012,1125040,1131478,1142446,1149693,1150108,1160898,1161074,1161494,1161515,1161766,1162249,1162252,1162321,1162327,1162356-1162357,1162390,1162397,1162399,1164077,1164523

Modified: karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastClusterManager.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastClusterManager.java?rev=1164621&r1=1164620&r2=1164621&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastClusterManager.java
(original)
+++ karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastClusterManager.java
Fri Sep  2 16:44:16 2011
@@ -24,6 +24,7 @@ import org.apache.karaf.cellar.core.Grou
 import org.apache.karaf.cellar.core.Node;
 import org.apache.karaf.cellar.core.event.EventConsumer;
 import org.apache.karaf.cellar.core.event.EventProducer;
+import org.apache.karaf.cellar.core.utils.CombinedClassLoader;
 import org.osgi.service.cm.ConfigurationAdmin;
 
 import java.util.Collection;
@@ -41,11 +42,8 @@ public class HazelcastClusterManager ext
 
     private IdGenerator idgenerator;
 
-    private List<EventProducer> producerList;
-    private List<EventConsumer> consumerList;
-
     private ConfigurationAdmin configurationAdmin;
-
+    private CombinedClassLoader combinedClassLoader;
 
     /**
      * Returns a named distributed map.
@@ -183,21 +181,4 @@ public class HazelcastClusterManager ext
     public void setConfigurationAdmin(ConfigurationAdmin configurationAdmin) {
         this.configurationAdmin = configurationAdmin;
     }
-
-    public List<EventProducer> getProducerList() {
-        return producerList;
-    }
-
-    public void setProducerList(List<EventProducer> producerList) {
-        this.producerList = producerList;
-    }
-
-    public List<EventConsumer> getConsumerList() {
-        return consumerList;
-    }
-
-    public void setConsumerList(List<EventConsumer> consumerList) {
-        this.consumerList = consumerList;
-    }
-
 }

Modified: karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastEventTransportFactory.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastEventTransportFactory.java?rev=1164621&r1=1164620&r2=1164621&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastEventTransportFactory.java
(original)
+++ karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastEventTransportFactory.java
Fri Sep  2 16:44:16 2011
@@ -20,6 +20,7 @@ import org.apache.karaf.cellar.core.Disp
 import org.apache.karaf.cellar.core.event.EventConsumer;
 import org.apache.karaf.cellar.core.event.EventProducer;
 import org.apache.karaf.cellar.core.event.EventTransportFactory;
+import org.apache.karaf.cellar.core.utils.CombinedClassLoader;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -30,6 +31,7 @@ import java.util.Map;
 public class HazelcastEventTransportFactory extends HazelcastInstanceAware implements EventTransportFactory
{
 
     private Dispatcher dispatcher;
+    private CombinedClassLoader combinedClassLoader;
 
 
     @Override
@@ -64,7 +66,7 @@ public class HazelcastEventTransportFact
         } else {
 
                 IQueue queue = instance.getQueue(Constants.QUEUE + Constants.SEPARATOR +
name);
-                QueueConsumer consumer = new QueueConsumer();
+                QueueConsumer consumer = new QueueConsumer(combinedClassLoader);
                 consumer.setQueue(queue);
                 consumer.setNode(getNode());
                 consumer.setDispatcher(dispatcher);
@@ -80,4 +82,12 @@ public class HazelcastEventTransportFact
     public void setDispatcher(Dispatcher dispatcher) {
         this.dispatcher = dispatcher;
     }
+
+    public CombinedClassLoader getCombinedClassLoader() {
+        return combinedClassLoader;
+    }
+
+    public void setCombinedClassLoader(CombinedClassLoader combinedClassLoader) {
+        this.combinedClassLoader = combinedClassLoader;
+    }
 }

Modified: karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java?rev=1164621&r1=1164620&r2=1164621&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java
(original)
+++ karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java
Fri Sep  2 16:44:16 2011
@@ -26,6 +26,7 @@ import org.apache.karaf.cellar.core.Sync
 import org.apache.karaf.cellar.core.event.EventConsumer;
 import org.apache.karaf.cellar.core.event.EventProducer;
 import org.apache.karaf.cellar.core.event.EventTransportFactory;
+import org.apache.karaf.cellar.core.utils.CombinedClassLoader;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
@@ -68,6 +69,7 @@ public class HazelcastGroupManager imple
     private ConfigurationAdmin configurationAdmin;
 
     private EventTransportFactory eventTransportFactory;
+    private CombinedClassLoader combinedClassLoader;
 
     public void init() {
         //Add group to configuration
@@ -127,7 +129,7 @@ public class HazelcastGroupManager imple
     public void deleteGroup(String groupName) {
         ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
         try {
-            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+            Thread.currentThread().setContextClassLoader(combinedClassLoader);
             if (!groupName.equals(Configurations.DEFAULT_GROUP_NAME)) {
                 listGroups().remove(groupName);
             }
@@ -139,7 +141,7 @@ public class HazelcastGroupManager imple
     public Set<Group> listLocalGroups() {
         ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
         try {
-            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+            Thread.currentThread().setContextClassLoader(combinedClassLoader);
             return listGroups(getNode());
         } finally {
             Thread.currentThread().setContextClassLoader(originalClassLoader);
@@ -149,7 +151,7 @@ public class HazelcastGroupManager imple
     public Set<Group> listAllGroups() {
         ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
         try {
-            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+            Thread.currentThread().setContextClassLoader(combinedClassLoader);
             return new HashSet<Group>(listGroups().values());
         } finally {
             Thread.currentThread().setContextClassLoader(originalClassLoader);
@@ -159,7 +161,7 @@ public class HazelcastGroupManager imple
     public Group findGroupByName(String groupName) {
         ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
         try {
-            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+            Thread.currentThread().setContextClassLoader(combinedClassLoader);
             return listGroups().get(groupName);
         } finally {
             Thread.currentThread().setContextClassLoader(originalClassLoader);
@@ -169,7 +171,7 @@ public class HazelcastGroupManager imple
     public Map<String, Group> listGroups() {
         ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
         try {
-            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+            Thread.currentThread().setContextClassLoader(combinedClassLoader);
             return instance.getMap(GROUPS);
         } finally {
             Thread.currentThread().setContextClassLoader(originalClassLoader);
@@ -179,7 +181,7 @@ public class HazelcastGroupManager imple
     public Set<Group> listGroups(Node node) {
         ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
         try {
-            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+            Thread.currentThread().setContextClassLoader(combinedClassLoader);
             Set<Group> result = new HashSet<Group>();
 
             Map<String, Group> groupMap = instance.getMap(GROUPS);
@@ -200,7 +202,7 @@ public class HazelcastGroupManager imple
     public Set<String> listGroupNames() {
         ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
         try {
-            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+            Thread.currentThread().setContextClassLoader(combinedClassLoader);
             return listGroupNames(getNode());
         } finally {
             Thread.currentThread().setContextClassLoader(originalClassLoader);
@@ -211,7 +213,7 @@ public class HazelcastGroupManager imple
         Set<String> names = new HashSet<String>();
         ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
         try {
-            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+            Thread.currentThread().setContextClassLoader(combinedClassLoader);
             Map<String, Group> groups = listGroups();
 
             if (groups != null && !groups.isEmpty()) {
@@ -475,4 +477,12 @@ public class HazelcastGroupManager imple
     public void setEventTransportFactory(EventTransportFactory eventTransportFactory) {
         this.eventTransportFactory = eventTransportFactory;
     }
+
+    public CombinedClassLoader getCombinedClassLoader() {
+        return combinedClassLoader;
+    }
+
+    public void setCombinedClassLoader(CombinedClassLoader combinedClassLoader) {
+        this.combinedClassLoader = combinedClassLoader;
+    }
 }

Modified: karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/QueueConsumer.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/QueueConsumer.java?rev=1164621&r1=1164620&r2=1164621&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/QueueConsumer.java
(original)
+++ karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/QueueConsumer.java
Fri Sep  2 16:44:16 2011
@@ -23,6 +23,7 @@ import org.apache.karaf.cellar.core.cont
 import org.apache.karaf.cellar.core.control.SwitchStatus;
 import org.apache.karaf.cellar.core.event.Event;
 import org.apache.karaf.cellar.core.event.EventConsumer;
+import org.apache.karaf.cellar.core.utils.CombinedClassLoader;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -48,11 +49,15 @@ public class QueueConsumer<E extends Eve
     private IQueue queue;
     private Dispatcher dispatcher;
     private Node node;
+    private CombinedClassLoader combinedClassLoader;
 
 
     public QueueConsumer() {
     }
 
+    public QueueConsumer(CombinedClassLoader combinedClassLoader) {
+        this.combinedClassLoader = combinedClassLoader;
+    }
 
     /**
      * Initialization method.
@@ -82,7 +87,9 @@ public class QueueConsumer<E extends Eve
         ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
         try {
             while (isConsuming) {
-                Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+                if(combinedClassLoader != null) {
+                    Thread.currentThread().setContextClassLoader(combinedClassLoader);
+                } else Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
                 E e = null;
                 try {
                         e = getQueue().poll(10, TimeUnit.SECONDS);

Modified: karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastServiceFactory.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastServiceFactory.java?rev=1164621&r1=1164620&r2=1164621&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastServiceFactory.java
(original)
+++ karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastServiceFactory.java
Fri Sep  2 16:44:16 2011
@@ -21,6 +21,7 @@ import com.hazelcast.config.XmlConfigBui
 import com.hazelcast.core.Hazelcast;
 import com.hazelcast.core.HazelcastInstance;
 import org.apache.karaf.cellar.core.discovery.DiscoveryTask;
+import org.apache.karaf.cellar.core.utils.CombinedClassLoader;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.slf4j.Logger;
@@ -56,9 +57,6 @@ public class HazelcastServiceFactory imp
     public static final String TCPIP_ENABLED="tcpIpEnabled";
     public static final String TCPIP_MEMBERS="tcpIpMembers";
 
-
-
-
     private String username = GroupConfig.DEFAULT_GROUP_NAME;
     private String password = GroupConfig.DEFAULT_GROUP_PASSWORD;
 
@@ -71,10 +69,12 @@ public class HazelcastServiceFactory imp
     private String tcpIpMembers = "";
     private Set<String> tcpIpMemberSet = new LinkedHashSet<String>();
 
+    private DiscoveryTask discoveryTask;
+    private CombinedClassLoader combinedClassLoader;
+
     private BundleContext bundleContext;
 
     private ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
-    private DiscoveryTask discoveryTask;
 
     private Semaphore semaphore = new Semaphore(1);
 
@@ -92,6 +92,9 @@ public class HazelcastServiceFactory imp
 
     public void init() {
         scheduler.scheduleAtFixedRate(discoveryTask, 0, 10, TimeUnit.SECONDS);
+        if(combinedClassLoader != null) {
+            combinedClassLoader.addBundle(bundleContext.getBundle());
+        }
     }
 
     public void destroy() {
@@ -107,7 +110,9 @@ public class HazelcastServiceFactory imp
         try {
             Boolean updated = Boolean.FALSE;
             //We need it to properly instantiate Hazelcast.
-            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+            if(combinedClassLoader != null) {
+                Thread.currentThread().setContextClassLoader(combinedClassLoader);
+            }
             if (properties != null) {
                 if (properties.containsKey(USERNAME)) {
                     String newUsername = (String) properties.get(USERNAME);
@@ -241,6 +246,9 @@ public class HazelcastServiceFactory imp
      * @return
      */
     public HazelcastInstance buildInstance() {
+        if(combinedClassLoader != null) {
+            Thread.currentThread().setContextClassLoader(combinedClassLoader);
+        }
         try {
             semaphore.acquire();
         } catch (InterruptedException e) {
@@ -434,4 +442,11 @@ public class HazelcastServiceFactory imp
     public void setDiscoveryTask(DiscoveryTask discoveryTask) {
         this.discoveryTask = discoveryTask;
     }
+    public CombinedClassLoader getCombinedClassLoader() {
+        return combinedClassLoader;
+    }
+
+    public void setCombinedClassLoader(CombinedClassLoader combinedClassLoader) {
+        this.combinedClassLoader = combinedClassLoader;
+    }
 }

Modified: karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/resources/META-INF/spring/beans.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/resources/META-INF/spring/beans.xml?rev=1164621&r1=1164620&r2=1164621&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/resources/META-INF/spring/beans.xml
(original)
+++ karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/resources/META-INF/spring/beans.xml
Fri Sep  2 16:44:16 2011
@@ -30,6 +30,7 @@
     <bean id="instanceFactory" class="org.apache.karaf.cellar.hazelcast.factory.HazelcastServiceFactory"
           init-method="init" destroy-method="destroy">
         <property name="discoveryTask" ref="discoveryTask"/>
+        <property name="combinedClassLoader" ref="combinedClassLoader"/>
         <osgix:managed-properties persistent-id="org.apache.karaf.cellar.instance" update-strategy="bean-managed"
                                   update-method="createOrUpdate"/>
     </bean>
@@ -51,6 +52,7 @@
     <bean id="clusterManager" class="org.apache.karaf.cellar.hazelcast.HazelcastClusterManager">
         <property name="instance" ref="hazelcast"/>
         <property name="configurationAdmin" ref="configurationAdmin"/>
+        <property name="combinedClassLoader" ref="combinedClassLoader"/>
     </bean>
 
     <!-- Group Manager -->
@@ -58,13 +60,21 @@
         <property name="instance" ref="hazelcast"/>
         <property name="configurationAdmin" ref="configurationAdmin"/>
         <property name="eventTransportFactory" ref="eventTransportFactory"/>
+        <property name="combinedClassLoader" ref="combinedClassLoader"/>
     </bean>
 
     <bean id="eventTransportFactory" class="org.apache.karaf.cellar.hazelcast.HazelcastEventTransportFactory">
         <property name="dispatcher"  ref="dispatcher"/>
         <property name="instance" ref="hazelcast"/>
+        <property name="combinedClassLoader" ref="combinedClassLoader"/>
     </bean>
 
+    <bean id="cellarExtender" class="org.apache.karaf.cellar.hazelcast.CellarExtender"
 init-method="init" destroy-method="destroy">
+        <property name="combinedClassLoader" ref="combinedClassLoader"/>
+    </bean>
+
+    <bean id="combinedClassLoader" class="org.apache.karaf.cellar.core.utils.CombinedClassLoader"
init-method="init" destroy-method="destroy"/>
+
 
     <!-- Hazelcast Cluster and Node -->
     <bean id="node" factory-bean="clusterManager" factory-method="getNode"/>



Mime
View raw message