geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r452193 - in /geronimo/sandbox/gcache/server/src: main/java/org/apache/geronimo/gcache/command/ main/java/org/apache/geronimo/gcache/transports/ main/java/org/apache/geronimo/gcache/transports/tcp/ test/java/org/apache/geronimo/gcache/command/
Date Mon, 02 Oct 2006 20:21:24 GMT
Author: jgenender
Date: Mon Oct  2 13:21:22 2006
New Revision: 452193

URL: http://svn.apache.org/viewvc?view=rev&rev=452193
Log:
Add visitor

Added:
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/CommandVisitor.java
  (with props)
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandVisitor.java
  (with props)
Modified:
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BulkSendCommand.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/Command.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/GetCacheCommand.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/MessageAckCommand.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/PutEntryCommand.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/PutSessionCommand.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/RemoveEntryCommand.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/RemoveSessionCommand.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/DefaultSelectionKeyProcessor.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/ClearCacheCommandTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/PutEntryCommandTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/PutSessionCommandTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/RemoveEntryCommandTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/RemoveSessionCommandTest.java

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java?view=diff&rev=452193&r1=452192&r2=452193
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java
Mon Oct  2 13:21:22 2006
@@ -20,6 +20,7 @@
 
 import org.apache.geronimo.gcache.CacheInfoHolder;
 import org.apache.geronimo.gcache.transports.tcp.Constants;
+import org.apache.geronimo.gcache.transports.CommandVisitor;
 import org.apache.geronimo.gcache.util.ByteArrayInputStream;
 import org.apache.geronimo.gcache.util.ByteArrayOutputStream;
 import org.apache.geronimo.gcache.util.UniqueId;
@@ -57,7 +58,7 @@
     }
 
 
-    public void execute(CacheInfoHolder info) throws IOException{
+    public void execute(CommandVisitor visitor) throws IOException{
         // nothing to do in the base
     }
 

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BulkSendCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BulkSendCommand.java?view=diff&rev=452193&r1=452192&r2=452193
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BulkSendCommand.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BulkSendCommand.java
Mon Oct  2 13:21:22 2006
@@ -19,6 +19,7 @@
 package org.apache.geronimo.gcache.command;
 
 import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.transports.CommandVisitor;
 
 import java.nio.channels.ReadableByteChannel;
 import java.nio.channels.WritableByteChannel;
@@ -53,7 +54,8 @@
         writeInt(channel, numberOfCommands);
     }
 
-    public void execute(CacheInfoHolder info) throws IOException{
-       //Nothing to execute, this is just an outbound header
+    public void execute(CommandVisitor visitor) throws IOException{
+
+        visitor.processBulkSend(this);
     }
 }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java?view=diff&rev=452193&r1=452192&r2=452193
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java
Mon Oct  2 13:21:22 2006
@@ -20,6 +20,7 @@
 
 import net.sf.ehcache.Cache;
 import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.transports.CommandVisitor;
 
 import java.io.IOException;
 
@@ -29,11 +30,7 @@
         return CommandTypes.CLEARCACHE_COMMAND;
     }
 
-    public void execute(CacheInfoHolder info) throws IOException {
-        Cache cache = info.getCache(getCacheName(), true);
-        cache.removeAll();
-
-        //Notify peers
-        info.getCacheNotifier().notifyClearCache(this);
+    public void execute(CommandVisitor visitor) throws IOException {
+        visitor.processClearCache(this);
     }
 }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/Command.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/Command.java?view=diff&rev=452193&r1=452192&r2=452193
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/Command.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/Command.java
Mon Oct  2 13:21:22 2006
@@ -20,6 +20,7 @@
 
 import org.apache.geronimo.gcache.marshal.MarshalAware;
 import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.transports.CommandVisitor;
 
 import java.io.IOException;
 
@@ -32,5 +33,5 @@
 
     public byte getCommandType() throws IOException;
 
-    public void execute(CacheInfoHolder info) throws IOException;
+    public void execute(CommandVisitor visitor) throws IOException;
 }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/GetCacheCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/GetCacheCommand.java?view=diff&rev=452193&r1=452192&r2=452193
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/GetCacheCommand.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/GetCacheCommand.java
Mon Oct  2 13:21:22 2006
@@ -19,6 +19,7 @@
 package org.apache.geronimo.gcache.command;
 
 import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.transports.CommandVisitor;
 
 import java.io.IOException;
 import java.util.List;
@@ -38,6 +39,7 @@
         return CommandTypes.GET_CACHE_COMMAND;
     }
 
-    public void execute(CacheInfoHolder info) throws IOException {
+    public void execute(CommandVisitor visitor) throws IOException {
+        visitor.processGetCache(this);
     }
 }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/MessageAckCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/MessageAckCommand.java?view=diff&rev=452193&r1=452192&r2=452193
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/MessageAckCommand.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/MessageAckCommand.java
Mon Oct  2 13:21:22 2006
@@ -19,6 +19,7 @@
 package org.apache.geronimo.gcache.command;
 
 import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.transports.CommandVisitor;
 
 import java.io.IOException;
 import java.nio.channels.ReadableByteChannel;
@@ -55,7 +56,7 @@
         writeLong(channel, messageId);
     }
 
-    public void execute(CacheInfoHolder info) throws IOException{
-        //Nothing to send, this is just an ack
+    public void execute(CommandVisitor visitor) throws IOException{
+        visitor.processMessageAck(this);
     }
 }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/PutEntryCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/PutEntryCommand.java?view=diff&rev=452193&r1=452192&r2=452193
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/PutEntryCommand.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/PutEntryCommand.java
Mon Oct  2 13:21:22 2006
@@ -19,6 +19,7 @@
 package org.apache.geronimo.gcache.command;
 
 import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.transports.CommandVisitor;
 import org.apache.geronimo.gcache.util.ByteArray;
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.Element;
@@ -34,34 +35,8 @@
         return CommandTypes.PUT_ENTRY_COMMAND;
     }
 
-    public void execute(CacheInfoHolder info) throws IOException {
-        Cache cache = info.getCache(getCacheName(), true);
-
-        //Check if we are using sessions
-        if (this.hasSession()){
-
-            Map sessionMap = null;
-
-            //We are so use the session maps that is stored
-            Element element = cache.get(getSessionId());
-            if (element != null){
-                sessionMap = (Map)element.getObjectValue();
-            } else {
-                sessionMap = Collections.synchronizedMap(new HashMap());
-            }
-
-            sessionMap.put(getHashableKey(), getRawPayload());
-            //Put the session away
-            cache.put(new Element(getSessionId(), sessionMap));
-
-        } else {
-
-            //No session map so store the value
-            cache.put(new Element(getHashableKey(), getRawPayload()));
-        }
-
-        //Notify peers
-        info.getCacheNotifier().notifyPut(this);
+    public void execute(CommandVisitor visitor) throws IOException {
+        visitor.processPutEntry(this);
     }
 
 }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/PutSessionCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/PutSessionCommand.java?view=diff&rev=452193&r1=452192&r2=452193
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/PutSessionCommand.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/PutSessionCommand.java
Mon Oct  2 13:21:22 2006
@@ -22,6 +22,7 @@
 import org.apache.geronimo.gcache.util.ByteArrayInputStream;
 import org.apache.geronimo.gcache.util.ByteArrayOutputStream;
 import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.transports.CommandVisitor;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
@@ -261,13 +262,7 @@
         return sessionMap;
     }
 
-    public void execute(CacheInfoHolder info) throws IOException {
-        Cache cache = info.getCache(getCacheName(), true);
-
-        //Place the raw session in the cache
-        cache.put(new Element(getSessionId(), getRawSessionFromPayload()));
-
-        //Notify peers
-        info.getCacheNotifier().notifyPutSession(this);
+    public void execute(CommandVisitor visitor) throws IOException {
+        visitor.processPutSession(this);
     }
 }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/RemoveEntryCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/RemoveEntryCommand.java?view=diff&rev=452193&r1=452192&r2=452193
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/RemoveEntryCommand.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/RemoveEntryCommand.java
Mon Oct  2 13:21:22 2006
@@ -19,6 +19,7 @@
 package org.apache.geronimo.gcache.command;
 
 import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.transports.CommandVisitor;
 import org.apache.geronimo.gcache.util.ByteArray;
 
 import java.util.Map;
@@ -35,34 +36,7 @@
         return CommandTypes.REMOVE_ENTRY_COMMAND;
     }
 
-    public void execute(CacheInfoHolder info) throws IOException {
-        Cache cache = info.getCache(getCacheName(), true);
-
-        //Check if we are using sessions
-        if (this.hasSession()){
-
-            Map sessionMap = null;
-
-            //We are so use the session maps that is stored
-            Element element = cache.get(getSessionId());
-            if (element != null){
-                sessionMap = (Map)element.getObjectValue();
-            } else {
-                sessionMap = Collections.synchronizedMap(new HashMap());
-            }
-
-            sessionMap.remove(getHashableKey());
-
-            //Put the session away
-            cache.put(new Element(getSessionId(), sessionMap));
-
-        } else {
-
-            //No session map so store the value
-            cache.remove(getHashableKey());
-        }
-
-        //Notify peers
-        info.getCacheNotifier().notifyRemove(this);
+    public void execute(CommandVisitor visitor) throws IOException {
+        visitor.processRemoveEntry(this);
     }
 }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/RemoveSessionCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/RemoveSessionCommand.java?view=diff&rev=452193&r1=452192&r2=452193
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/RemoveSessionCommand.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/RemoveSessionCommand.java
Mon Oct  2 13:21:22 2006
@@ -20,6 +20,7 @@
 
 import net.sf.ehcache.Cache;
 import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.transports.CommandVisitor;
 
 import java.io.IOException;
 
@@ -29,17 +30,7 @@
         return CommandTypes.REMOVE_SESSION_COMMAND;
     }
 
-    public void execute(CacheInfoHolder info) throws IOException {
-        Cache cache = info.getCache(getCacheName(), true);
-
-        //Be sure a session was sent
-        if (!this.hasSession()){
-            throw new IOException("Session does not exist.");
-        }
-
-        cache.remove(this.getSessionId());
-
-        //Notify peers
-        info.getCacheNotifier().notifyRemoveSession(this);
+    public void execute(CommandVisitor visitor) throws IOException {
+        visitor.processRemoveSession(this);
     }
 }

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/CommandVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/CommandVisitor.java?view=auto&rev=452193
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/CommandVisitor.java
(added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/CommandVisitor.java
Mon Oct  2 13:21:22 2006
@@ -0,0 +1,42 @@
+/*
+ * 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.BulkSendCommand;
+import org.apache.geronimo.gcache.command.ClearCacheCommand;
+import org.apache.geronimo.gcache.command.GetCacheCommand;
+import org.apache.geronimo.gcache.command.MessageAckCommand;
+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.command.RemoveSessionCommand;
+
+import java.io.IOException;
+
+public interface CommandVisitor {
+
+    public void processRemoveSession(RemoveSessionCommand command);
+    public void processRemoveEntry(RemoveEntryCommand command);
+    public void processPutSession(PutSessionCommand command) throws IOException;
+    public void processPutEntry(PutEntryCommand command);
+    public void processMessageAck(MessageAckCommand command);
+    public void processGetCache(GetCacheCommand command);
+    public void processClearCache(ClearCacheCommand command);
+    public void processBulkSend(BulkSendCommand command);
+}

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

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

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

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/DefaultSelectionKeyProcessor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/DefaultSelectionKeyProcessor.java?view=diff&rev=452193&r1=452192&r2=452193
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/DefaultSelectionKeyProcessor.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/DefaultSelectionKeyProcessor.java
Mon Oct  2 13:21:22 2006
@@ -113,7 +113,8 @@
         command.readExternal(readChannel);
 
         //Do something with the data
-        command.execute(infoHolder);
+        TCPCommandVisitor visitor = new TCPCommandVisitor(infoHolder, key);
+        command.execute(visitor);
 
         // Test for closed connection on the client side
         if (count < 0) {

Added: 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=auto&rev=452193
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandVisitor.java
(added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandVisitor.java
Mon Oct  2 13:21:22 2006
@@ -0,0 +1,159 @@
+/*
+ * 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.transports.CommandVisitor;
+import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.command.RemoveSessionCommand;
+import org.apache.geronimo.gcache.command.RemoveEntryCommand;
+import org.apache.geronimo.gcache.command.PutSessionCommand;
+import org.apache.geronimo.gcache.command.PutEntryCommand;
+import org.apache.geronimo.gcache.command.MessageAckCommand;
+import org.apache.geronimo.gcache.command.GetCacheCommand;
+import org.apache.geronimo.gcache.command.ClearCacheCommand;
+import org.apache.geronimo.gcache.command.BulkSendCommand;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.Element;
+
+import java.util.Map;
+import java.util.Collections;
+import java.util.HashMap;
+import java.io.IOException;
+import java.nio.channels.SelectionKey;
+
+public class TCPCommandVisitor implements CommandVisitor {
+    Log log = LogFactory.getLog(TCPCommandVisitor.class);
+
+    private CacheInfoHolder infoHolder;
+    private SelectionKey key;
+
+    public TCPCommandVisitor(CacheInfoHolder infoHolder, SelectionKey key) {
+        this.key = key;
+        this.infoHolder = infoHolder;
+    }
+
+    public void processRemoveSession(RemoveSessionCommand command) {
+
+        Cache cache = infoHolder.getCache(command.getCacheName(), true);
+
+        //Be sure a session was sent
+        if (command.hasSession()) {
+            cache.remove(command.getSessionId());
+        }
+
+        //Notify peers
+        infoHolder.getCacheNotifier().notifyRemoveSession(command);
+    }
+
+    public void processRemoveEntry(RemoveEntryCommand command) {
+
+
+        Cache cache = infoHolder.getCache(command.getCacheName(), true);
+
+        //Check if we are using sessions
+        if (command.hasSession()) {
+
+            Map sessionMap = null;
+
+            //We are so use the session maps that is stored
+            Element element = cache.get(command.getSessionId());
+            if (element != null) {
+                sessionMap = (Map) element.getObjectValue();
+            } else {
+                sessionMap = Collections.synchronizedMap(new HashMap());
+            }
+
+            sessionMap.remove(command.getHashableKey());
+
+            //Put the session away
+            cache.put(new Element(command.getSessionId(), sessionMap));
+
+        } else {
+
+            //No session map so store the value
+            cache.remove(command.getHashableKey());
+        }
+
+        //Notify peers
+        infoHolder.getCacheNotifier().notifyRemove(command);
+    }
+
+    public void processPutSession(PutSessionCommand command) {
+        Cache cache = infoHolder.getCache(command.getCacheName(), true);
+
+        //Place the raw session in the cache
+        try {
+            cache.put(new Element(command.getSessionId(), command.getRawSessionFromPayload()));
+        } catch (IOException e) {
+            log.info(e);
+        }
+
+        //Notify peers
+        infoHolder.getCacheNotifier().notifyPutSession(command);
+    }
+
+    public void processPutEntry(PutEntryCommand command) {
+        Cache cache = infoHolder.getCache(command.getCacheName(), true);
+
+        //Check if we are using sessions
+        if (command.hasSession()) {
+
+            Map sessionMap = null;
+
+            //We are so use the session maps that is stored
+            Element element = cache.get(command.getSessionId());
+            if (element != null) {
+                sessionMap = (Map) element.getObjectValue();
+            } else {
+                sessionMap = Collections.synchronizedMap(new HashMap());
+            }
+
+            sessionMap.put(command.getHashableKey(), command.getRawPayload());
+            //Put the session away
+            cache.put(new Element(command.getSessionId(), sessionMap));
+
+        } else {
+
+            //No session map so store the value
+            cache.put(new Element(command.getHashableKey(), command.getRawPayload()));
+        }
+
+        //Notify peers
+        infoHolder.getCacheNotifier().notifyPut(command);
+    }
+
+    public void processMessageAck(MessageAckCommand command) {
+    }
+
+    public void processGetCache(GetCacheCommand command) {
+    }
+
+    public void processClearCache(ClearCacheCommand command) {
+        Cache cache = infoHolder.getCache(command.getCacheName(), true);
+        cache.removeAll();
+
+        //Notify peers
+        infoHolder.getCacheNotifier().notifyClearCache(command);
+    }
+
+    public void processBulkSend(BulkSendCommand command) {
+    }
+}

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

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

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

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/ClearCacheCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/ClearCacheCommandTest.java?view=diff&rev=452193&r1=452192&r2=452193
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/ClearCacheCommandTest.java
(original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/ClearCacheCommandTest.java
Mon Oct  2 13:21:22 2006
@@ -20,10 +20,14 @@
 
 import org.testng.annotations.Test;
 import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.transports.tcp.TCPCommandVisitor;
 import net.sf.ehcache.CacheManager;
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.Element;
 
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Channels;
+
 public class ClearCacheCommandTest {
 
     @Test
@@ -58,7 +62,8 @@
         command.setCacheName(cacheName1);
 
         CacheInfoHolder info = new CacheInfoHolder(cacheMgr);
-        command.execute(info);
+        TCPCommandVisitor visitor = new TCPCommandVisitor(info, null);
+        command.execute(visitor);
 
         //Cache1 should be empty
         assert cache1.getSize() == 0;

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/PutEntryCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/PutEntryCommandTest.java?view=diff&rev=452193&r1=452192&r2=452193
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/PutEntryCommandTest.java
(original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/PutEntryCommandTest.java
Mon Oct  2 13:21:22 2006
@@ -20,6 +20,7 @@
 
 import org.testng.annotations.Test;
 import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.transports.tcp.TCPCommandVisitor;
 import org.apache.geronimo.gcache.util.ByteArray;
 
 import net.sf.ehcache.CacheManager;
@@ -39,7 +40,6 @@
         String data = "My Data";
 
         CacheManager cacheMgr = CacheManager.create();
-        CacheInfoHolder info = new CacheInfoHolder(cacheMgr);
 
         PutEntryCommand command = new PutEntryCommand();
 
@@ -48,7 +48,9 @@
         command.setSessionId(sessionId);
         command.setPayload(data);
 
-        command.execute(info);
+        CacheInfoHolder info = new CacheInfoHolder(cacheMgr);
+        TCPCommandVisitor visitor = new TCPCommandVisitor(info, null);
+        command.execute(visitor);
 
         Cache cache = cacheMgr.getCache(cacheName);
         assert cache != null;

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/PutSessionCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/PutSessionCommandTest.java?view=diff&rev=452193&r1=452192&r2=452193
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/PutSessionCommandTest.java
(original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/PutSessionCommandTest.java
Mon Oct  2 13:21:22 2006
@@ -21,6 +21,7 @@
 import org.testng.annotations.Test;
 import org.testng.annotations.BeforeSuite;
 import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.transports.tcp.TCPCommandVisitor;
 import org.apache.geronimo.gcache.util.ByteArray;
 import net.sf.ehcache.CacheManager;
 import net.sf.ehcache.Cache;
@@ -84,7 +85,8 @@
         assert cache.getSize() == 0;
 
         //Execute the command and it should repopulate the cache
-        command.execute(info);
+        TCPCommandVisitor visitor = new TCPCommandVisitor(info, null);
+        command.execute(visitor);
 
         //Test the cache it repoulated
         runTest();
@@ -111,7 +113,8 @@
         command.setSessionId(sessionId);
         command.setPayloadFromSession(sessionMap);
 
-        command.execute(info);
+        TCPCommandVisitor visitor = new TCPCommandVisitor(info, null);
+        command.execute(visitor);
 
         //Test the cache got populated
         runTest();
@@ -155,7 +158,8 @@
         command.setSessionId(sessionId);
         command.setPayload(data);
 
-        command.execute(info);
+        TCPCommandVisitor visitor = new TCPCommandVisitor(info, null);
+        command.execute(visitor);
 
     }
 }

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/RemoveEntryCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/RemoveEntryCommandTest.java?view=diff&rev=452193&r1=452192&r2=452193
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/RemoveEntryCommandTest.java
(original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/RemoveEntryCommandTest.java
Mon Oct  2 13:21:22 2006
@@ -20,6 +20,7 @@
 
 import org.testng.annotations.Test;
 import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.transports.tcp.TCPCommandVisitor;
 import org.apache.geronimo.gcache.util.ByteArray;
 import net.sf.ehcache.Element;
 import net.sf.ehcache.CacheManager;
@@ -59,7 +60,8 @@
 
         //Execute the command
         CacheInfoHolder info = new CacheInfoHolder(cacheMgr);
-        command.execute(info);
+        TCPCommandVisitor visitor = new TCPCommandVisitor(info, null);
+        command.execute(visitor);
 
         //Check the cache
         Element element = cache.get(sessionId);

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/RemoveSessionCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/RemoveSessionCommandTest.java?view=diff&rev=452193&r1=452192&r2=452193
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/RemoveSessionCommandTest.java
(original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/RemoveSessionCommandTest.java
Mon Oct  2 13:21:22 2006
@@ -22,6 +22,7 @@
 import net.sf.ehcache.CacheManager;
 import net.sf.ehcache.Element;
 import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.transports.tcp.TCPCommandVisitor;
 import org.apache.geronimo.gcache.util.ByteArray;
 import org.testng.annotations.Test;
 
@@ -29,7 +30,7 @@
 import java.util.Map;
 
 public class RemoveSessionCommandTest {
-        @Test
+    @Test
     public void testRemoveEntry() throws Exception {
         String cacheName = "Test";
         String key = "My Key";
@@ -59,7 +60,8 @@
 
         //Execute the command
         CacheInfoHolder info = new CacheInfoHolder(cacheMgr);
-        command.execute(info);
+        TCPCommandVisitor visitor = new TCPCommandVisitor(info, null);
+        command.execute(visitor);
 
         //Check the cache
         Element element = cache.get(sessionId);



Mime
View raw message