geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r471069 - in /geronimo/sandbox/gcache/server/src: main/java/org/apache/geronimo/gcache/transports/tcp/ test/java/org/apache/geronimo/gcache/server/ test/resources/
Date Sat, 04 Nov 2006 00:23:24 GMT
Author: jgenender
Date: Fri Nov  3 16:23:23 2006
New Revision: 471069

URL: http://svn.apache.org/viewvc?view=rev&rev=471069
Log:
Clean up tests - server works - yay

Modified:
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPAuthenticationFilter.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCacheNotifier.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandRequestDecoder.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketHandler.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/server/GCacheManagerTest.java
    geronimo/sandbox/gcache/server/src/test/resources/gcache-config.xml

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPAuthenticationFilter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPAuthenticationFilter.java?view=diff&rev=471069&r1=471068&r2=471069
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPAuthenticationFilter.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPAuthenticationFilter.java
Fri Nov  3 16:23:23 2006
@@ -117,7 +117,7 @@
         AuthCommand auth = (AuthCommand) obj;
         String authUserId = auth.getUserId();
         if (log.isDebugEnabled()) {
-            log.debug("User Id read was '" + authUserId + "'");
+            log.debug("User Id read was '" + authUserId + "' from " + sess.getRemoteAddress().toString());
         }
         if (!userId.equals(authUserId)) {
             log.error("Authentication failure for "
@@ -128,7 +128,7 @@
 
         String authPassword = auth.getPassword();
         if (log.isDebugEnabled()) {
-            log.debug("Password read was '" + authPassword + "'");
+            log.debug("Password read was '" + authPassword + "' from " + sess.getRemoteAddress().toString());
         }
         if (!password.equals(authPassword)) {
             log.error("Authentication failure for "

Modified: 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=diff&rev=471069&r1=471068&r2=471069
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCacheNotifier.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCacheNotifier.java
Fri Nov  3 16:23:23 2006
@@ -39,61 +39,61 @@
     }
 
     public void notifyClearCache(ClearCacheCommand command) {
-	sendToEndpoints(command);
+        sendToEndpoints(command);
     }
 
     public void notifyPut(PutEntryCommand command) {
-	sendToEndpoints(command);
+        sendToEndpoints(command);
     }
 
     public void notifyPutSession(PutSessionCommand command) {
-	sendToEndpoints(command);
+        sendToEndpoints(command);
     }
 
     public void notifyRemove(RemoveEntryCommand command) {
-	sendToEndpoints(command);
+        sendToEndpoints(command);
     }
 
     public void notifyRemoveSession(RemoveSessionCommand command) {
-	sendToEndpoints(command);
+        sendToEndpoints(command);
     }
 
     private void sendToEndpoints(BaseCommand command) {
 
-	ByteBuffer buffer = null;
-	try {
-	    buffer = ByteBuffer.wrap(command.createPacket(true));
-	} catch (Exception e) {
-	    log.error("Cannot marshal packet, cannot send to endpoints", e);
-	    return;
-	}
-
-	TCPEndpoint origEndpoint = (TCPEndpoint) command.getAttachment();
-
-	//Spin through the client list
-	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;
-		}
-
-		IoSession sess = tcp.getIoSession();
-		sess.write(buffer);
-
-		//See if we need to request an Ack
-		TCPMessageAckCommandFilter filter = (TCPMessageAckCommandFilter) sess
-			.getFilterChain().get(TCPMessageAckCommandFilter.NAME);
-		if (filter != null) {
-		    long commandId = command.getCommandId();
-		    filter.requestAck(commandId, sess);
-		}
+        ByteBuffer buffer = null;
+        try {
+            buffer = ByteBuffer.wrap(command.createPacket(true));
+        } catch (Exception e) {
+            log.error("Cannot marshal packet, cannot send to endpoints", e);
+            return;
+        }
+
+        TCPEndpoint origEndpoint = (TCPEndpoint) command.getAttachment();
+
+        //Spin through the client list
+        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;
+                }
+
+                IoSession sess = tcp.getIoSession();
+                sess.write(buffer);
+
+                //See if we need to request 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/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandRequestDecoder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandRequestDecoder.java?view=diff&rev=471069&r1=471068&r2=471069
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandRequestDecoder.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandRequestDecoder.java
Fri Nov  3 16:23:23 2006
@@ -35,95 +35,94 @@
 
 
     public MessageDecoderResult decodable(IoSession session, ByteBuffer in) {
-	// Return NEED_DATA if the whole header is not read yet.
-	try {
-	    return messageComplete(in);
-	} catch (Exception ex) {
-	    ex.printStackTrace();
-	}
+        // Return NEED_DATA if the whole header is not read yet.
+        try {
+            return messageComplete(in);
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
 
-	return MessageDecoderResult.NOT_OK;
+        return MessageDecoderResult.NOT_OK;
     }
 
     public MessageDecoderResult decode(IoSession session, ByteBuffer in,
-	    ProtocolDecoderOutput out) throws Exception {
-	// TODO Auto-generated method stub
+                                       ProtocolDecoderOutput out) throws Exception {
+        // TODO Auto-generated method stub
 
-	byte magic[] = new byte[Constants.MAGIC.length];
-	in.get(magic);
+        byte magic[] = new byte[Constants.MAGIC.length];
+        in.get(magic);
 
-	// Get the command
-	byte commandIdentifier = in.get();
+        // Get the command
+        byte commandIdentifier = in.get();
 
-	// Get the command length
-	in.getInt();
-	
-	Command command = CommandTypes.createCommand(commandIdentifier);
-	if (log.isDebugEnabled()){
-	    log.debug("Command is type " + command.getClass().getSimpleName());
-	}
-	
-	command.readExternal(in);
-	
-	out.write(command);
-	
-	return MessageDecoderResult.OK;
+        // Get the command length
+        in.getInt();
+
+        Command command = CommandTypes.createCommand(commandIdentifier);
+        if (log.isDebugEnabled()) {
+            log.debug("Command is type " + command.getClass().getSimpleName() + " from "
+ session.getRemoteAddress().toString());
+        }
+
+        command.readExternal(in);
+
+        out.write(command);
+
+        return MessageDecoderResult.OK;
     }
 
     private MessageDecoderResult messageComplete(ByteBuffer in)
-	    throws Exception {
+            throws Exception {
 
-	// HEADER BREAKDOWN
-	// ---------------------------------------------------------
-	// MAGIC HEADER - 6 bytes
-	// COMMAND - 1 byte
-	// COMMAND LENGTH - 4 bytes
-	// COMMAND - ? bytes as defined above
-
-	if (in.remaining() < Constants.HEADER_SIZE)
-	    return MessageDecoderResult.NEED_DATA;
-
-	if (log.isDebugEnabled()) {
-	    log.debug("Header read:");
-	    // log.debug(HexDump.hexString(buffer.array()));
-	}
-
-	// Read the magic
-	byte magic[] = new byte[Constants.MAGIC.length];
-	in.get(magic);
-
-	// Better match the Magic
-	if (!Arrays.equals(Constants.MAGIC, magic)) {
-	    // Magic doesn't match, so close the socket
-	    log.debug("Magic did not match!");
-	    // infoHolder.getEndpointManager().removeEndpoint( new
-                // TCPEndpoint(channel));
-
-	    // disconnect(channel);
-	    // return;
-	}
-
-	log.debug("Magic found");
-
-	// Get the command
-	byte commandIdentifier = in.get();
-	if (log.isDebugEnabled()) {
-	    log.debug("Command Identifier = " + commandIdentifier);
-	}
-
-	// Get the command length
-	int length = in.getInt();
-	if (log.isDebugEnabled()) {
-	    log.debug("Command length = " + length);
-	}
-
-	// Be sure we have all of the data we need
-	if (in.remaining() != length) {
-	    return MessageDecoderResult.NEED_DATA;
-	}
-	
+        // HEADER BREAKDOWN
+        // ---------------------------------------------------------
+        // MAGIC HEADER - 6 bytes
+        // COMMAND - 1 byte
+        // COMMAND LENGTH - 4 bytes
+        // COMMAND - ? bytes as defined above
+
+        if (in.remaining() < Constants.HEADER_SIZE)
+            return MessageDecoderResult.NEED_DATA;
+
+        if (log.isDebugEnabled()) {
+            log.debug("Header read:");
+            // log.debug(HexDump.hexString(buffer.array()));
+        }
+
+        // Read the magic
+        byte magic[] = new byte[Constants.MAGIC.length];
+        in.get(magic);
+
+        // Better match the Magic
+        if (!Arrays.equals(Constants.MAGIC, magic)) {
+            // Magic doesn't match, so close the socket
+            log.debug("Magic did not match!");
+            // infoHolder.getEndpointManager().removeEndpoint( new
+            // TCPEndpoint(channel));
+
+            // disconnect(channel);
+            // return;
+        }
+
+        log.debug("Magic found");
+
+        // Get the command
+        byte commandIdentifier = in.get();
+        if (log.isDebugEnabled()) {
+            log.debug("Command Identifier = " + commandIdentifier);
+        }
+
+        // Get the command length
+        int length = in.getInt();
+        if (log.isDebugEnabled()) {
+            log.debug("Command length = " + length);
+        }
+
+        // Be sure we have all of the data we need
+        if (in.remaining() != length) {
+            return MessageDecoderResult.NEED_DATA;
+        }
 
-	/**
+        /**
          * // TODO - This really should be done with a ByteBuffer pool
          * ByteBuffer commandBuffer = ByteBuffer.allocate(length);
          * bcr.reset(channel, commandBuffer); count = bcr.readBuffer(length); if
@@ -134,12 +133,12 @@
          * Command was bad if (log.isDebugEnabled()) { log.debug("Command read
          * size (" + count + ") did not equal expected length (" + length +
          * ")"); } // TODO - Send back a resend? return; }
-         * 
+         *
          * byte commandArray[] = commandBuffer.array();
-         * 
+         *
          * if (log.isDebugEnabled()) { log.debug("Command read:");
          * log.debug(HexDump.hexString(commandArray)); }
-         * 
+         *
          * ByteArrayInputStream bias = new ByteArrayInputStream(commandBuffer
          * .array()); ReadableByteChannel readChannel =  Channels.newChannel(bias); // Create
the command and unmarshal the
          * data Command command = CommandTypes.createCommand(commandIdentifier);
@@ -148,7 +147,7 @@
          * command.readExternal(readChannel);
          */
 
-	return MessageDecoderResult.OK;
+        return MessageDecoderResult.OK;
     }
 
 }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketHandler.java?view=diff&rev=471069&r1=471068&r2=471069
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketHandler.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketHandler.java
Fri Nov  3 16:23:23 2006
@@ -28,75 +28,75 @@
 import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
 
 /**
- * This class is the main worker of the gcache functionality. Essentialy this 
+ * This class is the main worker of the gcache functionality. Essentialy this
  */
 public class TCPSocketHandler extends IoHandlerAdapter {
-    
+
     public final static int DEFAULT_THREAD_POOL_SIZE = 10;
     private final CacheInfoHolder infoHolder;
     private final ScheduledThreadPoolExecutor scheduler;
-    
+
     public TCPSocketHandler(final CacheInfoHolder infoHolder) {
-	this(infoHolder, DEFAULT_THREAD_POOL_SIZE);
+        this(infoHolder, DEFAULT_THREAD_POOL_SIZE);
     }
-    
+
     public TCPSocketHandler(final CacheInfoHolder infoHolder, int threadPoolSize) {
-	this.infoHolder = infoHolder;
-	scheduler = (ScheduledThreadPoolExecutor)Executors.newScheduledThreadPool(threadPoolSize);
-	
-	//Install the schedule purger to purge any cancelled tasks
-	//to prevent memory leaks
-	scheduler.scheduleWithFixedDelay(new SchedulePurger(), 10000, 10000, TimeUnit.MILLISECONDS);
+        this.infoHolder = infoHolder;
+        scheduler = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(threadPoolSize);
+
+        //Install the schedule purger to purge any cancelled tasks
+        //to prevent memory leaks
+        scheduler.scheduleWithFixedDelay(new SchedulePurger(), 10000, 10000, TimeUnit.MILLISECONDS);
     }
-    
+
     public CacheInfoHolder getInfoHolder() {
         return infoHolder;
     }
 
     @Override
     public void messageReceived(IoSession session, Object obj) throws Exception {
-	
-	Command command = (Command) obj;
-	
-	// Do something with the data
-	TCPCommandVisitor visitor = new TCPCommandVisitor(infoHolder, session);
-	
-	command.execute(visitor);
+
+        Command command = (Command) obj;
+
+        // Do something with the data
+        TCPCommandVisitor visitor = new TCPCommandVisitor(infoHolder, session);
+
+        command.execute(visitor);
 
     }
 
     @Override
     public void exceptionCaught(IoSession sess, Throwable cause) throws Exception {
-	SessionLog.error( sess, "", cause );
-	infoHolder.getEndpointManager().removeEndpoint(new TCPEndpoint(sess));
-	sess.close();
+        SessionLog.error(sess, "", cause);
+        infoHolder.getEndpointManager().removeEndpoint(new TCPEndpoint(sess));
+        sess.close();
     }
 
 
     @Override
     public void sessionClosed(IoSession sess) throws Exception {
-	//Remove the client from the list
-	infoHolder.getEndpointManager().removeEndpoint(new TCPEndpoint(sess));
+        //Remove the client from the list
+        infoHolder.getEndpointManager().removeEndpoint(new TCPEndpoint(sess));
+    }
+
+    public void destroy() {
+        //Shut down the scheduler.
+        scheduler.shutdownNow();
     }
-    
-    public void destroy(){
-	//Shut down the scheduler.
-	scheduler.shutdownNow();
-    }
-    
-    public ScheduledFuture schedule(Runnable task, long delay){
-	return scheduler.schedule(task, delay, TimeUnit.MILLISECONDS);
+
+    public ScheduledFuture schedule(Runnable task, long delay) {
+        return scheduler.schedule(task, delay, TimeUnit.MILLISECONDS);
     }
-    
+
     /**
      * Task to remove cancelled tasks from the scheduler
      */
-    class SchedulePurger implements Runnable{
+    class SchedulePurger implements Runnable {
+
+        public void run() {
+            scheduler.purge();
+        }
 
-	public void run() {
-	    scheduler.purge();
-	}
-	
     }
-    
+
 }

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/server/GCacheManagerTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/server/GCacheManagerTest.java?view=diff&rev=471069&r1=471068&r2=471069
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/server/GCacheManagerTest.java
(original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/server/GCacheManagerTest.java
Fri Nov  3 16:23:23 2006
@@ -34,6 +34,9 @@
 import java.util.HashMap;
 import java.util.Map;
 
+/**
+ * Test the GCache
+ */
 public class GCacheManagerTest {
     GCacheManager mgr;
 
@@ -61,6 +64,9 @@
         client2.connect(new InetSocketAddress("localhost", 4123), 2000);
         authenticate(client2);
 
+        //Give the clients time to authenticate
+        Thread.sleep(1000);
+        
         //Client 1 will send a session
         sendSession(client);
 

Modified: geronimo/sandbox/gcache/server/src/test/resources/gcache-config.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/resources/gcache-config.xml?view=diff&rev=471069&r1=471068&r2=471069
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/resources/gcache-config.xml (original)
+++ geronimo/sandbox/gcache/server/src/test/resources/gcache-config.xml Fri Nov  3 16:23:23
2006
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gcache-config>
 	<server order="1" serverName="gcache">
-		<transport name="default" uri="tcp://default" discoveryUri="multicast://default" />
+		<transport name="default" uri="tcp://default?enableLogging=true" discoveryUri="multicast://default"
/>
 	</server>
 	
 	<diskStore path="${java.io.tmpdir}/gcache" />



Mime
View raw message