geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r448118 - in /geronimo/sandbox/gcache/server/src: main/java/org/apache/geronimo/gcache/ main/java/org/apache/geronimo/gcache/command/ main/java/org/apache/geronimo/gcache/marshal/ main/java/org/apache/geronimo/gcache/server/impl/ main/java/...
Date Wed, 20 Sep 2006 08:09:24 GMT
Author: jgenender
Date: Wed Sep 20 01:09:22 2006
New Revision: 448118

URL: http://svn.apache.org/viewvc?view=rev&rev=448118
Log:
GERONIMO-2418 Add marshalling code

Added:
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/AddEntryCommand.java   (with props)
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java   (with props)
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/Command.java   (with props)
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java   (with props)
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/marshal/
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/marshal/MarshalAware.java   (with props)
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/DefaultSelectionKeyProcessor.java   (with props)
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/SelectionKeyProcessor.java   (with props)
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/AddEntryCommandTest.java   (with props)
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/BaseCommandTest.java   (with props)
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/MockSelectionKeyProcessor.java   (with props)
Modified:
    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/impl/DefaultThreadPoolImpl.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPBootstrapCacheLoader.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPBootstrapCacheLoaderFactory.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPCacheManagerPeerListener.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPCacheManagerPeerListenerFactory.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketHandler.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketServer.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TcpSocketServerTest.java

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/ThreadSupport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/ThreadSupport.java?view=diff&rev=448118&r1=448117&r2=448118
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/ThreadSupport.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/ThreadSupport.java Wed Sep 20 01:09:22 2006
@@ -16,8 +16,14 @@
  */
 package org.apache.geronimo.gcache;
 
-public abstract class ThreadSupport extends Thread{
+/**
+ * provide basic support for multi-threading a process. Subclass this class and
+ * provide implementations of initialize, execute and cleanUp and the threaded
+ * behavior is handled here
+ */
+public abstract class ThreadSupport extends Thread {
     private boolean stopped;
+
     private boolean running;
 
     public final void run() {
@@ -27,7 +33,7 @@
         stopped = false;
         running = true;
 
-        while(!stopped){
+        while (!stopped) {
             execute();
         }
 
@@ -39,11 +45,11 @@
     protected abstract void execute();
     protected abstract void cleanUp();
 
-    public void halt(){
+    public void halt() {
         stopped = true;
     }
 
-    public boolean isRunning(){
+    public boolean isRunning() {
         return running;
     }
 

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/AddEntryCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/AddEntryCommand.java?view=auto&rev=448118
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/AddEntryCommand.java (added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/AddEntryCommand.java Wed Sep 20 01:09:22 2006
@@ -0,0 +1,81 @@
+/*
+ * 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.ObjectOutputStream;
+import java.io.Serializable;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channels;
+import java.nio.channels.WritableByteChannel;
+
+import org.apache.geronimo.gcache.marshal.MarshalAware;
+import java.io.ByteArrayOutputStream;
+
+public class AddEntryCommand extends BaseCommand {
+    private static final int DEFAULT_CAPACITY = 1024;
+
+    // the key to store the payload under
+    private String key;
+
+    // this is the actual data that must be added to the distributed cache
+    private ByteBuffer payload = ByteBuffer.allocate(DEFAULT_CAPACITY);
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+    
+    public void execute() {
+        //TODO: make this add the payload to the local cache then call back to the pusher
+    }
+
+    public void setValue(Object value) throws IOException {
+        if (value instanceof Serializable) {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            ObjectOutputStream stream = new ObjectOutputStream(baos);
+            stream.writeObject(value);
+            stream.flush();
+            stream.close();
+            setPayload(ByteBuffer.wrap(baos.toByteArray()));
+        } else if (value instanceof MarshalAware) {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream(34);
+            WritableByteChannel channel = Channels.newChannel(baos);
+            ((MarshalAware)value).writeExternal(channel);
+            channel.close();
+            setPayload(ByteBuffer.wrap(baos.toByteArray()));
+        } else {
+            throw new RuntimeException("Invalid argument - " + value
+                    + " is not an instance of java.io.Seriallizable"
+                    + " or MarshalAware");
+        }
+    }
+
+    public ByteBuffer getPayload() {
+        return payload;
+    }
+
+    public void setPayload(ByteBuffer payload) {
+        this.payload = payload;
+    }
+
+}

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

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

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

Added: 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=auto&rev=448118
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java (added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java Wed Sep 20 01:09:22 2006
@@ -0,0 +1,80 @@
+/*
+ * 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.ByteBuffer;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+import java.nio.charset.Charset;
+
+public class BaseCommand implements Command {
+    private String commandId = null;
+
+    public String getCommandId() {
+        return commandId;
+    }
+
+    public void setCommandId(String commandId) {
+        this.commandId = commandId;
+    }
+
+    public void execute() {
+        // nothing to do in the base
+    }
+    
+    public void readExternal(ReadableByteChannel channel) throws IOException {
+        // this is the root so no super impl, others should call super first
+
+        // first the length of the string
+        ByteBuffer buffer = ByteBuffer.allocateDirect(4);
+        int read = channel.read(buffer);
+        int idLength = 0;
+        if (read == 4) {
+            buffer.flip();
+            idLength = buffer.getInt();
+        } else {
+            throw new IOException("Could not read identifier length from the channel");
+        }
+        buffer = null;
+        // should read idLength * 2 bytes from the channel to get the string
+        // the length method on String returns the number of 16 bit characters
+        buffer = ByteBuffer.allocateDirect(idLength);
+        read = channel.read(buffer);
+        if(read != idLength) {
+            throw new IOException("Could not read identifier from the channel");
+        }
+        buffer.flip();
+        commandId = Charset.defaultCharset().decode(buffer).toString();
+        buffer = null;
+    }
+
+    public void writeExternal(WritableByteChannel channel) throws IOException {
+        // this is the root so no super impl, others should call super first
+        // first the length of the string
+        ByteBuffer buffer = ByteBuffer.allocateDirect(4);
+        buffer.putInt(commandId.length());
+        buffer.flip();
+        channel.write(buffer);
+        // now write the string - buffer comes back flipped
+        buffer = Charset.defaultCharset().encode(commandId);
+        channel.write(buffer);
+    }
+
+}

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

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

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

Added: 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=auto&rev=448118
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/Command.java (added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/Command.java Wed Sep 20 01:09:22 2006
@@ -0,0 +1,33 @@
+/*
+ * 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.geronimo.gcache.marshal.MarshalAware;
+
+/**
+ * Commands are pushed around the cluster to the various nodes and they are
+ * invoked upon reciept.
+ */
+public interface Command extends MarshalAware {
+    String getCommandId();
+
+    void setCommandId(String commandId);
+    
+    void execute();
+}

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

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

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

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java?view=auto&rev=448118
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java (added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java Wed Sep 20 01:09:22 2006
@@ -0,0 +1,13 @@
+package org.apache.geronimo.gcache.command;
+
+public class CommandTypes {
+    public static final int ADD_ENTRY_COMMAND = 1;
+
+    public static Command createCommand(int identifier) {
+        Command command = null;
+        if(identifier == ADD_ENTRY_COMMAND) {
+            command = new AddEntryCommand();
+        }
+        return command;
+    }
+}

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

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

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

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/marshal/MarshalAware.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/marshal/MarshalAware.java?view=auto&rev=448118
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/marshal/MarshalAware.java (added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/marshal/MarshalAware.java Wed Sep 20 01:09:22 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.marshal;
+
+import java.io.IOException;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+
+/**
+ * Implement this interface to specify that you want to marshal the object your self 
+ */
+public interface MarshalAware {
+    /**
+     * if you are part of a hiearchy call super.readExternal then read your bits
+     * @param channel
+     * @throws IOException
+     */
+    void readExternal(ReadableByteChannel channel) throws IOException;
+    /**
+     * if you are part of a hiearchy call super.writeExternal then write your bits
+     * @param channel
+     * @throws IOException
+     */
+    void writeExternal(WritableByteChannel channel) throws IOException;
+}

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

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

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

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/impl/DefaultThreadPoolImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/impl/DefaultThreadPoolImpl.java?view=diff&rev=448118&r1=448117&r2=448118
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/impl/DefaultThreadPoolImpl.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/impl/DefaultThreadPoolImpl.java Wed Sep 20 01:09:22 2006
@@ -1,27 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.geronimo.gcache.server.impl;
 
 import org.apache.geronimo.gcache.server.spi.ThreadPool;
 import edu.emory.mathcs.backport.java.util.concurrent.*;
 
 /**
- *
- * 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.
- */
-
-/**
  * Default implementation for a simple Thread Pool
  * This thread pool will be used unless one is provided using
  * the ThreadPool interface.  This allows the GCache server to
@@ -29,7 +29,7 @@
  * thread pools.  If custom, then an adapter utilizing
  * the ThreadPool interface will need to be created.
  */
-public class DefaultThreadPoolImpl implements ThreadPool{
+public class DefaultThreadPoolImpl implements ThreadPool {
 
     public static final int DEFAULT_CORE_SIZE = 10;
     public static final int DEFAULT_MAX_SIZE = 10;

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPBootstrapCacheLoader.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPBootstrapCacheLoader.java?view=diff&rev=448118&r1=448117&r2=448118
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPBootstrapCacheLoader.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPBootstrapCacheLoader.java Wed Sep 20 01:09:22 2006
@@ -1,9 +1,4 @@
-package org.apache.geronimo.gcache.server.listeners;
-
-import net.sf.ehcache.bootstrap.BootstrapCacheLoader;
-import net.sf.ehcache.Ehcache;
-
-/**
+/*
  * Copyright 2006 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,19 +13,45 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.geronimo.gcache.server.listeners;
+
+import net.sf.ehcache.Ehcache;
+import net.sf.ehcache.bootstrap.BootstrapCacheLoader;
+
+/**
+ * This class is responsbile for bootstrapping a cache. Bootstrapping involves loading
+ * members from a peer cache. This bootsrapper will connect to a peer 
+ * Loads cache members from peer caches. 
+ */
 public class TCPBootstrapCacheLoader implements BootstrapCacheLoader {
 
+    /**
+     * Bootstraps the cache from a random peer.
+     * 
+     * Bootstrapping requires the establishment of a cluster. This can be
+     * instantaneous for manually configued clusters or may take a number of
+     * seconds for multicast ones.
+     * 
+     */
     public void load(Ehcache ehcache) {
-        //TODO Add code here
+        // TODO Add code here
     }
 
+    /**
+     * true if the bootsrtapper will load content in the background
+     */
     public boolean isAsynchronous() {
-        //TODO Add code here
-        return false;  //To change body of implemented methods use File | Settings | File Templates.
+        // TODO Add code here
+        return false; // To change body of implemented methods use File |
+                        // Settings | File Templates.
     }
 
+    /**
+     * clone the bootstrapper - including the configuration
+     */
     public Object clone() throws CloneNotSupportedException {
-        //TODO Add code here
-        return null;  //To change body of implemented methods use File | Settings | File Templates.
+        // TODO Add code here
+        return null; // To change body of implemented methods use File |
+                        // Settings | File Templates.
     }
 }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPBootstrapCacheLoaderFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPBootstrapCacheLoaderFactory.java?view=diff&rev=448118&r1=448117&r2=448118
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPBootstrapCacheLoaderFactory.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPBootstrapCacheLoaderFactory.java Wed Sep 20 01:09:22 2006
@@ -1,11 +1,4 @@
-package org.apache.geronimo.gcache.server.listeners;
-
-import net.sf.ehcache.bootstrap.BootstrapCacheLoaderFactory;
-import net.sf.ehcache.bootstrap.BootstrapCacheLoader;
-
-import java.util.Properties;
-
-/**
+/*
  * Copyright 2006 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,11 +13,28 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.geronimo.gcache.server.listeners;
+
+import java.util.Properties;
+
+import net.sf.ehcache.bootstrap.BootstrapCacheLoader;
+import net.sf.ehcache.bootstrap.BootstrapCacheLoaderFactory;
+
+/**
+ * A factory for the TCPBootstrapCacheLoader
+ */
 public class TCPBootstrapCacheLoaderFactory extends BootstrapCacheLoaderFactory {
 
+    /**
+     * Return a new instance of TCPBootstrapCacheLoader configured with the
+     * properties that are passed in
+     * 
+     * @param properties
+     *            the properties to use in configuring the new bootstrap loader
+     */
     public BootstrapCacheLoader createBootstrapCacheLoader(Properties properties) {
-        //TODO Add code here
-        return null;  //To change body of implemented methods use File | Settings | File Templates.
+        // TODO: use the properties
+        return new TCPBootstrapCacheLoader();
     }
 
 }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPCacheManagerPeerListener.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPCacheManagerPeerListener.java?view=diff&rev=448118&r1=448117&r2=448118
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPCacheManagerPeerListener.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPCacheManagerPeerListener.java Wed Sep 20 01:09:22 2006
@@ -1,12 +1,4 @@
-package org.apache.geronimo.gcache.server.listeners;
-
-import net.sf.ehcache.distribution.CacheManagerPeerListener;
-import net.sf.ehcache.CacheException;
-import net.sf.ehcache.Status;
-
-import java.util.List;
-
-/**
+/*
  * Copyright 2006 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,7 +13,34 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.geronimo.gcache.server.listeners;
+
+import net.sf.ehcache.distribution.CacheManagerPeerListener;
+import net.sf.ehcache.CacheException;
+import net.sf.ehcache.Status;
+
+import java.util.List;
+
+import org.apache.geronimo.openwire.transport.tcp.TcpTransportServer;
+
+/**
+ * Listens to changes on other peers in the cluster
+ */
 public class TCPCacheManagerPeerListener implements CacheManagerPeerListener {
+    //private TcpTransportServer server = null;
+    
+    public TCPCacheManagerPeerListener() {
+        super();
+        //server = Tcp
+    }
+    public TCPCacheManagerPeerListener(String uri) {
+        super();
+        
+    }
+    /**
+     * Call to start the listener and do any other network initialization.
+     * @throws CacheException
+     */
     public void init() throws CacheException {
         //TODO Add code here
     }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPCacheManagerPeerListenerFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPCacheManagerPeerListenerFactory.java?view=diff&rev=448118&r1=448117&r2=448118
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPCacheManagerPeerListenerFactory.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPCacheManagerPeerListenerFactory.java Wed Sep 20 01:09:22 2006
@@ -1,12 +1,4 @@
-package org.apache.geronimo.gcache.server.listeners;
-
-import net.sf.ehcache.distribution.CacheManagerPeerListenerFactory;
-import net.sf.ehcache.distribution.CacheManagerPeerListener;
-import net.sf.ehcache.CacheManager;
-
-import java.util.Properties;
-
-/**
+/*
  * Copyright 2006 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,11 +13,22 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.geronimo.gcache.server.listeners;
+
+import net.sf.ehcache.distribution.CacheManagerPeerListenerFactory;
+import net.sf.ehcache.distribution.CacheManagerPeerListener;
+import net.sf.ehcache.CacheManager;
+
+import java.util.Properties;
+
+/**
+ * Creates instances of TCPCacheManagerPeerListeners
+ *
+ */
 public class TCPCacheManagerPeerListenerFactory extends CacheManagerPeerListenerFactory {
 
     public CacheManagerPeerListener createCachePeerListener(CacheManager cacheManager, Properties properties) {
-        //TODO Add code here
-        return null;
+        return new TCPCacheManagerPeerListener();
     }
 
 }

Added: 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=auto&rev=448118
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/DefaultSelectionKeyProcessor.java (added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/DefaultSelectionKeyProcessor.java Wed Sep 20 01:09:22 2006
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.geronimo.gcache.transports.tcp;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.SocketChannel;
+
+import org.apache.geronimo.gcache.command.Command;
+import org.apache.geronimo.gcache.command.CommandTypes;
+
+public class DefaultSelectionKeyProcessor implements SelectionKeyProcessor {
+
+    public void process(SelectionKey key) throws IOException {
+        SocketChannel channel = (SocketChannel) key.channel();
+        // first byte is the identifier, the next 4 are the checksum
+        ByteBuffer buffer = ByteBuffer.allocateDirect(5);
+        int count;
+        while ((count = channel.read(buffer)) > 0) {
+            buffer.flip();
+            int commandIdentifier = buffer.getInt();
+            Command command = CommandTypes.createCommand(commandIdentifier);
+            command.readExternal(channel);
+            command.execute();
+        }
+
+        // Test for closed connection
+        if (count < 0) {
+            channel.close();
+        }
+    }
+
+}

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

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

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

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/SelectionKeyProcessor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/SelectionKeyProcessor.java?view=auto&rev=448118
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/SelectionKeyProcessor.java (added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/SelectionKeyProcessor.java Wed Sep 20 01:09:22 2006
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.geronimo.gcache.transports.tcp;
+
+import java.io.IOException;
+import java.nio.channels.SelectionKey;
+
+/**
+ * Processes the reciept of data
+ * $Revision$ 
+ */
+public interface SelectionKeyProcessor {
+    /**
+     * the key is expected to contain cache updates
+     * first byte is the command identifier
+     * 
+     * @param key
+     * @throws IOException
+     */
+    void process(SelectionKey key) throws IOException;
+}

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

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

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

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketHandler.java?view=diff&rev=448118&r1=448117&r2=448118
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketHandler.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketHandler.java Wed Sep 20 01:09:22 2006
@@ -16,25 +16,24 @@
  */
 package org.apache.geronimo.gcache.transports.tcp;
 
-import org.apache.geronimo.gcache.ThreadSupport;
-import org.apache.geronimo.openwire.util.ByteArrayInputStream;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.nio.channels.Selector;
+import java.io.IOException;
+import java.nio.channels.SelectableChannel;
 import java.nio.channels.SelectionKey;
-import java.nio.channels.SocketChannel;
+import java.nio.channels.Selector;
 import java.nio.channels.ServerSocketChannel;
-import java.nio.channels.SelectableChannel;
-import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
-import java.io.IOException;
-import java.io.ObjectInputStream;
+import java.nio.channels.SocketChannel;
 import java.util.Iterator;
-import java.net.Socket;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gcache.ThreadSupport;
+
+/**
+ */
 public class TCPSocketHandler extends ThreadSupport {
     Log log = LogFactory.getLog(TCPSocketHandler.class);
+    
+    private SelectionKeyProcessor processor = new DefaultSelectionKeyProcessor();
 
     private Selector selector = null;
     private int timeOut = 0;
@@ -76,28 +75,10 @@
                     SocketChannel channel = server.accept();
                     if (channel == null)
                         continue;
-                    channel.configureBlocking(false);
                     register(channel, SelectionKey.OP_READ);
                 }
                 if (key.isReadable()) {
-                   System.out.println("READ");
-                    SocketChannel channel = (SocketChannel)key.channel();
-
-                    ByteBuffer buffer = ByteBuffer.allocateDirect(5);
-                    buffer.clear();
-                    int count;
-                    while((count = channel.read(buffer)) > 0){
-                        buffer.flip();
-                    }
-                    String test = Charset.forName("UTF-8").decode(buffer).toString();
-                    System.out.print(test);
-                    buffer.clear();
-                    System.out.println();
-
-                    //Test for closed connection
-                    if (count < 0){
-                        channel.close();
-                    }
+                    processor.process(key);
                 }
             }
         } catch (IOException e) {
@@ -118,6 +99,14 @@
         } catch (IOException e) {
             throw new RuntimeException(e);
         }
+    }
+
+    public SelectionKeyProcessor getProcessor() {
+        return processor;
+    }
+
+    public void setProcessor(SelectionKeyProcessor processor) {
+        this.processor = processor;
     }
 
 }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketServer.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketServer.java?view=diff&rev=448118&r1=448117&r2=448118
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketServer.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketServer.java Wed Sep 20 01:09:22 2006
@@ -44,13 +44,15 @@
 
         server = ServerSocketChannel.open();
         server.configureBlocking(false);
-
+        //TODO: refactor so this impl is not created here but instead its deferred
         handler = new TCPSocketHandler(timeOut);
 
+        // bind the server to the address
         ServerSocket socket = server.socket();
         socket.setReuseAddress(true);
         socket.bind(inet);
 
+        // register the handler and start looking for data
         handler.register(server, SelectionKey.OP_ACCEPT);
         handler.start();
     }

Added: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/AddEntryCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/AddEntryCommandTest.java?view=auto&rev=448118
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/AddEntryCommandTest.java (added)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/AddEntryCommandTest.java Wed Sep 20 01:09:22 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.command;
+
+import java.io.ByteArrayInputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+
+import org.testng.annotations.Test;
+
+public class AddEntryCommandTest {
+    @Test
+    public void testPayload() throws Exception {
+        String commandId = "the command id";
+        AddEntryCommand command = new AddEntryCommand();
+        command.setCommandId(commandId);
+        BaseCommand baseCommand = new BaseCommand();
+        String baseCommandId = "base command id";
+        baseCommand.setCommandId(baseCommandId);
+        // setValue will call setPayload
+        command.setValue(baseCommand);
+        ByteBuffer buffer = command.getPayload();
+        ByteArrayInputStream bias = new ByteArrayInputStream(buffer.array());
+        ReadableByteChannel channel = Channels.newChannel(bias);
+        BaseCommand readCommand = new BaseCommand();
+        readCommand.readExternal(channel);
+        assert readCommand.getCommandId().equals(baseCommandId);
+    }
+}

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

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

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

Added: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/BaseCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/BaseCommandTest.java?view=auto&rev=448118
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/BaseCommandTest.java (added)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/BaseCommandTest.java Wed Sep 20 01:09:22 2006
@@ -0,0 +1,75 @@
+/*
+ * 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.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+import java.nio.charset.Charset;
+
+import org.testng.annotations.Test;
+
+public class BaseCommandTest {
+
+    @Test
+    public void testReadBaseCommand() throws Exception {
+        BaseCommand command = new BaseCommand();
+        String commandId = "this is the id";
+        command.setCommandId("bad id");
+        byte bytes[] = new byte[34];
+        // write the length
+        ByteBuffer buffer = ByteBuffer.allocateDirect(4);
+        buffer.putInt(commandId.length());
+        buffer.flip();
+        for(int i = 0;i < buffer.limit();i++) {
+            bytes[i] = buffer.get();
+        }
+        // now write the string - buffer comes back flipped
+        buffer = Charset.defaultCharset().encode(commandId);
+        for(int i = 0;i < buffer.limit();i++) {
+            bytes[i + 4] = buffer.get();
+        }
+        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+        ReadableByteChannel channel = Channels.newChannel(bais);
+        command.readExternal(channel);
+        // make sure reading changed the id
+        assert command.getCommandId().equals(commandId);
+    }
+    
+    @Test
+    public void testWriteBaseCommand() throws Exception {
+        BaseCommand writtenCommand = new BaseCommand();
+        String commandId = "this is the id";
+        writtenCommand.setCommandId(commandId);
+        ByteArrayOutputStream baos = new ByteArrayOutputStream(34);
+        WritableByteChannel channel = Channels.newChannel(baos);
+        writtenCommand.writeExternal(channel);
+        // make sure writing did not change the id
+        assert writtenCommand.getCommandId().equals(commandId);
+        ByteBuffer buffer = ByteBuffer.wrap(baos.toByteArray());
+        int idLength = buffer.getInt();
+        assert idLength == commandId.length();
+        String newCommandId = Charset.defaultCharset().decode(buffer).toString();
+        assert newCommandId.equals(commandId);
+    }
+    
+}

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

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

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

Added: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/MockSelectionKeyProcessor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/MockSelectionKeyProcessor.java?view=auto&rev=448118
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/MockSelectionKeyProcessor.java (added)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/MockSelectionKeyProcessor.java Wed Sep 20 01:09:22 2006
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.geronimo.gcache.transports.tcp;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.SocketChannel;
+import java.nio.charset.Charset;
+
+/**
+ * Provides a simple processor that will print what it reads 
+ */
+public class MockSelectionKeyProcessor implements SelectionKeyProcessor {
+
+    public void process(SelectionKey key) throws IOException {
+        System.out.println("READ");
+        SocketChannel channel = (SocketChannel) key.channel();
+
+        ByteBuffer buffer = ByteBuffer.allocateDirect(1024);
+        int count;
+        while ((count = channel.read(buffer)) > 0) {
+            buffer.flip();
+            String test = Charset.forName("UTF-8").decode(buffer).toString();
+            System.out.print("read " + count + " bytes:{" + test + "}");
+            buffer.clear();
+        }
+
+        // Test for closed connection
+        if (count < 0) {
+            channel.close();
+        }
+    }
+
+}

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

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

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

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TcpSocketServerTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TcpSocketServerTest.java?view=diff&rev=448118&r1=448117&r2=448118
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TcpSocketServerTest.java (original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TcpSocketServerTest.java Wed Sep 20 01:09:22 2006
@@ -25,6 +25,7 @@
     public void runServer() throws Exception {
         ThreadPool pool = new DefaultThreadPoolImpl(10);
         TCPSocketServer server = new TCPSocketServer("localhost", 45678, pool, 2000);
+        // TODO: need a way to substitute the MockSelectionKeyProcessor before invoking the server
         server.start();
         Thread.sleep(100000);
         server.stop();



Mime
View raw message