geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hanhongf...@apache.org
Subject svn commit: r1158486 - in /geronimo/server/trunk/plugins/activemq: activemq-broker-blueprint/src/main/plan/ activemq-broker-blueprint/src/main/resources/OSGI-INF/blueprint/ activemq-broker-blueprint/src/main/resources/etc/ activemq-ra/ geronimo-activem...
Date Wed, 17 Aug 2011 01:48:08 GMT
Author: hanhongfang
Date: Wed Aug 17 01:48:08 2011
New Revision: 1158486

URL: http://svn.apache.org/viewvc?rev=1158486&view=rev
Log:
GERONIMO-6110 On 3.0 we don't register the 61616 port and the IP address for the server socket
is not correct.

Modified:
    geronimo/server/trunk/plugins/activemq/activemq-broker-blueprint/src/main/plan/plan.xml
    geronimo/server/trunk/plugins/activemq/activemq-broker-blueprint/src/main/resources/OSGI-INF/blueprint/activemq.xml
    geronimo/server/trunk/plugins/activemq/activemq-broker-blueprint/src/main/resources/etc/blueprint-activemq-placeholder.cfg
    geronimo/server/trunk/plugins/activemq/activemq-ra/pom.xml
    geronimo/server/trunk/plugins/activemq/geronimo-activemq-blueprint/src/main/java/org/apache/geronimo/activemq/ActiveMQBrokerServiceMonitorGBean.java

Modified: geronimo/server/trunk/plugins/activemq/activemq-broker-blueprint/src/main/plan/plan.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/activemq/activemq-broker-blueprint/src/main/plan/plan.xml?rev=1158486&r1=1158485&r2=1158486&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/activemq/activemq-broker-blueprint/src/main/plan/plan.xml
(original)
+++ geronimo/server/trunk/plugins/activemq/activemq-broker-blueprint/src/main/plan/plan.xml
Wed Aug 17 01:48:08 2011
@@ -41,5 +41,5 @@
         <!--</reference>-->
     <!--</gbean>-->
     <!---->
-    <!--<gbean name="ActiveMQBrokerServiceMonitor" class="org.apache.geronimo.activemq.ActiveMQBrokerServiceMonitorGBean"/>-->
+    <gbean name="ActiveMQBrokerServiceMonitor" class="org.apache.geronimo.activemq.ActiveMQBrokerServiceMonitorGBean"/>
 </module>

Modified: geronimo/server/trunk/plugins/activemq/activemq-broker-blueprint/src/main/resources/OSGI-INF/blueprint/activemq.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/activemq/activemq-broker-blueprint/src/main/resources/OSGI-INF/blueprint/activemq.xml?rev=1158486&r1=1158485&r2=1158486&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/activemq/activemq-broker-blueprint/src/main/resources/OSGI-INF/blueprint/activemq.xml
(original)
+++ geronimo/server/trunk/plugins/activemq/activemq-broker-blueprint/src/main/resources/OSGI-INF/blueprint/activemq.xml
Wed Aug 17 01:48:08 2011
@@ -34,7 +34,7 @@
         <cm:default-properties>
             <cm:property name="activemq.brokerName" value="DefaultActiveMQBroker"/>
             <cm:property name="activemq.data" value="var/activemq"/>
-            <cm:property name="serverHostname" value="localhost"/>
+            <cm:property name="serverHostname" value="0.0.0.0"/>
             <cm:property name="activemq.port" value="61616"/>
             <cm:property name="portOffset" value="0"/>
         </cm:default-properties>

Modified: geronimo/server/trunk/plugins/activemq/activemq-broker-blueprint/src/main/resources/etc/blueprint-activemq-placeholder.cfg
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/activemq/activemq-broker-blueprint/src/main/resources/etc/blueprint-activemq-placeholder.cfg?rev=1158486&r1=1158485&r2=1158486&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/activemq/activemq-broker-blueprint/src/main/resources/etc/blueprint-activemq-placeholder.cfg
(original)
+++ geronimo/server/trunk/plugins/activemq/activemq-broker-blueprint/src/main/resources/etc/blueprint-activemq-placeholder.cfg
Wed Aug 17 01:48:08 2011
@@ -20,6 +20,6 @@
 activemq.brokerName=DefaultActiveMQBroker
 activemq.data=var/activmeq
 
-serverHostname=localhost
+serverHostname=0.0.0.0
 activemq.port=61616
 portOffset=0
\ No newline at end of file

Modified: geronimo/server/trunk/plugins/activemq/activemq-ra/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/activemq/activemq-ra/pom.xml?rev=1158486&r1=1158485&r2=1158486&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/activemq/activemq-ra/pom.xml (original)
+++ geronimo/server/trunk/plugins/activemq/activemq-ra/pom.xml Wed Aug 17 01:48:08 2011
@@ -90,7 +90,7 @@
                                         <attribute name="ServerUrl">tcp://${ActiveMQHostname}:${ActiveMQPort
+ PortOffset}</attribute>
                                 </gbean>
                              </config-xml-content>
-                            <config-substitution key="ActiveMQHostname">localhost</config-substitution>
+                            <config-substitution key="ActiveMQHostname">0.0.0.0</config-substitution>
                             <config-substitution key="ActiveMQPort">61616</config-substitution>
                         </plugin-artifact>
                     </instance>

Modified: geronimo/server/trunk/plugins/activemq/geronimo-activemq-blueprint/src/main/java/org/apache/geronimo/activemq/ActiveMQBrokerServiceMonitorGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/activemq/geronimo-activemq-blueprint/src/main/java/org/apache/geronimo/activemq/ActiveMQBrokerServiceMonitorGBean.java?rev=1158486&r1=1158485&r2=1158486&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/activemq/geronimo-activemq-blueprint/src/main/java/org/apache/geronimo/activemq/ActiveMQBrokerServiceMonitorGBean.java
(original)
+++ geronimo/server/trunk/plugins/activemq/geronimo-activemq-blueprint/src/main/java/org/apache/geronimo/activemq/ActiveMQBrokerServiceMonitorGBean.java
Wed Aug 17 01:48:08 2011
@@ -19,6 +19,8 @@ package org.apache.geronimo.activemq;
 
 import java.net.URI;
 import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -28,7 +30,6 @@ import org.apache.activemq.broker.Broker
 import org.apache.activemq.broker.TransportConnector;
 import org.apache.geronimo.activemq.management.ActiveMQTransportConnector;
 import org.apache.geronimo.gbean.AbstractName;
-import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
@@ -37,85 +38,111 @@ import org.apache.geronimo.gbean.annotat
 import org.apache.geronimo.gbean.annotation.ParamSpecial;
 import org.apache.geronimo.gbean.annotation.SpecialAttributeType;
 import org.apache.geronimo.kernel.Kernel;
-import org.apache.geronimo.kernel.lifecycle.LifecycleListener;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+import org.osgi.service.blueprint.container.BlueprintEvent;
+import org.osgi.service.blueprint.container.BlueprintListener;
 
-public class ActiveMQBrokerServiceMonitorGBean implements GBeanLifecycle, LifecycleListener
{
+public class ActiveMQBrokerServiceMonitorGBean implements GBeanLifecycle{
 
     private Kernel kernel;
 
-    private Map<AbstractName, List<AbstractName>> brokerNameConnectorNamesMap
= new ConcurrentHashMap<AbstractName, List<AbstractName>>();
+    private Map<String, List<AbstractName>> brokerNameConnectorNamesMap = new
ConcurrentHashMap<String, List<AbstractName>>();
 
     private BundleContext bundleContext;
-
-    public ActiveMQBrokerServiceMonitorGBean(@ParamSpecial(type = SpecialAttributeType.kernel)
Kernel kernel, @ParamSpecial(type = SpecialAttributeType.bundleContext) BundleContext bundleContext)
{
+    
+    private AbstractName abstractName; 
+    
+    private ServiceRegistration registration;
+
+    public ActiveMQBrokerServiceMonitorGBean(@ParamSpecial(type = SpecialAttributeType.kernel)
Kernel kernel,
+            @ParamSpecial(type = SpecialAttributeType.bundleContext) BundleContext bundleContext,
+            @ParamSpecial(type = SpecialAttributeType.abstractName) AbstractName abstractName)
{
         this.kernel = kernel;
         this.bundleContext = bundleContext;
+        this.abstractName = abstractName;
     }
 
-    public void doFail() {
-        kernel.getLifecycleMonitor().removeLifecycleListener(this);
-    }
-
-    public void doStart() throws Exception {
-        AbstractNameQuery brokerServiceQuery = new AbstractNameQuery(new URI("?#org.apache.geronimo.activemq.BrokerServiceGBean"));
-        kernel.getLifecycleMonitor().addLifecycleListener(this, brokerServiceQuery);
-        Set<AbstractName> brokerServiceNames = kernel.listGBeans(brokerServiceQuery);
-        for (AbstractName brokerServiceName : brokerServiceNames) {
-            if (kernel.isRunning(brokerServiceName)) {
-                startConnectorWrapperGBeans(brokerServiceName);
+    public void doStart() throws Exception {     
+        BlueprintListener listener = new BlueprintListener() {
+            @Override
+            public void blueprintEvent(BlueprintEvent event) {
+                if (event.getType() == BlueprintEvent.CREATED) {
+                    startConnectorGBeans(event.getBundle());
+                } else if (event.getType() == BlueprintEvent.DESTROYED) {
+                    stopConnectorGBeans(event.getBundle());
+                }
+            }
+        };        
+        registration = bundleContext.registerService(BlueprintListener.class.getName(), listener,
new Hashtable());
+        
+        startConnectorGBeans(null);
+   }
+    
+    protected void startConnectorGBeans(Bundle bundle) {
+        Set<BrokerService> brokerServices = getBrokerService(bundle);
+        if (brokerServices == null) {
+            return;
+        }
+        for (BrokerService brokerService : brokerServices) {
+            if (brokerService.isStarted()) {
+                startConnectorWrapperGBeans(brokerService);
             }
         }
     }
-
-    public void doStop() throws Exception {
-        kernel.getLifecycleMonitor().removeLifecycleListener(this);
-    }
-
-    public void failed(AbstractName abstractName) {
-        stopConnectorWrapperGBeans(abstractName);
-    }
-
-    public void loaded(AbstractName abstractName) {
-    }
-
-    public void running(AbstractName abstractName) {
-        startConnectorWrapperGBeans(abstractName);
-    }
-
-    public void starting(AbstractName abstractName) {
-    }
-
-    public void stopped(AbstractName abstractName) {
-        stopConnectorWrapperGBeans(abstractName);
+    
+    protected void stopConnectorGBeans(Bundle bundle) {
+        Set<BrokerService> brokerServices = getBrokerService(bundle);
+        if (brokerServices == null) {
+            return;
+        }
+        for (BrokerService brokerService : brokerServices) {
+            stopConnectorWrapperGBeans(brokerService.getBrokerName());
+        }
     }
 
-    public void stopping(AbstractName abstractName) {
+    public void doStop() throws Exception {
+        doFail();
     }
-
-    public void unloaded(AbstractName abstractName) {
+    
+    public void doFail() {
+        if (registration != null) {
+            registration.unregister();            
+        }        
+        for (String brokerName: brokerNameConnectorNamesMap.keySet()) {
+            stopConnectorWrapperGBeans(brokerName);
+        }
+        brokerNameConnectorNamesMap.clear();
     }
-
-    protected void startConnectorWrapperGBeans(AbstractName brokerAbstractName) {
-        try {
-            BrokerService brokerService = ((BrokerServiceGBean) kernel.getGBean(brokerAbstractName)).getBrokerContainer();
+    
+    protected void startConnectorWrapperGBeans(BrokerService brokerService) {
+        try {           
             List<AbstractName> connectorNames = new ArrayList<AbstractName>();
             GBeanInfo gBeanInfo = new AnnotationGBeanInfoFactory().getGBeanInfo(ActiveMQTransportConnector.class);
             for (TransportConnector transportConnector : brokerService.getTransportConnectors())
{
-                AbstractName connectorAbName = kernel.getNaming().createSiblingName(brokerAbstractName,
transportConnector.getUri().toString().replace(':', '_'), GBeanInfoBuilder.DEFAULT_J2EE_TYPE);
+                AbstractName connectorAbName = kernel.getNaming().createSiblingName(this.abstractName,
transportConnector.getUri().toString().replace(':', '_'), GBeanInfoBuilder.DEFAULT_J2EE_TYPE);
                 GBeanData gbeanData = new GBeanData(connectorAbName, gBeanInfo);
                 gbeanData.setAttribute("transportConnector", transportConnector);
                 kernel.loadGBean(gbeanData, bundleContext);
                 kernel.startGBean(connectorAbName);
                 connectorNames.add(connectorAbName);
             }
-            brokerNameConnectorNamesMap.put(brokerAbstractName, connectorNames);
+            // in case this brokerService has been processed, remove the old connectorNames
+            List<AbstractName> oldConnectorNames = brokerNameConnectorNamesMap.remove(brokerService.getBrokerName());
+            if (oldConnectorNames!=null) {
+                stopConnectorWrapperGBeans(brokerService.getBrokerName());
+            }
+            // add new connectorsNames
+            brokerNameConnectorNamesMap.put(brokerService.getBrokerName(), connectorNames);
         } catch (Exception e) {
         }
     }
-
-    protected void stopConnectorWrapperGBeans(AbstractName brokerAbstractName) {
-        List<AbstractName> connectorNames = brokerNameConnectorNamesMap.remove(brokerAbstractName);
+ 
+    protected void stopConnectorWrapperGBeans(String brokerName) {
+        List<AbstractName> connectorNames = brokerNameConnectorNamesMap.get(brokerName);
         if (connectorNames == null) {
             return;
         }
@@ -126,5 +153,40 @@ public class ActiveMQBrokerServiceMonito
             } catch (Exception e) {
             }
         }
+    }    
+    
+    private Set<BrokerService> getBrokerService(Bundle bundle) {
+        Set<BrokerService> brokerServices = new HashSet<BrokerService>();
+ 
+        try {        
+            String filter;
+            if (bundle == null) {
+                filter = null;
+            } else {
+                String symbolicName = bundle.getSymbolicName();
+                String version = bundle.getVersion().toString();
+                filter = "(&(osgi.blueprint.container.symbolicname=" + symbolicName
+                        + ")(osgi.blueprint.container.version=" + version + "))";
+            }
+            
+            String clazz = "org.osgi.service.blueprint.container.BlueprintContainer";   
        
+            ServiceReference[] references = bundleContext.getServiceReferences(clazz, filter);
+            if (references != null) {
+                for (ServiceReference reference: references) {
+                    BlueprintContainer container = (BlueprintContainer) bundleContext.getService(reference);
+                    @SuppressWarnings("unchecked")
+                    Set<String> ids = (Set<String>) container.getComponentIds();
+                    for (Object id: ids) {
+                        Object object = container.getComponentInstance((String)id);
+                        if (object instanceof BrokerService) {
+                            brokerServices.add((BrokerService)object);
+                        }
+                    }
+                }
+            }            
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        return brokerServices;
     }
 }



Mime
View raw message