geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r465912 - in /geronimo/sandbox/gcache/server/src: main/java/org/apache/geronimo/gcache/ main/java/org/apache/geronimo/gcache/command/ main/java/org/apache/geronimo/gcache/server/listeners/ main/java/org/apache/geronimo/gcache/transports/tcp...
Date Thu, 19 Oct 2006 22:34:46 GMT
Author: jgenender
Date: Thu Oct 19 15:34:45 2006
New Revision: 465912

URL: http://svn.apache.org/viewvc?view=rev&rev=465912
Log:
dd a TCP Cache Notifier for endpoints

Added:
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCacheNotifier.java
  (with props)
Modified:
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java
    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/server/listeners/CacheNotifier.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/DefaultCacheNotifier.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandVisitor.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPEndpoint.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/AbstractServer.java

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java?view=diff&rev=465912&r1=465911&r2=465912
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java
Thu Oct 19 15:34:45 2006
@@ -53,6 +53,7 @@
 
     public void setCacheNotifier(CacheNotifier cacheNotifier) {
         this.cacheNotifier = cacheNotifier;
+        cacheNotifier.setInfo(this);
     }
 
     public Cache getCache(String cacheName, boolean create){

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=465912&r1=465911&r2=465912
==============================================================================
--- 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
Thu Oct 19 15:34:45 2006
@@ -43,6 +43,20 @@
      * where a response is required as a coorilation id.
      */
     private long commandId = 0;
+    
+    /**
+     * Allows an object to be attached for passing around during processing
+     * of the command
+     */
+    private transient Object attachment = null;
+    
+    public Object getAttachment() {
+        return attachment;
+    }
+
+    public void setAttachment(Object attachment) {
+        this.attachment = attachment;
+    }
 
     /**
      * Get the command type. Types are integers and are used by gcache to

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/CacheNotifier.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/CacheNotifier.java?view=diff&rev=465912&r1=465911&r2=465912
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/CacheNotifier.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/CacheNotifier.java
Thu Oct 19 15:34:45 2006
@@ -18,20 +18,32 @@
  */
 package org.apache.geronimo.gcache.server.listeners;
 
+import org.apache.geronimo.gcache.CacheInfoHolder;
 import org.apache.geronimo.gcache.command.ClearCacheCommand;
 import org.apache.geronimo.gcache.command.PutEntryCommand;
+import org.apache.geronimo.gcache.command.PutSessionCommand;
 import org.apache.geronimo.gcache.command.RemoveEntryCommand;
 import org.apache.geronimo.gcache.command.RemoveSessionCommand;
-import org.apache.geronimo.gcache.command.PutSessionCommand;
 
-public interface CacheNotifier {
-    public void notifyClearCache(ClearCacheCommand command);
+public abstract class CacheNotifier {
+    
+    protected CacheInfoHolder info;
+    
+    public CacheInfoHolder getInfo() {
+        return info;
+    }
+
+    public void setInfo(CacheInfoHolder info) {
+        this.info = info;
+    }
+
+    public abstract void notifyClearCache(ClearCacheCommand command);
 
-    public void notifyPut(PutEntryCommand command);
+    public abstract void notifyPut(PutEntryCommand command);
 
-    public void notifyPutSession(PutSessionCommand command);
+    public abstract void notifyPutSession(PutSessionCommand command);
 
-    public void notifyRemove(RemoveEntryCommand command);
+    public abstract void notifyRemove(RemoveEntryCommand command);
 
-    public void notifyRemoveSession(RemoveSessionCommand command);
+    public abstract void notifyRemoveSession(RemoveSessionCommand command);
 }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/DefaultCacheNotifier.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/DefaultCacheNotifier.java?view=diff&rev=465912&r1=465911&r2=465912
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/DefaultCacheNotifier.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/DefaultCacheNotifier.java
Thu Oct 19 15:34:45 2006
@@ -27,7 +27,7 @@
 /**
  * Default implementation of a cache notifier that does nothing
  */
-public class DefaultCacheNotifier implements CacheNotifier {
+public class DefaultCacheNotifier extends CacheNotifier {
 
     public void notifyClearCache(ClearCacheCommand command){
     }

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCacheNotifier.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCacheNotifier.java?view=auto&rev=465912
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCacheNotifier.java
(added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCacheNotifier.java
Thu Oct 19 15:34:45 2006
@@ -0,0 +1,89 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.gcache.transports.tcp;
+
+import java.io.IOException;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gcache.command.BaseCommand;
+import org.apache.geronimo.gcache.command.ClearCacheCommand;
+import org.apache.geronimo.gcache.command.PutEntryCommand;
+import org.apache.geronimo.gcache.command.PutSessionCommand;
+import org.apache.geronimo.gcache.command.RemoveEntryCommand;
+import org.apache.geronimo.gcache.command.RemoveSessionCommand;
+import org.apache.geronimo.gcache.server.listeners.CacheNotifier;
+import org.apache.geronimo.gcache.transports.Endpoint;
+import org.apache.mina.common.ByteBuffer;
+
+public class TCPCacheNotifier extends CacheNotifier {
+    private Log log = LogFactory.getLog(TCPCacheNotifier.class);
+
+    public TCPCacheNotifier() {
+    }
+
+    public void notifyClearCache(ClearCacheCommand command) {
+	sendToEndpoints(command);
+    }
+
+    public void notifyPut(PutEntryCommand command) {
+	sendToEndpoints(command);
+    }
+
+    public void notifyPutSession(PutSessionCommand command) {
+	sendToEndpoints(command);
+    }
+
+    public void notifyRemove(RemoveEntryCommand command) {
+	sendToEndpoints(command);
+    }
+
+    public void notifyRemoveSession(RemoveSessionCommand command) {
+	sendToEndpoints(command);
+    }
+
+    private void sendToEndpoints(BaseCommand command) {
+
+	ByteBuffer buffer = null;
+	try {
+	    buffer = ByteBuffer.wrap(command.createPacket(true));
+	} catch (IOException e) {
+	    log.error("Cannot marshal packet, cannot send to endpoints", e);
+	    return;
+	}
+	
+	TCPEndpoint origEndpoint = (TCPEndpoint) command.getAttachment();
+	Set<Endpoint> set = info.getEndpointManager().getEndpoints();
+	synchronized (set) {
+	    for (Endpoint endpoint : set) {
+		TCPEndpoint tcp = (TCPEndpoint) endpoint;
+
+		//Don't update from whence it came
+		if (origEndpoint != null && origEndpoint.equals(tcp)) {
+		    continue;
+		}
+		
+		tcp.getIoSession().write(buffer);
+
+	    }
+	}
+
+    }
+
+}

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

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

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

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=465912&r1=465911&r2=465912
==============================================================================
--- 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
Thu Oct 19 15:34:45 2006
@@ -51,10 +51,10 @@
 
     private CacheInfoHolder infoHolder;
 
-    private IoSession sess;
+    private TCPEndpoint endpoint;
 
     public TCPCommandVisitor(CacheInfoHolder infoHolder, IoSession sess) {
-	this.sess = sess;
+	endpoint = new TCPEndpoint(sess);
 	this.infoHolder = infoHolder;
     }
 
@@ -101,6 +101,7 @@
 	}
 
 	// Notify peers
+	command.setAttachment(endpoint);
 	infoHolder.getCacheNotifier().notifyRemove(command);
     }
 
@@ -115,9 +116,10 @@
 	    // Ack the message
 	    MessageAckCommand ack = new MessageAckCommand();
 	    ack.setMessageId(command.getCommandId());
+	    IoSession sess = endpoint.getIoSession();
 	    if (sess != null)
 		sess.write(ack);
-
+	    
 	} catch (IOException e) {
 	    // TODO - What should we do on an IOException, ignore it or
                 // remove the client?
@@ -125,6 +127,7 @@
 	}
 
 	// Notify peers
+	command.setAttachment(endpoint);
 	infoHolder.getCacheNotifier().notifyPutSession(command);
     }
 
@@ -157,6 +160,7 @@
 	}
 
 	// Notify peers
+	command.setAttachment(endpoint);
 	infoHolder.getCacheNotifier().notifyPut(command);
     }
 
@@ -168,7 +172,8 @@
 	Cache cache = infoHolder.getCache(command.getCacheName(), true);
 	
 	//Add the client endpoint
-	infoHolder.getEndpointManager().addEndpoint(new TCPEndpoint(sess));
+	infoHolder.getEndpointManager().addEndpoint(endpoint);
+	IoSession sess = endpoint.getIoSession();
 	
 	//Send a bulk command
 	BulkSendCommand bulk = new BulkSendCommand();
@@ -215,6 +220,7 @@
 	cache.removeAll();
 
 	// Notify peers
+	command.setAttachment(endpoint);
 	infoHolder.getCacheNotifier().notifyClearCache(command);
     }
 

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPEndpoint.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPEndpoint.java?view=diff&rev=465912&r1=465911&r2=465912
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPEndpoint.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPEndpoint.java
Thu Oct 19 15:34:45 2006
@@ -34,13 +34,21 @@
 
     @Override
     public boolean equals(Object obj) {
+	
 	TCPEndpoint endpoint = (TCPEndpoint) obj;
-	boolean blah = ioSession.equals(endpoint.ioSession);
+	if (ioSession == null){
+	    if (endpoint.ioSession == null)
+		return true;
+	    
+	    return false;
+	}
 	return ioSession.equals(endpoint.ioSession);
     }
 
     @Override
     public int hashCode() {
+	if (ioSession == null)
+	    return 0;
 	return ioSession.hashCode();
     }
 

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/AbstractServer.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/AbstractServer.java?view=diff&rev=465912&r1=465911&r2=465912
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/AbstractServer.java
(original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/AbstractServer.java
Thu Oct 19 15:34:45 2006
@@ -47,6 +47,7 @@
     public void setUp() throws Exception{
         CacheManager mgr = CacheManager.create();
         info = new CacheInfoHolder(mgr);
+        info.setCacheNotifier(new TCPCacheNotifier());
 
         server = new TCPSocketTransportServer(host, port, info);
 



Mime
View raw message