geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r471024 - in /geronimo/sandbox/gcache: ./ server/ server/src/main/java/org/apache/geronimo/gcache/ server/src/main/java/org/apache/geronimo/gcache/command/ server/src/main/java/org/apache/geronimo/gcache/server/ server/src/main/java/org/apa...
Date Fri, 03 Nov 2006 22:34:54 GMT
Author: jgenender
Date: Fri Nov  3 14:34:52 2006
New Revision: 471024

URL: http://svn.apache.org/viewvc?view=rev&rev=471024
Log:
Server - yay

Added:
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/GCacheManager.java   (contents, props changed)
      - copied, changed from r465933, geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/GCacheServer.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/DiscoveryManager.java   (with props)
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/network/
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/network/ConnectionManager.java   (with props)
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/server/
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/server/GCacheManagerTest.java   (with props)
Removed:
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/GCacheServer.java
Modified:
    geronimo/sandbox/gcache/pom.xml
    geronimo/sandbox/gcache/server/pom.xml
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/DiscoveryCommand.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/TransportService.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgent.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgentFactory.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/multicast/MulticastDiscoveryAgent.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/multicast/MulticastDiscoveryAgentFactory.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketTransportService.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketTransportServiceFactory.java
    geronimo/sandbox/gcache/server/src/main/xsd/gcache.xsd
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/discovery/multicast/MulticastDiscoveryAgentTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/AbstractService.java

Modified: geronimo/sandbox/gcache/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/pom.xml?view=diff&rev=471024&r1=471023&r2=471024
==============================================================================
--- geronimo/sandbox/gcache/pom.xml (original)
+++ geronimo/sandbox/gcache/pom.xml Fri Nov  3 14:34:52 2006
@@ -30,6 +30,12 @@
     <dependencies>
 
         <dependency>
+            <groupId>commons-cli</groupId>
+            <artifactId>commons-cli</artifactId>
+            <version>1.0</version>
+        </dependency>
+
+        <dependency>
             <groupId>com.sun.xml.bind</groupId>
             <artifactId>jaxb-impl</artifactId>
             <version>2.0.3</version>

Modified: geronimo/sandbox/gcache/server/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/pom.xml?view=diff&rev=471024&r1=471023&r2=471024
==============================================================================
--- geronimo/sandbox/gcache/server/pom.xml (original)
+++ geronimo/sandbox/gcache/server/pom.xml Fri Nov  3 14:34:52 2006
@@ -27,6 +27,11 @@
         </dependency>
 
         <dependency>
+            <groupId>commons-cli</groupId>
+            <artifactId>commons-cli</artifactId>
+        </dependency>
+
+        <dependency>
             <groupId>commons-logging</groupId>
             <artifactId>commons-logging</artifactId>
         </dependency>
@@ -40,7 +45,7 @@
             <groupId>log4j</groupId>
             <artifactId>log4j</artifactId>
         </dependency>
-        
+
         <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-simple</artifactId>
@@ -71,6 +76,16 @@
     </dependencies>
     <build>
         <plugins>
+            <plugin>
+                <artifactId>maven-jar-plugin</artifactId>
+                <configuration>
+                    <archive>
+                        <manifest>
+                            <Main-Class>org.apache.geronimo.gcache.server.GCacheManager</Main-Class>
+                        </manifest>
+                    </archive>
+                </configuration>
+            </plugin>
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>jaxb2-maven-plugin</artifactId>

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java?view=diff&rev=471024&r1=471023&r2=471024
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java Fri Nov  3 14:34:52 2006
@@ -24,15 +24,22 @@
 import org.apache.geronimo.gcache.server.listeners.CacheNotifier;
 import org.apache.geronimo.gcache.server.listeners.DefaultCacheNotifier;
 import org.apache.geronimo.gcache.transports.EndpointManager;
+import org.apache.geronimo.gcache.transports.DiscoveryManager;
 
 public class CacheInfoHolder {
     private final CacheManager cacheManager;
     private CacheNotifier cacheNotifier = null;
     private EndpointManager endpointManager;
+    private DiscoveryManager discoveryManager;
 
     public CacheInfoHolder(CacheManager cacheManager) {
         this.cacheManager = cacheManager;
         this.endpointManager = new EndpointManager();
+        this.discoveryManager = new DiscoveryManager();
+    }
+
+    public DiscoveryManager getDiscoveryManager() {
+        return discoveryManager;
     }
 
     public EndpointManager getEndpointManager() {

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/DiscoveryCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/DiscoveryCommand.java?view=diff&rev=471024&r1=471023&r2=471024
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/DiscoveryCommand.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/DiscoveryCommand.java Fri Nov  3 14:34:52 2006
@@ -23,7 +23,16 @@
     
     private String nodeName;
     private String service;
-    
+    private int order;
+
+    public int getOrder() {
+        return order;
+    }
+
+    public void setOrder(int order) {
+        this.order = order;
+    }
+
     public String getService() {
         return service;
     }

Copied: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/GCacheManager.java (from r465933, geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/GCacheServer.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/GCacheManager.java?view=diff&rev=471024&p1=geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/GCacheServer.java&r1=465933&p2=geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/GCacheManager.java&r2=471024
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/GCacheServer.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/GCacheManager.java Fri Nov  3 14:34:52 2006
@@ -18,33 +18,71 @@
  */
 package org.apache.geronimo.gcache.server;
 
-import org.apache.geronimo.gcache.server.config.Configuration;
-import org.apache.geronimo.gcache.server.core.GCacheThread;
+import org.apache.commons.cli.*;
+import org.apache.geronimo.gcache.dd.ConfigBuilder;
+import org.apache.geronimo.gcache.dd.GcacheConfiguration;
+import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.transports.tcp.TCPCacheNotifier;
+import org.apache.geronimo.gcache.transports.network.ConnectionManager;
+
+import java.io.File;
+import java.net.URI;
+
+import net.sf.ehcache.CacheManager;
+
+public class GCacheManager {
+
+    private static final String OPT_CONFIG = "c";
+    private String configFile;
+    private CacheInfoHolder info;
+    private CacheManager cacheMgr;
+    private ConnectionManager connectionManager;
 
-public class GCacheServer {
+    public GCacheManager(String configFile) {
+        this.configFile = configFile;
+    }
 
-    private final Configuration config;
+    public void start() throws Exception {
+        ConfigBuilder builder = new ConfigBuilder();
 
-    private GCacheThread gcache = null;
+        GcacheConfiguration config = builder.getConfig(configFile == null ? null : (new File(configFile)).toURL());
 
-    public GCacheServer(Configuration config) {
-	this.config = config;
-    }
+        //Create a cache with the configuration from the gcache-config file
+        cacheMgr = new CacheManager(config.getEhcacheConfig());
+        info = new CacheInfoHolder(cacheMgr);
+
+        connectionManager = new ConnectionManager(info);
+        connectionManager.setTransportURI(config.getTransportUri());
+        connectionManager.setDiscoveryURI(config.getDiscoveryUri());
+        connectionManager.setOrder(config.getOrder());
+        connectionManager.setNodeName(config.getServerName());
+        connectionManager.start();
 
-    public void start() {
-	if (gcache == null) {
-	    gcache = new GCacheThread(config);
-	    gcache.start();
-	}
     }
 
-    public void stop() {
-	if (gcache != null)
-	    gcache.halt();
-	gcache = null;
+    public void stop() throws Exception{
+        //TODO - Do we clear the cacheMgr??
+        connectionManager.stop();
     }
 
-    public static void main(String[] args) {
+    public static void main(String[] args) throws Exception {
+
+        Options opt = new Options();
+
+        opt.addOption("h", false, "print this message");
+        opt.addOption(OPT_CONFIG, false, "Configuration file");
+        opt.addOption(OptionBuilder.withArgName("file").hasArg().withDescription("use given file for configuration").create("c"));
+
+        BasicParser parser = new BasicParser();
+        CommandLine cl = parser.parse(opt, args);
+
+        if (cl.hasOption('h')) {
+            HelpFormatter f = new HelpFormatter();
+            f.printHelp("Options", opt);
+        }
 
+        String config = cl.getOptionValue(OPT_CONFIG);
+        GCacheManager mgr = new GCacheManager(config);
+        mgr.start();
     }
 }

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/GCacheManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/GCacheManager.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/GCacheManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/DiscoveryManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/DiscoveryManager.java?view=auto&rev=471024
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/DiscoveryManager.java (added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/DiscoveryManager.java Fri Nov  3 14:34:52 2006
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.geronimo.gcache.transports;
+
+import org.apache.geronimo.gcache.command.DiscoveryCommand;
+import org.apache.geronimo.gcache.transports.discovery.DiscoveryListener;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.*;
+
+public class DiscoveryManager implements DiscoveryListener {
+
+    private static final Log log = LogFactory.getLog(DiscoveryManager.class);
+
+    private Map index = Collections.synchronizedMap(new HashMap());
+    private Map services = Collections.synchronizedSortedMap(new TreeMap());
+    private static Long sequence = System.currentTimeMillis();
+
+    public String[] getServices() {
+        Collection c = services.values();
+        return (String[])c.toArray(new String[c.size()]);
+    }
+
+    public void onServiceAdd(DiscoveryCommand command) {
+
+        //Remove if it already exists
+        onServiceRemove(command);
+
+        long indexNo = command.getOrder();
+        if (command.getOrder() == 0) {
+            synchronized (sequence) {
+                indexNo = sequence++;
+            }
+        }
+        
+        services.put(indexNo, command.getService());
+        index.put(command.getNodeName(), indexNo);
+    }
+
+    public void onServiceRemove(DiscoveryCommand command) {
+        Long indexNo = (Long) index.get(command.getNodeName());
+        if (indexNo != null) {
+            services.remove(indexNo);
+            index.remove(command.getNodeName());
+        }
+    }
+
+}

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/DiscoveryManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/DiscoveryManager.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/DiscoveryManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/TransportService.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/TransportService.java?view=diff&rev=471024&r1=471023&r2=471024
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/TransportService.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/TransportService.java Fri Nov  3 14:34:52 2006
@@ -31,7 +31,8 @@
     public void setInfo(CacheInfoHolder info) {
         this.info = info;
     }
-    
+
+    public abstract String getService() throws Exception;
     public abstract void start() throws Exception;
     public abstract void stop() throws Exception;
 }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgent.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgent.java?view=diff&rev=471024&r1=471023&r2=471024
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgent.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgent.java Fri Nov  3 14:34:52 2006
@@ -32,7 +32,6 @@
     /**
      * register a service
      * @param name
-     * @param details
      * @throws IOException
      */
     public abstract void registerService(String name) throws IOException;
@@ -43,4 +42,8 @@
      * so that other listeners of this DiscoveryAgent can also be made aware of the failure.
      */
     public abstract void serviceFailed(DiscoveryCommand command) throws IOException;
+
+    public abstract void setNodeName(String name);
+
+    public abstract void setOrder(int order);
 }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgentFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgentFactory.java?view=diff&rev=471024&r1=471023&r2=471024
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgentFactory.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgentFactory.java Fri Nov  3 14:34:52 2006
@@ -21,6 +21,7 @@
 import java.net.URI;
 
 import org.apache.geronimo.gcache.util.FactoryFinder;
+import org.apache.geronimo.gcache.CacheInfoHolder;
 import org.apache.geronimo.openwire.util.IOExceptionSupport;
 
 import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
@@ -52,11 +53,11 @@
         return daf;
     }
     
-    public static DiscoveryAgent createDiscoveryAgent(URI uri) throws IOException {
+    public static DiscoveryAgent createDiscoveryAgent(URI uri, CacheInfoHolder info) throws IOException {
         DiscoveryAgentFactory tf = findDiscoveryAgentFactory(uri);
-        return tf.doCreateDiscoveryAgent(uri);
+        return tf.doCreateDiscoveryAgent(uri, info);
 
     }
 
-    abstract protected DiscoveryAgent doCreateDiscoveryAgent(URI uri) throws IOException;
+    abstract protected DiscoveryAgent doCreateDiscoveryAgent(URI uri, CacheInfoHolder info) throws IOException;
 }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/multicast/MulticastDiscoveryAgent.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/multicast/MulticastDiscoveryAgent.java?view=diff&rev=471024&r1=471023&r2=471024
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/multicast/MulticastDiscoveryAgent.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/multicast/MulticastDiscoveryAgent.java Fri Nov  3 14:34:52 2006
@@ -46,8 +46,8 @@
 public class MulticastDiscoveryAgent extends DiscoveryAgent implements Runnable {
 
     Log log = LogFactory.getLog(MulticastDiscoveryAgent.class);
-    
-    public static final String DEFAULT_DISCOVERY_URI_STRING="multicast://224.3.2.1:4321";
+
+    public static final String DEFAULT_DISCOVERY_URI_STRING = "multicast://224.3.2.1:4321";
 
     private static final int BUFF_SIZE = 8192;
 
@@ -72,9 +72,9 @@
     private Map nodes = new ConcurrentHashMap();
 
     private MulticastSocket mcast;
-    
+
     private InetAddress inetAddress;
-    
+
     private SocketAddress sockAddress;
 
     private int timeToLive = 1;
@@ -91,22 +91,34 @@
 
     private URI discoveryURI;
 
-    private String selfService=null;
+    private String selfService = null;
 
     private String nodeName;
-    
-    private boolean reportAdvertizeFailed=true;
+
+    private boolean reportAdvertizeFailed = true;
+
+    private int order = 0;
 
     private final Executor executor = new ThreadPoolExecutor(1, 1, 30,
-	    TimeUnit.SECONDS, new LinkedBlockingQueue(), new ThreadFactory() {
-		public Thread newThread(Runnable runable) {
-		    Thread t = new Thread(runable,
-			    "Multicast Transport Service Notifier");
-		    t.setDaemon(true);
-		    return t;
-		}
-	    });
-    
+            TimeUnit.SECONDS, new LinkedBlockingQueue(), new ThreadFactory() {
+        public Thread newThread(Runnable runable) {
+            Thread t = new Thread(runable,
+                    "Multicast Transport Service Notifier");
+            t.setDaemon(true);
+            return t;
+        }
+    });
+
+
+    public void setOrder(int order) {
+        this.order = order;
+    }
+
+    public String getService() throws Exception {
+        //The discovery agent is not a service, so return null
+        return null;
+    }
+
     public URI getDiscoveryURI() {
         return discoveryURI;
     }
@@ -116,274 +128,287 @@
     }
 
     public int getTimeToLive() {
-	return timeToLive;
+        return timeToLive;
     }
 
     public void setTimeToLive(int timeToLive) {
-	this.timeToLive = timeToLive;
+        this.timeToLive = timeToLive;
     }
 
     public long getKeepAliveInterval() {
-	return keepAliveInterval;
+        return keepAliveInterval;
     }
 
     public void setKeepAliveInterval(long keepAliveInterval) {
-	this.keepAliveInterval = keepAliveInterval;
+        this.keepAliveInterval = keepAliveInterval;
     }
 
     public boolean isLoopBackMode() {
-	return loopBackMode;
+        return loopBackMode;
     }
 
     public void setLoopBackMode(boolean loopBackMode) {
-	this.loopBackMode = loopBackMode;
+        this.loopBackMode = loopBackMode;
     }
 
     public String getGroup() {
-	return group;
+        return group;
     }
 
     public void setGroup(String group) {
-	this.group = group;
+        this.group = group;
     }
 
     public String getType() {
-	return group + "." + TYPE_SUFFIX;
+        return group + "." + TYPE_SUFFIX;
     }
 
     public String getNodeName() {
-	return nodeName;
+        return nodeName;
     }
 
     public void setNodeName(String nodeName) {
-	this.nodeName = nodeName;
+        this.nodeName = nodeName;
     }
 
     public DiscoveryListener getDiscoveryListener() {
-	return discoveryListener;
+        return discoveryListener;
     }
 
     public void setDiscoveryListener(DiscoveryListener discoveryListener) {
-	this.discoveryListener = discoveryListener;
+        this.discoveryListener = discoveryListener;
     }
 
     public void start() throws Exception {
-	if (started.compareAndSet(false, true)) {
-            if(group==null|| group.length()==0){
+        if (started.compareAndSet(false, true)) {
+            if (group == null || group.length() == 0) {
                 throw new IOException("You must specify a group to discover");
             }
-            if (nodeName == null || nodeName.length()==0){
-                log.warn("brokerName not set");
+            if (nodeName == null || nodeName.length() == 0) {
+                log.warn("nodeName not set");
             }
-            String type=getType();
-            if(!type.endsWith(".")){
-                log.warn("The type '"+type+"' should end with '.' to be a valid Discovery type");
-                type+=".";
+            String type = getType();
+            if (!type.endsWith(".")) {
+                log.warn("The type '" + type + "' should end with '.' to be a valid Discovery type");
+                type += ".";
             }
-            
-	    if(discoveryURI==null){
-                discoveryURI=new URI(DEFAULT_DISCOVERY_URI_STRING);
+
+            if ((discoveryURI == null) || discoveryURI.getHost().equals("default")) {
+                discoveryURI = new URI(DEFAULT_DISCOVERY_URI_STRING);
             }
-	    int port = discoveryURI.getPort();
-	    String host = discoveryURI.getHost();
-            
-	    this.inetAddress=InetAddress.getByName(host);
-            this.sockAddress=new InetSocketAddress(this.inetAddress,port);
+            int port = discoveryURI.getPort();
+            String host = discoveryURI.getHost();
+
+            this.inetAddress = InetAddress.getByName(host);
+            this.sockAddress = new InetSocketAddress(this.inetAddress, port);
+
+            InetSocketAddress inet = new InetSocketAddress(host, port);
+            mcast = new MulticastSocket(inet);
+            mcast.setLoopbackMode(loopBackMode);
+            mcast.setTimeToLive(timeToLive);
+            mcast.joinGroup(inet.getAddress());
+            mcast.setSoTimeout((int) keepAliveInterval);
+
+            runner = new Thread(this);
+            runner.setName("MulticastDiscovery: " + selfService);
+            runner.setDaemon(true);
+            runner.start();
             
-	    InetSocketAddress inet = new InetSocketAddress(host, port);
-	    mcast = new MulticastSocket(inet);
-	    mcast.setLoopbackMode(loopBackMode);
-	    mcast.setTimeToLive(timeToLive);
-	    mcast.joinGroup(inet.getAddress());
-	    mcast.setSoTimeout((int) keepAliveInterval);
-
-	    runner = new Thread(this);
-	    runner.setName("MulticastDiscovery: " + selfService);
-	    runner.setDaemon(true);
-	    runner.start();
-	}
+            log.info("MulticastDiscoveryAgent started on " + discoveryURI.toString());
+        }
     }
 
     public void stop() throws Exception {
-	if (started.compareAndSet(true, false)) {
-	    doAdvertizeSelf();
-	    mcast.close();
-	}
+        if (started.compareAndSet(true, false)) {
+            doAdvertizeSelf();
+            mcast.close();
+            log.info("MulticastDiscoveryAgent stopped.");
+        }
     }
 
     public void run() {
-	byte[] buf = new byte[BUFF_SIZE];
-	DatagramPacket packet = new DatagramPacket(buf, 0, buf.length);
-	while (started.get()) {
-	    doTimeKeepingServices();
-	    try {
-		mcast.receive(packet);
-		if (packet.getLength() > 0) {
-		    String str = new String(packet.getData(), packet
-			    .getOffset(), packet.getLength());
-		    processData(str);
-		}
-	    } catch (SocketTimeoutException se) {
-		// ignore
-	    } catch (IOException e) {
-		if (started.get()) {
-		    log.error("failed to process packet: " + e);
-		}
-	    }
-	}
+        byte[] buf = new byte[BUFF_SIZE];
+        DatagramPacket packet = new DatagramPacket(buf, 0, buf.length);
+        while (started.get()) {
+            doTimeKeepingServices();
+            try {
+                mcast.receive(packet);
+                if (packet.getLength() > 0) {
+                    String str = new String(packet.getData(), packet
+                            .getOffset(), packet.getLength());
+                    processData(str);
+                }
+            } catch (SocketTimeoutException se) {
+                // ignore
+            } catch (IOException e) {
+                if (started.get()) {
+                    log.error("failed to process packet: " + e);
+                }
+            }
+        }
     }
 
     private void doTimeKeepingServices() {
-	if (started.get()) {
-	    long currentTime = System.currentTimeMillis();
-	    if ((currentTime - keepAliveInterval) > lastAdvertizeTime) {
-		doAdvertizeSelf();
-		lastAdvertizeTime = currentTime;
-	    }
-	    doExpireOldServices();
-	}
+        if (started.get()) {
+            long currentTime = System.currentTimeMillis();
+            if ((currentTime - keepAliveInterval) > lastAdvertizeTime) {
+                doAdvertizeSelf();
+                lastAdvertizeTime = currentTime;
+            }
+            doExpireOldServices();
+        }
     }
 
     private void doAdvertizeSelf() {
-	if (selfService != null) {
-	    String payload = getType();
-	    payload += started.get() ? ALIVE : DEAD;
-	    payload += DELIMITER + nodeName + DELIMITER;
-	    payload += selfService;
-	    try {
-		byte[] data = payload.getBytes();
-		DatagramPacket packet = new DatagramPacket(data, 0,
-			data.length, sockAddress);
-		mcast.send(packet);
-	    } catch (IOException e) {
-		// If a send fails, chances are all subsequent sends will fail too.. No need to keep reporting the
-		// same error over and over.
-		if (reportAdvertizeFailed) {
-		    reportAdvertizeFailed = false;
-		    log.error("Failed to advertise our service: " + payload, e);
-		    if ("Operation not permitted".equals(e.getMessage())) {
-			log.error("The 'Operation not permitted' error has been know to be caused by improper firewall/network setup.  Please make sure that the OS is properly configured to allow multicast traffic over: "
-					+ mcast.getLocalAddress());
-		    }
-		}
-	    }
-	}
+        if (selfService != null) {
+            String payload = getType();
+            payload += started.get() ? ALIVE : DEAD;
+            payload += DELIMITER + order;
+            payload += DELIMITER + nodeName + DELIMITER;
+            payload += selfService;
+            try {
+                byte[] data = payload.getBytes();
+                DatagramPacket packet = new DatagramPacket(data, 0,
+                        data.length, sockAddress);
+                mcast.send(packet);
+            } catch (IOException e) {
+                // If a send fails, chances are all subsequent sends will fail too.. No need to keep reporting the
+                // same error over and over.
+                if (reportAdvertizeFailed) {
+                    reportAdvertizeFailed = false;
+                    log.error("Failed to advertise our service: " + payload, e);
+                    if ("Operation not permitted".equals(e.getMessage())) {
+                        log.error("The 'Operation not permitted' error has been know to be caused by improper firewall/network setup.  Please make sure that the OS is properly configured to allow multicast traffic over: "
+                                + mcast.getLocalAddress());
+                    }
+                }
+            }
+        }
     }
 
     private void doExpireOldServices() {
-	long expireTime = System.currentTimeMillis()
-		- (keepAliveInterval * HEARTBEAT_MISS_BEFORE_DEATH);
-	for (Iterator i = services.entrySet().iterator(); i.hasNext();) {
-	    Map.Entry entry = (Map.Entry) i.next();
-	    AtomicLong lastHeartBeat = (AtomicLong) entry.getValue();
-	    if (lastHeartBeat.get() < expireTime) {
-		String nodeName = (String) nodes.get(entry.getKey());
-		processDead(nodeName, entry.getKey().toString());
-	    }
-	}
+        long expireTime = System.currentTimeMillis()
+                - (keepAliveInterval * HEARTBEAT_MISS_BEFORE_DEATH);
+        for (Iterator i = services.entrySet().iterator(); i.hasNext();) {
+            Map.Entry entry = (Map.Entry) i.next();
+            AtomicLong lastHeartBeat = (AtomicLong) entry.getValue();
+            if (lastHeartBeat.get() < expireTime) {
+                String nodeName = (String) nodes.get(entry.getKey());
+                processDead(nodeName, entry.getKey().toString());
+            }
+        }
     }
 
     private void processData(String str) {
-	if (discoveryListener != null) {
-	    if (str.startsWith(getType())) {
-		String payload = str.substring(getType().length());
-		if (payload.startsWith(ALIVE)) {
-		    String nodeName = getNodeName(payload.substring(ALIVE
-			    .length()));
-		    String service = payload.substring(ALIVE.length()
-			    + nodeName.length() + 2);
-		    if (!nodeName.equals(this.nodeName)) {
-			processAlive(nodeName, service);
-		    }
-		} else {
-		    String nodeName = getNodeName(payload.substring(DEAD
-			    .length()));
-		    String service = payload.substring(DEAD.length()
-			    + nodeName.length() + 2);
-		    if (!nodeName.equals(this.nodeName)) {
-			processDead(nodeName, service);
-		    }
-		}
-	    }
-	}
+        if (discoveryListener != null) {
+            if (str.startsWith(getType())) {
+                String payload = str.substring(getType().length());
+                if (payload.startsWith(ALIVE)) {
+                    String order = getOrder(payload.substring(ALIVE.length()));
+                    String nodeName = getNodeName(payload.substring(ALIVE.length() + order.length() + 1));
+                    String service = payload.substring(ALIVE.length() + order.length() + nodeName.length() + 3);
+                    if (!nodeName.equals(this.nodeName)) {
+                        processAlive(order, nodeName, service);
+                    }
+                } else {
+                    String order = getOrder(payload.substring(DEAD.length()));
+                    String nodeName = getNodeName(payload.substring(DEAD.length() + order.length() + 1));
+                    String service = payload.substring(DEAD.length() + order.length() + nodeName.length() + 3);
+                    if (!nodeName.equals(this.nodeName)) {
+                        processDead(nodeName, service);
+                    }
+                }
+            }
+        }
     }
 
     @SuppressWarnings("unchecked")
-    private void processAlive(String nodeName, String service) {
-	if (selfService == null || !service.equals(selfService)) {
-	    AtomicLong lastKeepAlive = (AtomicLong) services.get(service);
-	    if (lastKeepAlive == null) {
-		nodes.put(service, nodeName);
-		if (discoveryListener != null) {
-		    final DiscoveryCommand event = new DiscoveryCommand();
-		    event.setService(service);
-		    event.setNodeName(nodeName);
-
-		    // Have the listener process the event async so that 
-		    // he does not block this thread since we are doing time sensitive
-		    // processing of events.
-		    executor.execute(new Runnable() {
-			public void run() {
-			    DiscoveryListener discoveryListener = MulticastDiscoveryAgent.this.discoveryListener;
-			    if (discoveryListener != null) {
-				discoveryListener.onServiceAdd(event);
-			    }
-			}
-		    });
-		}
-		lastKeepAlive = new AtomicLong(System.currentTimeMillis());
-		services.put(service, lastKeepAlive);
-		doAdvertizeSelf();
-
-	    }
-	    lastKeepAlive.set(System.currentTimeMillis());
-	}
+    private void processAlive(String order, String nodeName, String service) {
+        if (selfService == null || !service.equals(selfService)) {
+            AtomicLong lastKeepAlive = (AtomicLong) services.get(service);
+            if (lastKeepAlive == null) {
+                nodes.put(service, nodeName);
+                if (discoveryListener != null) {
+                    final DiscoveryCommand event = new DiscoveryCommand();
+                    event.setService(service);
+                    event.setNodeName(nodeName);
+                    event.setOrder(Integer.parseInt(order));
+
+                    // Have the listener process the event async so that
+                    // he does not block this thread since we are doing time sensitive
+                    // processing of events.
+                    executor.execute(new Runnable() {
+                        public void run() {
+                            DiscoveryListener discoveryListener = MulticastDiscoveryAgent.this.discoveryListener;
+                            if (discoveryListener != null) {
+                                discoveryListener.onServiceAdd(event);
+                            }
+                        }
+                    });
+                }
+                lastKeepAlive = new AtomicLong(System.currentTimeMillis());
+                services.put(service, lastKeepAlive);
+                doAdvertizeSelf();
+
+            }
+            lastKeepAlive.set(System.currentTimeMillis());
+        }
     }
 
     private void processDead(String brokerName, String service) {
-	if (!service.equals(selfService)) {
-	    if (services.remove(service) != null) {
-		nodes.remove(service);
-		if (discoveryListener != null) {
-		    final DiscoveryCommand event = new DiscoveryCommand();
-		    event.setService(service);
-		    event.setNodeName(brokerName);
-
-		    // Have the listener process the event async so that 
-		    // he does not block this thread since we are doing time sensitive
-		    // processing of events.
-		    executor.execute(new Runnable() {
-			public void run() {
-			    DiscoveryListener discoveryListener = MulticastDiscoveryAgent.this.discoveryListener;
-			    if (discoveryListener != null) {
-				discoveryListener.onServiceRemove(event);
-			    }
-			}
-		    });
-		}
-	    }
-	}
+        if (!service.equals(selfService)) {
+            if (services.remove(service) != null) {
+                nodes.remove(service);
+                if (discoveryListener != null) {
+                    final DiscoveryCommand event = new DiscoveryCommand();
+                    event.setService(service);
+                    event.setNodeName(brokerName);
+
+                    // Have the listener process the event async so that
+                    // he does not block this thread since we are doing time sensitive
+                    // processing of events.
+                    executor.execute(new Runnable() {
+                        public void run() {
+                            DiscoveryListener discoveryListener = MulticastDiscoveryAgent.this.discoveryListener;
+                            if (discoveryListener != null) {
+                                discoveryListener.onServiceRemove(event);
+                            }
+                        }
+                    });
+                }
+            }
+        }
     }
 
     public void registerService(String name) throws IOException {
-	this.selfService = name;
-	if (started.get()) {
-	    doAdvertizeSelf();
-	}
+        this.selfService = name;
+        if (started.get()) {
+            doAdvertizeSelf();
+        }
     }
 
     public void serviceFailed(DiscoveryCommand command) throws IOException {
-	processDead(command.getNodeName(), command.getService());
+        processDead(command.getNodeName(), command.getService());
     }
 
     private String getNodeName(String str) {
-	String result = null;
-	int start = str.indexOf(DELIMITER);
-	if (start >= 0) {
-	    int end = str.indexOf(DELIMITER, start + 1);
-	    result = str.substring(start + 1, end);
-	}
-	return result;
+        String result = null;
+        int start = str.indexOf(DELIMITER);
+        if (start >= 0) {
+            int end = str.indexOf(DELIMITER, start + 1);
+            result = str.substring(start + 1, end);
+        }
+        return result;
+    }
+
+    private String getOrder(String str) {
+        String result = null;
+        int start = str.indexOf(DELIMITER);
+        if (start >= 0) {
+            int end = str.indexOf(DELIMITER, start + 1);
+            result = str.substring(start + 1, end);
+        }
+        return result;
     }
 
 }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/multicast/MulticastDiscoveryAgentFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/multicast/MulticastDiscoveryAgentFactory.java?view=diff&rev=471024&r1=471023&r2=471024
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/multicast/MulticastDiscoveryAgentFactory.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/multicast/MulticastDiscoveryAgentFactory.java Fri Nov  3 14:34:52 2006
@@ -23,19 +23,22 @@
 
 import org.apache.geronimo.gcache.transports.discovery.DiscoveryAgent;
 import org.apache.geronimo.gcache.transports.discovery.DiscoveryAgentFactory;
+import org.apache.geronimo.gcache.transports.DiscoveryManager;
 import org.apache.geronimo.gcache.util.IOExceptionSupport;
 import org.apache.geronimo.gcache.util.IntrospectionSupport;
 import org.apache.geronimo.gcache.util.URISupport;
+import org.apache.geronimo.gcache.CacheInfoHolder;
 
 public class MulticastDiscoveryAgentFactory extends DiscoveryAgentFactory {
 
     @Override
-    protected DiscoveryAgent doCreateDiscoveryAgent(URI uri) throws IOException {
+    protected DiscoveryAgent doCreateDiscoveryAgent(URI uri, CacheInfoHolder info) throws IOException {
         try {
             
             Map options = URISupport.parseParamters(uri);
             MulticastDiscoveryAgent rc = new MulticastDiscoveryAgent();
             rc.setGroup(uri.getHost());
+            rc.setDiscoveryListener(info.getDiscoveryManager());
             IntrospectionSupport.setProperties(rc, options);
             return rc;
             

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/network/ConnectionManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/network/ConnectionManager.java?view=auto&rev=471024
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/network/ConnectionManager.java (added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/network/ConnectionManager.java Fri Nov  3 14:34:52 2006
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.geronimo.gcache.transports.network;
+
+import org.apache.geronimo.gcache.transports.TransportService;
+import org.apache.geronimo.gcache.transports.TransportFactory;
+import org.apache.geronimo.gcache.transports.discovery.DiscoveryAgent;
+import org.apache.geronimo.gcache.transports.discovery.DiscoveryAgentFactory;
+import org.apache.geronimo.gcache.CacheInfoHolder;
+
+import java.net.URI;
+
+public class ConnectionManager{
+
+    private CacheInfoHolder info;
+    private URI transportURI;
+    private URI discoveryURI;
+    private TransportService transport;
+    private DiscoveryAgent discovery;
+    private String nodeName;
+    private int order;
+
+    public ConnectionManager(CacheInfoHolder info){
+        this.info = info;
+    }
+
+    public void start() throws Exception {
+        transport = TransportFactory.createTransportService(transportURI, info);
+        if (discoveryURI != null){
+            discovery = DiscoveryAgentFactory.createDiscoveryAgent(discoveryURI, info);
+            discovery.registerService(transport.getService());
+            discovery.setNodeName(nodeName);
+            discovery.setOrder(order);
+        }
+
+        transport.start();
+
+        if (discovery != null)
+            discovery.start();
+    }
+
+    public void stop() throws Exception {
+
+        if (discovery != null)
+            discovery.stop();
+
+        if (transport != null){
+            transport.stop();
+        }
+    }
+
+    public void setTransportURI(URI transportURI) {
+        this.transportURI = transportURI;
+    }
+
+    public void setDiscoveryURI(URI discoveryURI) {
+        this.discoveryURI = discoveryURI;
+    }
+
+    public void setNodeName(String nodeName) {
+        this.nodeName = nodeName;
+    }
+
+    public void setOrder(int order) {
+        this.order = order;
+    }
+}

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/network/ConnectionManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/network/ConnectionManager.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/network/ConnectionManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketTransportService.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketTransportService.java?view=diff&rev=471024&r1=471023&r2=471024
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketTransportService.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketTransportService.java Fri Nov  3 14:34:52 2006
@@ -18,6 +18,7 @@
 
 import java.net.InetSocketAddress;
 import java.net.URI;
+import java.net.InetAddress;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -29,14 +30,15 @@
 import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
 
 public class TCPSocketTransportService extends TransportService {
-    
+
     private final static Log log = LogFactory.getLog(TCPSocketTransportService.class);
-    
+
+    public static final int DEFAULT_PORT = 4123;
     public static final long DEFAULT_ACK_TIMEOUT = 10000;
     public final static String DEFAULT_USERNAME = "system";
     public final static String DEFAULT_PASSWORD = "manager";
-    
-    IoAcceptor acceptor = null; 
+
+    IoAcceptor acceptor = null;
     private URI tcpURI;
     private boolean requireMessageAck = false;
     private boolean enableLogging = false;
@@ -45,12 +47,34 @@
     private String userId = DEFAULT_USERNAME;
     private String password = DEFAULT_PASSWORD;
 
+    public String getService() throws Exception{
+        if (tcpURI == null){
+            throw new Exception("TCP URI has not been set.");
+        }
+
+        String host = tcpURI.getHost();
+        if (host.equals("0.0.0.0")){
+            host = InetAddress.getLocalHost().getHostAddress().toString();
+        }
+        return tcpURI.getScheme() + "://" + host + ":" + tcpURI.getPort();
+    }
+
     public URI getTcpURI() {
         return tcpURI;
     }
 
-    public void setTcpURI(URI tcpURI) {
-        this.tcpURI = tcpURI;
+    public void setTcpURI(URI tcpURI) throws Exception{
+        int port = tcpURI.getPort();
+        if (port == -1){
+            port = DEFAULT_PORT;
+        }
+        if (tcpURI.getHost().equals("default")){
+            String query = tcpURI.getQuery();
+            String uri = tcpURI.getScheme() + "://" + "0.0.0.0" + ":" + port + (query == null ? "" : "?" + query); 
+            this.tcpURI = new URI(uri);
+        } else {
+            this.tcpURI = tcpURI;
+        }
     }
 
     public String getPassword() {
@@ -94,54 +118,54 @@
     }
 
     public void start() throws Exception {
-	int port = tcpURI.getPort();
-	String host = tcpURI.getHost();
+        int port = tcpURI.getPort();
+        String host = tcpURI.getHost();
+
+        InetSocketAddress inet = new InetSocketAddress(host, port);
 
-	InetSocketAddress inet = new InetSocketAddress(host, port);
-	
-	acceptor = new SocketAcceptor();
+        acceptor = new SocketAcceptor();
         SocketAcceptorConfig cfg = new SocketAcceptorConfig();
-        cfg.setReuseAddress( true );
-        
-	//If we requested logging, add that too
-        if (enableLogging){
-            cfg.getFilterChain().addLast( "logFilter", new LoggingFilter() );
+        cfg.setReuseAddress(true);
+
+        //If we requested logging, add that too
+        if (enableLogging) {
+            cfg.getFilterChain().addLast("logFilter", new LoggingFilter());
         }
-        
+
         //Add the filter to hande the GCache Codec
-        cfg.getFilterChain().addLast( "protocolFilter", new ProtocolCodecFilter( new TCPCommandProtocolCodecFactory() ) );
-        
-        //Add teh authentication filter
-	cfg.getFilterChain().addLast(TCPAuthenticationFilter.NAME, new TCPAuthenticationFilter(userId, password));
-	
+        cfg.getFilterChain().addLast("protocolFilter", new ProtocolCodecFilter(new TCPCommandProtocolCodecFactory()));
+
+        //Add the authentication filter
+        cfg.getFilterChain().addLast(TCPAuthenticationFilter.NAME, new TCPAuthenticationFilter(userId, password));
+
         //Add the BulkCommandFilter for filtering when a BulkCommand is being read
-        cfg.getFilterChain().addLast( TCPBulkCommandFilter.NAME, new TCPBulkCommandFilter() );
-        
+        cfg.getFilterChain().addLast(TCPBulkCommandFilter.NAME, new TCPBulkCommandFilter());
+
         //If we require message acks, then set up the message ack filter
-	if (requireMessageAck){
-	    cfg.getFilterChain().addLast(TCPMessageAckCommandFilter.NAME, new TCPMessageAckCommandFilter(ackTimeout));
-	}        
-	
-	
+        if (requireMessageAck) {
+            cfg.getFilterChain().addLast(TCPMessageAckCommandFilter.NAME, new TCPMessageAckCommandFilter(ackTimeout));
+        }
+
+
         handler = new TCPSocketHandler(info);
-        acceptor.bind( inet, handler, cfg );
+        acceptor.bind(inet, handler, cfg);
     }
 
     public void stop() throws Exception {
-	
-	if (handler != null){
-	    try {
-		handler.destroy();
-		handler = null;
-	    } catch (Exception e) {
-		log.error(e);
-		//Ignore since there is not much that can be done
-	    }
-	}
-	if (acceptor != null){
-	    acceptor.unbindAll();
-	    acceptor = null;
-	}
+
+        if (handler != null) {
+            try {
+                handler.destroy();
+                handler = null;
+            } catch (Exception e) {
+                log.error(e);
+                //Ignore since there is not much that can be done
+            }
+        }
+        if (acceptor != null) {
+            acceptor.unbindAll();
+            acceptor = null;
+        }
     }
 
 }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketTransportServiceFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketTransportServiceFactory.java?view=diff&rev=471024&r1=471023&r2=471024
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketTransportServiceFactory.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketTransportServiceFactory.java Fri Nov  3 14:34:52 2006
@@ -37,6 +37,10 @@
             
             Map options = URISupport.parseParamters(uri);
             TCPSocketTransportService rc = new TCPSocketTransportService();
+
+            //Set a proper notifier
+            info.setCacheNotifier(new TCPCacheNotifier());
+            
             rc.setInfo(info);
             rc.setTcpURI(uri);
             IntrospectionSupport.setProperties(rc, options);

Modified: geronimo/sandbox/gcache/server/src/main/xsd/gcache.xsd
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/xsd/gcache.xsd?view=diff&rev=471024&r1=471023&r2=471024
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/xsd/gcache.xsd (original)
+++ geronimo/sandbox/gcache/server/src/main/xsd/gcache.xsd Fri Nov  3 14:34:52 2006
@@ -22,10 +22,10 @@
 			<xs:element name="transport" type="gcache:transportType" />
 		</xs:sequence>
 		<xs:attribute name="serverName" use="required" type="xs:NCName" />
-		<xs:attribute name="order" use="required">
+		<xs:attribute name="order" use="optional" default="0">
 			<xs:simpleType>
 				<xs:restriction base="xs:int">
-					<xs:minInclusive value="1" />
+					<xs:minInclusive value="0" />
 				</xs:restriction>
 			</xs:simpleType>
 		</xs:attribute>

Added: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/server/GCacheManagerTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/server/GCacheManagerTest.java?view=auto&rev=471024
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/server/GCacheManagerTest.java (added)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/server/GCacheManagerTest.java Fri Nov  3 14:34:52 2006
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.geronimo.gcache.server;
+
+import org.testng.annotations.Test;
+
+public class GCacheManagerTest {
+
+    @Test
+    public void testGCacheManager() throws Exception{
+
+        GCacheManager mgr = new GCacheManager(null);
+
+        mgr.start();
+
+        mgr.stop();
+    }
+}

Propchange: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/server/GCacheManagerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/server/GCacheManagerTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/server/GCacheManagerTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/discovery/multicast/MulticastDiscoveryAgentTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/discovery/multicast/MulticastDiscoveryAgentTest.java?view=diff&rev=471024&r1=471023&r2=471024
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/discovery/multicast/MulticastDiscoveryAgentTest.java (original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/discovery/multicast/MulticastDiscoveryAgentTest.java Fri Nov  3 14:34:52 2006
@@ -26,66 +26,118 @@
 import org.apache.geronimo.gcache.command.DiscoveryCommand;
 import org.apache.geronimo.gcache.transports.discovery.DiscoveryAgentFactory;
 import org.apache.geronimo.gcache.transports.discovery.DiscoveryListener;
+import org.apache.geronimo.gcache.CacheInfoHolder;
 import org.testng.annotations.Test;
 
 public class MulticastDiscoveryAgentTest {
-    
+
     private static Log log = LogFactory.getLog(MulticastDiscoveryAgentTest.class);
-    
+
     Set<String> add = new HashSet<String>();
     Set<String> remove = new HashSet<String>();
-    
+
+    @Test
+    public void testMulticastDiscoveryAgent() throws Exception {
+
+        String multicast = "multicast://224.1.2.3:4123";
+        String nodeName1 = "node1";
+        String nodeName2 = "node2";
+        String multicastURI1 = multicast + "?nodeName=" + nodeName1;
+        String multicastURI2 = multicast + "?nodeName=" + nodeName2;
+        String service1 = "tcp://localhost:1234";
+        String service2 = "tcp://localhost:5432";
+
+        CacheInfoHolder info = new CacheInfoHolder(null);
+
+        //Startup first agent
+        log.debug("Creating first agent for " + multicastURI1);
+        MulticastDiscoveryAgent agent = (MulticastDiscoveryAgent) DiscoveryAgentFactory.createDiscoveryAgent(new URI(multicastURI1), info);
+        agent.registerService(service1);
+        agent.setDiscoveryListener(new Listener());
+
+        //Startup second agent
+        log.debug("Creating second agent for " + multicastURI2);
+        MulticastDiscoveryAgent agent2 = (MulticastDiscoveryAgent) DiscoveryAgentFactory.createDiscoveryAgent(new URI(multicastURI2), info);
+        agent2.registerService(service2);
+        agent2.setDiscoveryListener(new Listener());
+
+        agent.start();
+        agent2.start();
+
+        Thread.sleep(1500);
+        
+        agent2.stop();
+
+        Thread.sleep(500);
+
+        agent.stop();
+
+        assert add.contains(nodeName1);
+        assert add.contains(nodeName2);
+        assert remove.contains(nodeName2);
+    }
+
     @Test
-    public void testMulticastDiscoveryAgent() throws Exception{
-	
-	String multicast = "multicast://224.1.2.3:4123";
-	String nodeName1 = "node1";
-	String nodeName2 = "node2";
-	String multicastURI1 =  multicast + "?nodeName=" + nodeName1;
-	String multicastURI2 =  multicast + "?nodeName=" + nodeName2;
-	String service1 = "tcp://localhost:1234";
-	String service2 = "tcp://localhost:5432";
-	
-	//Startup first agent
-	log.debug("Creating first agent for " + multicastURI1);
-	MulticastDiscoveryAgent agent = (MulticastDiscoveryAgent)DiscoveryAgentFactory.createDiscoveryAgent(new URI(multicastURI1));
-	agent.registerService(service1);
-	agent.setDiscoveryListener(new Listener());
-	
-	//Startup second agent
-	log.debug("Creating second agent for " + multicastURI2);
-	MulticastDiscoveryAgent agent2 = (MulticastDiscoveryAgent)DiscoveryAgentFactory.createDiscoveryAgent(new URI(multicastURI2));
-	agent2.registerService(service2);
-	agent2.setDiscoveryListener(new Listener());
-	
-	agent.start();
-	agent2.start();
-	
-	Thread.sleep(1500);
-	
-	agent2.stop();
-	
-	Thread.sleep(500);
-	
-	agent.stop();
-	
-	assert add.contains(nodeName1);
-	assert add.contains(nodeName2);
-	assert remove.contains(nodeName2);
+    public void testMulticastDiscoveryManager() throws Exception {
+
+        String multicast = "multicast://224.1.2.3:4123";
+        String nodeName1 = "node1";
+        String nodeName2 = "node2";
+        String service1 = "tcp://localhost:1234";
+        String service2 = "tcp://localhost:5432";
+
+        //We will use the same CacheInfoHolder here to use the same DiscoveryManager
+        //This would not normally ever be done, but it tests multipl adds/removals
+        CacheInfoHolder info = new CacheInfoHolder(null);
+
+        //Startup first agent
+        log.debug("Creating first agent for " + nodeName1);
+        MulticastDiscoveryAgent agent = (MulticastDiscoveryAgent) DiscoveryAgentFactory.createDiscoveryAgent(new URI(multicast), info);
+        agent.registerService(service1);
+        agent.setNodeName(nodeName1);
+        agent.setOrder(2);
+
+        //Startup second agent
+        log.debug("Creating second agent for " + nodeName2);
+        MulticastDiscoveryAgent agent2 = (MulticastDiscoveryAgent) DiscoveryAgentFactory.createDiscoveryAgent(new URI(multicast), info);
+        agent2.registerService(service2);
+        agent2.setNodeName(nodeName2);
+        agent2.setOrder(1);
+
+        agent.start();
+        agent2.start();
+
+        Thread.sleep(1500);
+
+        String services[] = info.getDiscoveryManager().getServices();
+        assert services.length == 2;
+        assert services[0].equals(service2);
+        assert services[1].equals(service1);
+
+        agent2.stop();
+
+        Thread.sleep(500);
+
+        services = info.getDiscoveryManager().getServices();
+        assert services.length == 1;
+        assert services[0].equals(service1);
+
+        agent.stop();
+
     }
-    
-    class Listener implements DiscoveryListener{
 
-	public void onServiceAdd(DiscoveryCommand command) {
-	    log.debug("Node Found!!! Adding node for " + command.getNodeName() + " service=" + command.getService());
-	    add.add(command.getNodeName());
-	}
-
-	public void onServiceRemove(DiscoveryCommand command) {
-	    log.debug("Node lost!!! Removing node for " + command.getNodeName() + " service=" + command.getService());
-	    remove.add(command.getNodeName());
-	}
-	
+    class Listener implements DiscoveryListener {
+
+        public void onServiceAdd(DiscoveryCommand command) {
+            log.debug("Node Found!!! Adding node for " + command.getNodeName() + " service=" + command.getService());
+            add.add(command.getNodeName());
+        }
+
+        public void onServiceRemove(DiscoveryCommand command) {
+            log.debug("Node lost!!! Removing node for " + command.getNodeName() + " service=" + command.getService());
+            remove.add(command.getNodeName());
+        }
+
     }
 
 }

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/AbstractService.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/AbstractService.java?view=diff&rev=471024&r1=471023&r2=471024
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/AbstractService.java (original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/AbstractService.java Fri Nov  3 14:34:52 2006
@@ -39,7 +39,8 @@
 import org.testng.annotations.BeforeClass;
 
 public abstract class AbstractService {
-    protected String protocol = "tcp://localhost:45678";
+    //protected String protocol = "tcp://localhost:45678";
+    protected String protocol = "tcp://default?enableLogging=true";
 
     protected TCPSocketTransportService server = null;
 
@@ -53,10 +54,9 @@
     public void setUp() throws Exception {
         CacheManager mgr = CacheManager.create();
         info = new CacheInfoHolder(mgr);
-        info.setCacheNotifier(new TCPCacheNotifier());
 
         URI uri = new URI(protocol);
-        
+
         server = (TCPSocketTransportService)TCPSocketTransportServiceFactory.createTransportService(uri, info);
         
         server.setAckTimeout(10000);
@@ -65,15 +65,18 @@
 
         server.start();
 
+        String service = server.getService();
+        URI serviceURI = new URI(service);
+
         //Create a client socket
         client = new Socket();
-        client.connect(new InetSocketAddress(uri.getHost(), uri.getPort()),
+        client.connect(new InetSocketAddress(serviceURI.getHost(), serviceURI.getPort()),
                 2000);
         authenticate(client);
 
         //Create a second client socket
         client2 = new Socket();
-        client2.connect(new InetSocketAddress(uri.getHost(), uri.getPort()),
+        client2.connect(new InetSocketAddress(serviceURI.getHost(), serviceURI.getPort()),
                 2000);
         authenticate(client2);
     }



Mime
View raw message