[Carbon-commits] [Carbon] svn commit r47352 - in trunk/carbon: org.wso2.carbon.core org.wso2.carbon.core/src/main/java/org/wso2/carbon/core/internal org.wso2.carbon.dnsserverregistration/src/main/java/org/wso2/carbon/dnsserverregistration/internal

senaka at wso2.com senaka at wso2.com
Sun Oct 18 01:54:36 PDT 2009


Author: senaka
Date: Sun Oct 18 01:54:36 2009
New Revision: 47352
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=47352

Log:
Re-ordering logging of server registration and making sure that the server registration happens after the listener manager service has been published and just before the server has been started.


Modified:
   trunk/carbon/org.wso2.carbon.core/pom.xml
   trunk/carbon/org.wso2.carbon.core/src/main/java/org/wso2/carbon/core/internal/StartupFinalizerServiceComponent.java
   trunk/carbon/org.wso2.carbon.dnsserverregistration/src/main/java/org/wso2/carbon/dnsserverregistration/internal/ServerRegistrationComponent.java

Modified: trunk/carbon/org.wso2.carbon.core/pom.xml
URL: http://wso2.org/svn/browse/wso2/trunk/carbon/org.wso2.carbon.core/pom.xml?rev=47352&r1=47351&r2=47352&view=diff
==============================================================================
--- trunk/carbon/org.wso2.carbon.core/pom.xml	(original)
+++ trunk/carbon/org.wso2.carbon.core/pom.xml	Sun Oct 18 01:54:36 2009
@@ -58,6 +58,11 @@
 
         <dependency>
             <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.dnsserverregistration</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.wso2.carbon</groupId>
             <artifactId>org.wso2.carbon.user.core</artifactId>
             <exclusions>
                 <exclusion>

Modified: trunk/carbon/org.wso2.carbon.core/src/main/java/org/wso2/carbon/core/internal/StartupFinalizerServiceComponent.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon/org.wso2.carbon.core/src/main/java/org/wso2/carbon/core/internal/StartupFinalizerServiceComponent.java?rev=47352&r1=47351&r2=47352&view=diff
==============================================================================
--- trunk/carbon/org.wso2.carbon.core/src/main/java/org/wso2/carbon/core/internal/StartupFinalizerServiceComponent.java	(original)
+++ trunk/carbon/org.wso2.carbon.core/src/main/java/org/wso2/carbon/core/internal/StartupFinalizerServiceComponent.java	Sun Oct 18 01:54:36 2009
@@ -30,6 +30,7 @@
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.component.ComponentContext;
 import org.wso2.carbon.CarbonConstants;
+import org.wso2.carbon.dnsserverregistration.ServerRegistration;
 import org.wso2.carbon.core.util.ClusteringUtil;
 import org.wso2.carbon.registry.core.service.RegistryService;
 import org.wso2.carbon.user.core.UserRealm;
@@ -64,6 +65,8 @@
  * cardinality="1..1" policy="dynamic" bind="setRealmService"  unbind="unsetRealmService"
  * @scr.reference name="registry.service" interface="org.wso2.carbon.registry.core.service.RegistryService"
  * cardinality="1..1" policy="dynamic"  bind="setRegistryService" unbind="unsetRegistryService"
+ * @scr.reference name="server.registration" interface="org.wso2.carbon.dnsserverregistration.ServerRegistration"
+ * cardinality="0..1" policy="dynamic"  bind="setServerRegistration" unbind="unsetServerRegistration"
  */
 public class StartupFinalizerServiceComponent implements ServiceListener {
     private static final Log log = LogFactory.getLog(StartupFinalizerServiceComponent.class);
@@ -77,6 +80,8 @@
     private Timer pendingServicesObservationTimer = new Timer();
     private ServerConfiguration serverConfig;
     private ServiceRegistration listerManagerServiceRegistration;
+    private ServerRegistration serverRegistration = null;
+    private boolean listnerManagerStarted = false;
 
     protected synchronized void activate(ComponentContext ctxt) {
 
@@ -118,6 +123,7 @@
     }
 
     protected synchronized void deactivate(ComponentContext ctxt) {
+       listnerManagerStarted = false;
        listerManagerServiceRegistration.unregister();
     }
 
@@ -186,8 +192,17 @@
         listerManagerServiceRegistration =
                 bundleContext.registerService(ListenerManager.class.getName(), listenerManager, null);
         log.info("Started Transport Listener Manager");
-        setServerStartTimeParam();
-        printInfo();
+        listnerManagerStarted = true;
+        finalizeStartup();
+    }
+
+    private void finalizeStartup() {
+        // The server registration is the last thing to happen. Therefore, we will wait till it has
+        // completed.
+        if (listnerManagerStarted && serverRegistration != null) {
+            setServerStartTimeParam();
+            printInfo();
+        }
     }
 
     private void setServerStartTimeParam() {
@@ -239,6 +254,15 @@
     protected void unsetRegistryService(RegistryService registryService) {
     }
 
+    protected void setServerRegistration(ServerRegistration registration) {
+        this.serverRegistration = registration;
+        finalizeStartup();
+    }
+
+    protected void unsetServerRegistration(ServerRegistration registration) {
+        this.serverRegistration = null;
+    }
+
     public synchronized void serviceChanged(ServiceEvent event) {
         if (event.getType() == ServiceEvent.REGISTERED) {
             String service =

Modified: trunk/carbon/org.wso2.carbon.dnsserverregistration/src/main/java/org/wso2/carbon/dnsserverregistration/internal/ServerRegistrationComponent.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon/org.wso2.carbon.dnsserverregistration/src/main/java/org/wso2/carbon/dnsserverregistration/internal/ServerRegistrationComponent.java?rev=47352&r1=47351&r2=47352&view=diff
==============================================================================
--- trunk/carbon/org.wso2.carbon.dnsserverregistration/src/main/java/org/wso2/carbon/dnsserverregistration/internal/ServerRegistrationComponent.java	(original)
+++ trunk/carbon/org.wso2.carbon.dnsserverregistration/src/main/java/org/wso2/carbon/dnsserverregistration/internal/ServerRegistrationComponent.java	Sun Oct 18 01:54:36 2009
@@ -17,6 +17,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.axis2.engine.ListenerManager;
 import org.osgi.service.component.ComponentContext;
 import org.wso2.carbon.dnsserverregistration.ServerRegistration;
 import org.wso2.carbon.dnsserverregistration.ServerRegistrationConstants;
@@ -40,6 +41,11 @@
  *                cardinality="1..1" policy="dynamic"
  *                bind="setServerConfiguration"
  *                unbind="unsetServerConfiguration"
+ * @scr.reference name="listener.manager.service"
+ *                interface="org.apache.axis2.engine.ListenerManager"
+ *                cardinality="1..1" policy="dynamic"
+ *                bind="setListenerManager"
+ *                unbind="unsetListenerManager"
  */
 
 public class ServerRegistrationComponent {
@@ -52,20 +58,19 @@
 
 	protected void activate(ComponentContext ctxt) {
 		try {
-
 			ServerRegistration serverregistration = new ServerRegistration();
-			ctxt.getBundleContext().registerService(
-					ServerRegistration.class.getName(), serverregistration,
-					null);
-			log.info("Registered Server as  : "
+            // It is important that we log this message before publishing the service. If not, this
+            // log message will appear after the server has started, creating confusion.
+			log.info("Registering Server as: "
 					+ ServerRegistration.getServerConfigurationProperty() + "."
 					+ ServerRegistrationConstants.SERVICE_TYPE);
-
+            ctxt.getBundleContext().registerService(
+					ServerRegistration.class.getName(), serverregistration,
+					null);
 		} catch (Throwable e) {
 			log.error("Failed to register the server with jmdns ", e);
 		}
-
-	}
+    }
 
 	protected void deactivate(ComponentContext ctxt) {
 		log.debug("Registration bundle is deactivated ");
@@ -119,6 +124,12 @@
 		registryServiceInstance = null;
 	}
 
+    protected void setListenerManager(ListenerManager listenerManager) {
+    }
+
+    protected void unsetListenerManager(ListenerManager listenerManager) {
+    }
+
 	public static RegistryService getRegistryService() throws Exception {
 		if (registryServiceInstance == null) {
 			String msg = "Before activating Carbon UI bundle, an instance of "



More information about the Carbon-commits mailing list