geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r504250 - in /geronimo/sandbox/gcache: client/src/main/java/org/apache/geronimo/gcache/transports/tcp/ common/src/main/java/org/apache/geronimo/gcache/ common/src/main/java/org/apache/geronimo/gcache/command/ common/src/main/java/org/apache...
Date Tue, 06 Feb 2007 19:24:13 GMT
Author: jgenender
Date: Tue Feb  6 11:24:12 2007
New Revision: 504250

URL: http://svn.apache.org/viewvc?view=rev&rev=504250
Log:
Server to initially handle locks

Added:
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/ErrorCommand.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/LockAcquiredCommand.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/LockReleasedCommand.java
Modified:
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientCommandVisitor.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/CommandVisitor.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/Constants.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPAuthenticationFilter.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandVisitor.java

Modified: 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=diff&rev=504250&r1=504249&r2=504250
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientCommandVisitor.java
(original)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientCommandVisitor.java
Tue Feb  6 11:24:12 2007
@@ -30,9 +30,12 @@
 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.ErrorCommand;
 import org.apache.geronimo.gcache.command.GetCacheCommand;
 import org.apache.geronimo.gcache.command.GetSessionCommand;
+import org.apache.geronimo.gcache.command.LockAcquiredCommand;
 import org.apache.geronimo.gcache.command.LockCommand;
+import org.apache.geronimo.gcache.command.LockReleasedCommand;
 import org.apache.geronimo.gcache.command.MessageAckCommand;
 import org.apache.geronimo.gcache.command.PutEntryCommand;
 import org.apache.geronimo.gcache.command.PutSessionCommand;
@@ -218,12 +221,24 @@
         sendAck(command);
     }
 
+    public void processLockAcquired(LockAcquiredCommand command) {
+        // TODO - Fill in
+    }
+
     public void processLockSession(LockCommand command) {
-        // Shouldn't be processed on client
+        // TODO - Fill in
     }
 
     public void processReleaseLockSession(ReleaseLockCommand command) {
-        // Shouldn't be processed on client
+        // TODO - Fill in
+    }
+
+    public void processError(ErrorCommand command) {
+        // TODO - Fill in
+    }
+
+    public void processLockReleased(LockReleasedCommand command) {
+        // TODO - Fill in
     }
     
  

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java?view=diff&rev=504250&r1=504249&r2=504250
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java
(original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java
Tue Feb  6 11:24:12 2007
@@ -23,9 +23,10 @@
 
 import org.apache.geronimo.gcache.listeners.CacheNotifier;
 import org.apache.geronimo.gcache.listeners.DefaultCacheNotifier;
-import org.apache.geronimo.gcache.transports.EndpointManager;
-import org.apache.geronimo.gcache.transports.DiscoveryManager;
+import org.apache.geronimo.gcache.lock.LockManager;
 import org.apache.geronimo.gcache.transports.CommandVisitor;
+import org.apache.geronimo.gcache.transports.DiscoveryManager;
+import org.apache.geronimo.gcache.transports.EndpointManager;
 
 public class CacheInfoHolder {
     private final CacheManager cacheManager;
@@ -33,6 +34,7 @@
     private EndpointManager endpointManager;
     private DiscoveryManager discoveryManager;
     private CommandVisitor commandVisitor;
+    private LockManager lockManager;
 
     public CacheInfoHolder(CacheManager cacheManager) {
         this.cacheManager = cacheManager;
@@ -63,6 +65,14 @@
     public void setCacheNotifier(CacheNotifier cacheNotifier) {
         this.cacheNotifier = cacheNotifier;
         cacheNotifier.setInfo(this);
+    }
+
+    public LockManager getLockManager() {
+        return lockManager;
+    }
+
+    public void setLockManager(LockManager lockManager) {
+        this.lockManager = lockManager;
     }
 
     public CommandVisitor getCommandVisitor() {

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java?view=diff&rev=504250&r1=504249&r2=504250
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java
(original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java
Tue Feb  6 11:24:12 2007
@@ -16,6 +16,9 @@
     public static final byte DISCOVERY_COMMAND = 13;
     public static final byte LOCK_COMMAND = 14;
     public static final byte RELEASELOCK_COMMAND = 15;
+    public static final byte LOCK_ACQUIRED_COMMAND = 16;
+    public static final byte LOCK_RELEASED_COMMAND = 17;
+    public static final byte ERROR_COMMAND = 18;
 
     public static Command createCommand(int identifier) {
         Command command = null;
@@ -64,6 +67,15 @@
                 break;
             case (RELEASELOCK_COMMAND):
                 command = new LockCommand();
+                break;
+            case (LOCK_ACQUIRED_COMMAND):
+                command = new LockCommand();
+                break;
+            case (LOCK_RELEASED_COMMAND):
+                command = new LockReleasedCommand();
+                break;
+            case (ERROR_COMMAND):
+                command = new ErrorCommand();
                 break;
         }
         return command;

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/ErrorCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/ErrorCommand.java?view=auto&rev=504250
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/ErrorCommand.java
(added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/ErrorCommand.java
Tue Feb  6 11:24:12 2007
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.geronimo.gcache.command;
+
+import java.io.IOException;
+
+import org.apache.geronimo.gcache.transports.CommandVisitor;
+import org.apache.mina.common.ByteBuffer;
+
+public class ErrorCommand extends BaseCommand {
+    private long messageId = 0;
+    private String message;
+
+    public byte getCommandType() throws IOException {
+        return CommandTypes.LOCK_ACQUIRED_COMMAND;
+    }
+
+    public long getMessageId() {
+        return messageId;
+    }
+
+    public void setMessageId(long messageId) {
+        this.messageId = messageId;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
+    public void readExternal(ByteBuffer buffer) throws Exception {
+
+        super.readExternal(buffer);
+
+        messageId = buffer.getLong();
+        
+        message = readString(buffer); 
+
+    }
+
+    public void writeExternal(ByteBuffer buffer) throws Exception {
+
+        super.writeExternal(buffer);
+        buffer.putLong(messageId);
+        writeString(buffer, message);
+
+    }
+
+    public void execute(CommandVisitor visitor) throws IOException{
+        visitor.processError(this);
+    }
+}

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/LockAcquiredCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/LockAcquiredCommand.java?view=auto&rev=504250
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/LockAcquiredCommand.java
(added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/LockAcquiredCommand.java
Tue Feb  6 11:24:12 2007
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.geronimo.gcache.command;
+
+import java.io.IOException;
+
+import org.apache.geronimo.gcache.transports.CommandVisitor;
+import org.apache.mina.common.ByteBuffer;
+
+public class LockAcquiredCommand extends BaseCommand {
+
+    private long messageId = 0;
+
+    public byte getCommandType() throws IOException {
+        return CommandTypes.LOCK_ACQUIRED_COMMAND;
+    }
+
+    public long getMessageId() {
+        return messageId;
+    }
+
+    public void setMessageId(long messageId) {
+        this.messageId = messageId;
+    }
+
+    public void readExternal(ByteBuffer buffer) throws Exception {
+
+        super.readExternal(buffer);
+
+        messageId = buffer.getLong();
+
+    }
+
+    public void writeExternal(ByteBuffer buffer) throws Exception {
+
+        super.writeExternal(buffer);
+        buffer.putLong(messageId);
+
+    }
+
+    public void execute(CommandVisitor visitor) throws IOException{
+        visitor.processLockAcquired(this);
+    }
+}

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/LockReleasedCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/LockReleasedCommand.java?view=auto&rev=504250
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/LockReleasedCommand.java
(added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/LockReleasedCommand.java
Tue Feb  6 11:24:12 2007
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.geronimo.gcache.command;
+
+import java.io.IOException;
+
+import org.apache.geronimo.gcache.transports.CommandVisitor;
+import org.apache.mina.common.ByteBuffer;
+
+public class LockReleasedCommand extends BaseCommand {
+    
+    private long messageId = 0;
+
+    public byte getCommandType() throws IOException {
+        return CommandTypes.LOCK_RELEASED_COMMAND;
+    }
+
+    public long getMessageId() {
+        return messageId;
+    }
+
+    public void setMessageId(long messageId) {
+        this.messageId = messageId;
+    }
+
+    public void readExternal(ByteBuffer buffer) throws Exception {
+
+        super.readExternal(buffer);
+
+        messageId = buffer.getLong();
+
+    }
+
+    public void writeExternal(ByteBuffer buffer) throws Exception {
+
+        super.writeExternal(buffer);
+        buffer.putLong(messageId);
+
+    }
+
+    public void execute(CommandVisitor visitor) throws IOException{
+        visitor.processLockReleased(this);
+    }
+}

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/CommandVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/CommandVisitor.java?view=diff&rev=504250&r1=504249&r2=504250
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/CommandVisitor.java
(original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/CommandVisitor.java
Tue Feb  6 11:24:12 2007
@@ -22,8 +22,11 @@
 
 import org.apache.geronimo.gcache.command.BulkSendCommand;
 import org.apache.geronimo.gcache.command.ClearCacheCommand;
+import org.apache.geronimo.gcache.command.ErrorCommand;
 import org.apache.geronimo.gcache.command.GetCacheCommand;
+import org.apache.geronimo.gcache.command.LockAcquiredCommand;
 import org.apache.geronimo.gcache.command.LockCommand;
+import org.apache.geronimo.gcache.command.LockReleasedCommand;
 import org.apache.geronimo.gcache.command.MessageAckCommand;
 import org.apache.geronimo.gcache.command.PutEntryCommand;
 import org.apache.geronimo.gcache.command.PutSessionCommand;
@@ -43,4 +46,8 @@
     public void processBulkSend(BulkSendCommand command);
     public void processLockSession(LockCommand command);
     public void processReleaseLockSession(ReleaseLockCommand command);
+    public void processLockAcquired(LockAcquiredCommand command);
+    public void processLockReleased(LockReleasedCommand command);
+    public void processError(ErrorCommand command);
+    
 }

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/Constants.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/Constants.java?view=diff&rev=504250&r1=504249&r2=504250
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/Constants.java
(original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/Constants.java
Tue Feb  6 11:24:12 2007
@@ -28,5 +28,6 @@
     public final static String BULK_COUNT = "BULK_COUNT_";
     public final static String BULK_COMMAND_ID = "BULK_COMMAND_ID_";
     public final static String MESSAGE_ACK_ID = "MESSAGE_ACK_ID_";
+    public static final String CLIENT_ID = "CLIENT_ID";
     public final static String REMOTE_PUBLIC_KEY = "REMOTE_PUBLIC_KEY";
 }

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPAuthenticationFilter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPAuthenticationFilter.java?view=diff&rev=504250&r1=504249&r2=504250
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPAuthenticationFilter.java
(original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPAuthenticationFilter.java
Tue Feb  6 11:24:12 2007
@@ -144,7 +144,7 @@
 
         //Register authentication
         sess.setAttribute(Constants.AUTHENTICATED);
-
+        
         //Now add the client to the cache to start receiving events
         CacheInfoHolder infoHolder = ((TCPSocketHandler) sess.getHandler())
                 .getInfoHolder();

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=504250&r1=504249&r2=504250
==============================================================================
--- 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
Tue Feb  6 11:24:12 2007
@@ -32,14 +32,19 @@
 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.ErrorCommand;
 import org.apache.geronimo.gcache.command.GetCacheCommand;
+import org.apache.geronimo.gcache.command.LockAcquiredCommand;
 import org.apache.geronimo.gcache.command.LockCommand;
+import org.apache.geronimo.gcache.command.LockReleasedCommand;
 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.ReleaseLockCommand;
 import org.apache.geronimo.gcache.command.RemoveEntryCommand;
 import org.apache.geronimo.gcache.command.RemoveSessionCommand;
+import org.apache.geronimo.gcache.lock.LockManager;
+import org.apache.geronimo.gcache.lock.NotCurrentOwnerException;
 import org.apache.mina.common.IoSession;
 
 public class TCPCommandVisitor extends BaseCommandVisitor {
@@ -222,11 +227,61 @@
     }
 
     public void processLockSession(LockCommand command) {
-        
+        LockManager lockMgr = infoHolder.getLockManager();
+        IoSession sess = (IoSession) command.getAttachment();
+
+        // Acquire the lock
+        try {
+            lockMgr.acquire(command.getCacheName(), command.getSessionId(), sess.getRemoteAddress().toString());
+        } catch (InterruptedException e) {
+            log.error(e);
+            
+            //Something bad happened...so send back an error
+            ErrorCommand error = new ErrorCommand();
+            error.setMessageId(command.getCommandId());
+            error.setMessage("Lock was interrupted and was not acquired.");
+            sess.write(error);
+            return;
+        }
+
+        // Send back a lock acquired command
+        LockAcquiredCommand lockAcquired = new LockAcquiredCommand();
+        lockAcquired.setMessageId(command.getCommandId());
+        sess.write(lockAcquired);
     }
 
     public void processReleaseLockSession(ReleaseLockCommand command) {
+        LockManager lockMgr = infoHolder.getLockManager();
+        IoSession sess = (IoSession) command.getAttachment();
+
+        try {
+            lockMgr.release(command.getCacheName(), command.getSessionId(), sess.getRemoteAddress().toString());
+        } catch (NotCurrentOwnerException e) {
+            log.error(e);
+            
+            ErrorCommand error = new ErrorCommand();
+            error.setMessageId(command.getCommandId());
+            error.setMessage("Not current owner of lock.");
+            sess.write(error);
+            return;
+        }
         
+        LockReleasedCommand lockReleased = new LockReleasedCommand();
+        lockReleased.setMessageId(command.getCommandId());
+        sess.write(lockReleased);
+
+    }
+
+    public void processLockAcquired(LockAcquiredCommand command) {
+        // TODO - fill in
+    }
+
+    public void processError(ErrorCommand command) {
+        // TODO - fill in
+    }
+
+    public void processLockReleased(LockReleasedCommand command) {
+        // TODO - fill in
     }
 
 }



Mime
View raw message