You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jg...@apache.org on 2006/11/27 22:20:52 UTC
svn commit: r479767 - in /geronimo/sandbox/gcache: ./ client/
client/src/main/java/org/apache/geronimo/gcache/transports/
client/src/main/java/org/apache/geronimo/gcache/transports/tcp/
client/src/test/java/org/apache/geronimo/gcache/transports/ client...
Author: jgenender
Date: Mon Nov 27 13:20:48 2006
New Revision: 479767
URL: http://svn.apache.org/viewvc?view=rev&rev=479767
Log:
Add test and beginning of the client API
Added:
geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/
geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/
geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientCommandVisitor.java
geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/gcache/transports/
geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/gcache/transports/tcp/
geronimo/sandbox/gcache/client/src/test/resources/log4j.xml
geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/BaseCommandVisitor.java
geronimo/sandbox/gcache/server/src/main/resources/gcache-server-config-default.xml (contents, props changed)
- copied, changed from r477589, geronimo/sandbox/gcache/server/src/main/resources/gcache-config-default.xml
geronimo/sandbox/gcache/server/src/test/resources/gcache-server-config.xml (contents, props changed)
- copied, changed from r477589, geronimo/sandbox/gcache/server/src/test/resources/gcache-config.xml
Removed:
geronimo/sandbox/gcache/server/src/main/resources/gcache-config-default.xml
geronimo/sandbox/gcache/server/src/test/resources/gcache-config.xml
Modified:
geronimo/sandbox/gcache/client/pom.xml
geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java
geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CacheBaseCommand.java
geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommand.java
geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PutSessionCommand.java
geronimo/sandbox/gcache/pom.xml
geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/dd/ConfigBuilder.java
geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/dd/JaxbGcacheConfigFactory.java
geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandVisitor.java
Modified: geronimo/sandbox/gcache/client/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/pom.xml?view=diff&rev=479767&r1=479766&r2=479767
==============================================================================
--- geronimo/sandbox/gcache/client/pom.xml (original)
+++ geronimo/sandbox/gcache/client/pom.xml Mon Nov 27 13:20:48 2006
@@ -1,35 +1,39 @@
<project>
- <modelVersion>4.0.0</modelVersion>
+ <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.geronimo.gcache</groupId>
- <artifactId>gcache</artifactId>
- <version>1.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>gcache-client</artifactId>
- <packaging>jar</packaging>
- <version>${gcacheVersion}</version>
-
- <name>GCache :: Client</name>
-
- <dependencies>
-
- <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>
-
- </dependencies>
- <build>
- </build>
+ <parent>
+ <groupId>org.apache.geronimo.gcache</groupId>
+ <artifactId>gcache</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>gcache-client</artifactId>
+ <packaging>jar</packaging>
+ <version>${gcacheVersion}</version>
+
+ <name>GCache :: Client</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <classifier>jdk15</classifier>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.geronimo.gcache</groupId>
+ <artifactId>gcache-common</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>net.sf.ehcache</groupId>
+ <artifactId>ehcache</artifactId>
+ </dependency>
+
+ </dependencies>
+ <build></build>
</project>
Added: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientCommandVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientCommandVisitor.java?view=auto&rev=479767
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientCommandVisitor.java (added)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientCommandVisitor.java Mon Nov 27 13:20:48 2006
@@ -0,0 +1,193 @@
+package org.apache.geronimo.gcache.transports.tcp;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.Element;
+
+import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.command.BaseCommand;
+import org.apache.geronimo.gcache.command.BulkSendCommand;
+import org.apache.geronimo.gcache.command.ClearCacheCommand;
+import org.apache.geronimo.gcache.command.GetCacheCommand;
+import org.apache.geronimo.gcache.command.MessageAckCommand;
+import org.apache.geronimo.gcache.command.PutEntryCommand;
+import org.apache.geronimo.gcache.command.PutSessionCommand;
+import org.apache.geronimo.gcache.command.RemoveEntryCommand;
+import org.apache.geronimo.gcache.command.RemoveSessionCommand;
+import org.apache.mina.common.IoSession;
+
+public class TCPClientCommandVisitor extends BaseCommandVisitor {
+
+ private CacheInfoHolder infoHolder;
+
+ public TCPClientCommandVisitor(CacheInfoHolder infoHolder) {
+ super();
+ this.infoHolder = infoHolder;
+ }
+
+ public void processPutSession(PutSessionCommand command) {
+ Cache cache = infoHolder.getCache(command.getCacheName(), true);
+
+ cache.put(new Element(command.getSessionId(), command.getPayload()));
+
+ sendAck(command);
+
+ }
+
+ @SuppressWarnings( { "unchecked" })
+ public void processPutEntry(PutEntryCommand command) {
+ Cache cache = infoHolder.getCache(command.getCacheName(), true);
+
+ // Check if we are using sessions
+ if (command.hasSession()) {
+
+ Map sessionMap = null;
+
+ // We are so use the session maps that is stored
+ Element element = cache.get(command.getSessionId());
+ if (element != null) {
+ sessionMap = (Map) element.getObjectValue();
+ } else {
+ sessionMap = Collections.synchronizedMap(new HashMap());
+ }
+
+ sessionMap.put(command.getHashableKey(), command.getPayload());
+ // Put the session away
+ cache.put(new Element(command.getSessionId(), sessionMap));
+
+ } else {
+
+ // No session map so store the value
+ cache.put(new Element(command.getHashableKey(), command.getPayload()));
+ }
+
+ sendAck(command);
+ }
+
+ public void processMessageAck(MessageAckCommand command) {
+ // This should never get called as the filters will handle it
+ }
+
+ @SuppressWarnings("unchecked")
+ public void processGetCache(GetCacheCommand command) {
+ //As a client, this should never get called as a GetCacheCommand
+ //should never be received by a client. However, the code is here
+ //for future access depending on a strategy change.
+ Cache cache = infoHolder.getCache(command.getCacheName(), true);
+
+ IoSession sess = (IoSession) command.getAttachment();
+
+ // Send a bulk command
+ BulkSendCommand bulk = new BulkSendCommand();
+ bulk.setNumberOfCommands(cache.getSize());
+
+ long commandId = bulk.getCommandId();
+
+ if (sess != null)
+ sess.write(bulk);
+
+ for (Object key : (List<Object>) cache.getKeys()) {
+ Element element = cache.get(key);
+ Object payload = element.getValue();
+
+ BaseCommand newCommand = null;
+ // Test if we are sending a session or not
+ if (payload instanceof HashMap) {
+ PutSessionCommand psc = new PutSessionCommand();
+ psc.setCacheName(command.getCacheName());
+ psc.setSessionId((String) key);
+ psc.setPayloadFromSession((Map) payload);
+ newCommand = psc;
+ } else {
+ PutEntryCommand pec = new PutEntryCommand();
+ pec.setCacheName(command.getCacheName());
+ pec.setPayload(payload);
+ pec.setKey(key);
+ newCommand = pec;
+ }
+
+ // Set all the commands to the same commandId for a bulk send
+ newCommand.setCommandId(commandId);
+
+ // Send the packet. If there is a failure just abort
+ if (sess != null) {
+ sess.write(newCommand);
+ }
+ }
+
+ // We are returning a request there for we don't send an ack...
+ // we request one
+ requestAck(bulk);
+
+ }
+
+ public void processClearCache(ClearCacheCommand command) {
+ Cache cache = infoHolder.getCache(command.getCacheName(), true);
+ cache.removeAll();
+
+ sendAck(command);
+ }
+
+ public void processBulkSend(BulkSendCommand command) {
+
+ // Get the command count and set the attribute to count em down
+ int commandCount = command.getNumberOfCommands();
+
+ IoSession sess = (IoSession) command.getAttachment();
+ if (sess == null)
+ return;
+
+ // Setup the BulkCommand filter to process bulk commands
+ sess.setAttribute(Constants.BULK_COUNT + command.getCommandId(), commandCount);
+ sess.setAttribute(Constants.BULK_COMMAND_ID + command.getCommandId());
+
+ // Do not send an ack here, the filter will send it once all
+ // of the following commands have been received
+ }
+
+ public void processRemoveEntry(RemoveEntryCommand command) {
+ Cache cache = infoHolder.getCache(command.getCacheName(), true);
+
+ // Check if we are using sessions
+ if (command.hasSession()) {
+
+ Map sessionMap = null;
+
+ // We are so use the session maps that is stored
+ Element element = cache.get(command.getSessionId());
+ if (element != null) {
+ sessionMap = (Map) element.getObjectValue();
+ } else {
+ sessionMap = Collections.synchronizedMap(new HashMap());
+ }
+
+ sessionMap.remove(command.getKey());
+
+ // Put the session away
+ cache.put(new Element(command.getSessionId(), sessionMap));
+
+ } else {
+
+ // No session map so remove the value
+ cache.remove(command.getHashableKey());
+ }
+
+ sendAck(command);
+ }
+
+ public void processRemoveSession(RemoveSessionCommand command) {
+ Cache cache = infoHolder.getCache(command.getCacheName(), true);
+
+ // Be sure a session was sent
+ if (command.hasSession()) {
+ cache.remove(command.getSessionId());
+ }
+
+ sendAck(command);
+ }
+
+}
Added: geronimo/sandbox/gcache/client/src/test/resources/log4j.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/test/resources/log4j.xml?view=auto&rev=479767
==============================================================================
--- geronimo/sandbox/gcache/client/src/test/resources/log4j.xml (added)
+++ geronimo/sandbox/gcache/client/src/test/resources/log4j.xml Mon Nov 27 13:20:48 2006
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
+
+ <appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
+ <layout class="org.apache.log4j.PatternLayout">
+ <!--param name="ConversionPattern" value="[%p] %c %m%n"/-->
+ <param name="ConversionPattern" value="[%p] [%c{1}] %m%n"/>
+ </layout>
+ </appender>
+
+ <category name="net.sf.ehcache.config.ConfigurationFactory">
+ <priority value="ERROR"/>
+ </category>
+
+ <root>
+ <priority value="debug"/>
+ <appender-ref ref="ConsoleAppender"/>
+ </root>
+
+</log4j:configuration>
\ No newline at end of file
Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java?view=diff&rev=479767&r1=479766&r2=479767
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java Mon Nov 27 13:20:48 2006
@@ -43,13 +43,13 @@
* 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
+ * Allows an object to be attached for passing around during processing of
+ * the command
*/
private transient Object attachment = null;
-
+
public Object getAttachment() {
return attachment;
}
@@ -59,41 +59,40 @@
}
/**
- * 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.
+ * 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");
+ 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.
+ * 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;
+ 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
+ * 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;
+ // TODO - should this method be here. I am leaning towards this being a
+ // read only property.
+ this.commandId = commandId;
}
/**
@@ -101,111 +100,111 @@
* whatever task this command is supposed to do.
*/
public void execute(CommandVisitor visitor) throws Exception {
- // nothing to do in the base
+ // 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();
+ // 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
+ // this is the root so no super impl, others should call super first
- if (commandId == 0) {
- commandId = UniqueId.get();
- }
+ if (commandId == 0) {
+ commandId = UniqueId.get();
+ }
- buffer.putLong(commandId);
+ 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.
+ * 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;
+ 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();
+ 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 {
+ 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 {
- }
+ }
}
/**
@@ -217,106 +216,108 @@
*/
// 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());
- }
+ public static Object convertObjectFromBytes(byte data[]) {
+ if (data == null)
+ return null;
+
+ try {
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(data);
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ return ois.readObject();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
}
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);
+ 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();
+ // Read size
+ int byteCount = buffer.getInt();
- if (byteCount == -1)
- return null;
+ if (byteCount == -1)
+ return null;
- byte bytes[] = new byte[byteCount];
- buffer.get(bytes);
+ 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);
+ 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");
- }
+ public static byte[] convertObjectToBytes(Object object) {
+ /*
+ * 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) {
+ try {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream stream = new ObjectOutputStream(baos);
+ stream.writeObject(object);
+ stream.flush();
+ stream.close();
+ return baos.toByteArray();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ throw new RuntimeException("Invalid argument - Object" + " is not an instance of java.io.Serializable"
+ + " or MarshalAware");
+ }
}
}
Modified: 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=diff&rev=479767&r1=479766&r2=479767
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CacheBaseCommand.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CacheBaseCommand.java Mon Nov 27 13:20:48 2006
@@ -18,8 +18,6 @@
*/
package org.apache.geronimo.gcache.command;
-import java.io.IOException;
-
import org.apache.geronimo.gcache.util.ByteArray;
import org.apache.mina.common.ByteBuffer;
@@ -62,11 +60,11 @@
this.sessionId = sessionId;
}
- public void setKey(Object value) throws IOException {
+ public void setKey(Object value) {
setRawKey(convertObjectToBytes(value));
}
- public Object getKey() throws IOException{
+ public Object getKey() {
return convertObjectFromBytes(getRawKey());
}
Modified: 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=diff&rev=479767&r1=479766&r2=479767
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommand.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommand.java Mon Nov 27 13:20:48 2006
@@ -18,8 +18,6 @@
*/
package org.apache.geronimo.gcache.command;
-import java.io.IOException;
-
import org.apache.mina.common.ByteBuffer;
public class CachePayloadBaseCommand extends CacheBaseCommand {
@@ -41,11 +39,11 @@
writeBytes(buffer, payload);
}
- public void setPayload(Object value) throws IOException {
+ public void setPayload(Object value) {
setRawPayload(convertObjectToBytes(value));
}
- public Object getPayload() throws IOException {
+ public Object getPayload() {
return convertObjectFromBytes(getRawPayload());
}
Modified: 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=diff&rev=479767&r1=479766&r2=479767
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PutSessionCommand.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/PutSessionCommand.java Mon Nov 27 13:20:48 2006
@@ -36,207 +36,216 @@
private int entryCount;
public byte getCommandType() throws IOException {
- return CommandTypes.PUT_SESSION_COMMAND;
+ return CommandTypes.PUT_SESSION_COMMAND;
}
public void readExternal(ByteBuffer buffer) throws Exception {
- super.readExternal(buffer);
- entryCount = buffer.getInt();
+ super.readExternal(buffer);
+ entryCount = buffer.getInt();
}
public void writeExternal(ByteBuffer buffer) throws Exception {
- super.writeExternal(buffer);
- buffer.putInt(entryCount);
+ 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.
+ * 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;
+ public void setPayloadFromSession(Map session) {
+ 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();
- }
+ 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());
+
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } 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.
+ * 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 {
+ public Map getSessionFromPayload() {
- ByteBuffer buffer = null;
- try {
+ 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();
- }
+ 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.
+ * 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 {
+ public void setPayloadFromRawSession(Map session) {
- ByteBuffer buffer = null;
- try {
+ ByteBuffer buffer = null;
+ try {
- Set set = session.keySet();
- entryCount = set.size();
+ 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();
- }
+ // 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());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } 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.
+ * 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 {
+ public Map getRawSessionFromPayload() {
- ByteBuffer buffer = null;
- try {
+ ByteBuffer buffer = null;
+ try {
- Map<ByteArray, byte[]> sessionMap = Collections
- .synchronizedMap(new HashMap<ByteArray, byte[]>());
- buffer = ByteBuffer.wrap(getRawPayload());
+ Map<ByteArray, byte[]> sessionMap = Collections.synchronizedMap(new HashMap<ByteArray, byte[]>());
+ buffer = ByteBuffer.wrap(getRawPayload());
- int keySize;
- int dataSize;
+ int keySize;
+ int dataSize;
- for (int i = 0; i < this.entryCount; i++) {
- //Get the key Size
- keySize = buffer.getInt();
+ 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);
+ // Read the key
+ byte[] key = new byte[keySize];
+ buffer.get(key);
- //Get the data Size
- dataSize = buffer.getInt();
+ // Get the data Size
+ dataSize = buffer.getInt();
- //Get the data
- byte[] data = new byte[dataSize];
- buffer.get(data);
+ // Get the data
+ byte[] data = new byte[dataSize];
+ buffer.get(data);
- sessionMap.put(new ByteArray(key), data);
- }
+ sessionMap.put(new ByteArray(key), data);
+ }
- return sessionMap;
- } finally {
- if (buffer != null)
- buffer.release();
- }
+ return sessionMap;
+ } finally {
+ if (buffer != null)
+ buffer.release();
+ }
}
public void execute(CommandVisitor visitor) throws IOException {
- visitor.processPutSession(this);
+ visitor.processPutSession(this);
}
}
Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/BaseCommandVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/BaseCommandVisitor.java?view=auto&rev=479767
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/BaseCommandVisitor.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/BaseCommandVisitor.java Mon Nov 27 13:20:48 2006
@@ -0,0 +1,37 @@
+package org.apache.geronimo.gcache.transports.tcp;
+
+import org.apache.geronimo.gcache.command.BaseCommand;
+import org.apache.geronimo.gcache.command.MessageAckCommand;
+import org.apache.geronimo.gcache.transports.CommandVisitor;
+import org.apache.mina.common.IoSession;
+
+public abstract class BaseCommandVisitor implements CommandVisitor {
+
+ protected void sendAck(BaseCommand command) {
+
+ IoSession sess = (IoSession)command.getAttachment();
+ if (sess == null)
+ return;
+
+ if (sess.getFilterChain().contains(TCPMessageAckCommandFilter.class)) {
+ MessageAckCommand ack = new MessageAckCommand();
+ ack.setMessageId(command.getCommandId());
+ sess.write(ack);
+ }
+ }
+
+ protected void requestAck(BaseCommand command) {
+
+ IoSession sess = (IoSession)command.getAttachment();
+ if (sess == null)
+ return;
+
+ //See if we need to send an Ack
+ TCPMessageAckCommandFilter filter = (TCPMessageAckCommandFilter) sess
+ .getFilterChain().get(TCPMessageAckCommandFilter.NAME);
+ if (filter != null) {
+ long commandId = command.getCommandId();
+ filter.requestAck(commandId, sess);
+ }
+ }
+}
Modified: geronimo/sandbox/gcache/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/pom.xml?view=diff&rev=479767&r1=479766&r2=479767
==============================================================================
--- geronimo/sandbox/gcache/pom.xml (original)
+++ geronimo/sandbox/gcache/pom.xml Mon Nov 27 13:20:48 2006
@@ -21,6 +21,7 @@
<module>common</module>
<module>client</module>
<module>server</module>
+ <module>tests</module>
</modules>
<properties>
@@ -57,6 +58,12 @@
<dependency>
<groupId>org.apache.geronimo.gcache</groupId>
<artifactId>gcache-client</artifactId>
+ <version>${gcacheVersion}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.geronimo.gcache</groupId>
+ <artifactId>gcache-tests</artifactId>
<version>${gcacheVersion}</version>
</dependency>
Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/dd/ConfigBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/dd/ConfigBuilder.java?view=diff&rev=479767&r1=479766&r2=479767
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/dd/ConfigBuilder.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/dd/ConfigBuilder.java Mon Nov 27 13:20:48 2006
@@ -27,13 +27,12 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.geronimo.gcache.util.StringUtil;
public class ConfigBuilder {
private static final Log log = LogFactory.getLog(ConfigBuilder.class);
- private static final String CLASSPATH_CONFIGURATION_FILE = "gcache-config.xml";
- private static final String DEFAULT_CLASSPATH_CONFIGURATION_FILE = "gcache-config-default.xml";
+ private static final String CLASSPATH_CONFIGURATION_FILE = "gcache-server-config.xml";
+ private static final String DEFAULT_CLASSPATH_CONFIGURATION_FILE = "gcache-server-config-default.xml";
public GcacheConfiguration getConfig(URL fileURL){
Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/dd/JaxbGcacheConfigFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/dd/JaxbGcacheConfigFactory.java?view=diff&rev=479767&r1=479766&r2=479767
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/dd/JaxbGcacheConfigFactory.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/dd/JaxbGcacheConfigFactory.java Mon Nov 27 13:20:48 2006
@@ -17,12 +17,11 @@
*/
package org.apache.geronimo.gcache.dd;
-import org.xml.sax.Attributes;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLFilterImpl;
-import org.apache.geronimo.gcache.util.StringUtil;
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+import java.net.URL;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
@@ -30,11 +29,13 @@
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.sax.SAXSource;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.BufferedReader;
-import java.io.StringReader;
-import java.net.URL;
+
+import org.apache.geronimo.gcache.util.StringUtil;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLFilterImpl;
public class JaxbGcacheConfigFactory {
Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandVisitor.java?view=diff&rev=479767&r1=479766&r2=479767
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandVisitor.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandVisitor.java Mon Nov 27 13:20:48 2006
@@ -39,10 +39,9 @@
import org.apache.geronimo.gcache.command.PutSessionCommand;
import org.apache.geronimo.gcache.command.RemoveEntryCommand;
import org.apache.geronimo.gcache.command.RemoveSessionCommand;
-import org.apache.geronimo.gcache.transports.CommandVisitor;
import org.apache.mina.common.IoSession;
-public class TCPCommandVisitor implements CommandVisitor {
+public class TCPCommandVisitor extends BaseCommandVisitor {
Log log = LogFactory.getLog(TCPCommandVisitor.class);
private CacheInfoHolder infoHolder;
@@ -102,23 +101,15 @@
Cache cache = infoHolder.getCache(command.getCacheName(), true);
// Place the raw session in the cache
- try {
- cache.put(new Element(command.getSessionId(), command
- .getRawSessionFromPayload()));
-
- infoHolder.getCacheNotifier().notifyPutSession(command);
-
- sendAck(command);
-
- } catch (IOException e) {
- // TODO - What should we do on an IOException, ignore it or
- // remove the client?
- log.error(e);
- }
+ cache.put(new Element(command.getSessionId(), command.getRawSessionFromPayload()));
+
+ infoHolder.getCacheNotifier().notifyPutSession(command);
+
+ sendAck(command);
}
- @SuppressWarnings({"unchecked"})
+ @SuppressWarnings( { "unchecked" })
public void processPutEntry(PutEntryCommand command) {
Cache cache = infoHolder.getCache(command.getCacheName(), true);
@@ -142,8 +133,7 @@
} else {
// No session map so store the value
- cache.put(new Element(command.getHashableKey(), command
- .getRawPayload()));
+ cache.put(new Element(command.getHashableKey(), command.getRawPayload()));
}
infoHolder.getCacheNotifier().notifyPut(command);
@@ -151,63 +141,57 @@
}
public void processMessageAck(MessageAckCommand command) {
- //This should never get called as the filters will handle it
+ // This should never get called as the filters will handle it
}
@SuppressWarnings("unchecked")
public void processGetCache(GetCacheCommand command) {
Cache cache = infoHolder.getCache(command.getCacheName(), true);
- IoSession sess = (IoSession)command.getAttachment();
+ IoSession sess = (IoSession) command.getAttachment();
- //Send a bulk command
+ // Send a bulk command
BulkSendCommand bulk = new BulkSendCommand();
bulk.setNumberOfCommands(cache.getSize());
long commandId = bulk.getCommandId();
- try {
- if (sess != null)
- sess.write(bulk);
-
- for (Object key : (List<Object>) cache.getKeys()) {
- Element element = cache.get(key);
- Object payload = element.getValue();
-
- BaseCommand newCommand = null;
- // Test if we are sending a session or not
- if (payload instanceof HashMap) {
- PutSessionCommand psc = new PutSessionCommand();
- psc.setCacheName(command.getCacheName());
- psc.setSessionId((String) key);
- psc.setPayloadFromSession((Map) payload);
- newCommand = psc;
- } else {
- PutEntryCommand pec = new PutEntryCommand();
- pec.setCacheName(command.getCacheName());
- pec.setRawPayload((byte[]) payload);
- pec.setRawKey((byte[]) key);
- newCommand = pec;
- }
-
- //Set all the commands to the same commandId for a bulk send
- newCommand.setCommandId(commandId);
-
- //Send the packet. If there is a failure just abort
- if (sess != null) {
- sess.write(newCommand);
- }
+ if (sess != null)
+ sess.write(bulk);
+
+ for (Object key : (List<Object>) cache.getKeys()) {
+ Element element = cache.get(key);
+ Object payload = element.getValue();
+
+ BaseCommand newCommand = null;
+ // Test if we are sending a session or not
+ if (payload instanceof HashMap) {
+ PutSessionCommand psc = new PutSessionCommand();
+ psc.setCacheName(command.getCacheName());
+ psc.setSessionId((String) key);
+ psc.setPayloadFromRawSession((Map) payload);
+ newCommand = psc;
+ } else {
+ PutEntryCommand pec = new PutEntryCommand();
+ pec.setCacheName(command.getCacheName());
+ pec.setRawPayload((byte[]) payload);
+ pec.setRawKey((byte[]) key);
+ newCommand = pec;
}
- //We are returning a request there for we don't send an ack...
- //we request one
- requestAck(bulk);
-
- } catch (IOException e) {
- // TODO - What should we do on an IOException, ignore it or
- // remove the client?
- log.error(e);
+ // Set all the commands to the same commandId for a bulk send
+ newCommand.setCommandId(commandId);
+
+ // Send the packet. If there is a failure just abort
+ if (sess != null) {
+ sess.write(newCommand);
+ }
}
+
+ // We are returning a request there for we don't send an ack...
+ // we request one
+ requestAck(bulk);
+
}
public void processClearCache(ClearCacheCommand command) {
@@ -221,48 +205,19 @@
public void processBulkSend(BulkSendCommand command) {
- //Get the command count and set the attribute to count em down
+ // Get the command count and set the attribute to count em down
int commandCount = command.getNumberOfCommands();
- IoSession sess = (IoSession)command.getAttachment();
+ IoSession sess = (IoSession) command.getAttachment();
if (sess == null)
return;
- //Setup the BulkCommand filter to process bulk commands
- sess.setAttribute(Constants.BULK_COUNT + command.getCommandId(),
- commandCount);
+ // Setup the BulkCommand filter to process bulk commands
+ sess.setAttribute(Constants.BULK_COUNT + command.getCommandId(), commandCount);
sess.setAttribute(Constants.BULK_COMMAND_ID + command.getCommandId());
- //Do not send an ack here, the filter will send it once all
- //of the following commands have been received
- }
-
- private void sendAck(BaseCommand command) {
-
- IoSession sess = (IoSession)command.getAttachment();
- if (sess == null)
- return;
-
- if (sess.getFilterChain().contains(TCPMessageAckCommandFilter.class)) {
- MessageAckCommand ack = new MessageAckCommand();
- ack.setMessageId(command.getCommandId());
- sess.write(ack);
- }
- }
-
- private void requestAck(BaseCommand command) {
-
- IoSession sess = (IoSession)command.getAttachment();
- if (sess == null)
- return;
-
- //See if we need to send an Ack
- TCPMessageAckCommandFilter filter = (TCPMessageAckCommandFilter) sess
- .getFilterChain().get(TCPMessageAckCommandFilter.NAME);
- if (filter != null) {
- long commandId = command.getCommandId();
- filter.requestAck(commandId, sess);
- }
+ // Do not send an ack here, the filter will send it once all
+ // of the following commands have been received
}
}
Copied: geronimo/sandbox/gcache/server/src/main/resources/gcache-server-config-default.xml (from r477589, geronimo/sandbox/gcache/server/src/main/resources/gcache-config-default.xml)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/resources/gcache-server-config-default.xml?view=diff&rev=479767&p1=geronimo/sandbox/gcache/server/src/main/resources/gcache-config-default.xml&r1=477589&p2=geronimo/sandbox/gcache/server/src/main/resources/gcache-server-config-default.xml&r2=479767
==============================================================================
(empty)
Propchange: geronimo/sandbox/gcache/server/src/main/resources/gcache-server-config-default.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/gcache/server/src/main/resources/gcache-server-config-default.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/gcache/server/src/main/resources/gcache-server-config-default.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Copied: geronimo/sandbox/gcache/server/src/test/resources/gcache-server-config.xml (from r477589, geronimo/sandbox/gcache/server/src/test/resources/gcache-config.xml)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/resources/gcache-server-config.xml?view=diff&rev=479767&p1=geronimo/sandbox/gcache/server/src/test/resources/gcache-config.xml&r1=477589&p2=geronimo/sandbox/gcache/server/src/test/resources/gcache-server-config.xml&r2=479767
==============================================================================
(empty)
Propchange: geronimo/sandbox/gcache/server/src/test/resources/gcache-server-config.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/gcache/server/src/test/resources/gcache-server-config.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/gcache/server/src/test/resources/gcache-server-config.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml