[jboss-cvs] JBossAS SVN: r61893 - in branches/JBoss_4_0_3_SP1_CP: messaging/src/main/org/jboss/mq/il/jvm and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Mar 30 11:43:24 EDT 2007


Author: luc.texier at jboss.com
Date: 2007-03-30 11:43:24 -0400 (Fri, 30 Mar 2007)
New Revision: 61893

Added:
   branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/jbossmq/test/UIL2DisconnectClientsUnitTestCase.java
Modified:
   branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/il/ServerILJMXService.java
   branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/il/jvm/JVMServerILService.java
   branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/il/rmi/RMIServerILService.java
   branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/il/uil2/ServerSocketManagerHandler.java
   branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/il/uil2/UILServerILService.java
Log:
ASPATCH-176 Applied recommended changes

Modified: branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/il/ServerILJMXService.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/il/ServerILJMXService.java	2007-03-30 15:43:00 UTC (rev 61892)
+++ branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/il/ServerILJMXService.java	2007-03-30 15:43:24 UTC (rev 61893)
@@ -201,16 +201,27 @@
       ctx.unbind(xaConnectionFactoryJNDIRef);
    }
 
-   /**
-    * @return Description of the Returned Value
-    * @exception Exception Description of Exception
-    * @throws javax.naming.NamingException if the server is not found
-    */
-   public Invoker lookupJMSServer()
-   {
-      return jmsServer;
-   }
+    /**
+     * @return Description of the Returned Value
+     * @exception Exception Description of Exception
+     * @throws javax.naming.NamingException if the server is not found
+     */
+    public Invoker getJMSServer()
+    {
+       return jmsServer;
+    }
 
+    /**
+     * @return Description of the Returned Value
+     * @exception Exception Description of Exception
+     * @throws javax.naming.NamingException if the server is not found
+     */
+    public Invoker lookupJMSServer()
+    {
+       return getJMSServer();
+    }
+
+
    /**
     * @return long the period of time in ms to wait between connection pings
     *         factory should be bound to

Modified: branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/il/jvm/JVMServerILService.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/il/jvm/JVMServerILService.java	2007-03-30 15:43:00 UTC (rev 61892)
+++ branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/il/jvm/JVMServerILService.java	2007-03-30 15:43:24 UTC (rev 61893)
@@ -43,8 +43,7 @@
     * @returns    ServerIL the instance of this IL
     */
    public ServerIL getServerIL() {
-      return new JVMServerIL( lookupJMSServer() );
-      //return null;
+      return new JVMServerIL(getJMSServer());
    }
 
    /**

Modified: branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/il/rmi/RMIServerILService.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/il/rmi/RMIServerILService.java	2007-03-30 15:43:00 UTC (rev 61892)
+++ branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/il/rmi/RMIServerILService.java	2007-03-30 15:43:24 UTC (rev 61893)
@@ -68,7 +68,7 @@
    public void startService() throws Exception
    {
       super.startService();
-      serverIL = new RMIServerIL(lookupJMSServer());
+      serverIL = new RMIServerIL(getJMSServer());
       bindJNDIReferences();
 
    }

Modified: branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/il/uil2/ServerSocketManagerHandler.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/il/uil2/ServerSocketManagerHandler.java	2007-03-30 15:43:00 UTC (rev 61892)
+++ branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/il/uil2/ServerSocketManagerHandler.java	2007-03-30 15:43:24 UTC (rev 61893)
@@ -37,6 +37,7 @@
 import org.jboss.mq.il.uil2.msgs.PingMsg;
 import org.jboss.mq.il.Invoker;
 
+import EDU.oswego.cs.dl.util.concurrent.SynchronizedBoolean;
 /** This is the SocketManager callback handler for the UIL2 server side
  * socket. This handles messages that are requests from clients.
  *
@@ -50,13 +51,14 @@
    private ConnectionToken connectionToken;
    private Invoker server;
    private SocketManager socketMgr;
-   private boolean closed;
+   private UILServerILService uilServerILService;
+   private SynchronizedBoolean closed = new SynchronizedBoolean(false);
 
-   public ServerSocketManagerHandler(Invoker server, SocketManager socketMgr)
+   public ServerSocketManagerHandler(Invoker server, SocketManager socketMgr, UILServerILService uilServerILService)
    {
       this.server = server;
       this.socketMgr = socketMgr;
-      this.closed = false;
+      this.uilServerILService = uilServerILService;
    }
 
    /** The callback from the SocketManager
@@ -85,6 +87,7 @@
             AcknowledgementRequestMsg ackmsg = (AcknowledgementRequestMsg) msg;
             AcknowledgementRequest ack = ackmsg.getAck();
             server.acknowledge(connectionToken, ack);
+            // We send the reply although on newer clients it is ignored.
             socketMgr.sendReply(msg);
             break;
          case m_addMessage:
@@ -108,7 +111,7 @@
             break;
          case m_connectionClosing:
             server.connectionClosing(connectionToken);
-            closed = true;
+            closed.set(true);
             socketMgr.sendReply(msg);
             socketMgr.stop();
             break;
@@ -226,7 +229,8 @@
    {
       try
       {
-         if (closed == false)
+         uilServerILService.removeHandler(this);
+         if (closed.get() == false)
             server.connectionClosing(connectionToken);
       }
       catch (Exception e)

Modified: branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/il/uil2/UILServerILService.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/il/uil2/UILServerILService.java	2007-03-30 15:43:00 UTC (rev 61892)
+++ branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/il/uil2/UILServerILService.java	2007-03-30 15:43:24 UTC (rev 61893)
@@ -1,8 +1,23 @@
 /*
- * JBoss, the OpenSource J2EE webOS
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
  *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.jboss.mq.il.uil2;
 
@@ -12,6 +27,8 @@
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.UnknownHostException;
+
+import java.util.Iterator;
 import java.util.Properties;
 import javax.naming.InitialContext;
 import javax.net.ServerSocketFactory;
@@ -24,6 +41,9 @@
 import org.jboss.security.SecurityDomain;
 import org.jboss.system.server.ServerConfigUtil;
 
+import EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArrayList;
+import EDU.oswego.cs.dl.util.concurrent.SynchronizedBoolean;
+
 /** This is the server side MBean for the UIL2 transport layer.
  *
  * @author Scott.Stark at jboss.org
@@ -50,7 +70,7 @@
     */
    private ServerSocket serverSocket;
    private UILServerIL serverIL;
-   private boolean running;
+   private SynchronizedBoolean running = new SynchronizedBoolean(false);
    /** The server jms listening port */
    private int serverBindPort = 0;
    /** The server jms address the listening socket binds to */
@@ -111,7 +131,10 @@
       return connectionProperties;
    }
 
-   /**
+   /** The server handlers */
+   private CopyOnWriteArrayList handlers = new CopyOnWriteArrayList();
+
+    /**
     * Used to construct the GenericConnectionFactory (bindJNDIReferences()
     * builds it)
     *
@@ -128,7 +151,7 @@
    public void run()
    {
       boolean trace = log.isTraceEnabled();
-      while (running)
+      while (running.get())
       {
          Socket socket = null;
          SocketManager socketMgr = null;
@@ -140,20 +163,22 @@
             socket.setSoTimeout(readTimeout);
             socket.setTcpNoDelay(enableTcpNoDelay);
             socketMgr = new SocketManager(socket);
-            ServerSocketManagerHandler handler = new ServerSocketManagerHandler(server, socketMgr);
+            ServerSocketManagerHandler handler = new ServerSocketManagerHandler(getJMSServer(), socketMgr, this);
+            handlers.add(handler);
             socketMgr.setHandler(handler);
             socketMgr.setBufferSize(bufferSize);
             socketMgr.setChunkSize(chunkSize);
+            Invoker s = getJMSServer();
             socketMgr.start(server.getThreadGroup());
          }
          catch (IOException e)
          {
-            if (running)
+            if (running.get())
                log.warn("Failed to setup client connection", e);
          }
          catch(Throwable e)
          {
-            if (running || trace)
+            if (running.get() || trace)
                log.warn("Unexpected error in setup of client connection", e);            
          }
       }
@@ -167,8 +192,6 @@
    public void startService() throws Exception
    {
       super.startService();
-      running = true;
-      this.server = lookupJMSServer();
 
       // Use the default javax.net.ServerSocketFactory if none was set
       if (serverSocketFactory == null)
@@ -204,7 +227,8 @@
 
       InetAddress socketAddress = serverSocket.getInetAddress();
       log.info("JBossMQ UIL service available at : " + socketAddress + ":" + serverSocket.getLocalPort());
-      acceptThread = new Thread(server.getThreadGroup(), this, "UILServerILService Accept Thread");
+      acceptThread = new Thread(getJMSServer().getThreadGroup(), this, "UILServerILService Accept Thread");
+      running.set(true);
       acceptThread.start();
 
       /* We need to check the socketAddress against "0.0.0.0/0.0.0.0"
@@ -242,7 +266,7 @@
    {
       try
       {
-         running = false;
+         running.set(false);
          unbindJNDIReferences();
 
          // unbind Server Socket if needed
@@ -255,8 +279,29 @@
       {
          log.error("Exception occured when trying to stop UIL Service: ", e);
       }
+
+      // Try to close any open sockets that we know about
+      for (Iterator i = handlers.iterator(); i.hasNext();)
+      {
+         ServerSocketManagerHandler handler = (ServerSocketManagerHandler) i.next();
+         if (handler != null)
+         {
+            try
+            {
+               handler.close();
+            }
+            catch (Throwable ignored)
+            {
+            }
+         }
+      }
    }
 
+   protected void removeHandler(ServerSocketManagerHandler handler)
+   {
+      handlers.remove(handler);
+   }
+
    /**
     * Get the UIL server listening port
     *

Added: branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/jbossmq/test/UIL2DisconnectClientsUnitTestCase.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/jbossmq/test/UIL2DisconnectClientsUnitTestCase.java	                        (rev 0)
+++ branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/jbossmq/test/UIL2DisconnectClientsUnitTestCase.java	2007-03-30 15:43:24 UTC (rev 61893)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.jbossmq.test;
+
+import javax.management.ObjectName;
+
+import org.jboss.mx.util.ObjectNameFactory;
+
+/**
+ * A test to make sure exception listeners are fired when the UIL2 service is stopped
+ *
+ * @author <a href="mailto:adrian at jboss.org>Adrian Brock</a>
+ * @version <tt>$Revision: 57211 $</tt>
+ */
+public class UIL2DisconnectClientsUnitTestCase extends AbstractRestartDisconnectClientsTest
+{
+   static ObjectName UIL2 = ObjectNameFactory.create("jboss.mq:service=InvocationLayer,type=UIL2");
+   
+   public UIL2DisconnectClientsUnitTestCase(String name) throws Exception
+   {
+      super(name);
+   }
+
+   protected ObjectName getRestartObjectName()
+   {
+      return UIL2;
+   }
+}




More information about the jboss-cvs-commits mailing list