You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by sc...@apache.org on 2009/03/26 14:17:56 UTC

svn commit: r758624 - /incubator/etch/branches/config/services/config/example/src/main/java/org/apache/etch/services/config/example/

Author: sccomer
Date: Thu Mar 26 13:17:46 2009
New Revision: 758624

URL: http://svn.apache.org/viewvc?rev=758624&view=rev
Log:
cleaned up and tuned up the examples.

Modified:
    incubator/etch/branches/config/services/config/example/src/main/java/org/apache/etch/services/config/example/MainConfigExampleListener1.java
    incubator/etch/branches/config/services/config/example/src/main/java/org/apache/etch/services/config/example/MainConfigExampleListener2.java
    incubator/etch/branches/config/services/config/example/src/main/java/org/apache/etch/services/config/example/MainConfigExampleListener3.java
    incubator/etch/branches/config/services/config/example/src/main/java/org/apache/etch/services/config/example/MainConfigExampleListener4.java

Modified: incubator/etch/branches/config/services/config/example/src/main/java/org/apache/etch/services/config/example/MainConfigExampleListener1.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/config/services/config/example/src/main/java/org/apache/etch/services/config/example/MainConfigExampleListener1.java?rev=758624&r1=758623&r2=758624&view=diff
==============================================================================
--- incubator/etch/branches/config/services/config/example/src/main/java/org/apache/etch/services/config/example/MainConfigExampleListener1.java (original)
+++ incubator/etch/branches/config/services/config/example/src/main/java/org/apache/etch/services/config/example/MainConfigExampleListener1.java Thu Mar 26 13:17:46 2009
@@ -20,15 +20,14 @@
 package org.apache.etch.services.config.example;
 
 import org.apache.etch.bindings.java.support.ServerFactory;
+import org.apache.etch.services.config.example.ConfigExampleHelper.ConfigExampleServerFactory;
 import org.apache.etch.util.core.io.Transport;
 
 /**
  * Main program for ConfigExampleServer. This program makes a listener to accept
- * connections from MainConfigExampleClient. This is a standard generic etch
- * listener.
+ * connections from MainConfigExampleClient. This is a standard etch listener.
  */
-public class MainConfigExampleListener1 implements
-	ConfigExampleHelper.ConfigExampleServerFactory
+public class MainConfigExampleListener1 implements ConfigExampleServerFactory
 {
 	/**
 	 * Main program for ConfigExampleServer.

Modified: incubator/etch/branches/config/services/config/example/src/main/java/org/apache/etch/services/config/example/MainConfigExampleListener2.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/config/services/config/example/src/main/java/org/apache/etch/services/config/example/MainConfigExampleListener2.java?rev=758624&r1=758623&r2=758624&view=diff
==============================================================================
--- incubator/etch/branches/config/services/config/example/src/main/java/org/apache/etch/services/config/example/MainConfigExampleListener2.java (original)
+++ incubator/etch/branches/config/services/config/example/src/main/java/org/apache/etch/services/config/example/MainConfigExampleListener2.java Thu Mar 26 13:17:46 2009
@@ -22,15 +22,15 @@
 import org.apache.etch.bindings.java.support.ServerFactory;
 import org.apache.etch.services.config.ConfigurationServer;
 import org.apache.etch.services.config.YamlConfig;
+import org.apache.etch.services.config.example.ConfigExampleHelper.ConfigExampleServerFactory;
 import org.apache.etch.util.core.io.Transport;
 
 /**
  * Main program for ConfigExampleServer. This program makes a listener to accept
  * connections from MainConfigExampleClient. This is a standard etch listener
- * modified to load the listen uri from a local config file at startup.
+ * modified to load the listen uri from a local config at startup.
  */
-public class MainConfigExampleListener2 implements
-	ConfigExampleHelper.ConfigExampleServerFactory
+public class MainConfigExampleListener2 implements ConfigExampleServerFactory
 {
 	private static final String LOCAL = "services/config/example/local2";
 
@@ -44,11 +44,11 @@
 	 */
 	public static void main( String[] args ) throws Exception
 	{
-		// Open the local config file.
+		// Open the local config.
 		ConfigurationServer local = new YamlConfig( null, LOCAL );
 		System.out.println( "loaded local configuration named '" + LOCAL + "'" );
 
-		// Get the listener uri from the config file.
+		// Get the listener uri from the local config.
 		String uri = local.getStringPath( local.getRoot(), LISTEN_URI );
 		System.out.println( "listen uri = " + uri );
 

Modified: incubator/etch/branches/config/services/config/example/src/main/java/org/apache/etch/services/config/example/MainConfigExampleListener3.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/config/services/config/example/src/main/java/org/apache/etch/services/config/example/MainConfigExampleListener3.java?rev=758624&r1=758623&r2=758624&view=diff
==============================================================================
--- incubator/etch/branches/config/services/config/example/src/main/java/org/apache/etch/services/config/example/MainConfigExampleListener3.java (original)
+++ incubator/etch/branches/config/services/config/example/src/main/java/org/apache/etch/services/config/example/MainConfigExampleListener3.java Thu Mar 26 13:17:46 2009
@@ -32,8 +32,7 @@
  * modified to load the listen uri from a local config file at startup and
  * whenever the file changes.
  */
-public class MainConfigExampleListener3 implements
-	ConfigExampleServerFactory
+public class MainConfigExampleListener3 implements ConfigExampleServerFactory
 {
 	private static final String LOCAL = "services/config/example/local2";
 
@@ -50,11 +49,11 @@
 		// Create the server session factory.
 		factory = new MainConfigExampleListener3();
 		
-		// Open the local config file.
+		// Open the local config.
 		local = new YamlConfig( new MyLocalConfigurationClient(), LOCAL );
 		System.out.println( "loaded local configuration named '" + LOCAL + "'" );
 
-		// Subscribe to changes in the local config file.
+		// Subscribe to changes in the local config.
 		local.subscribe( local.getRoot() );
 		System.out.println( "subscribed to changes in '" + LOCAL + "'" );
 	}
@@ -68,11 +67,10 @@
 	{
 		public void configValuesChanged( Object[] updated )
 		{
+			System.out.println( "local config changed" );
 			try
 			{
-				String uri = local.getStringPath( local.getRoot(), LISTEN_URI );
-				System.out.println( "listen uri = " + uri );
-				resetListener( uri );
+				resetListener();
 			}
 			catch ( Exception e )
 			{
@@ -81,9 +79,9 @@
 		}
 	}
 
-	private static void resetListener( String listenUri ) throws Exception
+	private static void resetListener() throws Exception
 	{
-		// Stop any old listener.
+		// Stop the old listener.
 		if (listener != null)
 		{
 			System.out.println( "stopping listener " + listener );
@@ -91,8 +89,12 @@
 			listener = null;
 		}
 		
+		// Get the listener uri from the local config.
+		String uri = local.getStringPath( local.getRoot(), LISTEN_URI );
+		System.out.println( "listen uri = " + uri );
+		
 		// Create the listener stack.
-		listener = ConfigExampleHelper.newListener( listenUri, null, factory );
+		listener = ConfigExampleHelper.newListener( uri, null, factory );
 		System.out.println( "listener created " + listener );
 
 		// Start the listener stack.

Modified: incubator/etch/branches/config/services/config/example/src/main/java/org/apache/etch/services/config/example/MainConfigExampleListener4.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/config/services/config/example/src/main/java/org/apache/etch/services/config/example/MainConfigExampleListener4.java?rev=758624&r1=758623&r2=758624&view=diff
==============================================================================
--- incubator/etch/branches/config/services/config/example/src/main/java/org/apache/etch/services/config/example/MainConfigExampleListener4.java (original)
+++ incubator/etch/branches/config/services/config/example/src/main/java/org/apache/etch/services/config/example/MainConfigExampleListener4.java Thu Mar 26 13:17:46 2009
@@ -34,7 +34,10 @@
 
 /**
  * Main program for ConfigExampleServer. This program makes a listener to accept
- * connections from MainConfigExampleClient.
+ * connections from MainConfigExampleClient. This is a standard etch listener
+ * modified to load the listen uri from a remote config whenever it changes.
+ * The remote config is defined in a local config, which is also monitored for
+ * changes.
  */
 public class MainConfigExampleListener4 implements ConfigExampleServerFactory
 {
@@ -55,14 +58,14 @@
 		// Create the server session factory.
 		factory = new MainConfigExampleListener4();
 		
-		// Create the config client factory.
+		// Create the remote config client factory.
 		configClientFactory = new MyConfigurationClientFactory();
 		
-		// Open the local config file.
+		// Open the local config.
 		local = new YamlConfig( new MyLocalConfigurationClient(), LOCAL );
 		System.out.println( "loaded local configuration named '" + LOCAL + "'" );
 
-		// Subscribe to changes in the local config file.
+		// Subscribe to changes in the local config.
 		local.subscribe( local.getRoot() );
 		System.out.println( "subscribed to changes in '" + LOCAL + "'" );
 	}
@@ -78,11 +81,10 @@
 	{
 		public void configValuesChanged( Object[] updated )
 		{
+			System.out.println( "local config changed" );
 			try
 			{
-				String configUri = local.getStringPath( local.getRoot(), CONFIG_URI );
-				System.out.println( "local " + CONFIG_URI + " changed: " + configUri );
-				configUriChanged( configUri );
+				resetRemoteConfig();
 			}
 			catch ( Exception e )
 			{
@@ -91,25 +93,31 @@
 		}
 	}
 
-	private static void configUriChanged( String configUri ) throws Exception
+	private static void resetRemoteConfig() throws Exception
 	{
-		if (server != null)
+		if (remote != null)
 		{
-			System.out.println( "stopping remote config service" );
-			server._stopAndWaitDown( 4000 );
-			server = null;
+			System.out.println( "stopping remote config" );
+			remote._stopAndWaitDown( 4000 );
+			remote = null;
 		}
-
-		server = ConfigurationHelper.newServer( configUri, null, configClientFactory );
-		configName = new URL( configUri ).getUri();
 		
-		System.out.println( "starting remote config service connection "+server );
-		server._start();
+		// Get the remote config uri from the local config.
+		configUri = local.getStringPath( local.getRoot(), CONFIG_URI );
+		System.out.println( "remote config uri = " + configUri );
+
+		// Create the remote config stack.
+		remote = ConfigurationHelper.newServer( configUri, null, configClientFactory );
+		System.out.println( "remote config created "+remote );
+		
+		// Start the remote config stack.
+		System.out.println( "starting remote config "+remote );
+		remote._start();
 	}
 
-	private static RemoteConfigurationServer server;
+	private static String configUri;
 	
-	private static String configName;
+	private static RemoteConfigurationServer remote;
 
 	private static class MyConfigurationClientFactory implements
 		ConfigurationClientFactory
@@ -117,20 +125,13 @@
 		public ConfigurationClient newConfigurationClient(
 			RemoteConfigurationServer server ) throws Exception
 		{
-			return new MyRemoteConfigurationClient( server );
+			return new MyRemoteConfigurationClient();
 		}
 	}
 
 	private static class MyRemoteConfigurationClient extends
 		BaseConfigurationClient
 	{
-		public MyRemoteConfigurationClient( RemoteConfigurationServer server )
-		{
-			this.server = server;
-		}
-
-		private final RemoteConfigurationServer server;
-
 		@Override
 		public void _sessionNotify( Object event ) throws Exception
 		{
@@ -138,27 +139,25 @@
 			{
 				System.out.println( "remote config service connection is up" );
 				
-				System.out.println( "loading remote configuration named '"
+				String configName = new URL( configUri ).getUri();
+				System.out.println( "remote config name = '"
 					+ configName + "'" );
-				root = server.loadConfig( configName );
-				System.out.println( "loaded remote configuration named '"
+				
+				root = remote.loadConfig( configName );
+				System.out.println( "loaded remote config named '"
 					+ configName + "'" );
 				
-				System.out.println( "subscribing to remote configuration" );
-				server.subscribe( root );
+				System.out.println( "subscribing to remote config" );
+				remote.subscribe( root );
 			}
 		}
-		
-		private Object root;
 
 		@Override
 		public void configValuesChanged( Object[] updated )
 		{
 			try
 			{
-				String uri = server.getStringPath( root, LISTEN_URI );
-				System.out.println( "listen uri = " + uri );
-				resetListener( uri );
+				resetListener();
 			}
 			catch ( Exception e )
 			{
@@ -166,19 +165,25 @@
 			}
 		}
 	}
+	
+	private static Object root;
 
-	private static void resetListener( String listenUri ) throws Exception
+	private static void resetListener() throws Exception
 	{
-		// Stop any old listener.
+		// Stop the old listener.
 		if (listener != null)
 		{
 			System.out.println( "stopping listener " + listener );
 			listener.transportControl( Transport.STOP_AND_WAIT_DOWN, 4000 );
 			listener = null;
 		}
+		
+		// Get the listener uri from the remote config.
+		String uri = remote.getStringPath( root, LISTEN_URI );
+		System.out.println( "listen uri = " + uri );
 
 		// Create the listener stack.
-		listener = ConfigExampleHelper.newListener( listenUri, null, factory );
+		listener = ConfigExampleHelper.newListener( uri, null, factory );
 		System.out.println( "listener created " + listener );
 		
 		// Start the Listener