[jboss-cvs] JBoss Messaging SVN: r3092 - in trunk: docs/examples/distributed-queue/src/org/jboss/example/jms/distributedqueue and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Sep 10 17:42:30 EDT 2007
Author: clebert.suconic at jboss.com
Date: 2007-09-10 17:42:30 -0400 (Mon, 10 Sep 2007)
New Revision: 3092
Added:
trunk/src/main/org/jboss/messaging/util/AbstractHashSet.java
trunk/src/main/org/jboss/messaging/util/WeakHashSet.java
Modified:
trunk/docs/examples/common/src/org/jboss/example/jms/common/ExampleSupport.java
trunk/docs/examples/distributed-queue/src/org/jboss/example/jms/distributedqueue/DistributedQueueExample.java
trunk/docs/examples/distributed-topic/src/org/jboss/example/jms/distributedtopic/DistributedTopicExample.java
trunk/docs/examples/queue-failover/src/org/jboss/example/jms/failover/QueueFailoverExample.java
trunk/src/main/org/jboss/jms/client/delegate/ClientClusteredConnectionFactoryDelegate.java
trunk/src/main/org/jboss/messaging/util/ConcurrentReaderHashSet.java
Log:
http://jira.jboss.org/jira/browse/JBMESSAGING-1067
Modified: trunk/docs/examples/common/src/org/jboss/example/jms/common/ExampleSupport.java
===================================================================
--- trunk/docs/examples/common/src/org/jboss/example/jms/common/ExampleSupport.java 2007-09-10 19:34:16 UTC (rev 3091)
+++ trunk/docs/examples/common/src/org/jboss/example/jms/common/ExampleSupport.java 2007-09-10 21:42:30 UTC (rev 3092)
@@ -250,21 +250,6 @@
System.exit(0);
}
- // this is not necessary in real applications.. This is to avoid a client disconnect message on the server
- // since clustered connection factories are connected objects that will receive notifications
- // on the topology
- protected void releaseClusteredCF(ConnectionFactory cf)
- {
- try
- {
- ((ClientClusteredConnectionFactoryDelegate)
- ((JBossConnectionFactory)cf).getDelegate()).closeCallback();
- }
- catch (Exception ignored)
- {
- }
- }
-
// Inner classes -------------------------------------------------
}
Modified: trunk/docs/examples/distributed-queue/src/org/jboss/example/jms/distributedqueue/DistributedQueueExample.java
===================================================================
--- trunk/docs/examples/distributed-queue/src/org/jboss/example/jms/distributedqueue/DistributedQueueExample.java 2007-09-10 19:34:16 UTC (rev 3091)
+++ trunk/docs/examples/distributed-queue/src/org/jboss/example/jms/distributedqueue/DistributedQueueExample.java 2007-09-10 21:42:30 UTC (rev 3092)
@@ -154,10 +154,6 @@
throw e;
}
- // this is not necessary in real applications.. This is to avoid a client disconnect message on the server
- // since clustered connection factories are connected objects that will receive notifications
- // on the topology
- releaseClusteredCF(cf);
}
}
Modified: trunk/docs/examples/distributed-topic/src/org/jboss/example/jms/distributedtopic/DistributedTopicExample.java
===================================================================
--- trunk/docs/examples/distributed-topic/src/org/jboss/example/jms/distributedtopic/DistributedTopicExample.java 2007-09-10 19:34:16 UTC (rev 3091)
+++ trunk/docs/examples/distributed-topic/src/org/jboss/example/jms/distributedtopic/DistributedTopicExample.java 2007-09-10 21:42:30 UTC (rev 3092)
@@ -167,10 +167,6 @@
throw e;
}
- // this is not necessary in real applications.. This is to avoid a client disconnect message on the server
- // since clustered connection factories are connected objects that will receive notifications
- // on the topology
- releaseClusteredCF(cf);
}
}
Modified: trunk/docs/examples/queue-failover/src/org/jboss/example/jms/failover/QueueFailoverExample.java
===================================================================
--- trunk/docs/examples/queue-failover/src/org/jboss/example/jms/failover/QueueFailoverExample.java 2007-09-10 19:34:16 UTC (rev 3091)
+++ trunk/docs/examples/queue-failover/src/org/jboss/example/jms/failover/QueueFailoverExample.java 2007-09-10 21:42:30 UTC (rev 3092)
@@ -147,11 +147,6 @@
throw e;
}
- // this is not necessary in real applications.. This is to avoid a client disconnect message on the server
- // since clustered connection factories are connected objects that will receive notifications
- // on the topology
- releaseClusteredCF(cf);
-
}
}
Modified: trunk/src/main/org/jboss/jms/client/delegate/ClientClusteredConnectionFactoryDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientClusteredConnectionFactoryDelegate.java 2007-09-10 19:34:16 UTC (rev 3091)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientClusteredConnectionFactoryDelegate.java 2007-09-10 21:42:30 UTC (rev 3092)
@@ -23,6 +23,8 @@
import java.io.Serializable;
import java.util.Map;
+import java.util.Set;
+import java.util.Collections;
import javax.jms.JMSException;
@@ -41,6 +43,7 @@
import org.jboss.jms.wireformat.ConnectionFactoryRemoveCallbackRequest;
import org.jboss.logging.Logger;
import org.jboss.messaging.util.Version;
+import org.jboss.messaging.util.WeakHashSet;
/**
* A ClientClusteredConnectionFactoryDelegate.
@@ -101,6 +104,7 @@
if (trace) log.trace("Getting topology");
TopologyResult topology = getTopology();
if (trace) log.trace("delegates.size = " + topology.getDelegates().length);
+ addShutdownHook();
break;
}
@@ -133,6 +137,11 @@
}
+ private void addShutdownHook()
+ {
+ finalizerHook.addDelegate(this);
+ }
+
private void removeCallback() throws Throwable
{
ConnectionFactoryRemoveCallbackRequest request =
@@ -375,4 +384,45 @@
// Inner classes --------------------------------------------------------------------------------
+ static FinalizerShutdownHook finalizerHook;
+
+ static
+ {
+ finalizerHook = new FinalizerShutdownHook();
+ Runtime.getRuntime().addShutdownHook(finalizerHook);
+
+ }
+
+
+ // A Single ShutdownHook for the entire class
+ static class FinalizerShutdownHook extends Thread
+ {
+
+ Set<ClientClusteredConnectionFactoryDelegate> delegates;
+
+ public FinalizerShutdownHook()
+ {
+ delegates = Collections.synchronizedSet(new WeakHashSet());
+ }
+
+ public void addDelegate(ClientClusteredConnectionFactoryDelegate delegate)
+ {
+ delegates.add(delegate);
+ }
+
+ public void run()
+ {
+ for (ClientClusteredConnectionFactoryDelegate delegate: delegates)
+ {
+ try
+ {
+ delegate.finalize();
+ }
+ catch (Throwable ignored)
+ {
+ }
+ }
+ }
+ }
+
}
Added: trunk/src/main/org/jboss/messaging/util/AbstractHashSet.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/AbstractHashSet.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/util/AbstractHashSet.java 2007-09-10 21:42:30 UTC (rev 3092)
@@ -0,0 +1,81 @@
+/*
+ * 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.
+ */
+
+package org.jboss.messaging.util;
+
+import java.util.AbstractSet;
+import java.util.Map;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ * @version <tt>$Revision$</tt>
+ * $Id$
+ */
+public abstract class AbstractHashSet<Key> extends AbstractSet<Key>
+{
+ private Map theMap;
+
+ private static Object dummy = new Object();
+
+ public AbstractHashSet()
+ {
+ theMap = buildInternalHashMap();
+ }
+
+ protected abstract Map buildInternalHashMap();
+
+ public int size()
+ {
+ return theMap.size();
+ }
+
+ public Iterator<Key> iterator()
+ {
+ return theMap.keySet().iterator();
+ }
+
+ public boolean isEmpty()
+ {
+ return theMap.isEmpty();
+ }
+
+ public boolean add(Key o)
+ {
+ return theMap.put(o, dummy) == dummy;
+ }
+
+ public boolean contains(Object o)
+ {
+ return theMap.containsKey(o);
+ }
+
+ public void clear()
+ {
+ theMap.clear();
+ }
+
+ public boolean remove(Object o)
+ {
+ return theMap.remove(o) == dummy;
+ }
+}
Property changes on: trunk/src/main/org/jboss/messaging/util/AbstractHashSet.java
___________________________________________________________________
Name: svn:keywords
+ Id LastChangedDate Author Revision
Modified: trunk/src/main/org/jboss/messaging/util/ConcurrentReaderHashSet.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/ConcurrentReaderHashSet.java 2007-09-10 19:34:16 UTC (rev 3091)
+++ trunk/src/main/org/jboss/messaging/util/ConcurrentReaderHashSet.java 2007-09-10 21:42:30 UTC (rev 3092)
@@ -21,10 +21,7 @@
*/
package org.jboss.messaging.util;
-import java.util.AbstractSet;
-import java.util.Iterator;
import java.util.Map;
-
import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
/**
@@ -34,54 +31,21 @@
* Offers same concurrency as ConcurrentHashMap but for a Set
*
* @author <a href="tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="clebert.suconic at jboss.com">Clebert Suconic</a>
* @version <tt>$Revision$</tt>
*
* $Id$
*/
-public class ConcurrentReaderHashSet extends AbstractSet
+public class ConcurrentReaderHashSet<Key> extends AbstractHashSet<Key>
{
- private Map theMap;
-
- private static Object dummy = new Object();
-
public ConcurrentReaderHashSet()
{
- theMap = new ConcurrentReaderHashMap();
+ super();
}
-
- public int size()
+
+ protected Map buildInternalHashMap()
{
- return theMap.size();
+ return new ConcurrentReaderHashMap();
}
-
- public Iterator iterator()
- {
- return theMap.keySet().iterator();
- }
-
- public boolean isEmpty()
- {
- return theMap.isEmpty();
- }
-
- public boolean add(Object o)
- {
- return theMap.put(o, dummy) == dummy;
- }
-
- public boolean contains(Object o)
- {
- return theMap.containsKey(o);
- }
-
- public void clear()
- {
- theMap.clear();
- }
-
- public boolean remove(Object o)
- {
- return theMap.remove(o) == dummy;
- }
}
Added: trunk/src/main/org/jboss/messaging/util/WeakHashSet.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/WeakHashSet.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/util/WeakHashSet.java 2007-09-10 21:42:30 UTC (rev 3092)
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+
+package org.jboss.messaging.util;
+
+import java.util.Map;
+import java.util.WeakHashMap;
+
+/**
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ * @version <tt>$Revision$</tt>
+ * $Id$
+ */
+public class WeakHashSet<Key> extends AbstractHashSet<Key>
+{
+ public WeakHashSet()
+ {
+ super();
+ }
+
+
+ protected Map buildInternalHashMap()
+ {
+ return new WeakHashMap();
+ }
+}
Property changes on: trunk/src/main/org/jboss/messaging/util/WeakHashSet.java
___________________________________________________________________
Name: svn:keywords
+ Id LastChangedDate Author Revision
More information about the jboss-cvs-commits
mailing list