You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by er...@apache.org on 2005/10/28 03:24:14 UTC

svn commit: r329025 - in /directory/standalone/trunk/osgi/ntp: project.xml src/main/java/org/apache/ntp/NtpServerFactory.java

Author: erodriguez
Date: Thu Oct 27 18:24:09 2005
New Revision: 329025

URL: http://svn.apache.org/viewcvs?rev=329025&view=rev
Log:
o  Put NTP under core configuration.
o  Updated MINA to 0.8.0.

Modified:
    directory/standalone/trunk/osgi/ntp/project.xml
    directory/standalone/trunk/osgi/ntp/src/main/java/org/apache/ntp/NtpServerFactory.java

Modified: directory/standalone/trunk/osgi/ntp/project.xml
URL: http://svn.apache.org/viewcvs/directory/standalone/trunk/osgi/ntp/project.xml?rev=329025&r1=329024&r2=329025&view=diff
==============================================================================
--- directory/standalone/trunk/osgi/ntp/project.xml (original)
+++ directory/standalone/trunk/osgi/ntp/project.xml Thu Oct 27 18:24:09 2005
@@ -7,7 +7,7 @@
   <properties>
     <osgi.bundle.category>Network Service</osgi.bundle.category>
     <osgi.bundle.activator>org.apache.ntp.Activator</osgi.bundle.activator>
-    <osgi.import.package>org.ungoverned.gravity.servicebinder,org.osgi.framework,org.apache.mina.registry,org.apache.mina.protocol,org.apache.mina.common,org.osgi.service.cm</osgi.import.package>
+    <osgi.import.package>org.apache.ldap.server.configuration,org.ungoverned.gravity.servicebinder,org.osgi.framework,org.apache.mina.registry,org.apache.mina.protocol,org.apache.mina.common,org.osgi.service.cm</osgi.import.package>
   </properties>
   <package>org.apache.ntp</package>
   <shortDescription>Apache NTP Network Service</shortDescription>

Modified: directory/standalone/trunk/osgi/ntp/src/main/java/org/apache/ntp/NtpServerFactory.java
URL: http://svn.apache.org/viewcvs/directory/standalone/trunk/osgi/ntp/src/main/java/org/apache/ntp/NtpServerFactory.java?rev=329025&r1=329024&r2=329025&view=diff
==============================================================================
--- directory/standalone/trunk/osgi/ntp/src/main/java/org/apache/ntp/NtpServerFactory.java (original)
+++ directory/standalone/trunk/osgi/ntp/src/main/java/org/apache/ntp/NtpServerFactory.java Thu Oct 27 18:24:09 2005
@@ -17,13 +17,15 @@
 
 package org.apache.ntp;
 
+import java.util.Collections;
 import java.util.Dictionary;
 import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.mina.registry.ServiceRegistry;
-import org.osgi.service.cm.Configuration;
+import org.apache.protocol.common.MapAdapter;
 import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.cm.ManagedServiceFactory;
@@ -36,21 +38,20 @@
     /** the log for this class */
     private static final Logger log = LoggerFactory.getLogger( NtpServerFactory.class );
 
-    private static final String FACTORY_PID = "org.apache.ntp";
-    private static final String DEFAULT_PID = FACTORY_PID + ".default";
+    private static final String DEFAULT_PID = "org.apache.ntp.default";
 
-    private Map servers = new HashMap();
-    private Object updateLock = new Object();
-    private ServiceRegistry registry;
     private ConfigurationAdmin cm;
+    private ServiceRegistry registry;
+
+    private Map servers = Collections.synchronizedMap( new HashMap() );
 
     public void updated( String pid, Dictionary config ) throws ConfigurationException
     {
-        log.debug( getName() + " updating with " + config );
+        log.debug( getName() + " (" + pid + ") updating with " + config );
 
-        NtpConfig ntpConfig = new NtpConfig( config );
+        NtpConfiguration ntpConfig = new NtpConfiguration( new MapAdapter( config ) );
 
-        synchronized ( updateLock )
+        synchronized ( servers )
         {
             if ( pid.equals( DEFAULT_PID ) && servers.size() > 0 )
             {
@@ -66,6 +67,11 @@
             // For a given pid, do we have the service?
             NtpServer ntpServer = (NtpServer) servers.get( pid );
 
+            if ( ntpServer != null )
+            {
+                log.debug( "isDifferent" + ntpServer.isDifferent( config ) );
+            }
+
             // If we don't have the service, create it with the config.
             // Or, if we do have the service, re-create it if the config is different.
             if ( ntpServer == null || ntpServer.isDifferent( config ) )
@@ -79,11 +85,14 @@
 
     public void deleted( String pid )
     {
-        NtpServer ntpServer = (NtpServer) servers.remove( pid );
-
-        if ( ntpServer != null )
+        synchronized ( servers )
         {
-            ntpServer.destroy();
+            NtpServer ntpServer = (NtpServer) servers.remove( pid );
+
+            if ( ntpServer != null )
+            {
+                ntpServer.destroy();
+            }
         }
     }
 
@@ -94,28 +103,15 @@
 
     /**
      * All required services have been bound, but our service(s) are not yet
-     * registered.  So, we check the Config Admin service for configs or we
-     * start a server with its default properties.
+     * registered.  If there is no Config Admin we start a server with default properties.
      */
     public void activate()
     {
         try
         {
-            Configuration[] configs = null;
-
-            if ( cm != null )
-            {
-                String filter = "(service.factoryPid=" + FACTORY_PID + ")";
-                configs = cm.listConfigurations( filter );
-
-                log.debug( "filter:         " + filter );
-                log.debug( "configs.length: " + configs.length );
-                log.debug( "configs[ 0 ]:   " + configs[ 0 ] );
-            }
-
-            if ( cm == null || configs == null || configs.length == 0 )
+            if ( cm == null )
             {
-                updated( NtpServerFactory.DEFAULT_PID, NtpConfig.getDefaultConfig() );
+                updated( DEFAULT_PID, new Hashtable( NtpConfiguration.getDefaultConfig() ) );
             }
         }
         catch ( Exception e )
@@ -134,11 +130,17 @@
      */
     public void deactivate()
     {
-        Iterator it = servers.keySet().iterator();
-
-        while ( it.hasNext() )
+        synchronized ( servers )
         {
-            deleted( (String) it.next() );
+            Iterator it = servers.values().iterator();
+
+            while ( it.hasNext() )
+            {
+                NtpServer ntpServer = (NtpServer) it.next();
+                ntpServer.destroy();
+            }
+
+            servers.clear();
         }
     }