Author: jmesnil
Date: 2010-07-09 09:42:29 -0400 (Fri, 09 Jul 2010)
New Revision: 9387
Added:
trunk/src/main/org/hornetq/utils/HQIterator.java
trunk/src/main/org/hornetq/utils/concurrent/ConcurrentHQDeque.java
trunk/src/main/org/hornetq/utils/concurrent/ConcurrentPriorityLinkedListImpl.java
Removed:
trunk/src/main/org/hornetq/utils/ConcurrentHQDeque.java
trunk/src/main/org/hornetq/utils/concurrent/HQIterator.java
Modified:
trunk/build-hornetq.xml
trunk/docs/user-manual/en/client-classpath.xml
trunk/src/main/org/hornetq/core/client/impl/ClientConsumerImpl.java
trunk/src/main/org/hornetq/core/server/impl/QueueImpl.java
trunk/src/main/org/hornetq/utils/HQDeque.java
trunk/src/main/org/hornetq/utils/NonConcurrentHQDeque.java
trunk/src/main/org/hornetq/utils/PriorityLinkedList.java
trunk/src/main/org/hornetq/utils/PriorityLinkedListImpl.java
trunk/src/main/org/hornetq/utils/concurrent/HornetQConcurrentLinkedQueue.java
trunk/tests/src/org/hornetq/tests/unit/core/list/impl/ConcurrentPriorityLinkedListTest.java
trunk/tests/src/org/hornetq/tests/unit/core/list/impl/NonConcurrentPriorityLinkedListTest.java
trunk/tests/src/org/hornetq/tests/unit/core/list/impl/PriorityLinkedListTestBase.java
trunk/tests/src/org/hornetq/tests/unit/util/concurrent/HornetQConcurrentLinkedQueueTest.java
Log:
https://jira.jboss.org/browse/HORNETQ-428: Add JDK 1.5 support on client libraries
* add jars hornetq-core-client-java5.jar & hornetq-jms-client-java5.jar (compiled to
target java 1.5) in build-hornetq.xml
* refactor PriorityLinkedListImpl & extracted ConcurrentPriorityLinkedListImpl (used
on the server side)
* clean up classes in utils & utils.concurrent packages
* update documentation
Modified: trunk/build-hornetq.xml
===================================================================
--- trunk/build-hornetq.xml 2010-07-09 03:10:45 UTC (rev 9386)
+++ trunk/build-hornetq.xml 2010-07-09 13:42:29 UTC (rev 9387)
@@ -60,6 +60,8 @@
<property name="jms.sources.jar.name"
value="hornetq-jms-sources.jar"/>
<property name="jms.client.jar.name"
value="hornetq-jms-client.jar"/>
<property name="jms.client.sources.jar.name"
value="hornetq-jms-client-sources.jar"/>
+ <property name="jms.client.java5.jar.name"
value="hornetq-jms-client-java5.jar"/>
+ <property name="jms.client.java5.sources.jar.name"
value="hornetq-jms-client-java5-sources.jar"/>
<property name="jnp.client.jar.name"
value="jnp-client.jar"/>
<property name="jboss.integration.jar.name"
value="hornetq-jboss-as-integration.jar"/>
<property name="jboss.integration.sources.jar.name"
value="hornetq-jboss-as-integration-sources.jar"/>
@@ -71,6 +73,8 @@
<property name="logging.sources.jar.name"
value="hornetq-logging-sources.jar"/>
<property name="core.client.jar.name"
value="hornetq-core-client.jar"/>
<property name="core.client.sources.jar.name"
value="hornetq-core-client-sources.jar"/>
+ <property name="core.client.java5.jar.name"
value="hornetq-core-client-java5.jar"/>
+ <property name="core.client.java5.sources.jar.name"
value="hornetq-core-client-java5-sources.jar"/>
<property name="ra.jar.name" value="hornetq-ra.jar"/>
<property name="ra.sources.jar.name"
value="hornetq-ra-sources.jar"/>
<property name="ra.rar.name" value="hornetq-ra.rar"/>
@@ -86,7 +90,9 @@
<property name="build.dir" value="build"/>
<property name="build.classes.dir"
value="${build.dir}/classes"/>
<property name="build.core.classes.dir"
value="${build.dir}/classes/core"/>
+ <property name="build.core.client.java5.classes.dir"
value="${build.dir}/classes/core-client-java5"/>
<property name="build.jms.classes.dir"
value="${build.dir}/classes/jms"/>
+ <property name="build.jms.java5.classes.dir"
value="${build.dir}/classes/jms-java5"/>
<property name="build.jboss.integration.classes.dir"
value="${build.dir}/classes/jboss-integration"/>
<property name="build.twitter.integration.classes.dir"
value="${build.dir}/classes/twitter-integration"/>
<property name="build.service.classes.dir"
value="${build.dir}/classes/service"/>
@@ -372,7 +378,9 @@
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.classes.dir}"/>
<mkdir dir="${build.core.classes.dir}"/>
+ <mkdir dir="${build.core.client.java5.classes.dir}"/>
<mkdir dir="${build.jms.classes.dir}"/>
+ <mkdir dir="${build.jms.java5.classes.dir}"/>
<mkdir dir="${build.jboss.integration.classes.dir}"/>
<mkdir dir="${build.twitter.integration.classes.dir}"/>
<mkdir dir="${build.service.classes.dir}"/>
@@ -403,7 +411,7 @@
<!-- Compilation targets -->
<!-- ================================= -->
- <target name="compile" depends="compile-jms"/>
+ <target name="compile" depends="compile-jms,
compile-core-client-java5"/>
<target name="compile-core" depends="init">
<mkdir dir="${build.src.dir}/org/hornetq/core/filter/impl"/>
@@ -449,6 +457,49 @@
</target>
+ <target name="compile-core-client-java5" depends="init">
+ <mkdir dir="${build.src.dir}/org/hornetq/core/filter/impl"/>
+ <javacc
target="${src.main.dir}/org/hornetq/core/filter/impl/FilterParser.jj"
+ outputdirectory="${build.src.dir}/org/hornetq/core/filter/impl"
+ javacchome="${sun.javacc.lib}"
+ static="false"/>
+ <javac destdir="${build.core.client.java5.classes.dir}"
+ target="1.5"
+ source="1.5"
+ optimize="${javac.optimize}"
+ debug="${javac.debug}"
+ depend="${javac.depend}"
+ verbose="${javac.verbose}"
+ deprecation="${javac.deprecation}"
+ includeAntRuntime="${javac.include.ant.runtime}"
+ includeJavaRuntime="${javac.include.java.runtime}"
+ failonerror="${javac.fail.onerror}">
+ <src>
+ <pathelement path="${build.src.dir}"/>
+ <pathelement path="${src.main.dir}"/>
+ </src>
+ <exclude name="**/hornetq/**/server/**/*.java" />
+
+ <include name="**/hornetq/*.java"/>
+ <include name="**/hornetq/api/*.java"/>
+ <include name="**/hornetq/api/core/**/*.java"/>
+ <include name="**/hornetq/core/**/*.java"/>
+ <include name="**/hornetq/spi/**/*.java"/>
+ <include name="**/hornetq/utils/**/*.java"/>
+ <classpath refid="core.compilation.classpath"/>
+ </javac>
+ <java classname="org.jboss.netty.util.Version"
classpathref="org.jboss.netty.classpath"
+ outputproperty="netty.version" fork="true"/>
+ <echo>setting netty version ${netty.version}</echo>
+ <copy file="${src.config.dir}/common/hornetq-version.properties"
+
tofile="${build.core.client.java5.classes.dir}/hornetq-version.properties"
overwrite="true">
+ <filterset>
+ <filter token="NETTY.VERSION"
value="${netty.version}"/>
+ </filterset>
+ </copy>
+
+ </target>
+
<target name="compile-jms" depends="compile-core">
<javac destdir="${build.jms.classes.dir}"
target="${javac.target}"
@@ -469,6 +520,26 @@
</javac>
</target>
+ <target name="compile-jms-java5"
depends="compile-core-client-java5">
+ <javac destdir="${build.jms.java5.classes.dir}"
+ target="1.5"
+ source="1.5"
+ optimize="${javac.optimize}"
+ debug="${javac.debug}"
+ depend="${javac.depend}"
+ verbose="${javac.verbose}"
+ deprecation="${javac.deprecation}"
+ includeAntRuntime="${javac.include.ant.runtime}"
+ includeJavaRuntime="${javac.include.java.runtime}"
+ failonerror="${javac.fail.onerror}">
+ <src>
+ <pathelement path="${src.main.dir}"/>
+ </src>
+ <include name="**/jms/**/*.java"/>
+ <classpath refid="jms.compilation.classpath"/>
+ </javac>
+ </target>
+
<target name="compile-jboss-integration"
depends="compile-core">
<javac destdir="${build.jboss.integration.classes.dir}"
target="${javac.target}"
@@ -649,11 +720,11 @@
<!--
========================================================================================
-->
<target name="sources-jar" description="create jar files containing
source code"
- depends="jar-core-sources, jar-core-client-sources, jar-jms-sources,
jar-jms-client-sources, jar-jboss-integration-sources, jar-jboss-service-sources,
jar-bootstrap-sources, jar-logging-sources, jar-ra-sources, jar-resources-sources,
jar-twitter-integration-sources">
+ depends="jar-core-sources, jar-core-client-sources,
jar-core-client-java5-sources, jar-jms-sources, jar-jms-client-sources,
jar-jms-client-java5-sources, jar-jboss-integration-sources, jar-jboss-service-sources,
jar-bootstrap-sources, jar-logging-sources, jar-ra-sources, jar-resources-sources,
jar-twitter-integration-sources">
</target>
<target name="jar"
- depends="jar-core, jar-core-client, jar-jms, jar-jms-client,
jar-jboss-integration, jar-jboss-service, jar-bootstrap, jar-logging, jar-ra, jar-mc,
jar-jnp-client, jar-resources, sources-jar, jar-twitter-integration">
+ depends="jar-core, jar-core-client, jar-core-client-java5, jar-jms,
jar-jms-client, jar-jms-client-java5, jar-jboss-integration, jar-jboss-service,
jar-bootstrap, jar-logging, jar-ra, jar-mc, jar-jnp-client, jar-resources, sources-jar,
jar-twitter-integration">
</target>
<target name="jar-jnp-client" depends="init">
@@ -761,8 +832,28 @@
</jar>
</target>
- <target name="jar-jboss-integration"
depends="compile-jboss-integration">
+ <target name="jar-jms-client-java5"
depends="compile-jms-java5">
+ <jar jarfile="${build.jars.dir}/${jms.client.java5.jar.name}">
+ <fileset dir="${build.jms.java5.classes.dir}"
includes="org/hornetq/api/jms/**/*.class"/>
+ <fileset dir="${build.jms.java5.classes.dir}"
includes="org/hornetq/jms/client/*.class"/>
+ <fileset dir="${build.jms.java5.classes.dir}"
includes="org/hornetq/jms/referenceable/*.class"/>
+ </jar>
+
+ </target>
+
+ <target name="jar-jms-client-java5-sources">
+ <jar
jarfile="${build.jars.dir}/${jms.client.java5.sources.jar.name}">
+ <fileset dir="${src.main.dir}">
+ <include name="org/hornetq/api/jms/**/*.*"/>
+ <include name="org/hornetq/jms/client/**/*.*"/>
+ <include name="org/hornetq/jms/referenceable/**/*.*"/>
+ </fileset>
+ </jar>
+ </target>
+
+ <target name="jar-jboss-integration"
depends="compile-jboss-integration">
+
<jar jarfile="${build.jars.dir}/${jboss.integration.jar.name}">
<fileset dir="${build.jboss.integration.classes.dir}"
includes="**"/>
</jar>
@@ -907,6 +998,71 @@
</jar>
</target>
+ <target name="jar-core-client-java5"
depends="compile-core-client-java5">
+ <jar jarfile="${build.jars.dir}/${core.client.java5.jar.name}">
+ <fileset dir="${build.core.client.java5.classes.dir}">
+ <include name="hornetq-version.properties"/>
+ <include name="org/hornetq/api/**/*.class"/>
+ <include name="org/hornetq/*.class"/>
+ <include name="org/hornetq/core/buffers/**/*.class"/>
+ <include name="org/hornetq/core/client/**/*.class"/>
+ <include name="org/hornetq/core/filter/**/*.class"/>
+ <include name="org/hornetq/core/exception/**/*.class"/>
+ <include name="org/hornetq/core/remoting/impl/**/*.class"/>
+ <include name="org/hornetq/utils/**/*.class"/>
+ <include name="org/hornetq/core/cluster/**/*.class"/>
+ <include name="org/hornetq/core/list/**/*.class"/>
+ <include name="org/hornetq/core/logging/**/*.class"/>
+ <include name="org/hornetq/core/message/**/*.class"/>
+ <include name="org/hornetq/core/protocol/core/**/*.class"/>
+ <include name="org/hornetq/core/remoting/**/*.class"/>
+ <include name="org/hornetq/core/version/**/*.class"/>
+ <include name="org/hornetq/core/management/*.class"/>
+ <include
name="org/hornetq/core/transaction/impl/XidImpl.class"/>
+ <include name="org/hornetq/spi/core/logging/*.class"/>
+ <include name="org/hornetq/spi/core/protocol/*.class"/>
+ <include name="org/hornetq/spi/core/remoting/*.class"/>
+
+ <!-- required by SessionSendMessage -->
+ <include
name="org/hornetq/core/server/ServerMessage.class"/>
+ <include
name="org/hornetq/core/journal/EncodingSupport.class"/>
+ </fileset>
+ </jar>
+
+ </target>
+
+ <target name="jar-core-client-java5-sources">
+ <jar
jarfile="${build.jars.dir}/${core.client.java5.sources.jar.name}">
+ <fileset dir="${src.main.dir}">
+ <include name="hornetq-version.properties"/>
+ <include name="org/hornetq/api/**/*.*"/>
+ <include name="org/hornetq/*.*"/>
+ <include name="org/hornetq/core/buffers/**/*.*"/>
+ <include name="org/hornetq/core/client/**/*.*"/>
+ <include name="org/hornetq/core/filter/**/*.*"/>
+ <include name="org/hornetq/core/exception/**/*.*"/>
+ <include name="org/hornetq/core/remoting/impl/**/*.*"/>
+ <include name="org/hornetq/utils/**/*.*"/>
+ <include name="org/hornetq/core/cluster/**/*.*"/>
+ <include name="org/hornetq/core/list/**/*.*"/>
+ <include name="org/hornetq/core/logging/**/*.*"/>
+ <include name="org/hornetq/core/message/**/*.*"/>
+ <include name="org/hornetq/core/protocol/core/**/*.*"/>
+ <include name="org/hornetq/core/remoting/**/*.*"/>
+ <include name="org/hornetq/core/version/**/*.*"/>
+ <include name="org/hornetq/core/management/*.*"/>
+ <include
name="org/hornetq/core/transaction/impl/XidImpl.java"/>
+ <include name="org/hornetq/spi/core/logging/*.*"/>
+ <include name="org/hornetq/spi/core/protocol/*.*"/>
+ <include name="org/hornetq/spi/core/remoting/*.*"/>
+
+ <!-- required by SessionSendMessage -->
+ <include name="org/hornetq/core/server/ServerMessage.java"/>
+ <include
name="org/hornetq/core/journal/EncodingSupport.java"/>
+ </fileset>
+ </jar>
+ </target>
+
<target name="jar-ra" depends="jar-core-client, jar-jms-client,
compile-ra">
<jar jarfile="${build.jars.dir}/${ra.jar.name}">
<fileset dir="${build.ra.classes.dir}">
@@ -988,7 +1144,9 @@
<include name="${mc.jar.name}"/>
<include name="${ra.rar.name}"/>
<include name="${core.client.jar.name}"/>
+ <include name="${core.client.java5.jar.name}"/>
<include name="${jms.client.jar.name}"/>
+ <include name="${jms.client.java5.jar.name}"/>
<include name="${jnp.client.jar.name}"/>
<include name="${twitter.integration.jar.name}"/>
</fileset>
Modified: trunk/docs/user-manual/en/client-classpath.xml
===================================================================
--- trunk/docs/user-manual/en/client-classpath.xml 2010-07-09 03:10:45 UTC (rev 9386)
+++ trunk/docs/user-manual/en/client-classpath.xml 2010-07-09 13:42:29 UTC (rev 9387)
@@ -32,16 +32,20 @@
<para>If you are using just a pure HornetQ Core client (i.e. no JMS) then
you need <literal
hornetq-core-client.jar</literal> and
<literal>netty.jar</literal> on your client classpath.</para>
+ <para>If the client runs inside a <emphasis>Java 5 virtual
machine</emphasis>, use instead
<literal>hornetq-core-client-java5.jar</literal>.</para>
</section>
<section>
<title>JMS Client</title>
<para>If you are using JMS on the client side, then you will also need to
include <literal
hornetq-jms-client.jar</literal> and
<literal>jboss-jms-api.jar</literal>.</para>
+
<para>If the client runs inside a <emphasis>Java 5 virtual
machine</emphasis>, include instead
<literal>hornetq-jms-client-java5.jar</literal>.</para>
+
<note>
<para><literal>jboss-jms-api.jar</literal> just contains
Java EE API interface classes
needed for the <literal>javax.jms.*</literal> classes. If you
already have a jar
with these interface classes on your classpath, you will not need
it.</para>
</note>
+
</section>
<section>
<title>JMS Client with JNDI</title>
Modified: trunk/src/main/org/hornetq/core/client/impl/ClientConsumerImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/client/impl/ClientConsumerImpl.java 2010-07-09
03:10:45 UTC (rev 9386)
+++ trunk/src/main/org/hornetq/core/client/impl/ClientConsumerImpl.java 2010-07-09
13:42:29 UTC (rev 9387)
@@ -30,10 +30,10 @@
import org.hornetq.core.protocol.core.impl.wireformat.SessionReceiveContinuationMessage;
import org.hornetq.core.protocol.core.impl.wireformat.SessionReceiveLargeMessage;
import org.hornetq.utils.Future;
+import org.hornetq.utils.HQIterator;
import org.hornetq.utils.PriorityLinkedList;
import org.hornetq.utils.PriorityLinkedListImpl;
import org.hornetq.utils.TokenBucketLimiter;
-import org.hornetq.utils.concurrent.HQIterator;
/**
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
@@ -79,8 +79,7 @@
private final int ackBatchSize;
- private final PriorityLinkedList<ClientMessageInternal> buffer = new
PriorityLinkedListImpl<ClientMessageInternal>(false,
-
ClientConsumerImpl.NUM_PRIORITIES);
+ private final PriorityLinkedList<ClientMessageInternal> buffer = new
PriorityLinkedListImpl<ClientMessageInternal>(ClientConsumerImpl.NUM_PRIORITIES);
private final Runner runner = new Runner();
Modified: trunk/src/main/org/hornetq/core/server/impl/QueueImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/impl/QueueImpl.java 2010-07-09 03:10:45 UTC
(rev 9386)
+++ trunk/src/main/org/hornetq/core/server/impl/QueueImpl.java 2010-07-09 13:42:29 UTC
(rev 9387)
@@ -50,9 +50,9 @@
import org.hornetq.core.transaction.TransactionPropertyIndexes;
import org.hornetq.core.transaction.impl.TransactionImpl;
import org.hornetq.utils.ConcurrentHashSet;
+import org.hornetq.utils.HQIterator;
import org.hornetq.utils.PriorityLinkedList;
-import org.hornetq.utils.PriorityLinkedListImpl;
-import org.hornetq.utils.concurrent.HQIterator;
+import org.hornetq.utils.concurrent.ConcurrentPriorityLinkedListImpl;
/**
* Implementation of a Queue
@@ -82,8 +82,7 @@
private final PostOffice postOffice;
- private final PriorityLinkedList<MessageReference> messageReferences = new
PriorityLinkedListImpl<MessageReference>(true,
-
QueueImpl.NUM_PRIORITIES);
+ private final PriorityLinkedList<MessageReference> messageReferences = new
ConcurrentPriorityLinkedListImpl<MessageReference>(QueueImpl.NUM_PRIORITIES);
private final List<ConsumerHolder> consumerList = new
ArrayList<ConsumerHolder>();
Deleted: trunk/src/main/org/hornetq/utils/ConcurrentHQDeque.java
===================================================================
--- trunk/src/main/org/hornetq/utils/ConcurrentHQDeque.java 2010-07-09 03:10:45 UTC (rev
9386)
+++ trunk/src/main/org/hornetq/utils/ConcurrentHQDeque.java 2010-07-09 13:42:29 UTC (rev
9387)
@@ -1,140 +0,0 @@
-/*
- * Copyright 2010 Red Hat, Inc.
- * Red Hat 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.hornetq.utils;
-
-import java.util.Iterator;
-
-import org.hornetq.core.logging.Logger;
-import org.hornetq.utils.concurrent.BlockingDeque;
-import org.hornetq.utils.concurrent.HQIterator;
-import org.hornetq.utils.concurrent.HornetQConcurrentLinkedQueue;
-import org.hornetq.utils.concurrent.LinkedBlockingDeque;
-
-/**
- * A ConcurrentHQDeque
- *
- * @author Tim Fox
- *
- *
- */
-public class ConcurrentHQDeque<T> implements HQDeque<T>
-{
- private static final Logger log = Logger.getLogger(ConcurrentHQDeque.class);
-
- private final HornetQConcurrentLinkedQueue<T> bodyQueue;
-
- private final BlockingDeque<T> headQueue;
-
- public ConcurrentHQDeque()
- {
- this.bodyQueue = new HornetQConcurrentLinkedQueue<T>();
-
- this.headQueue = new LinkedBlockingDeque<T>();
- }
-
- public synchronized void addFirst(T t)
- {
- headQueue.addFirst(t);
- }
-
- public void addLast(T t)
- {
- bodyQueue.add(t);
- }
-
- public void clear()
- {
- bodyQueue.clear();
- headQueue.clear();
- }
-
- public synchronized T getFirst()
- {
- if (headQueue.isEmpty())
- {
- return bodyQueue.peek();
- }
- else
- {
- return headQueue.peek();
- }
- }
-
- public boolean isEmpty()
- {
- return bodyQueue.isEmpty() && headQueue.isEmpty();
- }
-
- public HQIterator<T> iterator()
- {
- return new Iter();
- }
-
- public T removeFirst()
- {
- if (headQueue.isEmpty())
- {
- return bodyQueue.remove();
- }
- else
- {
- return headQueue.remove();
- }
- }
-
- private class Iter implements HQIterator<T>
- {
- private Iterator<T> headIter;
-
- private HQIterator<T> bodyIter;
-
- private boolean inHead;
-
- private Iter()
- {
- headIter = headQueue.iterator();
-
- bodyIter = bodyQueue.hqIterator();
- }
-
- public T next()
- {
- if (headIter.hasNext())
- {
- inHead = true;
-
- return headIter.next();
- }
- else
- {
- inHead = false;
-
- return bodyIter.next();
- }
- }
-
- public void remove()
- {
- if (inHead)
- {
- headIter.remove();
- }
- else
- {
- bodyIter.remove();
- }
- }
-
- }
-}
Modified: trunk/src/main/org/hornetq/utils/HQDeque.java
===================================================================
--- trunk/src/main/org/hornetq/utils/HQDeque.java 2010-07-09 03:10:45 UTC (rev 9386)
+++ trunk/src/main/org/hornetq/utils/HQDeque.java 2010-07-09 13:42:29 UTC (rev 9387)
@@ -13,7 +13,6 @@
package org.hornetq.utils;
-import org.hornetq.utils.concurrent.HQIterator;
/**
* A HQDeque
Copied: trunk/src/main/org/hornetq/utils/HQIterator.java (from rev 9378,
trunk/src/main/org/hornetq/utils/concurrent/HQIterator.java)
===================================================================
--- trunk/src/main/org/hornetq/utils/HQIterator.java (rev 0)
+++ trunk/src/main/org/hornetq/utils/HQIterator.java 2010-07-09 13:42:29 UTC (rev 9387)
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat 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.hornetq.utils;
+
+/**
+ * A HQIterator
+ *
+ * @author Tim Fox
+ *
+ *
+ */
+public interface HQIterator<E>
+{
+ E next();
+
+ void remove();
+}
Modified: trunk/src/main/org/hornetq/utils/NonConcurrentHQDeque.java
===================================================================
--- trunk/src/main/org/hornetq/utils/NonConcurrentHQDeque.java 2010-07-09 03:10:45 UTC
(rev 9386)
+++ trunk/src/main/org/hornetq/utils/NonConcurrentHQDeque.java 2010-07-09 13:42:29 UTC
(rev 9387)
@@ -17,7 +17,6 @@
import java.util.LinkedList;
import org.hornetq.core.logging.Logger;
-import org.hornetq.utils.concurrent.HQIterator;
/**
* A NonConcurrentHQDeque
@@ -28,7 +27,7 @@
*/
public class NonConcurrentHQDeque<T> implements HQDeque<T>
{
- private static final Logger log = Logger.getLogger(ConcurrentHQDeque.class);
+ private static final Logger log = Logger.getLogger(NonConcurrentHQDeque.class);
private final LinkedList<T> queue;
Modified: trunk/src/main/org/hornetq/utils/PriorityLinkedList.java
===================================================================
--- trunk/src/main/org/hornetq/utils/PriorityLinkedList.java 2010-07-09 03:10:45 UTC (rev
9386)
+++ trunk/src/main/org/hornetq/utils/PriorityLinkedList.java 2010-07-09 13:42:29 UTC (rev
9387)
@@ -13,7 +13,6 @@
package org.hornetq.utils;
-import org.hornetq.utils.concurrent.HQIterator;
/**
* A type of linked list which maintains items according to a priority
Modified: trunk/src/main/org/hornetq/utils/PriorityLinkedListImpl.java
===================================================================
--- trunk/src/main/org/hornetq/utils/PriorityLinkedListImpl.java 2010-07-09 03:10:45 UTC
(rev 9386)
+++ trunk/src/main/org/hornetq/utils/PriorityLinkedListImpl.java 2010-07-09 13:42:29 UTC
(rev 9387)
@@ -18,7 +18,6 @@
import java.util.concurrent.atomic.AtomicInteger;
import org.hornetq.core.logging.Logger;
-import org.hornetq.utils.concurrent.HQIterator;
/**
* A priority linked list implementation
@@ -35,28 +34,27 @@
{
private static final Logger log = Logger.getLogger(PriorityLinkedListImpl.class);
- private HQDeque<T>[] levels;
+ protected HQDeque<T>[] levels;
- private final int priorities;
+ protected final int priorities;
private final AtomicInteger size = new AtomicInteger(0);
- public PriorityLinkedListImpl(final boolean concurrent, final int priorities)
+ public PriorityLinkedListImpl(final HQDeque<T>[] levels)
{
+ this.levels = levels;
+ this.priorities = levels.length;
+ }
+
+ public PriorityLinkedListImpl(final int priorities)
+ {
this.priorities = priorities;
levels = (HQDeque<T>[])Array.newInstance(HQDeque.class, priorities);
for (int i = 0; i < priorities; i++)
{
- if (concurrent)
- {
- levels[i] = new ConcurrentHQDeque<T>();
- }
- else
- {
- levels[i] = new NonConcurrentHQDeque<T>();
- }
+ levels[i] = new NonConcurrentHQDeque<T>();
}
}
Copied: trunk/src/main/org/hornetq/utils/concurrent/ConcurrentHQDeque.java (from rev 9378,
trunk/src/main/org/hornetq/utils/ConcurrentHQDeque.java)
===================================================================
--- trunk/src/main/org/hornetq/utils/concurrent/ConcurrentHQDeque.java
(rev 0)
+++ trunk/src/main/org/hornetq/utils/concurrent/ConcurrentHQDeque.java 2010-07-09 13:42:29
UTC (rev 9387)
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat 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.hornetq.utils.concurrent;
+
+import java.util.Iterator;
+
+import org.hornetq.core.logging.Logger;
+import org.hornetq.utils.HQDeque;
+import org.hornetq.utils.HQIterator;
+
+/**
+ * A ConcurrentHQDeque
+ *
+ * @author Tim Fox
+ *
+ *
+ */
+public class ConcurrentHQDeque<T> implements HQDeque<T>
+{
+ private static final Logger log = Logger.getLogger(ConcurrentHQDeque.class);
+
+ private final HornetQConcurrentLinkedQueue<T> bodyQueue;
+
+ private final BlockingDeque<T> headQueue;
+
+ public ConcurrentHQDeque()
+ {
+ this.bodyQueue = new HornetQConcurrentLinkedQueue<T>();
+
+ this.headQueue = new LinkedBlockingDeque<T>();
+ }
+
+ public synchronized void addFirst(T t)
+ {
+ headQueue.addFirst(t);
+ }
+
+ public void addLast(T t)
+ {
+ bodyQueue.add(t);
+ }
+
+ public void clear()
+ {
+ bodyQueue.clear();
+ headQueue.clear();
+ }
+
+ public synchronized T getFirst()
+ {
+ if (headQueue.isEmpty())
+ {
+ return bodyQueue.peek();
+ }
+ else
+ {
+ return headQueue.peek();
+ }
+ }
+
+ public boolean isEmpty()
+ {
+ return bodyQueue.isEmpty() && headQueue.isEmpty();
+ }
+
+ public HQIterator<T> iterator()
+ {
+ return new Iter();
+ }
+
+ public T removeFirst()
+ {
+ if (headQueue.isEmpty())
+ {
+ return bodyQueue.remove();
+ }
+ else
+ {
+ return headQueue.remove();
+ }
+ }
+
+ private class Iter implements HQIterator<T>
+ {
+ private Iterator<T> headIter;
+
+ private HQIterator<T> bodyIter;
+
+ private boolean inHead;
+
+ private Iter()
+ {
+ headIter = headQueue.iterator();
+
+ bodyIter = bodyQueue.hqIterator();
+ }
+
+ public T next()
+ {
+ if (headIter.hasNext())
+ {
+ inHead = true;
+
+ return headIter.next();
+ }
+ else
+ {
+ inHead = false;
+
+ return bodyIter.next();
+ }
+ }
+
+ public void remove()
+ {
+ if (inHead)
+ {
+ headIter.remove();
+ }
+ else
+ {
+ bodyIter.remove();
+ }
+ }
+
+ }
+}
Added: trunk/src/main/org/hornetq/utils/concurrent/ConcurrentPriorityLinkedListImpl.java
===================================================================
--- trunk/src/main/org/hornetq/utils/concurrent/ConcurrentPriorityLinkedListImpl.java
(rev 0)
+++
trunk/src/main/org/hornetq/utils/concurrent/ConcurrentPriorityLinkedListImpl.java 2010-07-09
13:42:29 UTC (rev 9387)
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat 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.hornetq.utils.concurrent;
+
+import java.lang.reflect.Array;
+
+import org.hornetq.utils.HQDeque;
+import org.hornetq.utils.PriorityLinkedListImpl;
+
+/**
+ * A concurrent priority linked list implementation.
+ *
+ * Requires Java 6.
+ *
+ * @author <a href="mailto:jmesnil@redhat.com>Jeff Mesnil</a>
+ * @version <tt>$Revision: 1174 $</tt>
+ *
+ * $Id: BasicPrioritizedDeque.java 1174 2006-08-02 14:14:32Z timfox $
+ */
+public class ConcurrentPriorityLinkedListImpl<T> extends
PriorityLinkedListImpl<T>
+{
+ public ConcurrentPriorityLinkedListImpl(final int priorities)
+ {
+ super(priorities);
+
+ levels = (HQDeque<T>[])Array.newInstance(HQDeque.class, priorities);
+
+ for (int i = 0; i < priorities; i++)
+ {
+ levels[i] = new ConcurrentHQDeque<T>();
+ }
+ }
+}
Deleted: trunk/src/main/org/hornetq/utils/concurrent/HQIterator.java
===================================================================
--- trunk/src/main/org/hornetq/utils/concurrent/HQIterator.java 2010-07-09 03:10:45 UTC
(rev 9386)
+++ trunk/src/main/org/hornetq/utils/concurrent/HQIterator.java 2010-07-09 13:42:29 UTC
(rev 9387)
@@ -1,28 +0,0 @@
-/*
- * Copyright 2010 Red Hat, Inc.
- * Red Hat 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.hornetq.utils.concurrent;
-
-/**
- * A HQIterator
- *
- * @author Tim Fox
- *
- *
- */
-public interface HQIterator<E>
-{
- E next();
-
- void remove();
-}
Modified: trunk/src/main/org/hornetq/utils/concurrent/HornetQConcurrentLinkedQueue.java
===================================================================
---
trunk/src/main/org/hornetq/utils/concurrent/HornetQConcurrentLinkedQueue.java 2010-07-09
03:10:45 UTC (rev 9386)
+++
trunk/src/main/org/hornetq/utils/concurrent/HornetQConcurrentLinkedQueue.java 2010-07-09
13:42:29 UTC (rev 9387)
@@ -9,6 +9,7 @@
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import org.hornetq.core.logging.Logger;
+import org.hornetq.utils.HQIterator;
/**
* An unbounded thread-safe {@linkplain Queue queue} based on linked nodes.
Modified:
trunk/tests/src/org/hornetq/tests/unit/core/list/impl/ConcurrentPriorityLinkedListTest.java
===================================================================
---
trunk/tests/src/org/hornetq/tests/unit/core/list/impl/ConcurrentPriorityLinkedListTest.java 2010-07-09
03:10:45 UTC (rev 9386)
+++
trunk/tests/src/org/hornetq/tests/unit/core/list/impl/ConcurrentPriorityLinkedListTest.java 2010-07-09
13:42:29 UTC (rev 9387)
@@ -14,6 +14,7 @@
package org.hornetq.tests.unit.core.list.impl;
import org.hornetq.utils.PriorityLinkedListImpl;
+import org.hornetq.utils.concurrent.ConcurrentPriorityLinkedListImpl;
/**
* A ConcurrentPriorityLinkedListTest
@@ -28,7 +29,7 @@
@Override
protected PriorityLinkedListImpl<Wibble> getList()
{
- return new PriorityLinkedListImpl<Wibble>(true, 10);
+ return new ConcurrentPriorityLinkedListImpl<Wibble>(10);
}
}
Modified:
trunk/tests/src/org/hornetq/tests/unit/core/list/impl/NonConcurrentPriorityLinkedListTest.java
===================================================================
---
trunk/tests/src/org/hornetq/tests/unit/core/list/impl/NonConcurrentPriorityLinkedListTest.java 2010-07-09
03:10:45 UTC (rev 9386)
+++
trunk/tests/src/org/hornetq/tests/unit/core/list/impl/NonConcurrentPriorityLinkedListTest.java 2010-07-09
13:42:29 UTC (rev 9387)
@@ -28,7 +28,7 @@
@Override
protected PriorityLinkedListImpl<Wibble> getList()
{
- return new PriorityLinkedListImpl<Wibble>(false, 10);
+ return new PriorityLinkedListImpl<Wibble>(10);
}
}
Modified:
trunk/tests/src/org/hornetq/tests/unit/core/list/impl/PriorityLinkedListTestBase.java
===================================================================
---
trunk/tests/src/org/hornetq/tests/unit/core/list/impl/PriorityLinkedListTestBase.java 2010-07-09
03:10:45 UTC (rev 9386)
+++
trunk/tests/src/org/hornetq/tests/unit/core/list/impl/PriorityLinkedListTestBase.java 2010-07-09
13:42:29 UTC (rev 9387)
@@ -16,8 +16,8 @@
import junit.framework.Assert;
import junit.framework.TestCase;
+import org.hornetq.utils.HQIterator;
import org.hornetq.utils.PriorityLinkedListImpl;
-import org.hornetq.utils.concurrent.HQIterator;
/**
* @author <a href="tim.fox(a)jboss.com>Tim Fox</a>
Modified:
trunk/tests/src/org/hornetq/tests/unit/util/concurrent/HornetQConcurrentLinkedQueueTest.java
===================================================================
---
trunk/tests/src/org/hornetq/tests/unit/util/concurrent/HornetQConcurrentLinkedQueueTest.java 2010-07-09
03:10:45 UTC (rev 9386)
+++
trunk/tests/src/org/hornetq/tests/unit/util/concurrent/HornetQConcurrentLinkedQueueTest.java 2010-07-09
13:42:29 UTC (rev 9387)
@@ -19,7 +19,7 @@
import junit.framework.TestCase;
import org.hornetq.core.logging.Logger;
-import org.hornetq.utils.concurrent.HQIterator;
+import org.hornetq.utils.HQIterator;
import org.hornetq.utils.concurrent.HornetQConcurrentLinkedQueue;
/**