[jboss-cvs] JBossAS SVN: r61548 - trunk/jbossmq/src/main/org/jboss/mq/il/uil2.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Mar 21 10:24:37 EDT 2007
Author: adrian at jboss.org
Date: 2007-03-21 10:24:36 -0400 (Wed, 21 Mar 2007)
New Revision: 61548
Modified:
trunk/jbossmq/src/main/org/jboss/mq/il/uil2/ServerSocketManagerHandler.java
trunk/jbossmq/src/main/org/jboss/mq/il/uil2/UILServerILService.java
Log:
Port JBAS-4222 from JBoss-4.2
Modified: trunk/jbossmq/src/main/org/jboss/mq/il/uil2/ServerSocketManagerHandler.java
===================================================================
--- trunk/jbossmq/src/main/org/jboss/mq/il/uil2/ServerSocketManagerHandler.java 2007-03-21 14:23:40 UTC (rev 61547)
+++ trunk/jbossmq/src/main/org/jboss/mq/il/uil2/ServerSocketManagerHandler.java 2007-03-21 14:24:36 UTC (rev 61548)
@@ -1,24 +1,24 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.
-*/
+ * 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.mq.il.uil2;
import java.rmi.RemoteException;
@@ -55,6 +55,8 @@
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.
*
@@ -68,13 +70,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
@@ -127,7 +130,7 @@
break;
case m_connectionClosing:
server.connectionClosing(connectionToken);
- closed = true;
+ closed.set(true);
socketMgr.sendReply(msg);
socketMgr.stop();
break;
@@ -257,7 +260,8 @@
{
try
{
- if (closed == false)
+ uilServerILService.removeHandler(this);
+ if (closed.get() == false)
server.connectionClosing(connectionToken);
}
catch (Exception e)
Modified: trunk/jbossmq/src/main/org/jboss/mq/il/uil2/UILServerILService.java
===================================================================
--- trunk/jbossmq/src/main/org/jboss/mq/il/uil2/UILServerILService.java 2007-03-21 14:23:40 UTC (rev 61547)
+++ trunk/jbossmq/src/main/org/jboss/mq/il/uil2/UILServerILService.java 2007-03-21 14:24:36 UTC (rev 61548)
@@ -1,24 +1,24 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.
-*/
+ * 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.mq.il.uil2;
import java.io.IOException;
@@ -27,18 +27,23 @@
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;
import org.jboss.mq.il.Invoker;
import org.jboss.mq.il.ServerIL;
import org.jboss.mq.il.ServerILJMXService;
+import org.jboss.mq.il.uil2.msgs.BaseMsg;
import org.jboss.mq.il.uil2.msgs.MsgTypes;
-import org.jboss.mq.il.uil2.msgs.BaseMsg;
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
@@ -64,7 +69,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 */
@@ -113,6 +118,9 @@
*/
private Properties connectionProperties;
+ /** The server handlers */
+ private CopyOnWriteArrayList handlers = new CopyOnWriteArrayList();
+
/**
* Used to construct the GenericConnectionFactory (bindJNDIReferences()
* builds it) Sets up the connection properties need by a client to use this
@@ -142,7 +150,7 @@
public void run()
{
boolean trace = log.isTraceEnabled();
- while (running)
+ while (running.get())
{
Socket socket = null;
SocketManager socketMgr = null;
@@ -154,7 +162,8 @@
socket.setSoTimeout(readTimeout);
socket.setTcpNoDelay(enableTcpNoDelay);
socketMgr = new SocketManager(socket);
- ServerSocketManagerHandler handler = new ServerSocketManagerHandler(getJMSServer(), socketMgr);
+ ServerSocketManagerHandler handler = new ServerSocketManagerHandler(getJMSServer(), socketMgr, this);
+ handlers.add(handler);
socketMgr.setHandler(handler);
socketMgr.setBufferSize(bufferSize);
socketMgr.setChunkSize(chunkSize);
@@ -163,12 +172,12 @@
}
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);
}
}
@@ -182,7 +191,6 @@
public void startService() throws Exception
{
super.startService();
- running = true;
// Use the default javax.net.ServerSocketFactory if none was set
if (serverSocketFactory == null)
@@ -219,6 +227,7 @@
InetAddress socketAddress = serverSocket.getInetAddress();
log.info("JBossMQ UIL service available at : " + socketAddress + ":" + serverSocket.getLocalPort());
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"
@@ -256,7 +265,7 @@
{
try
{
- running = false;
+ running.set(false);
unbindJNDIReferences();
// unbind Server Socket if needed
@@ -269,8 +278,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
*
More information about the jboss-cvs-commits
mailing list