geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r473002 [1/3] - in /geronimo/sandbox/gcache: ./ common/ common/src/ common/src/main/ common/src/main/java/ common/src/main/java/org/ common/src/main/java/org/apache/ common/src/main/java/org/apache/geronimo/ common/src/main/java/org/apache/...
Date Thu, 09 Nov 2006 18:23:31 GMT
Author: jgenender
Date: Thu Nov  9 10:23:28 2006
New Revision: 473002

URL: http://svn.apache.org/viewvc?view=rev&rev=473002
Log:
Refactor server code to common for both client and server

Added:
    geronimo/sandbox/gcache/common/
    geronimo/sandbox/gcache/common/pom.xml   (with props)
    geronimo/sandbox/gcache/common/src/
    geronimo/sandbox/gcache/common/src/main/
    geronimo/sandbox/gcache/common/src/main/java/
    geronimo/sandbox/gcache/common/src/main/java/org/
    geronimo/sandbox/gcache/common/src/main/java/org/apache/
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/AuthCommand.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BulkSendCommand.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CacheBaseCommand.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommand.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/Command.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/DiscoveryCommand.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/GetCacheCommand.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/HandShakeCommand.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/MessageAckCommand.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PublicKeyCommand.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PutEntryCommand.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PutSessionCommand.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/RemoveEntryCommand.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/RemoveSessionCommand.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/CacheNotifier.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/DefaultCacheNotifier.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/marshal/
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/marshal/MarshalAware.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/BaseCommandVisitor.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/CommandVisitor.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/Constants.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/DiscoveryManager.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/Endpoint.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/EndpointManager.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/TransportFactory.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/TransportService.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/discovery/
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgent.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgentFactory.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryListener.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/BufferChannelInputStream.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/BufferChannelReader.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/BufferChannelWriter.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteArray.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteArrayInputStream.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteArrayOutputStream.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteSequence.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/CipherUtil.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/FactoryFinder.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/HexDump.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/IOExceptionSupport.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/IntrospectionSupport.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/StringUtil.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/URISupport.java   (with props)
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/UniqueId.java   (with props)
    geronimo/sandbox/gcache/common/src/test/
    geronimo/sandbox/gcache/common/src/test/java/
    geronimo/sandbox/gcache/common/src/test/java/org/
    geronimo/sandbox/gcache/common/src/test/java/org/apache/
    geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/
    geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/
    geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/
    geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/AuthCommandTest.java   (with props)
    geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/BaseCommandTest.java   (with props)
    geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/BulkSendCommandTest.java   (with props)
    geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/CacheBaseCommandTest.java   (with props)
    geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommandTest.java   (with props)
    geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/ClearCacheCommandTest.java   (with props)
    geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/DiscoveryCommandTest.java   (with props)
    geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/MessageAckCommandTest.java   (with props)
    geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/PutEntryCommandTest.java   (with props)
    geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/PutSessionCommandTest.java   (with props)
    geronimo/sandbox/gcache/common/temp-testng-customsuite.xml   (with props)
Removed:
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/ThreadSupport.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/CommandVisitor.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/DiscoveryManager.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/Endpoint.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/EndpointManager.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/TransportFactory.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/TransportService.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgent.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgentFactory.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryListener.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/util/
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/AuthCommandTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/BaseCommandTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/BulkSendCommandTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CacheBaseCommandTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommandTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/DiscoveryCommandTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/MessageAckCommandTest.java
Modified:
    geronimo/sandbox/gcache/pom.xml
    geronimo/sandbox/gcache/server/pom.xml
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCacheNotifier.java

Added: geronimo/sandbox/gcache/common/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/pom.xml?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/pom.xml (added)
+++ geronimo/sandbox/gcache/common/pom.xml Thu Nov  9 10:23:28 2006
@@ -0,0 +1,60 @@
+<project>
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.geronimo.gcache</groupId>
+        <artifactId>gcache</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>gcache-common</artifactId>
+    <packaging>jar</packaging>
+    <version>${gcacheVersion}</version>
+
+    <name>GCache :: Common </name>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>backport-util-concurrent</groupId>                
+            <artifactId>backport-util-concurrent</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.testng</groupId>
+            <artifactId>testng</artifactId>
+            <classifier>jdk15</classifier>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>net.sf.ehcache</groupId>
+            <artifactId>ehcache</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.mina</groupId>
+            <artifactId>mina-core</artifactId>
+        </dependency>
+
+    </dependencies>
+    <build>
+    </build>
+
+</project>

Propchange: geronimo/sandbox/gcache/common/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,77 @@
+/*
+ * 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;
+
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.CacheManager;
+
+import org.apache.geronimo.gcache.listeners.CacheNotifier;
+import org.apache.geronimo.gcache.listeners.DefaultCacheNotifier;
+import org.apache.geronimo.gcache.transports.EndpointManager;
+import org.apache.geronimo.gcache.transports.DiscoveryManager;
+
+public class CacheInfoHolder {
+    private final CacheManager cacheManager;
+    private CacheNotifier cacheNotifier = null;
+    private EndpointManager endpointManager;
+    private DiscoveryManager discoveryManager;
+
+    public CacheInfoHolder(CacheManager cacheManager) {
+        this.cacheManager = cacheManager;
+        this.endpointManager = new EndpointManager();
+        this.discoveryManager = new DiscoveryManager();
+    }
+
+    public DiscoveryManager getDiscoveryManager() {
+        return discoveryManager;
+    }
+
+    public EndpointManager getEndpointManager() {
+        return endpointManager;
+    }
+
+    public CacheManager getCacheManager() {
+        return cacheManager;
+    }
+
+    public CacheNotifier getCacheNotifier() {
+        
+        if (cacheNotifier == null)
+            cacheNotifier = new DefaultCacheNotifier();
+
+        return cacheNotifier;
+    }
+
+    public void setCacheNotifier(CacheNotifier cacheNotifier) {
+        this.cacheNotifier = cacheNotifier;
+        cacheNotifier.setInfo(this);
+    }
+
+    public Cache getCache(String cacheName, boolean create){
+        Cache cache = cacheManager.getCache(cacheName);
+        if (cache == null){
+            //TODO setup the cache properly with a configuration
+            cacheManager.addCache(cacheName);
+            cache = cacheManager.getCache(cacheName);
+        }
+
+        return cache;
+    }
+
+}

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

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

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/AuthCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/AuthCommand.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/AuthCommand.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/AuthCommand.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,110 @@
+/**
+ *
+ * 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;
+import java.security.PublicKey;
+
+import org.apache.geronimo.gcache.util.CipherUtil;
+import org.apache.mina.common.ByteBuffer;
+
+public class AuthCommand extends BaseCommand {
+    
+    private String userId;
+    private String password;
+    
+    private PublicKey publicKey;
+    
+    
+    @Override
+    public byte getCommandType() throws IOException {
+	return CommandTypes.AUTH_COMMAND;
+    }
+
+    public PublicKey getPublicKey() {
+        return publicKey;
+    }
+
+    public void setPublicKey(PublicKey publicKey) {
+        this.publicKey = publicKey;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public String getUserId() {
+        return userId;
+    }
+
+    public void setUserId(String userId) {
+        this.userId = userId;
+    }
+
+    @Override
+    public void readExternal(ByteBuffer buffer) throws Exception {
+	super.readExternal(buffer);
+	
+	int len = buffer.getInt();
+	if (len == -1){
+	    userId = null;
+	} else {
+	    byte decrypted[] = new byte[len];
+	    buffer.get(decrypted);
+	    userId = CipherUtil.RSADecrypt(decrypted);
+	}
+	
+	len = buffer.getInt();
+	if (len == -1){
+	    password = null;
+	} else {
+	    byte decrypted[] = new byte[len];
+	    buffer.get(decrypted);
+	    password = CipherUtil.RSADecrypt(decrypted);
+	}
+    }
+    
+    @Override
+    public void writeExternal(ByteBuffer buffer) throws Exception {
+	super.writeExternal(buffer);
+	
+	if (publicKey == null)
+	    throw new Exception("PublicKey not set on AuthCommand, cannot encrypt packet.");
+	
+	if (userId == null){
+	    buffer.putInt(-1);
+	} else {
+	    byte encrypted[] = CipherUtil.RSAEncrypt(userId, publicKey);
+	    buffer.putInt(encrypted.length);
+	    buffer.put(encrypted);
+	}
+	
+	if (password == null){
+	    buffer.putInt(-1);
+	} else {
+	    byte encrypted[] = CipherUtil.RSAEncrypt(password, publicKey);
+	    buffer.putInt(encrypted.length);
+	    buffer.put(encrypted);
+	}
+    }
+
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/AuthCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/AuthCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/AuthCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 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=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,322 @@
+/*
+ * 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;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.nio.channels.Channels;
+import java.nio.channels.WritableByteChannel;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+
+import org.apache.geronimo.gcache.marshal.MarshalAware;
+import org.apache.geronimo.gcache.transports.CommandVisitor;
+import org.apache.geronimo.gcache.transports.Constants;
+import org.apache.geronimo.gcache.util.ByteArrayInputStream;
+import org.apache.geronimo.gcache.util.ByteArrayOutputStream;
+import org.apache.geronimo.gcache.util.UniqueId;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.util.CharsetUtil;
+
+public class BaseCommand implements Command {
+
+    /**
+     * a unique identifier for this command, used specifically in situations
+     * where a response is required as a coorilation id.
+     */
+    private long commandId = 0;
+    
+    /**
+     * Allows an object to be attached for passing around during processing
+     * of the command
+     */
+    private transient Object attachment = null;
+    
+    public Object getAttachment() {
+        return attachment;
+    }
+
+    public void setAttachment(Object attachment) {
+        this.attachment = attachment;
+    }
+
+    /**
+     * Get the command type. Types are integers and are used by gcache to
+     * create a new instance of the correct command when the command arrives
+     * at its destination.
+     */
+    public byte getCommandType() throws IOException {
+	throw new IOException(
+		"Invalid command type - subclasses must over ride getCommandType");
+    }
+
+    /**
+     * The command id is used to uniquely identify this command and is
+     * specifically used in the case where a response is required. If the
+     * command id is still set to the default 0 a unique id is generated by
+     * the UniqueId class.
+     * 
+     * @see org.apache.geronimo.gcache.util.UniqueId
+     */
+    public long getCommandId() {
+	if (commandId == 0) {
+	    commandId = UniqueId.get();
+	}
+	return commandId;
+    }
+
+    /**
+     * This method is provided for the cases where a specfic id is required
+     * to coordinate with another (external) framework. Typical use will not
+     * require this method to be called, the default mechanism will suffice.
+     * 
+     * @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;
+    }
+
+    /**
+     * This default implementation does nothing, subclasses will perform
+     * whatever task this command is supposed to do.
+     */
+    public void execute(CommandVisitor visitor) throws Exception {
+	// nothing to do in the base
+    }
+
+    /**
+     * @see org.apache.geronimo.gcache.marshal.MarshalAware.readExternal(ReadableByteChannel)
+     */
+    public void readExternal(ByteBuffer buffer) throws Exception {
+	// this is the root so no super impl, others should call super first
+	commandId = buffer.getLong();
+    }
+
+    /**
+     * @see org.apache.geronimo.gcache.marshal.MarshalAware.writeExternal(WritableByteChannel)
+     */
+    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);
+    }
+
+    /**
+     * Create a byte array to hold the data for this command. Header
+     * information (the first 13 bytes) are written first The first byte is
+     * the command type, the second 8 bytes are a checksum, the next 4 bytes
+     * are the command length. The remainder of the bytes will be the result
+     * of the writeExternal implementation of the command.
+     * 
+     * @return
+     * @throws IOException
+     */
+    public byte[] createPacket(boolean includeMagic) throws Exception {
+
+	ByteBuffer buffer = null;
+
+	try {
+	    buffer = ByteBuffer.allocate(256, false);
+	    buffer.setAutoExpand(true);
+
+	    // COMMAND TYPE - 1 byte
+	    // COMMAND LENGTH - 4 bytes
+	    // COMMAND - ? bytes as defined above/
+	    int startFrom = includeMagic ? Constants.MAGIC.length : 0;
+
+	    // Write magic if requested
+	    if (includeMagic)
+		buffer.put(Constants.MAGIC);
+
+	    // Write the command type
+	    buffer.put(getCommandType());
+
+	    // Mark the length position
+	    buffer.mark();
+
+	    // Place hold the length
+	    buffer.putInt(0);
+
+	    // Marshal the command
+	    writeExternal(buffer);
+
+	    int commandStart = startFrom + 5;
+
+	    int pos = buffer.position();
+	    int len = pos - commandStart;
+
+	    buffer.reset();
+	    // Write the length of the command
+	    buffer.putInt(len);
+	    buffer.position(pos);
+	    buffer.limit(pos);
+	    
+	    buffer.flip();
+	    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+	    WritableByteChannel channel = Channels.newChannel(baos);
+	    channel.write(buffer.buf());
+	    return baos.toByteArray();
+	} finally {
+	    if (buffer != null)
+		buffer.release();
+
+	}
+    }
+
+    public byte[] marshal() throws Exception {
+	ByteBuffer buffer = null;
+	try {
+	    buffer = ByteBuffer.allocate(4096, true);
+	    buffer.setAutoExpand(true);
+	    ByteArrayOutputStream baos = new ByteArrayOutputStream(34);
+	    WritableByteChannel channel = Channels.newChannel(baos);
+	    writeExternal(buffer);
+	    
+	    buffer.limit(buffer.position());
+	    buffer.flip();
+	    
+	    channel.write(buffer.buf());
+	    channel.close();
+	    
+	    return baos.toByteArray();
+	} finally {
+
+	}
+    }
+
+    /**
+     * Rebuld an object from an array of bytes.
+     * 
+     * @param data
+     * @return
+     * @throws IOException
+     */
+    // TODO - this method hoses MarshalAware - IMO this is not the place for
+    // this method, its a utility method
+    public static Object convertObjectFromBytes(byte data[]) throws IOException {
+	if (data == null)
+	    return null;
+
+	ByteArrayInputStream bais = new ByteArrayInputStream(data);
+	ObjectInputStream ois = new ObjectInputStream(bais);
+	try {
+	    return ois.readObject();
+	} catch (ClassNotFoundException e) {
+	    throw new IOException(e.getMessage());
+	}
+    }
+
+    protected String readString(ByteBuffer buffer) throws IOException {
+
+	CharsetDecoder decoder = CharsetUtil.getDefaultCharset().newDecoder();
+	byte nullFlag = buffer.get();
+	if (nullFlag == 0)
+	    return null;
+
+	String str = buffer.getString(decoder);
+
+	// String str = Charset.defaultCharset().decode(buffer).toString();
+
+	return str;
+    }
+    
+    protected void writeString(ByteBuffer buffer, String str)
+	    throws IOException {
+	
+	if (str == null){
+	    buffer.put((byte)0);
+	    return;
+	} else {
+	    buffer.put((byte)1);
+	}
+
+	CharsetEncoder encoder = CharsetUtil.getDefaultCharset().newEncoder();
+	buffer.putString(str, encoder);
+	
+	//Null terminate
+	buffer.put((byte)0);
+
+    }
+    
+    protected byte[] readBytes(ByteBuffer buffer) {
+
+	// Read size
+	int byteCount = buffer.getInt();
+
+	if (byteCount == -1)
+	    return null;
+
+	byte bytes[] = new byte[byteCount];
+	buffer.get(bytes);
+
+	return bytes;
+    }
+
+    protected void writeBytes(ByteBuffer buffer, byte[] bytes)
+	    throws IOException {
+	
+	if (bytes == null){
+	    buffer.putInt(-1);
+	    return;
+	}
+
+	buffer.putInt(bytes.length);
+	buffer.put(bytes);
+
+    }
+
+    public static byte[] convertObjectToBytes(Object object) throws IOException {
+	/*
+	 * MarshalAware is requried so objects that get put into the cache can
+	 * take advantage of the faster way of serializaing objects, if they
+	 * don't want to then they can skip it or for simplicity's sake they can
+	 * start with Serizliazable then implement MarshalAware if serizlization
+	 * performance becomes a concern.
+	 */
+	if (object instanceof MarshalAware) {
+	    /**
+	     * ByteArrayOutputStream baos = new ByteArrayOutputStream(34);
+	     * WritableByteChannel channel = Channels.newChannel(baos);
+	     * ((MarshalAware) object).writeExternal(channel);
+	     * channel.close(); return baos.toByteArray();
+	     */
+	    return null;
+	} else if (object instanceof Serializable) {
+	    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+	    ObjectOutputStream stream = new ObjectOutputStream(baos);
+	    stream.writeObject(object);
+	    stream.flush();
+	    stream.close();
+	    return baos.toByteArray();
+	} else {
+	    throw new RuntimeException("Invalid argument - Object"
+		    + " is not an instance of java.io.Serializable"
+		    + " or MarshalAware");
+	}
+    }
+
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BulkSendCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BulkSendCommand.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BulkSendCommand.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BulkSendCommand.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,62 @@
+/*
+ * 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;
+
+import org.apache.geronimo.gcache.transports.CommandVisitor;
+import org.apache.mina.common.ByteBuffer;
+
+/**
+ * This command is letting the client or server know that it can expext
+ * 'x' number of commands to follow
+ */
+public class BulkSendCommand extends BaseCommand {
+
+    private int numberOfCommands;
+
+    public byte getCommandType() throws IOException {
+        return CommandTypes.BULK_SEND_COMMAND;
+    }
+
+    public int getNumberOfCommands() {
+        return numberOfCommands;
+    }
+
+    public void setNumberOfCommands(int numberOfCommands) {
+        this.numberOfCommands = numberOfCommands;
+    }
+
+
+    public void readExternal(ByteBuffer buffer) throws Exception{
+        super.readExternal(buffer);
+
+        numberOfCommands = buffer.getInt();
+    }
+
+    public void writeExternal(ByteBuffer buffer) throws Exception {
+        super.writeExternal(buffer);
+        buffer.putInt(numberOfCommands);
+    }
+
+    public void execute(CommandVisitor visitor) throws Exception {
+
+        visitor.processBulkSend(this);
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BulkSendCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BulkSendCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BulkSendCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CacheBaseCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CacheBaseCommand.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CacheBaseCommand.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CacheBaseCommand.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,98 @@
+/*
+ * 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;
+
+import org.apache.geronimo.gcache.util.ByteArray;
+import org.apache.mina.common.ByteBuffer;
+
+public class CacheBaseCommand extends BaseCommand {
+
+    //Name of cache
+    private String cacheName = null;
+
+    // The Session to store the payload under
+    private String sessionId;
+
+    // The key to store the payload under
+    private byte[] key;
+
+    public String getCacheName() {
+        return cacheName;
+    }
+
+    public void setCacheName(String cacheName) {
+        this.cacheName = cacheName;
+    }
+
+    public boolean hasSession(){
+        return sessionId != null;
+    }
+
+    public byte[] getRawKey() {
+        return key;
+    }
+
+    public void setRawKey(byte[] key) {
+        this.key = key;
+    }
+
+    public String getSessionId() {
+        return sessionId;
+    }
+
+    public void setSessionId(String sessionId) {
+        this.sessionId = sessionId;
+    }
+
+    public void setKey(Object value) throws IOException {
+        setRawKey(convertObjectToBytes(value));
+    }
+
+    public Object getKey() throws IOException{
+        return convertObjectFromBytes(getRawKey());
+    }
+
+    public ByteArray getHashableKey(){
+        if (key == null){
+            return null;
+        }
+
+        return new ByteArray(key);
+    }
+
+    public void readExternal(ByteBuffer buffer) throws Exception{
+        super.readExternal(buffer);
+
+        //Process what we want read
+        cacheName = readString(buffer);
+        key = readBytes(buffer);
+        sessionId = readString(buffer);
+    }
+
+    public void writeExternal(ByteBuffer buffer) throws Exception {
+        super.writeExternal(buffer);
+
+        //Process what we want to write
+        writeString(buffer, cacheName);
+        writeBytes(buffer, key);
+        writeString(buffer, sessionId);
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CacheBaseCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CacheBaseCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CacheBaseCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommand.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommand.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommand.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,60 @@
+/*
+ * 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;
+
+import org.apache.mina.common.ByteBuffer;
+
+public class CachePayloadBaseCommand extends CacheBaseCommand {
+
+    // this is the actual data that must be added to the distributed cache
+    private byte[] payload = null;
+
+    public void readExternal(ByteBuffer buffer) throws Exception {
+	super.readExternal(buffer);
+
+	// Process what we want to read
+	payload = readBytes(buffer);
+    }
+
+    public void writeExternal(ByteBuffer buffer) throws Exception {
+	super.writeExternal(buffer);
+
+	// Process what we want to write
+	writeBytes(buffer, payload);
+    }
+
+    public void setPayload(Object value) throws IOException {
+	setRawPayload(convertObjectToBytes(value));
+    }
+
+    public Object getPayload() throws IOException {
+	return convertObjectFromBytes(getRawPayload());
+    }
+
+    public byte[] getRawPayload() {
+	return payload;
+    }
+
+    public void setRawPayload(byte[] data) {
+	this.payload = data;
+    }
+
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.geronimo.gcache.command;
+
+import java.io.IOException;
+
+import org.apache.geronimo.gcache.transports.CommandVisitor;
+
+public class ClearCacheCommand extends CacheBaseCommand {
+
+    public byte getCommandType() throws IOException {
+        return CommandTypes.CLEARCACHE_COMMAND;
+    }
+
+    public void execute(CommandVisitor visitor) throws IOException {
+        visitor.processClearCache(this);
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/Command.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/Command.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/Command.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/Command.java Thu Nov  9 10:23:28 2006
@@ -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.command;
+
+import java.io.IOException;
+
+import org.apache.geronimo.gcache.marshal.MarshalAware;
+import org.apache.geronimo.gcache.transports.CommandVisitor;
+
+/**
+ * Commands are pushed around the cluster to the various nodes and they are
+ * invoked upon reciept.
+ */
+public interface Command extends MarshalAware {
+    public long getCommandId();
+
+    public byte getCommandType() throws IOException;
+
+    public void execute(CommandVisitor visitor) throws Exception;
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/Command.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/Command.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/Command.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 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=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,59 @@
+package org.apache.geronimo.gcache.command;
+
+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 CLEARCACHE_COMMAND = 6;
+    public static final byte MESSAGE_ACK_COMMAND = 7;
+    public static final byte BULK_SEND_COMMAND = 8;
+    public static final byte REMOVE_SESSION_COMMAND = 9;
+    public static final byte PUT_SESSION_COMMAND = 10;
+    public static final byte GET_CACHE_COMMAND = 11;
+    public static final byte DISCOVERY_COMMAND = 12;
+
+    public static Command createCommand(int identifier) {
+        Command command = null;
+        switch (identifier) {
+            case(HAND_SHAKE_COMMAND):
+                command = new HandShakeCommand();
+                break;
+            case(AUTH_COMMAND):
+                command = new AuthCommand();
+                break;
+            case(PUBLIC_KEY_COMMAND):
+                command = new PublicKeyCommand();
+                break;
+            case(PUT_ENTRY_COMMAND):
+                command = new PutEntryCommand();
+                break;
+            case(REMOVE_ENTRY_COMMAND):
+                command = new RemoveEntryCommand();
+                break;
+            case(CLEARCACHE_COMMAND):
+                command = new ClearCacheCommand();
+                break;
+            case(MESSAGE_ACK_COMMAND):
+                command = new MessageAckCommand();
+                break;
+            case(BULK_SEND_COMMAND):
+                command = new BulkSendCommand();
+                break;
+            case(REMOVE_SESSION_COMMAND):
+                command = new RemoveSessionCommand();
+                break;
+            case(PUT_SESSION_COMMAND):
+                command = new PutSessionCommand();
+                break;
+            case(GET_CACHE_COMMAND):
+                command = new GetCacheCommand();
+                break;
+            case(DISCOVERY_COMMAND):
+                command = new DiscoveryCommand();
+                break;
+        }
+        return command;
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/DiscoveryCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/DiscoveryCommand.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/DiscoveryCommand.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/DiscoveryCommand.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,66 @@
+/**
+ *
+ * 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 org.apache.mina.common.ByteBuffer;
+
+public class DiscoveryCommand extends BaseCommand {
+    
+    private String nodeName;
+    private String service;
+    private int order;
+
+    public int getOrder() {
+        return order;
+    }
+
+    public void setOrder(int order) {
+        this.order = order;
+    }
+
+    public String getService() {
+        return service;
+    }
+
+    public void setService(String service) {
+        this.service = service;
+    }
+
+    public String getNodeName() {
+        return nodeName;
+    }
+
+    public void setNodeName(String nodeName) {
+        this.nodeName = nodeName;
+    }
+
+    @Override
+    public void readExternal(ByteBuffer buffer) throws Exception {
+	super.readExternal(buffer);
+        nodeName = readString(buffer);
+        service = readString(buffer);
+    }
+
+    @Override
+    public void writeExternal(ByteBuffer buffer) throws Exception {
+	super.writeExternal(buffer);
+        writeString(buffer, nodeName);
+        writeString(buffer, service);
+    }
+
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/DiscoveryCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/DiscoveryCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/DiscoveryCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/GetCacheCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/GetCacheCommand.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/GetCacheCommand.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/GetCacheCommand.java Thu Nov  9 10:23:28 2006
@@ -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.command;
+
+import java.io.IOException;
+
+import org.apache.geronimo.gcache.transports.CommandVisitor;
+
+/**
+ * This class represents a request to obtain a copy of an
+ * entire cache.  The sender should set the cache name, and
+ * the receiver will acknowledge this by sending a BulkSendCommand
+ * back to the client, followed by PutSessionCommands (for sessions)
+ * and PutEntryCommands for non-Session data.
+ */
+public class GetCacheCommand extends CacheBaseCommand{
+
+    public byte getCommandType() throws IOException {
+        return CommandTypes.GET_CACHE_COMMAND;
+    }
+
+    public void execute(CommandVisitor visitor) throws IOException {
+        visitor.processGetCache(this);
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/GetCacheCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/GetCacheCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/GetCacheCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/HandShakeCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/HandShakeCommand.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/HandShakeCommand.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/HandShakeCommand.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,78 @@
+/**
+ *
+ * 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;
+import java.security.PublicKey;
+import java.security.spec.InvalidKeySpecException;
+
+import org.apache.geronimo.gcache.util.CipherUtil;
+import org.apache.mina.common.ByteBuffer;
+
+public class HandShakeCommand extends BaseCommand {
+    
+    PublicKey publicKey = null;
+    
+    @Override
+    public byte getCommandType() throws IOException {
+	return CommandTypes.HAND_SHAKE_COMMAND;
+    }
+    
+    public PublicKey getPublicKey() {
+        return publicKey;
+    }
+
+    public void setPublicKey(PublicKey publicKey) {
+        this.publicKey = publicKey;
+    }
+
+    @Override
+    public void readExternal(ByteBuffer buffer) throws Exception {
+	super.readExternal(buffer);
+	
+	int len = buffer.getInt();
+	if (len == -1){
+	    publicKey = null;
+	    return;
+	}
+	
+	byte rawPublicKey[] = new byte[len];
+	buffer.get(rawPublicKey);
+	
+	try {
+	    publicKey = CipherUtil.bytesToPublicKey(rawPublicKey);
+	} catch (InvalidKeySpecException e) {
+	    throw new IOException(e.getMessage());
+	}
+    }
+
+    @Override
+    public void writeExternal(ByteBuffer buffer) throws Exception {
+	super.writeExternal(buffer);
+	if (publicKey == null){
+	    buffer.putInt(-1);
+	    return;
+	}
+	
+	byte rawPublicKey[] = publicKey.getEncoded();
+
+	buffer.putInt(rawPublicKey.length);
+	buffer.put(rawPublicKey);
+    }
+
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/HandShakeCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/HandShakeCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/HandShakeCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 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=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/MessageAckCommand.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/MessageAckCommand.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,60 @@
+/*
+ * 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;
+
+import org.apache.geronimo.gcache.transports.CommandVisitor;
+import org.apache.mina.common.ByteBuffer;
+
+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{
+        visitor.processMessageAck(this);
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/MessageAckCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/MessageAckCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/MessageAckCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PublicKeyCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PublicKeyCommand.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PublicKeyCommand.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PublicKeyCommand.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,32 @@
+/**
+ *
+ * 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 PublicKeyCommand extends HandShakeCommand {
+    //Same as the HandShake, but different type
+    //
+    //This just is a container as a response for a handshake event
+    //that sends back the key
+    @Override
+    public byte getCommandType() throws IOException {
+	return CommandTypes.PUBLIC_KEY_COMMAND;
+    }
+
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PublicKeyCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PublicKeyCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PublicKeyCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PutEntryCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PutEntryCommand.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PutEntryCommand.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PutEntryCommand.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,35 @@
+/*
+ * 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;
+
+import org.apache.geronimo.gcache.transports.CommandVisitor;
+
+public class PutEntryCommand extends CachePayloadBaseCommand {
+
+    public byte getCommandType() throws IOException {
+        return CommandTypes.PUT_ENTRY_COMMAND;
+    }
+
+    public void execute(CommandVisitor visitor) throws IOException {
+        visitor.processPutEntry(this);
+    }
+
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PutEntryCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PutEntryCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PutEntryCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PutSessionCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PutSessionCommand.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PutSessionCommand.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PutSessionCommand.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,242 @@
+/*
+ * 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;
+import java.nio.channels.Channels;
+import java.nio.channels.WritableByteChannel;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.geronimo.gcache.transports.CommandVisitor;
+import org.apache.geronimo.gcache.util.ByteArray;
+import org.apache.geronimo.gcache.util.ByteArrayOutputStream;
+import org.apache.mina.common.ByteBuffer;
+
+public class PutSessionCommand extends CachePayloadBaseCommand {
+
+    private int entryCount;
+
+    public byte getCommandType() throws IOException {
+	return CommandTypes.PUT_SESSION_COMMAND;
+    }
+
+    public void readExternal(ByteBuffer buffer) throws Exception {
+	super.readExternal(buffer);
+	entryCount = buffer.getInt();
+    }
+
+    public void writeExternal(ByteBuffer buffer) throws Exception {
+	super.writeExternal(buffer);
+	buffer.putInt(entryCount);
+    }
+
+    /**
+     * Converts a session map made up of objects into a byte array payload.
+     * This should be used primarily by the client as the server will only
+     * be dealing with raw data.
+     * @param session
+     * @throws IOException
+     */
+    public void setPayloadFromSession(Map session) throws IOException {
+	ByteBuffer buffer = null;
+
+	try {
+	    Set set = session.keySet();
+	    entryCount = set.size();
+
+	    //Set up the output stream
+	    buffer = ByteBuffer.allocate(1024, false);
+	    buffer.setAutoExpand(true);
+
+	    for (Object aSet : set) {
+
+		byte rawKey[] = convertObjectToBytes(aSet);
+
+		//Keysize
+		buffer.putInt(rawKey.length);
+		buffer.put(rawKey);
+
+		//Data
+		Object objData = session.get(aSet);
+		byte data[] = convertObjectToBytes(objData);
+
+		//Data Size
+		buffer.putInt(data.length);
+		buffer.put(data);
+
+	    }
+
+	    //Set the payload
+	    buffer.limit(buffer.position());
+	    buffer.flip();
+	    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+	    WritableByteChannel channel = Channels.newChannel(baos);
+	    channel.write(buffer.buf());
+	    setRawPayload(baos.toByteArray());
+
+	} finally {
+	    if (buffer != null)
+		buffer.release();
+	}
+    }
+
+    /**
+     * Returns a normal map made up of objects that have meaning to the client from the payload.
+     * This is used primarily by the client since the server only cares about the raw bytes.
+     * @return
+     * @throws IOException
+     */
+    public Map getSessionFromPayload() throws IOException {
+
+	ByteBuffer buffer = null;
+	try {
+
+	    Map<Object, Object> sessionMap = Collections
+		    .synchronizedMap(new HashMap<Object, Object>());
+	    buffer = ByteBuffer.wrap(getRawPayload());
+	    int keySize;
+	    int dataSize;
+
+	    for (int i = 0; i < this.entryCount; i++) {
+
+		keySize = buffer.getInt();
+
+		//Read the key
+		byte[] key = new byte[keySize];
+		buffer.get(key);
+		Object objKey = convertObjectFromBytes(key);
+
+		//Get the data Size
+		dataSize = buffer.getInt();
+
+		//Get the data
+		byte[] data = new byte[dataSize];
+		buffer.get(data);
+		Object objData = convertObjectFromBytes(data);
+
+		//Place the objects in the map
+		sessionMap.put(objKey, objData);
+	    }
+
+	    return sessionMap;
+	} finally {
+	    if (buffer != null)
+		buffer.release();
+	}
+    }
+
+    /**
+     * Sets the payload bytes from a raw session map, or one that is made up of byes.
+     * This is primarily used on the server and client's shouldn't access this method.
+     * @param session
+     * @throws IOException
+     */
+    public void setPayloadFromRawSession(Map session) throws IOException {
+
+	ByteBuffer buffer = null;
+	try {
+
+	    Set set = session.keySet();
+	    entryCount = set.size();
+
+	    //Set up the output stream
+	    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+	    buffer = ByteBuffer.allocate(1024, true);
+	    buffer.setAutoExpand(true);
+	    WritableByteChannel channel = Channels.newChannel(baos);
+
+	    for (Object aSet : set) {
+
+		ByteArray key = (ByteArray) aSet;
+		byte rawKey[] = key.getBytes();
+
+		//Keysize
+		buffer.putInt(rawKey.length);
+		buffer.put(rawKey);
+
+		//Data
+		byte data[] = (byte[]) session.get(key);
+
+		//Data Size
+		buffer.putInt(data.length);
+		buffer.put(data);
+
+	    }
+	    buffer.limit(buffer.position());
+	    buffer.flip();
+	    channel.write(buffer.buf());
+
+	    //Set the payload
+	    setRawPayload(baos.toByteArray());
+	} finally {
+	    if (buffer != null)
+		buffer.release();
+	}
+    }
+
+    /**
+     * Will create a raw session from the payload that is used for server side storage.
+     * This method is used primarily for the server and should not be used by the client.
+     * @return
+     * @throws IOException
+     */
+    public Map getRawSessionFromPayload() throws IOException {
+
+	ByteBuffer buffer = null;
+	try {
+
+	    Map<ByteArray, byte[]> sessionMap = Collections
+		    .synchronizedMap(new HashMap<ByteArray, byte[]>());
+	    buffer = ByteBuffer.wrap(getRawPayload());
+
+	    int keySize;
+	    int dataSize;
+
+	    for (int i = 0; i < this.entryCount; i++) {
+		//Get the key Size
+		keySize = buffer.getInt();
+
+		//Read the key
+		byte[] key = new byte[keySize];
+		buffer.get(key);
+
+		//Get the data Size
+		dataSize = buffer.getInt();
+
+		//Get the data
+		byte[] data = new byte[dataSize];
+		buffer.get(data);
+
+		sessionMap.put(new ByteArray(key), data);
+	    }
+
+	    return sessionMap;
+	} finally {
+	    if (buffer != null)
+		buffer.release();
+	}
+    }
+
+    public void execute(CommandVisitor visitor) throws IOException {
+	visitor.processPutSession(this);
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PutSessionCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PutSessionCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PutSessionCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/RemoveEntryCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/RemoveEntryCommand.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/RemoveEntryCommand.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/RemoveEntryCommand.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.geronimo.gcache.command;
+
+import java.io.IOException;
+
+import org.apache.geronimo.gcache.transports.CommandVisitor;
+
+public class RemoveEntryCommand extends CacheBaseCommand{
+
+    public byte getCommandType() throws IOException {
+        return CommandTypes.REMOVE_ENTRY_COMMAND;
+    }
+
+    public void execute(CommandVisitor visitor) throws IOException {
+        visitor.processRemoveEntry(this);
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/RemoveEntryCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/RemoveEntryCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/RemoveEntryCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/RemoveSessionCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/RemoveSessionCommand.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/RemoveSessionCommand.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/RemoveSessionCommand.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.geronimo.gcache.command;
+
+import java.io.IOException;
+
+import org.apache.geronimo.gcache.transports.CommandVisitor;
+
+public class RemoveSessionCommand extends CacheBaseCommand{
+
+    public byte getCommandType() throws IOException {
+        return CommandTypes.REMOVE_SESSION_COMMAND;
+    }
+
+    public void execute(CommandVisitor visitor) throws IOException {
+        visitor.processRemoveSession(this);
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/RemoveSessionCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/RemoveSessionCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/RemoveSessionCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/CacheNotifier.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/CacheNotifier.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/CacheNotifier.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/CacheNotifier.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,49 @@
+/*
+ * 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.listeners;
+
+import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.command.ClearCacheCommand;
+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;
+
+public abstract class CacheNotifier {
+    
+    protected CacheInfoHolder info;
+    
+    public CacheInfoHolder getInfo() {
+        return info;
+    }
+
+    public void setInfo(CacheInfoHolder info) {
+        this.info = info;
+    }
+
+    public abstract void notifyClearCache(ClearCacheCommand command);
+
+    public abstract void notifyPut(PutEntryCommand command);
+
+    public abstract void notifyPutSession(PutSessionCommand command);
+
+    public abstract void notifyRemove(RemoveEntryCommand command);
+
+    public abstract void notifyRemoveSession(RemoveSessionCommand command);
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/CacheNotifier.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/CacheNotifier.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/CacheNotifier.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/DefaultCacheNotifier.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/DefaultCacheNotifier.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/DefaultCacheNotifier.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/DefaultCacheNotifier.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,46 @@
+/*
+ * 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.listeners;
+
+import org.apache.geronimo.gcache.command.PutEntryCommand;
+import org.apache.geronimo.gcache.command.RemoveEntryCommand;
+import org.apache.geronimo.gcache.command.ClearCacheCommand;
+import org.apache.geronimo.gcache.command.RemoveSessionCommand;
+import org.apache.geronimo.gcache.command.PutSessionCommand;
+
+/**
+ * Default implementation of a cache notifier that does nothing
+ */
+public class DefaultCacheNotifier extends CacheNotifier {
+
+    public void notifyClearCache(ClearCacheCommand command){
+    }
+
+    public void notifyPut(PutEntryCommand command) {
+    }
+
+    public void notifyRemoveSession(RemoveSessionCommand command) {
+    }
+
+    public void notifyRemove(RemoveEntryCommand command) {
+    }
+
+    public void notifyPutSession(PutSessionCommand command) {
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/DefaultCacheNotifier.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/DefaultCacheNotifier.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/DefaultCacheNotifier.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message