Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 76333 invoked from network); 28 Oct 2005 01:24:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 28 Oct 2005 01:24:36 -0000 Received: (qmail 19890 invoked by uid 500); 28 Oct 2005 01:24:36 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 19865 invoked by uid 500); 28 Oct 2005 01:24:35 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 19854 invoked by uid 99); 28 Oct 2005 01:24:35 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Oct 2005 18:24:35 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 27 Oct 2005 18:24:32 -0700 Received: (qmail 76245 invoked by uid 65534); 28 Oct 2005 01:24:14 -0000 Message-ID: <20051028012414.76243.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r329025 - in /directory/standalone/trunk/osgi/ntp: project.xml src/main/java/org/apache/ntp/NtpServerFactory.java Date: Fri, 28 Oct 2005 01:24:14 -0000 To: commits@directory.apache.org From: erodriguez@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 @@ Network Service org.apache.ntp.Activator - org.ungoverned.gravity.servicebinder,org.osgi.framework,org.apache.mina.registry,org.apache.mina.protocol,org.apache.mina.common,org.osgi.service.cm + 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 org.apache.ntp Apache NTP Network Service 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(); } }