geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r508252 - in /geronimo/sandbox/gcache: client/src/main/java/org/apache/geronimo/gcache/client/ client/src/main/java/org/apache/geronimo/gcache/transports/ client/src/main/java/org/apache/geronimo/gcache/transports/tcp/ client/src/test/java/...
Date Fri, 16 Feb 2007 00:31:59 GMT
Author: jgenender
Date: Thu Feb 15 16:31:57 2007
New Revision: 508252

URL: http://svn.apache.org/viewvc?view=rev&rev=508252
Log:
Client talking to server

Added:
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransportService.java
      - copied, changed from r491952, geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransport.java
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/DisconnectionException.java
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPReceiverFuture.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/AuthSuccessfulCommand.java
    geronimo/sandbox/gcache/tests/src/test/java/org/apache/geronimo/gcache/transports/
    geronimo/sandbox/gcache/tests/src/test/java/org/apache/geronimo/gcache/transports/tcp/
    geronimo/sandbox/gcache/tests/src/test/java/org/apache/geronimo/gcache/transports/tcp/AuthenticationTest.java
Removed:
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransport.java
Modified:
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/GCacheClient.java
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientConnectionManager.java
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransportFactory.java
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketHandler.java
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportService.java
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportServiceFactory.java
    geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportServiceFactoryTest.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/LockAcquiredCommand.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/LockReleasedCommand.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/MessageAckCommand.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/BaseCommandVisitor.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPAuthenticationFilter.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandRequestDecoder.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandRequestEncoder.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPMessageAckCommandFilter.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketHandler.java
    geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/MessageAckCommandTest.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandVisitor.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/server/GCacheManagerTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketServiceTest.java
    geronimo/sandbox/gcache/tests/pom.xml
    geronimo/sandbox/gcache/tests/src/test/java/org/apache/geronimo/gcache/AbstractParent.java
    geronimo/sandbox/gcache/tests/src/test/resources/gcache-server-config.xml

Modified: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/GCacheClient.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/GCacheClient.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/GCacheClient.java (original)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/GCacheClient.java Thu Feb 15 16:31:57 2007
@@ -53,6 +53,8 @@
         
         connectionManager = new ClientConnectionManager(info);
         connectionManager.setDiscoveryURI(config.getDiscoveryUri());
+        connectionManager.setUserName(config.getUser());
+        connectionManager.setPassword(config.getPassword());
         connectionManager.start();
 
     }
@@ -62,7 +64,6 @@
     }
 
     public void put(String session, Object key, Object value) {
-
     }
 
     public void get(String session, Object key) {
@@ -70,6 +71,15 @@
     }
 
     public void remove(String session, Object key) {
+
+    }
+    
+    public void lock(String session, Object key) {
+        connectionManager.waitForConnection();
+        //TODO: Add lock calls here
+    }
+    
+    public void release(String session, Object key) {
 
     }
 

Modified: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientConnectionManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientConnectionManager.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientConnectionManager.java (original)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientConnectionManager.java Thu Feb 15 16:31:57 2007
@@ -18,8 +18,10 @@
  */
 package org.apache.geronimo.gcache.transports;
 
+import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -27,11 +29,17 @@
 import org.apache.geronimo.gcache.transports.discovery.DiscoveryAgentFactory;
 
 public class ClientConnectionManager extends ConnectionManager {
-    
+
     private static Log log = LogFactory.getLog(ClientConnectionManager.class);
 
     private boolean stopped = true;
 
+    AtomicBoolean connected = new AtomicBoolean(false);
+    
+    private Object connectionLatch = new Object();
+
+    private ConnectionMonitor monitor;
+
     public ClientConnectionManager(CacheInfoHolder info) {
         super(info);
     }
@@ -48,6 +56,9 @@
         if (discovery != null)
             discovery.start();
 
+        monitor = new ConnectionMonitor(this);
+        monitor.start();
+
     }
 
     @Override
@@ -55,12 +66,41 @@
 
         stopped = true;
 
+        // Shut down the connection monitor
+        monitor.signal();
+
         if (discovery != null)
             discovery.stop();
 
+        if (transport != null) {
+            transport.stop();
+        }
+
+    }
+
+    public boolean isConnected() {
+        return connected.get();
     }
 
-    private void connectToServer() throws Exception {
+    public void waitForConnection() {
+        if (!isConnected()) {
+            try {
+                synchronized(connectionLatch){
+                    connectionLatch.wait();
+                }
+            } catch (InterruptedException e) {
+                log.error(e);
+            }
+        }
+    }
+
+    public void onDisconnect() throws Exception {
+        // Signal the monitor to get a connection
+        connected.set(false);
+        monitor.signal();
+    }
+
+    private void connectToServer() {
         DiscoveryManager disc = info.getDiscoveryManager();
         while (!stopped) {
             String services[] = disc.getServices();
@@ -71,8 +111,8 @@
                 sleeper(1000);
                 continue;
             }
-            
-            //TODO - We need to identify the master here!!!!
+
+            // TODO - We need to identify the master here!!!!
 
             // Ok, we have some servers, lets go for the first one in line
             URI uri = null;
@@ -86,14 +126,59 @@
                 // And try again
                 continue;
             }
-            
+
             transportURI = uri;
-            transport = ClientTransportFactory.createTransportService(transportURI, info);
+            try {
+                if (log.isDebugEnabled()) {
+                    log.debug("Attempting to connect client to " + transportURI.toASCIIString());
+                }
+                transport = ClientTransportFactory.createTransportService(transportURI, info, this);
+            } catch (IOException e) {
+                transport = null;
+                log.error(e);
+                // Take a nap
+                sleeper(1000);
+                // And try again
+                continue;
+            }
             transport.setUserName(userName);
             transport.setPassword(password);
-            
-            transport.start();
-            
+
+            try {
+                transport.start();
+                int tries = 0;
+
+                // Try to connect 3 times
+                while (!((ClientTransportService) transport).connect()) {
+                    if (tries++ > 2)
+                        break;
+                    sleeper(500);
+                }
+                if (tries > 2) {
+                    log.error("Unable to connect to " + transportURI);
+                    continue;
+                }
+
+                // Now authenticate
+                if (!((ClientTransportService) transport).join()) {
+                    log.error("Unable to authenticate to " + transportURI.toASCIIString());
+                    continue;
+                }
+                
+                connected.set(true);
+                synchronized(connectionLatch){
+                    connectionLatch.notifyAll();
+                }
+                
+            } catch (Exception e) {
+                transport = null;
+                log.error(e);
+                // Take a nap
+                sleeper(1000);
+                // And try again
+                continue;
+            }
+
             return;
 
         }
@@ -106,6 +191,52 @@
             // This really should not ever happen
             log.error(e);
         }
+    }
+
+    class ConnectionMonitor extends Thread {
+        private Object monitor = new Object();
+
+        private ClientConnectionManager mgr;
+
+        public ConnectionMonitor(ClientConnectionManager mgr) {
+            super();
+            this.mgr = mgr;
+        }
+
+        public void signal() {
+            // Shut down the old transport
+            if (transport != null) {
+                try {
+                    transport.stop();
+                } catch (Exception e) {
+                    log.error(e);
+                }
+            }
+
+            // Signal the monitor to reconnect
+            synchronized (monitor) {
+                monitor.notify();
+            }
+        }
+
+        @Override
+        public void run() {
+            do {
+                mgr.connectToServer();
+
+                synchronized (monitor) {
+                    try {
+                        monitor.wait();
+                    } catch (InterruptedException e) {
+                        // We are done
+                        return;
+                    }
+                }
+
+            } while (!stopped);
+
+        }
+
     }
 
 }

Modified: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransportFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransportFactory.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransportFactory.java (original)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransportFactory.java Thu Feb 15 16:31:57 2007
@@ -54,12 +54,12 @@
             return tf;
         }
         
-        public static TransportService createTransportService(URI uri, CacheInfoHolder info) throws IOException {
+        public static TransportService createTransportService(URI uri, CacheInfoHolder info, ClientConnectionManager connectionManager) throws IOException{
             ClientTransportFactory tf = findTransportFactory(uri);
-            return tf.doCreateTransportService(uri, info);
+            return tf.doCreateTransportService(uri, info, connectionManager);
 
         }
         
-        abstract protected TransportService doCreateTransportService(URI uri, CacheInfoHolder info) throws IOException;
+        abstract protected TransportService doCreateTransportService(URI uri, CacheInfoHolder info, ClientConnectionManager connectionManager) throws IOException;
 
 }

Copied: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransportService.java (from r491952, geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransport.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransportService.java?view=diff&rev=508252&p1=geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransport.java&r1=491952&p2=geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransportService.java&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransport.java (original)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransportService.java Thu Feb 15 16:31:57 2007
@@ -18,8 +18,8 @@
  */
 package org.apache.geronimo.gcache.transports;
 
-public interface ClientTransport {
-
+public interface ClientTransportService {
+    
     public boolean connect();
 
     public void putSession(String cacheName, String sessionId, Object value);
@@ -30,5 +30,5 @@
 
     public void removeEntry(String cacheName, String sessionId, Object key);
 
-    public void join();
+    public boolean join();
 }

Added: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/DisconnectionException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/DisconnectionException.java?view=auto&rev=508252
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/DisconnectionException.java (added)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/DisconnectionException.java Thu Feb 15 16:31:57 2007
@@ -0,0 +1,41 @@
+/*
+ * 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;
+
+public class DisconnectionException extends Exception {
+
+    private static final long serialVersionUID = -111080993146368517L;
+
+    public DisconnectionException() {
+        super();
+    }
+
+    public DisconnectionException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public DisconnectionException(String message) {
+        super(message);
+    }
+
+    public DisconnectionException(Throwable cause) {
+        super(cause);
+    }
+
+}

Modified: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketHandler.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketHandler.java (original)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketHandler.java Thu Feb 15 16:31:57 2007
@@ -18,29 +18,76 @@
  */
 package org.apache.geronimo.gcache.transports.tcp;
 
+import java.util.concurrent.ConcurrentHashMap;
+
 import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.command.BaseCommand;
+import org.apache.geronimo.gcache.command.Command;
+import org.apache.geronimo.gcache.transports.ClientConnectionManager;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.common.WriteFuture;
 
 public class TCPClientSocketHandler extends TCPSocketHandler {
+    ConcurrentHashMap<Long, TCPReceiverFuture> receivers = new ConcurrentHashMap<Long, TCPReceiverFuture>();
+    ClientConnectionManager connectionManager;
 
-    public TCPClientSocketHandler(CacheInfoHolder infoHolder, int threadPoolSize) {
+    public TCPClientSocketHandler(CacheInfoHolder infoHolder, ClientConnectionManager connectionManager, int threadPoolSize) {
         super(infoHolder, threadPoolSize);
+        this.connectionManager = connectionManager;
     }
 
-    public TCPClientSocketHandler(CacheInfoHolder infoHolder) {
+    public TCPClientSocketHandler(CacheInfoHolder infoHolder, ClientConnectionManager connectionManager) {
         super(infoHolder);
+        this.connectionManager = connectionManager;
     }
 
     @Override
     public void exceptionCaught(IoSession arg0, Throwable arg1) throws Exception {
-        // TODO Auto-generated method stub
-        super.exceptionCaught(arg0, arg1);
     }
 
     @Override
-    public void sessionClosed(IoSession arg0) throws Exception {
-        // TODO Auto-generated method stub
-        super.sessionClosed(arg0);
+    public void sessionClosed(IoSession sess) throws Exception {
+        //Clean up any open receivers by forcing a disconnect
+        for (Long key : receivers.keySet()) {
+            TCPReceiverFuture receiver = receivers.remove(key);
+            if (receiver != null){
+                receiver.disconnect();
+            }            
+        }
+        connectionManager.onDisconnect();
+    }
+
+    @Override
+    public void messageReceived(IoSession session, Object obj) throws Exception {
+
+        Command command = (Command) obj;
+        
+        //Lookup and remove if we have a receiver
+        TCPReceiverFuture receiver = receivers.remove(command.getCommandId());
+        
+        //If we have a receiver, process the answer directly to the client
+        if (receiver != null) {
+            receiver.setResponse(command);
+            return;
+        }
+        
+        //Otherwise process the answer with the visitor
+        command.setAttachment(session);
+        command.execute(infoHolder.getCommandVisitor());
+
+    }
+
+    public TCPReceiverFuture synchronousSend(IoSession sess, BaseCommand command) {
+        TCPReceiverFuture receiver = new TCPReceiverFuture();
+        command.getCommandId();
+        receivers.put(command.getCommandId(), receiver);
+        WriteFuture future = sess.write(command);
+
+        // Wait for it to be written
+        future.join();
+
+        return receiver;
+
     }
 
 }

Modified: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportService.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportService.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportService.java (original)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportService.java Thu Feb 15 16:31:57 2007
@@ -19,15 +19,24 @@
 package org.apache.geronimo.gcache.transports.tcp;
 
 import java.net.InetSocketAddress;
+import java.security.PublicKey;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeoutException;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gcache.command.AuthCommand;
+import org.apache.geronimo.gcache.command.AuthSuccessfulCommand;
 import org.apache.geronimo.gcache.command.BaseCommand;
+import org.apache.geronimo.gcache.command.Command;
 import org.apache.geronimo.gcache.command.HandShakeCommand;
+import org.apache.geronimo.gcache.command.PublicKeyCommand;
 import org.apache.geronimo.gcache.command.PutEntryCommand;
 import org.apache.geronimo.gcache.command.PutSessionCommand;
 import org.apache.geronimo.gcache.command.RemoveEntryCommand;
-import org.apache.geronimo.gcache.transports.ClientTransport;
+import org.apache.geronimo.gcache.transports.ClientConnectionManager;
+import org.apache.geronimo.gcache.transports.ClientTransportService;
+import org.apache.geronimo.gcache.transports.DisconnectionException;
 import org.apache.geronimo.gcache.util.CipherUtil;
 import org.apache.mina.common.ConnectFuture;
 import org.apache.mina.common.IoHandler;
@@ -38,7 +47,7 @@
 import org.apache.mina.transport.socket.nio.SocketConnector;
 import org.apache.mina.transport.socket.nio.SocketConnectorConfig;
 
-public class TCPClientSocketTransportService extends TCPTransportService implements ClientTransport{
+public class TCPClientSocketTransportService extends TCPTransportService implements ClientTransportService {
 
     private static Log log = LogFactory.getLog(TCPClientSocketTransportService.class);
 
@@ -47,6 +56,12 @@
     private IoHandler handler;
 
     private IoSession sess;
+    
+    private String userId = "system";
+    
+    private String password = "manager";
+    
+    private ClientConnectionManager connectionManager;
 
     @Override
     public void start() throws Exception {
@@ -59,15 +74,27 @@
         disconnect();
     }
 
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public void setUserId(String userId) {
+        this.userId = userId;
+    }
+
+    public void setConnectionManager(ClientConnectionManager connectionManager) {
+        this.connectionManager = connectionManager;
+    }
+
     public boolean connect() {
-        //Get the proper attributes
+        // Get the proper attributes
         int port = tcpURI.getPort();
         String host = tcpURI.getHost();
-        
-        //Create an address
+
+        // Create an address
         InetSocketAddress address = new InetSocketAddress(host, port);
-        
-        if (sess!= null && sess.isConnected()) {
+
+        if (sess != null && sess.isConnected()) {
             throw new IllegalStateException("Already connected. Disconnect first.");
         }
 
@@ -93,7 +120,8 @@
                 cfg.getFilterChain().addLast(TCPMessageAckCommandFilter.NAME, new TCPMessageAckCommandFilter(ackTimeout));
             }
 
-            handler = new TCPSocketHandler(info);
+            handler = new TCPClientSocketHandler(info, connectionManager);
+            
 
             ConnectFuture future = connector.connect(address, handler, cfg);
             future.join();
@@ -110,72 +138,117 @@
 
     private void disconnect() {
         if (sess != null) {
-            if (sess.isConnected()) {
-                sess.getCloseFuture().join();
-            }
+//            if (sess.isConnected()) {
+//                sess.getCloseFuture().join();
+//            }
             sess.close();
             sess = null;
         }
     }
 
-    public void join() {
+    public boolean join() {
+        
+        //Send a handshake and introduce myself
         HandShakeCommand command = new HandShakeCommand();
         command.setPublicKey(CipherUtil.publicKey);
+        try {
+            Command response = sendAndReceive(command);
+            if (!(response instanceof PublicKeyCommand)) {
+                log.error("Response expected a PublicKeyCommand and received a " + response.getClass().getSimpleName() + " instead.");
+                return false;
+            }
+            
+            //Expect a PublicKey from the server
+            PublicKey serverKey = ((PublicKeyCommand)response).getPublicKey();
+            
+            //Send auth credentials
+            AuthCommand auth = new AuthCommand();
+            auth.setPassword(password);
+            auth.setUserId(userId);
+            auth.setPublicKey(serverKey);
+            response = sendAndReceive(auth);
+            if (!(response instanceof AuthSuccessfulCommand)) {
+                log.error("Response expected a PublicKeyCommand and received a " + response.getClass().getSimpleName() + " instead.");
+                return false;
+            }
+            
+        }catch (DisconnectionException e) {
+            log.error(e);
+            return false;
+        }catch (TimeoutException e) {
+            log.error(e);
+            return false;
+        } catch (InterruptedException e) {
+            log.error(e);
+            return false;
+        } catch (ExecutionException e) {
+            log.error(e);
+            return false;
+        }
+
+        return true;
     }
 
-   public void putSession(String cacheName, String sessionId, Object value) {
-        
+    public void putSession(String cacheName, String sessionId, Object value) {
+
         PutSessionCommand command = new PutSessionCommand();
-        
+
         command.setCacheName(cacheName);
         command.setSessionId(sessionId);
         command.setKey(value);
         command.setPayload(value);
-        
+
         send(command);
     }
-        
+
     public void removeEntry(String cacheName, String sessionId, Object key) {
         RemoveEntryCommand command = new RemoveEntryCommand();
-        
+
         command.setCacheName(cacheName);
         command.setSessionId(sessionId);
         command.setKey(key);
-        
+
         send(command);
     }
-    
+
     public void removeSession(String cacheName, String session) {
         PutSessionCommand command = new PutSessionCommand();
-        
+
         command.setCacheName(cacheName);
         command.setSessionId(session);
-        
+
         send(command);
     }
-    
+
     public void putEntry(String cacheName, String sessionId, Object key, Object value) {
-        
+
         PutEntryCommand command = new PutEntryCommand();
-        
+
         command.setCacheName(cacheName);
         command.setSessionId(sessionId);
         command.setKey(value);
         command.setPayload(value);
-        
+
         send(command);
-    } 
-    
-    public void send(BaseCommand command){
-        
+    }
+
+    public void send(BaseCommand command) {
+
         WriteFuture future = sess.write(command);
-        
-        //Request ack if setup to do so
+
+        // Request ack if setup to do so
         command.setAttachment(sess);
-        ((TCPClientCommandVisitor)info.getCommandVisitor()).requestAck(command);
-        
-        //Wait for it to be written
+        ((TCPClientCommandVisitor) info.getCommandVisitor()).requestAck(command);
+
+        // Wait for it to be written
         future.join();
-        
+
+    }
+
+    private Command sendAndReceive(BaseCommand command) throws InterruptedException, ExecutionException, TimeoutException, DisconnectionException {
+        TCPClientSocketHandler handler = (TCPClientSocketHandler) sess.getHandler();
+        TCPReceiverFuture future = handler.synchronousSend(sess, command);
+        //TODO: Offer a timeout
+        return (Command) future.get();
     }
 }

Modified: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportServiceFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportServiceFactory.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportServiceFactory.java (original)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportServiceFactory.java Thu Feb 15 16:31:57 2007
@@ -23,6 +23,7 @@
 import java.util.Map;
 
 import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.transports.ClientConnectionManager;
 import org.apache.geronimo.gcache.transports.ClientTransportFactory;
 import org.apache.geronimo.gcache.transports.TransportService;
 import org.apache.geronimo.gcache.util.IOExceptionSupport;
@@ -32,7 +33,7 @@
 public class TCPClientSocketTransportServiceFactory extends ClientTransportFactory {
 
     @Override
-    protected TransportService doCreateTransportService(URI uri, CacheInfoHolder info) throws IOException {
+    protected TransportService doCreateTransportService(URI uri, CacheInfoHolder info, ClientConnectionManager connectionManager) throws IOException {
         try {
 
             Map options = URISupport.parseParamters(uri);
@@ -40,6 +41,7 @@
 
             rc.setInfo(info);
             rc.setTcpURI(uri);
+            rc.setConnectionManager(connectionManager);
             IntrospectionSupport.setProperties(rc, options);
             return rc;
 

Added: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPReceiverFuture.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPReceiverFuture.java?view=auto&rev=508252
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPReceiverFuture.java (added)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPReceiverFuture.java Thu Feb 15 16:31:57 2007
@@ -0,0 +1,67 @@
+/*
+ * 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.tcp;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.geronimo.gcache.transports.DisconnectionException;
+
+public class TCPReceiverFuture{
+    
+    private CountDownLatch latch = new CountDownLatch(1);
+    private Object response;
+    
+    
+    private AtomicBoolean done = new AtomicBoolean(false);
+    private AtomicBoolean disconnected = new AtomicBoolean(false);
+
+    public Object get() throws InterruptedException, ExecutionException, DisconnectionException {
+        latch.await();
+        if (disconnected.get())
+            throw new DisconnectionException();
+        return response;
+    }
+
+    public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException, DisconnectionException {
+        latch.await(timeout, unit);
+        if (disconnected.get())
+            throw new DisconnectionException();
+        return response;
+    }
+
+    public boolean isDone() {
+        return done.get();
+    }
+
+    public void setResponse(Object response) {
+        this.response = response;
+        done.set(false);
+        latch.countDown();
+    }
+    
+    protected void disconnect(){
+        disconnected.set(true);
+        latch.countDown();
+    }
+
+}

Modified: geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportServiceFactoryTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportServiceFactoryTest.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportServiceFactoryTest.java (original)
+++ geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportServiceFactoryTest.java Thu Feb 15 16:31:57 2007
@@ -21,6 +21,7 @@
 import java.net.URI;
 
 import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.transports.ClientConnectionManager;
 import org.testng.annotations.Test;
 
 public class TCPClientSocketTransportServiceFactoryTest {
@@ -29,8 +30,9 @@
     public void testTCPClientSocketTransportServiceFactory() throws Exception{
         
         CacheInfoHolder info = new CacheInfoHolder(null);
+        ClientConnectionManager mgr = new ClientConnectionManager(info);
         URI uri = new URI("tcp://default");
-        TCPClientSocketTransportService service = (TCPClientSocketTransportService)TCPClientSocketTransportServiceFactory.createTransportService(uri, info);
+        TCPClientSocketTransportService service = (TCPClientSocketTransportService)TCPClientSocketTransportServiceFactory.createTransportService(uri, info, mgr);
         
         assert service instanceof TCPClientSocketTransportService;
         assert service != null;

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/AuthSuccessfulCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/AuthSuccessfulCommand.java?view=auto&rev=508252
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/AuthSuccessfulCommand.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/AuthSuccessfulCommand.java Thu Feb 15 16:31:57 2007
@@ -0,0 +1,28 @@
+/*
+ * 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.command;
+
+import java.io.IOException;
+
+public class AuthSuccessfulCommand extends BaseCommand {
+
+    public byte getCommandType() throws IOException {
+        return CommandTypes.AUTH_SUCCESSFUL_COMMAND;
+    }
+}

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java Thu Feb 15 16:31:57 2007
@@ -90,8 +90,6 @@
      * @param commandId
      */
     public void setCommandId(long commandId) {
-        // TODO - should this method be here. I am leaning towards this being a
-        // read only property.
         this.commandId = commandId;
     }
 
@@ -116,12 +114,8 @@
      */
     public void writeExternal(ByteBuffer buffer) throws Exception {
         // this is the root so no super impl, others should call super first
-
-        if (commandId == 0) {
-            commandId = UniqueId.get();
-        }
-
-        buffer.putLong(commandId);
+        
+        buffer.putLong(getCommandId());
     }
 
     /**

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java Thu Feb 15 16:31:57 2007
@@ -3,20 +3,21 @@
 public class CommandTypes {
     public static final byte HAND_SHAKE_COMMAND = 1;
     public static final byte AUTH_COMMAND = 2;
-    public static final byte PUBLIC_KEY_COMMAND = 3;
-    public static final byte PUT_ENTRY_COMMAND = 4;
-    public static final byte REMOVE_ENTRY_COMMAND = 5;
-    public static final byte MESSAGE_ACK_COMMAND = 6;
-    public static final byte BULK_SEND_COMMAND = 7;
-    public static final byte GET_SESSION_COMMAND = 8;
-    public static final byte REMOVE_SESSION_COMMAND = 9;
-    public static final byte PUT_SESSION_COMMAND = 10;
-    public static final byte DISCOVERY_COMMAND = 11;
-    public static final byte LOCK_COMMAND = 12;
-    public static final byte RELEASELOCK_COMMAND = 13;
-    public static final byte LOCK_ACQUIRED_COMMAND = 14;
-    public static final byte LOCK_RELEASED_COMMAND = 15;
-    public static final byte ERROR_COMMAND = 16;
+    public static final byte AUTH_SUCCESSFUL_COMMAND = 3;
+    public static final byte PUBLIC_KEY_COMMAND = 4;
+    public static final byte PUT_ENTRY_COMMAND = 5;
+    public static final byte REMOVE_ENTRY_COMMAND = 6;
+    public static final byte MESSAGE_ACK_COMMAND = 7;
+    public static final byte BULK_SEND_COMMAND = 8;
+    public static final byte GET_SESSION_COMMAND = 9;
+    public static final byte REMOVE_SESSION_COMMAND = 10; 
+    public static final byte PUT_SESSION_COMMAND = 11;
+    public static final byte DISCOVERY_COMMAND = 12;
+    public static final byte LOCK_COMMAND = 13;
+    public static final byte RELEASELOCK_COMMAND = 14;
+    public static final byte LOCK_ACQUIRED_COMMAND = 15;
+    public static final byte LOCK_RELEASED_COMMAND = 16;
+    public static final byte ERROR_COMMAND = 17;
 
     public static Command createCommand(int identifier) {
         Command command = null;
@@ -26,6 +27,9 @@
                 break;
             case(AUTH_COMMAND):
                 command = new AuthCommand();
+                break;
+            case(AUTH_SUCCESSFUL_COMMAND):
+                command = new AuthSuccessfulCommand();
                 break;
             case(PUBLIC_KEY_COMMAND):
                 command = new PublicKeyCommand();

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/LockAcquiredCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/LockAcquiredCommand.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/LockAcquiredCommand.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/LockAcquiredCommand.java Thu Feb 15 16:31:57 2007
@@ -21,37 +21,11 @@
 import java.io.IOException;
 
 import org.apache.geronimo.gcache.transports.CommandVisitor;
-import org.apache.mina.common.ByteBuffer;
 
 public class LockAcquiredCommand extends BaseCommand {
 
-    private long messageId = 0;
-
     public byte getCommandType() throws IOException {
         return CommandTypes.LOCK_ACQUIRED_COMMAND;
-    }
-
-    public long getMessageId() {
-        return messageId;
-    }
-
-    public void setMessageId(long messageId) {
-        this.messageId = messageId;
-    }
-
-    public void readExternal(ByteBuffer buffer) throws Exception {
-
-        super.readExternal(buffer);
-
-        messageId = buffer.getLong();
-
-    }
-
-    public void writeExternal(ByteBuffer buffer) throws Exception {
-
-        super.writeExternal(buffer);
-        buffer.putLong(messageId);
-
     }
 
     public void execute(CommandVisitor visitor) throws IOException{

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/LockReleasedCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/LockReleasedCommand.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/LockReleasedCommand.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/LockReleasedCommand.java Thu Feb 15 16:31:57 2007
@@ -25,33 +25,8 @@
 
 public class LockReleasedCommand extends BaseCommand {
     
-    private long messageId = 0;
-
     public byte getCommandType() throws IOException {
         return CommandTypes.LOCK_RELEASED_COMMAND;
-    }
-
-    public long getMessageId() {
-        return messageId;
-    }
-
-    public void setMessageId(long messageId) {
-        this.messageId = messageId;
-    }
-
-    public void readExternal(ByteBuffer buffer) throws Exception {
-
-        super.readExternal(buffer);
-
-        messageId = buffer.getLong();
-
-    }
-
-    public void writeExternal(ByteBuffer buffer) throws Exception {
-
-        super.writeExternal(buffer);
-        buffer.putLong(messageId);
-
     }
 
     public void execute(CommandVisitor visitor) throws IOException{

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/MessageAckCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/MessageAckCommand.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/MessageAckCommand.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/MessageAckCommand.java Thu Feb 15 16:31:57 2007
@@ -25,33 +25,8 @@
 
 public class MessageAckCommand extends BaseCommand{
 
-    private long messageId = 0;
-
     public byte getCommandType() throws IOException {
         return CommandTypes.MESSAGE_ACK_COMMAND;
-    }
-
-    public long getMessageId() {
-        return messageId;
-    }
-
-    public void setMessageId(long messageId) {
-        this.messageId = messageId;
-    }
-
-    public void readExternal(ByteBuffer buffer) throws Exception {
-
-        super.readExternal(buffer);
-
-        messageId = buffer.getLong();
-
-    }
-
-    public void writeExternal(ByteBuffer buffer) throws Exception {
-
-        super.writeExternal(buffer);
-        buffer.putLong(messageId);
-
     }
 
     public void execute(CommandVisitor visitor) throws IOException{

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/BaseCommandVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/BaseCommandVisitor.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/BaseCommandVisitor.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/BaseCommandVisitor.java Thu Feb 15 16:31:57 2007
@@ -23,7 +23,7 @@
 
         if (sess.getFilterChain().contains(TCPMessageAckCommandFilter.class)) {
             MessageAckCommand ack = new MessageAckCommand();
-            ack.setMessageId(command.getCommandId());
+            ack.setCommandId(command.getCommandId());
             sess.write(ack);
         }
     }
@@ -35,8 +35,7 @@
             return;
 
         //See if we need to send an Ack
-        TCPMessageAckCommandFilter filter = (TCPMessageAckCommandFilter) sess
-                .getFilterChain().get(TCPMessageAckCommandFilter.NAME);
+        TCPMessageAckCommandFilter filter = (TCPMessageAckCommandFilter) sess.getFilterChain().get(TCPMessageAckCommandFilter.NAME);
         if (filter != null) {
             long commandId = command.getCommandId();
             filter.requestAck(commandId, sess);

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPAuthenticationFilter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPAuthenticationFilter.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPAuthenticationFilter.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPAuthenticationFilter.java Thu Feb 15 16:31:57 2007
@@ -23,8 +23,8 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.geronimo.gcache.CacheInfoHolder;
 import org.apache.geronimo.gcache.command.AuthCommand;
+import org.apache.geronimo.gcache.command.AuthSuccessfulCommand;
 import org.apache.geronimo.gcache.command.HandShakeCommand;
-import org.apache.geronimo.gcache.command.MessageAckCommand;
 import org.apache.geronimo.gcache.command.PublicKeyCommand;
 import org.apache.geronimo.gcache.util.CipherUtil;
 import org.apache.mina.common.IoFilterAdapter;
@@ -104,8 +104,7 @@
             return;
         }
 
-        ScheduledFuture authTask = (ScheduledFuture) sess
-                .getAttribute(Constants.AUTH_TASK);
+        ScheduledFuture authTask = (ScheduledFuture) sess.getAttribute(Constants.AUTH_TASK);
 
         //Cancel the timer
         if (!authTask.cancel(false)) {
@@ -145,18 +144,18 @@
         //Register authentication
         sess.setAttribute(Constants.AUTHENTICATED);
         
+        log.info(sess.getRemoteAddress().toString() + " successfully authenticated.");
+
         //Now add the client to the cache to start receiving events
         CacheInfoHolder infoHolder = ((TCPSocketHandler) sess.getHandler())
                 .getInfoHolder();
         infoHolder.getEndpointManager().addEndpoint(sess);
-
-        //See if we need to send an Ack
-        if (sess.getFilterChain().contains(TCPMessageAckCommandFilter.NAME)){
-            log.debug("Sending MessageAck");
-            MessageAckCommand ack = new MessageAckCommand();
-            ack.setMessageId(auth.getCommandId());
-            sess.write(ack);
-        }
+        
+        //Tell the client they have authenticated
+        AuthSuccessfulCommand authSuccess = new AuthSuccessfulCommand();
+        authSuccess.setCommandId(auth.getCommandId());
+        
+        sess.write(authSuccess);
 
     }
 
@@ -191,6 +190,7 @@
 
         //Send out our public key
         PublicKeyCommand keyCommand = new PublicKeyCommand();
+        keyCommand.setCommandId(handShake.getCommandId());
         keyCommand.setPublicKey(CipherUtil.publicKey);
 
         sess.write(keyCommand);

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandRequestDecoder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandRequestDecoder.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandRequestDecoder.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandRequestDecoder.java Thu Feb 15 16:31:57 2007
@@ -57,14 +57,15 @@
 
         // Get the command length
         in.getInt();
-
+        
+        //Create and populate the command
         Command command = CommandTypes.createCommand(commandIdentifier);
+        command.readExternal(in);
+        
         if (log.isDebugEnabled()) {
-            log.debug("Command is type " + command.getClass().getSimpleName() + " from " + session.getRemoteAddress().toString());
+            log.debug("Command is type " + command.getClass().getSimpleName() + "(" + command.getCommandId() +") from " + session.getRemoteAddress().toString());
         }
 
-        command.readExternal(in);
-
         out.write(command);
 
         return MessageDecoderResult.OK;
@@ -108,7 +109,7 @@
         // Get the command
         byte commandIdentifier = in.get();
         if (log.isDebugEnabled()) {
-            log.debug("Command Identifier = " + commandIdentifier);
+            log.debug("Command Type = " + commandIdentifier);
         }
 
         // Get the command length

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandRequestEncoder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandRequestEncoder.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandRequestEncoder.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandRequestEncoder.java Thu Feb 15 16:31:57 2007
@@ -24,6 +24,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.geronimo.gcache.command.AuthCommand;
+import org.apache.geronimo.gcache.command.AuthSuccessfulCommand;
 import org.apache.geronimo.gcache.command.BaseCommand;
 import org.apache.geronimo.gcache.command.BulkSendCommand;
 import org.apache.geronimo.gcache.command.Command;
@@ -55,6 +56,7 @@
     {
         Set<Class> types= new HashSet<Class> ();
         types.add( AuthCommand.class );
+        types.add( AuthSuccessfulCommand.class );
         types.add( BulkSendCommand.class );
         types.add( ErrorCommand.class );
         types.add( GetSessionCommand.class );
@@ -74,10 +76,10 @@
     
     public void encode(IoSession sess, Object obj, ProtocolEncoderOutput out) throws Exception {
 	
+	Command command = (Command)obj;
 	if (log.isDebugEnabled()){
-	    log.debug("Sending " + obj.getClass().getSimpleName() + " to " + sess.getRemoteAddress().toString());
+	    log.debug("Sending " + command.getClass().getSimpleName() + "(" + command.getCommandId() + ") to " + sess.getRemoteAddress().toString());
 	}
-	Command command = (Command)obj;
 	out.write(ByteBuffer.wrap(((BaseCommand)command).createPacket(true)));
     }
 

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPMessageAckCommandFilter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPMessageAckCommandFilter.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPMessageAckCommandFilter.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPMessageAckCommandFilter.java Thu Feb 15 16:31:57 2007
@@ -48,7 +48,7 @@
         if (obj instanceof MessageAckCommand) {
 
             MessageAckCommand command = (MessageAckCommand) obj;
-            Long commandId = command.getMessageId();
+            Long commandId = command.getCommandId();
 
             ScheduledFuture handle = (ScheduledFuture) sess.getAttribute(Constants.MESSAGE_ACK_ID + commandId);
             if (handle != null) {

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketHandler.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketHandler.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketHandler.java Thu Feb 15 16:31:57 2007
@@ -20,7 +20,6 @@
 import org.apache.geronimo.gcache.command.Command;
 import org.apache.mina.common.IoHandlerAdapter;
 import org.apache.mina.common.IoSession;
-import org.apache.mina.util.SessionLog;
 
 import edu.emory.mathcs.backport.java.util.concurrent.Executors;
 import edu.emory.mathcs.backport.java.util.concurrent.ScheduledFuture;

Modified: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/MessageAckCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/MessageAckCommandTest.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/MessageAckCommandTest.java (original)
+++ geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/MessageAckCommandTest.java Thu Feb 15 16:31:57 2007
@@ -27,7 +27,7 @@
     public void testMessageAckCommand() throws Exception {
 
         MessageAckCommand command = (MessageAckCommand) CommandTypes.createCommand(CommandTypes.MESSAGE_ACK_COMMAND);
-        command.setMessageId(99);
+        command.setCommandId(99);
         long commandId = command.getCommandId();
 
         //Convert the command to bytes
@@ -36,7 +36,6 @@
         MessageAckCommand readCommand = new MessageAckCommand();
         readCommand.readExternal(ByteBuffer.wrap(marshalled));
         assert readCommand.getCommandId() == commandId;
-        assert readCommand.getMessageId() == 99;
 
     }
 }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandVisitor.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandVisitor.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandVisitor.java Thu Feb 15 16:31:57 2007
@@ -213,7 +213,7 @@
 
         // Send back a lock acquired command
         LockAcquiredCommand lockAcquired = new LockAcquiredCommand();
-        lockAcquired.setMessageId(command.getCommandId());
+        lockAcquired.setCommandId(command.getCommandId());
         sess.write(lockAcquired);
     }
 
@@ -234,7 +234,7 @@
         }
         
         LockReleasedCommand lockReleased = new LockReleasedCommand();
-        lockReleased.setMessageId(command.getCommandId());
+        lockReleased.setCommandId(command.getCommandId());
         sess.write(lockReleased);
 
     }

Modified: 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=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/server/GCacheManagerTest.java (original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/server/GCacheManagerTest.java Thu Feb 15 16:31:57 2007
@@ -27,12 +27,17 @@
 import java.util.Map;
 
 import org.apache.geronimo.gcache.command.AuthCommand;
+import org.apache.geronimo.gcache.command.AuthSuccessfulCommand;
 import org.apache.geronimo.gcache.command.BaseCommand;
 import org.apache.geronimo.gcache.command.Command;
 import org.apache.geronimo.gcache.command.CommandTypes;
 import org.apache.geronimo.gcache.command.HandShakeCommand;
+import org.apache.geronimo.gcache.command.LockAcquiredCommand;
+import org.apache.geronimo.gcache.command.LockCommand;
+import org.apache.geronimo.gcache.command.LockReleasedCommand;
 import org.apache.geronimo.gcache.command.PublicKeyCommand;
 import org.apache.geronimo.gcache.command.PutSessionCommand;
+import org.apache.geronimo.gcache.command.ReleaseLockCommand;
 import org.apache.geronimo.gcache.transports.tcp.Constants;
 import org.apache.geronimo.gcache.util.CipherUtil;
 import org.apache.mina.common.ByteBuffer;
@@ -74,10 +79,16 @@
         Thread.sleep(1000);
         
         //Client 1 will send a session
+        lockSession(client);
+        Command read = readCommand(client);
+        assert read instanceof LockAcquiredCommand;
         sendSession(client);
+        releaseSession(client);
+        read = readCommand(client);
+        assert read instanceof LockReleasedCommand;
 
         //Client 2 should have a notification
-        Command read = readCommand(client2);
+        read = readCommand(client2);
         assert read instanceof PutSessionCommand;
 
         Map session = ((PutSessionCommand) read).getSessionFromPayload();
@@ -111,6 +122,8 @@
         auth.setPublicKey(keyCommand.getPublicKey());
 
         sendCommand(socket, auth);
+        Command read = readCommand(socket);
+        assert read instanceof AuthSuccessfulCommand;
 
     }
 
@@ -174,6 +187,31 @@
         command.setCacheName("Cache1");
         command.setSessionId("Session1");
         command.setPayloadFromSession(session);
+
+        //Send the packet
+        sendCommand(socket, command);
+
+    }
+    
+    
+    private void lockSession(Socket socket) throws Exception {
+
+        //Create a lock
+        LockCommand command = new LockCommand();
+        command.setCacheName("Cache1");
+        command.setSessionId("Session1");
+
+        //Send the packet
+        sendCommand(socket, command);
+
+    }
+    
+    private void releaseSession(Socket socket) throws Exception {
+
+        //Release lock
+        ReleaseLockCommand command = new ReleaseLockCommand(); 
+        command.setCacheName("Cache1");
+        command.setSessionId("Session1");
 
         //Send the packet
         sendCommand(socket, command);

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketServiceTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketServiceTest.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketServiceTest.java (original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketServiceTest.java Thu Feb 15 16:31:57 2007
@@ -66,7 +66,7 @@
         assert ackCommand instanceof MessageAckCommand;
 
         //Is the ack for the original message?
-        assert command.getCommandId() == ((MessageAckCommand)ackCommand).getMessageId();
+        assert command.getCommandId() == ((MessageAckCommand)ackCommand).getCommandId();
 
     }
 

Modified: geronimo/sandbox/gcache/tests/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/tests/pom.xml?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/tests/pom.xml (original)
+++ geronimo/sandbox/gcache/tests/pom.xml Thu Feb 15 16:31:57 2007
@@ -43,6 +43,11 @@
 			<artifactId>ehcache</artifactId>
 		</dependency>
 
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+        </dependency>
+
 	</dependencies>
 	<build></build>
 

Modified: geronimo/sandbox/gcache/tests/src/test/java/org/apache/geronimo/gcache/AbstractParent.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/tests/src/test/java/org/apache/geronimo/gcache/AbstractParent.java?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/tests/src/test/java/org/apache/geronimo/gcache/AbstractParent.java (original)
+++ geronimo/sandbox/gcache/tests/src/test/java/org/apache/geronimo/gcache/AbstractParent.java Thu Feb 15 16:31:57 2007
@@ -1,24 +1,10 @@
 package org.apache.geronimo.gcache;
 
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.Socket;
-import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.geronimo.gcache.client.GCacheClient;
-import org.apache.geronimo.gcache.command.AuthCommand;
-import org.apache.geronimo.gcache.command.BaseCommand;
-import org.apache.geronimo.gcache.command.Command;
-import org.apache.geronimo.gcache.command.CommandTypes;
-import org.apache.geronimo.gcache.command.HandShakeCommand;
-import org.apache.geronimo.gcache.command.PublicKeyCommand;
-import org.apache.geronimo.gcache.command.PutSessionCommand;
 import org.apache.geronimo.gcache.server.GCacheManager;
-import org.apache.geronimo.gcache.transports.tcp.Constants;
-import org.apache.geronimo.gcache.util.CipherUtil;
-import org.apache.mina.common.ByteBuffer;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 
@@ -46,87 +32,12 @@
         mgr.stop();
     }
 
-    protected void authenticate(Socket socket) throws Exception {
-        HandShakeCommand command = new HandShakeCommand();
-        command.setPublicKey(CipherUtil.publicKey);
-
-        //Send the handshake
-        sendCommand(socket, command);
-
-        PublicKeyCommand keyCommand = (PublicKeyCommand) readCommand(socket);
-
-        AuthCommand auth = new AuthCommand();
-        auth.setUserId("system");
-        auth.setPassword("manager");
-        auth.setPublicKey(keyCommand.getPublicKey());
-
-        sendCommand(socket, auth);
-
-    }
-
-    protected void sendCommand(Socket socket, BaseCommand command)
-            throws Exception {
-
-        byte bytes[] = command.createPacket(true);
-
-        OutputStream out = socket.getOutputStream();
-        out.write(bytes);
-        out.flush();
-
-    }
-
-    protected Command readCommand(Socket socket) throws Exception {
-
-        byte recBuf[] = new byte[Constants.HEADER_SIZE];
-
-        socket.setSoTimeout(2000);
-        InputStream is = socket.getInputStream();
-        int read = is.read(recBuf);
-        assert read == Constants.HEADER_SIZE;
-        ByteBuffer receiveHeader = ByteBuffer.wrap(recBuf);
-
-        //Read the magic
-        byte magic[] = new byte[Constants.MAGIC.length];
-        receiveHeader.get(magic);
-
-        //Better match the Magic
-        assert Arrays.equals(Constants.MAGIC, magic);
-
-        //Get the command
-        byte commandIdentifier = receiveHeader.get();
-
-        //Get the command length
-        int length = receiveHeader.getInt();
-        receiveHeader.release();
-
-        //pull the command
-        recBuf = new byte[length];
-        int count = is.read(recBuf);
-        assert count == length;
-        ByteBuffer commandBuffer = ByteBuffer.wrap(recBuf);
-
-        //Create the command and unmarshal the data
-        Command command = CommandTypes.createCommand(commandIdentifier);
-        command.readExternal(ByteBuffer.wrap(commandBuffer.array()));
-
-        return command;
-
-    }
-
-    private void sendSession(Socket socket) throws Exception {
-
+    private Map makeSession(){
         //Create a session
         Map<String, String> session = new HashMap<String, String>();
         session.put("key1", "data1");
         session.put("key2", "data2");
         session.put("key3", "data3");
-        PutSessionCommand command = new PutSessionCommand();
-        command.setCacheName("Cache1");
-        command.setSessionId("Session1");
-        command.setPayloadFromSession(session);
-
-        //Send the packet
-        sendCommand(socket, command);
-
+        return session;
     }    
 }

Added: geronimo/sandbox/gcache/tests/src/test/java/org/apache/geronimo/gcache/transports/tcp/AuthenticationTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/tests/src/test/java/org/apache/geronimo/gcache/transports/tcp/AuthenticationTest.java?view=auto&rev=508252
==============================================================================
--- geronimo/sandbox/gcache/tests/src/test/java/org/apache/geronimo/gcache/transports/tcp/AuthenticationTest.java (added)
+++ geronimo/sandbox/gcache/tests/src/test/java/org/apache/geronimo/gcache/transports/tcp/AuthenticationTest.java Thu Feb 15 16:31:57 2007
@@ -0,0 +1,36 @@
+/*
+ * 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.tcp;
+
+import org.apache.geronimo.gcache.AbstractParent;
+import org.testng.annotations.Test;
+
+public class AuthenticationTest extends AbstractParent {
+    
+    @Test
+    public void testAuth() throws Exception{
+       client1.lock("Test", "xyz");
+       client2.lock("Test2", "xyz");
+       client1.lock("Test3", "xyz");
+       client1.lock("Test4", "xyz");
+       client2.lock("Test5", "xyz");
+       client2.lock("Test6", "xyz");
+    }
+
+}

Modified: geronimo/sandbox/gcache/tests/src/test/resources/gcache-server-config.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/tests/src/test/resources/gcache-server-config.xml?view=diff&rev=508252&r1=508251&r2=508252
==============================================================================
--- geronimo/sandbox/gcache/tests/src/test/resources/gcache-server-config.xml (original)
+++ geronimo/sandbox/gcache/tests/src/test/resources/gcache-server-config.xml Thu Feb 15 16:31:57 2007
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<gcache-config>
+<gcache-server-config>
 	<server order="1" serverName="gcache">
 		<transport name="default" uri="tcp://default?enableLogging=true" discoveryUri="multicast://default" />
 	</server>
@@ -20,4 +20,4 @@
 		timeToIdleSeconds="0" timeToLiveSeconds="1800" overflowToDisk="false"
 		diskPersistent="true" diskExpiryThreadIntervalSeconds="60"
 		memoryStoreEvictionPolicy="LFU" />
-</gcache-config>
+</gcache-server-config>



Mime
View raw message