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:05:30 UTC
svn commit: r329018 - in
/directory/protocol-providers/ntp/trunk/src/java/org/apache/ntp:
NtpConfiguration.java NtpServer.java
Author: erodriguez
Date: Thu Oct 27 18:05:26 2005
New Revision: 329018
URL: http://svn.apache.org/viewcvs?rev=329018&view=rev
Log:
Moving configuration and server wrapper out of OSGi bundle subproject into ntp-protocol.
Added:
directory/protocol-providers/ntp/trunk/src/java/org/apache/ntp/NtpServer.java (with props)
Modified:
directory/protocol-providers/ntp/trunk/src/java/org/apache/ntp/NtpConfiguration.java
Modified: directory/protocol-providers/ntp/trunk/src/java/org/apache/ntp/NtpConfiguration.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/ntp/trunk/src/java/org/apache/ntp/NtpConfiguration.java?rev=329018&r1=329017&r2=329018&view=diff
==============================================================================
--- directory/protocol-providers/ntp/trunk/src/java/org/apache/ntp/NtpConfiguration.java (original)
+++ directory/protocol-providers/ntp/trunk/src/java/org/apache/ntp/NtpConfiguration.java Thu Oct 27 18:05:26 2005
@@ -22,29 +22,30 @@
import java.util.Map;
import org.apache.ldap.server.DirectoryService;
-import org.apache.ldap.server.configuration.Configuration;
import org.apache.ldap.server.configuration.ConfigurationException;
+import org.apache.protocol.common.LoadStrategy;
+import org.apache.protocol.common.ServiceConfiguration;
-public class NtpConfiguration extends Configuration
+public class NtpConfiguration extends ServiceConfiguration
{
- /** the prop key const for the port */
- public static final String NTP_PORT_KEY = "ntp.port";
-
/** the default port */
- private static final String NTP_DEFAULT_PORT = "123";
+ private static final String DEFAULT_IP_PORT = "123";
+
+ /** the default pid */
+ private static final String DEFAULT_PID = "org.apache.ntp";
- private static final String SERVICE_PID = "service.pid";
- private static final String PID = "org.apache.ntp";
- private static final String name = "Apache NTP Service";
+ /** the default name */
+ private static final String DEFAULT_NAME = "Apache NTP Service";
- private Map configuration = new HashMap();
+ /** the default prefix */
+ private static final String DEFAULT_PREFIX = "ntp.";
/**
* Creates a new instance with default settings.
*/
public NtpConfiguration()
{
- this( getDefaultConfig() );
+ this( getDefaultConfig(), LoadStrategy.LDAP );
}
/**
@@ -53,26 +54,31 @@
*/
public NtpConfiguration( String instanceId )
{
- this( getDefaultConfig() );
+ this( getDefaultConfig(), LoadStrategy.LDAP );
setInstanceId( instanceId );
}
public NtpConfiguration( Map properties )
{
+ this( properties, LoadStrategy.LDAP );
+ }
+
+ public NtpConfiguration( Map properties, int strategy )
+ {
if ( properties == null )
{
configuration = getDefaultConfig();
}
else
{
- configuration.putAll( properties );
+ loadProperties( DEFAULT_PREFIX, properties, strategy );
}
int port = getPort();
if ( port < 1 || port > 0xFFFF )
{
- throw new ConfigurationException( "Invalid value: " + NTP_PORT_KEY + "=" + port );
+ throw new ConfigurationException( "Invalid value: " + IP_PORT_KEY + "=" + port );
}
}
@@ -80,8 +86,8 @@
{
Map defaults = new HashMap();
- defaults.put( SERVICE_PID, PID );
- defaults.put( NTP_PORT_KEY, NTP_DEFAULT_PORT );
+ defaults.put( SERVICE_PID, DEFAULT_PID );
+ defaults.put( IP_PORT_KEY, DEFAULT_IP_PORT );
return defaults;
}
@@ -90,7 +96,7 @@
{
int port = getPort();
- if ( port == Integer.parseInt( (String) config.get( NTP_PORT_KEY ) ) )
+ if ( port == Integer.parseInt( (String) config.get( IP_PORT_KEY ) ) )
{
return false;
}
@@ -100,23 +106,18 @@
public String getName()
{
- return name;
+ return DEFAULT_NAME;
}
public int getPort()
{
- String key = NTP_PORT_KEY;
+ String key = IP_PORT_KEY;
if ( configuration.containsKey( key ) )
{
return Integer.parseInt( get( key ) );
}
- return Integer.parseInt( NTP_DEFAULT_PORT );
- }
-
- private String get( String key )
- {
- return (String) configuration.get( key );
+ return Integer.parseInt( DEFAULT_IP_PORT );
}
}
Added: directory/protocol-providers/ntp/trunk/src/java/org/apache/ntp/NtpServer.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/ntp/trunk/src/java/org/apache/ntp/NtpServer.java?rev=329018&view=auto
==============================================================================
--- directory/protocol-providers/ntp/trunk/src/java/org/apache/ntp/NtpServer.java (added)
+++ directory/protocol-providers/ntp/trunk/src/java/org/apache/ntp/NtpServer.java Thu Oct 27 18:05:26 2005
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.ntp;
+
+import java.io.IOException;
+import java.util.Dictionary;
+
+import org.apache.mina.common.TransportType;
+import org.apache.mina.protocol.ProtocolProvider;
+import org.apache.mina.registry.Service;
+import org.apache.mina.registry.ServiceRegistry;
+import org.apache.ntp.protocol.NtpProtocolProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NtpServer
+{
+ /** the log for this class */
+ private static final Logger log = LoggerFactory.getLogger( NtpServer.class );
+
+ private NtpConfiguration config;
+ private ServiceRegistry registry;
+
+ private ProtocolProvider provider;
+ private Service tcpService;
+ private Service udpService;
+
+ public NtpServer( NtpConfiguration config, ServiceRegistry registry )
+ {
+ this.config = config;
+ this.registry = registry;
+
+ String name = config.getName();
+ int port = config.getPort();
+
+ try
+ {
+ provider = new NtpProtocolProvider();
+
+ udpService = new Service( name, TransportType.DATAGRAM, port );
+ tcpService = new Service( name, TransportType.SOCKET, port );
+
+ registry.bind( udpService, provider );
+ registry.bind( tcpService, provider );
+
+ log.debug( name + " listening on port " + port );
+ }
+ catch ( IOException ioe )
+ {
+ log.error( ioe.getMessage(), ioe );
+ }
+ }
+
+ public boolean isDifferent( Dictionary newConfig )
+ {
+ return config.isDifferent( newConfig );
+ }
+
+ public void destroy()
+ {
+ registry.unbind( udpService );
+ registry.unbind( tcpService );
+
+ registry = null;
+ provider = null;
+ udpService = null;
+ tcpService = null;
+
+ log.debug( config.getName() + " has stopped listening on port " + config.getPort() );
+ }
+}
Propchange: directory/protocol-providers/ntp/trunk/src/java/org/apache/ntp/NtpServer.java
------------------------------------------------------------------------------
svn:eol-style = native