From 933eb2f9e4040a3a9200b1a461dc4e004aafbf81 Mon Sep 17 00:00:00 2001 From: "Hiram R. Chirino" Date: Sat, 11 Aug 2007 00:49:19 +0000 Subject: [PATCH] More checkstyle fixes and Generics usage. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@564814 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/activemq/ActiveMQConnection.java | 107 ++-- .../activemq/ActiveMQConnectionFactory.java | 6 +- .../activemq/ActiveMQConnectionMetaData.java | 16 +- .../activemq/ActiveMQMessageConsumer.java | 36 +- .../ActiveMQMessageTransformation.java | 7 +- .../org/apache/activemq/AdvisoryConsumer.java | 14 +- .../org/apache/activemq/StreamConnection.java | 2 +- .../activemq/advisory/AdvisoryBroker.java | 29 +- .../activemq/advisory/AdvisorySupport.java | 5 +- .../activemq/broker/BrokerBroadcaster.java | 12 +- .../apache/activemq/broker/BrokerFactory.java | 5 +- .../apache/activemq/broker/BrokerFilter.java | 4 +- .../activemq/broker/BrokerRegistry.java | 4 +- .../apache/activemq/broker/EmptyBroker.java | 5 +- .../apache/activemq/broker/ErrorBroker.java | 5 +- .../activemq/broker/MutableBrokerFilter.java | 4 +- .../activemq/broker/TransportConnection.java | 106 ++-- .../broker/TransportStatusDetector.java | 6 +- .../activemq/broker/ft/MasterConnector.java | 2 +- .../activemq/broker/jmx/BrokerView.java | 2 +- .../activemq/broker/jmx/DestinationView.java | 8 +- .../broker/jmx/DurableSubscriptionView.java | 2 +- .../jmx/InactiveDurableSubscriptionView.java | 2 +- .../broker/jmx/ManagedRegionBroker.java | 5 +- .../broker/region/AbstractRegion.java | 2 +- .../broker/region/DestinationFactoryImpl.java | 2 +- .../region/DurableTopicSubscription.java | 16 +- .../activemq/broker/region/RegionBroker.java | 10 +- .../activemq/broker/region/TopicRegion.java | 8 +- .../cursors/FilePendingMessageCursor.java | 18 +- .../region/cursors/StoreQueueCursor.java | 2 +- .../region/group/SimpleMessageGroupMap.java | 12 +- .../region/group/SimpleMessageGroupSet.java | 2 +- .../broker/region/policy/DispatchPolicy.java | 3 +- .../LastImageSubscriptionRecoveryPolicy.java | 4 +- .../policy/RoundRobinDispatchPolicy.java | 6 +- .../TimedSubscriptionRecoveryPolicy.java | 21 +- .../view/ConnectionDotFileInterceptor.java | 5 +- .../activemq/command/ActiveMQDestination.java | 3 +- .../activemq/command/ControlCommand.java | 4 +- .../activemq/command/DiscoveryEvent.java | 8 +- .../activemq/command/JournalTransaction.java | 8 +- .../apache/activemq/command/RemoveInfo.java | 8 +- .../activemq/filter/ConstantExpression.java | 8 +- .../activemq/filter/DestinationMapNode.java | 6 +- .../activemq/filter/DestinationPath.java | 5 +- .../filter/PrefixDestinationFilter.java | 3 +- .../filter/WildcardDestinationFilter.java | 2 +- .../jndi/ActiveMQInitialContextFactory.java | 10 +- .../apache/activemq/jndi/ReadOnlyContext.java | 1 + .../apache/activemq/kaha/StoreFactory.java | 5 +- .../apache/activemq/kaha/impl/KahaStore.java | 22 +- .../impl/container/BaseContainerImpl.java | 4 +- .../impl/container/ContainerEntrySet.java | 8 +- .../kaha/impl/container/ContainerKeySet.java | 8 +- .../container/ContainerValueCollection.java | 4 +- .../impl/container/ListContainerImpl.java | 12 +- .../kaha/impl/index/hash/HashBin.java | 18 +- .../kaha/impl/index/tree/TreePage.java | 15 +- .../management/JMSConnectionStatsImpl.java | 6 +- .../management/JMSSessionStatsImpl.java | 24 +- .../activemq/management/JMSStatsImpl.java | 5 +- .../activemq/management/StatisticImpl.java | 4 +- .../apache/activemq/management/StatsImpl.java | 5 +- .../org/apache/activemq/memory/LRUMap.java | 2 +- .../org/apache/activemq/memory/MapCache.java | 2 +- .../activemq/memory/buffer/MessageQueue.java | 10 +- .../buffer/OrderBasedMessageBuffer.java | 8 +- .../memory/buffer/SizeBasedMessageBuffer.java | 15 +- .../list/DestinationBasedMessageList.java | 10 +- .../memory/list/SimpleMessageList.java | 18 +- .../activemq/network/DemandSubscription.java | 2 +- .../network/NetworkBridgeFactory.java | 5 +- .../openwire/CommandIdComparator.java | 9 +- .../openwire/OpenWireFormatFactory.java | 2 +- .../openwire/v1/BaseDataStreamMarshaller.java | 8 +- .../openwire/v1/MarshallerFactory.java | 5 +- .../openwire/v2/BaseDataStreamMarshaller.java | 8 +- .../openwire/v2/MarshallerFactory.java | 5 +- .../openwire/v3/BaseDataStreamMarshaller.java | 114 +++-- .../openwire/v3/MarshallerFactory.java | 5 +- .../apache/activemq/pool/ConnectionPool.java | 12 +- .../pool/PooledConnectionFactory.java | 12 +- .../apache/activemq/pool/PooledSession.java | 14 +- .../apache/activemq/proxy/ProxyConnector.java | 7 +- .../security/AuthorizationBroker.java | 10 +- .../activemq/security/AuthorizationEntry.java | 33 +- .../activemq/security/AuthorizationMap.java | 12 +- .../security/DefaultAuthorizationMap.java | 42 +- .../security/JaasAuthenticationBroker.java | 9 +- .../JaasCertificateSecurityContext.java | 3 +- .../security/LDAPAuthorizationMap.java | 51 +- .../activemq/security/SecurityContext.java | 19 +- .../security/SimpleAuthenticationBroker.java | 2 +- .../security/SimpleAuthorizationMap.java | 15 +- .../apache/activemq/state/ProducerState.java | 1 - .../store/amq/AMQTopicMessageStore.java | 5 +- .../org/apache/activemq/store/amq/AMQTx.java | 12 +- .../store/amq/RecoveryListenerAdapter.java | 2 +- .../activemq/store/jdbc/JDBCAdapter.java | 2 +- .../store/jdbc/JDBCPersistenceAdapter.java | 14 +- .../store/jdbc/JDBCTopicMessageStore.java | 4 +- .../activemq/store/jdbc/Statements.java | 8 +- .../jdbc/adapter/DefaultJDBCAdapter.java | 16 +- .../store/journal/JournalMessageStore.java | 1 + .../journal/JournalPersistenceAdapter.java | 70 +-- .../JournalPersistenceAdapterFactory.java | 4 +- .../journal/JournalTopicMessageStore.java | 12 +- .../journal/JournalTransactionStore.java | 56 +-- .../store/kahadaptor/KahaMessageStore.java | 2 +- .../kahadaptor/KahaPersistenceAdapter.java | 18 +- .../store/kahadaptor/KahaReferenceStore.java | 6 +- .../kahadaptor/KahaReferenceStoreAdapter.java | 19 +- .../kahadaptor/KahaTopicMessageStore.java | 38 +- .../kahadaptor/KahaTopicReferenceStore.java | 40 +- .../store/kahadaptor/KahaTransaction.java | 25 +- .../store/kahadaptor/TopicSubAck.java | 2 +- .../store/memory/MemoryMessageStore.java | 12 +- .../memory/MemoryPersistenceAdapter.java | 21 +- .../store/memory/MemoryTopicMessageStore.java | 40 +- .../activemq/store/memory/MemoryTopicSub.java | 2 +- .../store/memory/MemoryTransactionStore.java | 38 +- .../activemq/thread/DefaultThreadPools.java | 8 +- .../org/apache/activemq/thread/Scheduler.java | 30 +- .../activemq/thread/TaskRunnerFactory.java | 2 +- .../org/apache/activemq/thread/Valve.java | 4 +- .../activemq/transaction/Transaction.java | 10 +- .../activemq/transport/FutureResponse.java | 6 +- .../transport/ResponseCorrelator.java | 10 +- .../apache/activemq/transport/Transport.java | 2 +- .../activemq/transport/TransportFactory.java | 12 +- .../activemq/transport/TransportFilter.java | 4 +- .../activemq/transport/TransportLogger.java | 8 +- .../TransportServerThreadSupport.java | 4 +- .../activemq/transport/TransportSupport.java | 4 +- .../transport/TransportThreadSupport.java | 4 +- .../discovery/DiscoveryAgentFactory.java | 4 +- .../discovery/DiscoveryTransport.java | 4 +- .../discovery/DiscoveryTransportFactory.java | 2 +- .../multicast/MulticastDiscoveryAgent.java | 23 +- .../discovery/rendezvous/JmDNSFactory.java | 5 +- .../rendezvous/RendezvousDiscoveryAgent.java | 10 +- .../simple/SimpleDiscoveryAgent.java | 7 +- .../transport/failover/FailoverTransport.java | 131 ++--- .../transport/fanout/FanoutTransport.java | 47 +- .../fanout/FanoutTransportFactory.java | 2 +- .../transport/mock/MockTransport.java | 4 +- .../MulticastDatagramHeaderMarshaller.java | 2 - .../multicast/MulticastTransport.java | 2 +- .../transport/peer/PeerTransportFactory.java | 2 +- .../reliable/DefaultReplayBuffer.java | 6 +- .../transport/reliable/ReliableTransport.java | 8 +- .../transport/stomp/FrameTranslator.java | 6 +- .../stomp/LegacyFrameTranslator.java | 2 +- .../activemq/transport/stomp/StompFrame.java | 8 +- .../transport/stomp/StompSubscription.java | 2 +- .../transport/stomp/StompWireFormat.java | 4 +- .../transport/tcp/SslTransportFactory.java | 6 +- .../transport/tcp/SslTransportServer.java | 4 +- .../tcp/TcpBufferedOutputStream.java | 13 - .../activemq/transport/tcp/TcpTransport.java | 17 +- .../transport/tcp/TcpTransportFactory.java | 6 +- .../transport/tcp/TcpTransportServer.java | 6 +- .../transport/udp/CommandDatagramChannel.java | 3 +- .../transport/udp/CommandDatagramSocket.java | 3 +- .../udp/DatagramHeaderMarshaller.java | 4 +- .../transport/udp/DefaultBufferPool.java | 4 +- .../activemq/transport/udp/UdpTransport.java | 4 +- .../transport/udp/UdpTransportFactory.java | 2 +- .../transport/udp/UdpTransportServer.java | 6 +- .../activemq/transport/vm/VMTransport.java | 13 +- .../transport/vm/VMTransportFactory.java | 24 +- .../apache/activemq/util/BrokerSupport.java | 5 +- .../activemq/util/ByteSequenceData.java | 3 + .../util/DataByteArrayInputStream.java | 4 +- .../util/DataByteArrayOutputStream.java | 2 +- .../apache/activemq/util/FactoryFinder.java | 4 +- .../org/apache/activemq/util/HexSupport.java | 5 +- .../activemq/util/IOExceptionSupport.java | 7 +- .../org/apache/activemq/util/IOHelper.java | 5 +- .../org/apache/activemq/util/IdGenerator.java | 26 +- .../activemq/util/IntrospectionSupport.java | 20 +- .../activemq/util/JMSExceptionSupport.java | 3 + .../org/apache/activemq/util/JMXSupport.java | 8 +- .../org/apache/activemq/util/MapHelper.java | 6 +- .../activemq/util/TypeConversionSupport.java | 39 +- .../org/apache/activemq/util/URISupport.java | 17 +- .../activemq/xbean/BrokerFactoryBean.java | 1 - .../xbean/PooledBrokerFactoryBean.java | 10 +- .../org/apache/activemq/AMQDeadlockTest3.java | 3 +- .../activemq/ActiveMQMessageAuditTest.java | 19 +- .../activemq/CombinationTestSupport.java | 40 +- .../activemq/ConnectionCleanupTest.java | 2 +- .../activemq/EmbeddedBrokerTestSupport.java | 2 - .../org/apache/activemq/JMSConsumerTest.java | 6 +- .../JMSDurableTopicRedeliverTest.java | 5 +- .../activemq/JMSExclusiveConsumerTest.java | 5 +- .../org/apache/activemq/JMSMessageTest.java | 7 +- .../org/apache/activemq/JMSUsecaseTest.java | 12 +- .../org/apache/activemq/JmsBenchmark.java | 1 - .../JmsCreateConsumerInOnMessageTest.java | 2 +- .../JmsDurableTopicSendReceiveTest.java | 4 +- ...msDurableTopicWildcardSendReceiveTest.java | 16 +- .../JmsMultipleClientsTestSupport.java | 33 +- ...veTwoConnectionsStartBeforeBrokerTest.java | 4 +- ...JmsQueueSendReceiveTwoConnectionsTest.java | 2 - .../activemq/JmsQueueTransactionTest.java | 6 +- .../activemq/JmsSendReceiveTestSupport.java | 19 +- ...sSendReceiveWithMessageExpirationTest.java | 5 +- .../org/apache/activemq/JmsTestSupport.java | 2 +- .../activemq/JmsTopicRedeliverTest.java | 5 +- .../activemq/JmsTopicRequestReplyTest.java | 28 +- .../apache/activemq/JmsTopicSelectorTest.java | 5 +- .../activemq/JmsTopicSendReceiveTest.java | 5 +- .../activemq/JmsTransactionTestSupport.java | 38 +- .../activemq/LargeMessageTestSupport.java | 4 +- .../apache/activemq/LargeStreamletTest.java | 11 +- .../org/apache/activemq/LoadTestBurnIn.java | 15 +- .../MessageListenerRedeliveryTest.java | 12 +- .../apache/activemq/SpringTestSupport.java | 4 +- .../java/org/apache/activemq/TestSupport.java | 1 - .../activemq/ZeroPrefetchConsumerTest.java | 4 +- .../advisory/ConsumerListenerTest.java | 4 +- .../advisory/ProducerListenerTest.java | 4 +- .../activemq/advisory/TempDestDeleteTest.java | 6 +- .../apache/activemq/broker/BrokerTest.java | 5 +- .../activemq/broker/BrokerTestSupport.java | 8 +- .../java/org/apache/activemq/broker/Main.java | 15 +- .../broker/MarshallingBrokerTest.java | 2 +- .../broker/MessageExpirationTest.java | 4 +- .../activemq/broker/ProgressPrinter.java | 4 +- .../apache/activemq/broker/StubBroker.java | 8 +- .../activemq/broker/StubConnection.java | 14 +- .../broker/policy/DeadLetterTest.java | 7 +- .../broker/policy/DeadLetterTestSupport.java | 11 +- .../IndividualDeadLetterViaXmlTest.java | 5 +- .../apache/activemq/bugs/CraigsBugTest.java | 2 +- .../apache/activemq/bugs/MessageSender.java | 18 +- .../org/apache/activemq/bugs/Receiver.java | 18 +- .../bugs/TransactionNotStartedErrorTest.java | 459 +++++++++--------- .../command/ActiveMQBytesMessageTest.java | 14 +- .../command/ActiveMQDestinationTest.java | 8 +- .../command/ActiveMQMapMessageTest.java | 23 +- .../activemq/command/ActiveMQMessageTest.java | 18 +- .../command/ActiveMQObjectMessageTest.java | 18 +- .../command/ActiveMQStreamMessageTest.java | 18 +- .../activemq/demo/DefaultQueueSender.java | 11 +- .../apache/activemq/demo/SimpleConsumer.java | 8 +- .../apache/activemq/demo/SimpleProducer.java | 10 +- .../activemq/demo/SimpleQueueReceiver.java | 10 +- .../activemq/demo/SimpleQueueSender.java | 10 +- .../activemq/filter/DestinationMapTest.java | 1 + .../activemq/jndi/InitialContextTest.java | 4 +- .../activemq/kaha/ListContainerTest.java | 5 +- .../org/apache/activemq/kaha/StoreTest.java | 17 +- .../buffer/MemoryBufferTestSupport.java | 4 +- .../activemq/network/DuplexNetworkTest.java | 2 - .../network/ForwardingBridgeTest.java | 2 +- .../network/NetworkReconnectTest.java | 6 +- .../activemq/network/SimpleNetworkTest.java | 3 +- .../activemq/network/jms/QueueBridgeTest.java | 2 +- .../network/jms/TopicBridgeSpringTest.java | 2 +- .../DataFileGeneratorTestSupport.java | 14 +- .../perf/InactiveDurableTopicTest.java | 3 +- .../activemq/perf/MemoryAllocationTest.java | 4 +- .../apache/activemq/perf/SimpleTopicTest.java | 13 +- .../activemq/proxy/ProxyConnectorTest.java | 10 +- .../activemq/proxy/ProxyTestSupport.java | 6 +- .../security/AuthorizationMapTest.java | 4 +- ...asCertificateAuthenticationBrokerTest.java | 24 +- .../security/LDAPAuthorizationMapTest.java | 2 +- .../security/SecurityTestSupport.java | 14 +- .../SimpleSecurityBrokerSystemTest.java | 18 +- .../security/StubSecurityContext.java | 2 +- .../apache/activemq/spring/ConsumerBean.java | 6 +- .../test/JmsSendReceiveTestSupport.java | 16 +- ...eceiveWithEmbeddedBrokerAndUserIDTest.java | 4 +- .../test/message/NestedMapMessageTest.java | 4 +- .../activemq/transport/StubTransport.java | 4 +- .../activemq/transport/TopicClusterTest.java | 5 +- .../transport/TransportBrokerTestSupport.java | 6 +- .../failover/FailoverTransportBrokerTest.java | 2 +- .../transport/failover/ReconnectTest.java | 5 +- .../activemq/transport/stomp/StompTest.java | 3 +- .../transport/tcp/SslSocketHelper.java | 9 +- .../tcp/SslTransportFactoryTest.java | 2 +- .../activemq/transport/tcp/StubSSLSocket.java | 3 +- .../transport/tcp/StubX509Certificate.java | 7 +- .../activemq/usecases/AMQFailoverIssue.java | 3 +- .../usecases/AMQStackOverFlowTest.java | 3 +- .../usecases/ChangeSentMessageTest.java | 2 +- .../usecases/CompositePublishTest.java | 10 +- .../usecases/ConsumeTopicPrefetchTest.java | 6 +- .../CreateTemporaryQueueBeforeStartTest.java | 6 +- .../MultiBrokersMultiClientsUsingTcpTest.java | 7 +- ...QueueConsumedMessageInTransactionTest.java | 8 +- .../usecases/QueueDuplicatesTest.java | 4 +- .../usecases/ReliableReconnectTest.java | 6 +- .../apache/activemq/usecases/TestSupport.java | 4 +- .../ThreeBrokerQueueNetworkUsingTcpTest.java | 7 +- .../ThreeBrokerTopicNetworkUsingTcpTest.java | 7 +- .../activemq/usecases/TopicRedeliverTest.java | 7 +- .../TransactionRollbackOrderTest.java | 8 +- ...sageNotSentToRemoteWhenNoConsumerTest.java | 7 +- .../usecases/TwoBrokerMulticastQueueTest.java | 3 +- .../TwoBrokerQueueClientsReconnectTest.java | 9 +- .../apache/activemq/util/MessageIdList.java | 10 +- .../activemq/util/ReflectionSupportTest.java | 2 +- .../ManagementContextXBeanConfigTest.java | 2 +- .../openwire/tool/CHeadersGenerator.java | 14 +- .../apache/activemq/tool/AcidTestTool.java | 23 +- 311 files changed, 2041 insertions(+), 1743 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java b/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java index cac9ba839f..16b6836b62 100755 --- a/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java +++ b/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java @@ -106,7 +106,7 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon private static final Log LOG = LogFactory.getLog(ActiveMQConnection.class); private static final IdGenerator CONNECTION_ID_GENERATOR = new IdGenerator(); - public final ConcurrentHashMap activeTempDestinations = new ConcurrentHashMap(); + public final ConcurrentHashMap activeTempDestinations = new ConcurrentHashMap(); protected boolean dispatchAsync; protected boolean alwaysSessionAsync = true; @@ -151,14 +151,14 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon private final AtomicBoolean closing = new AtomicBoolean(false); private final AtomicBoolean closed = new AtomicBoolean(false); private final AtomicBoolean transportFailed = new AtomicBoolean(false); - private final CopyOnWriteArrayList sessions = new CopyOnWriteArrayList(); - private final CopyOnWriteArrayList connectionConsumers = new CopyOnWriteArrayList(); - private final CopyOnWriteArrayList inputStreams = new CopyOnWriteArrayList(); - private final CopyOnWriteArrayList outputStreams = new CopyOnWriteArrayList(); - private final CopyOnWriteArrayList transportListeners = new CopyOnWriteArrayList(); + private final CopyOnWriteArrayList sessions = new CopyOnWriteArrayList(); + private final CopyOnWriteArrayList connectionConsumers = new CopyOnWriteArrayList(); + private final CopyOnWriteArrayList inputStreams = new CopyOnWriteArrayList(); + private final CopyOnWriteArrayList outputStreams = new CopyOnWriteArrayList(); + private final CopyOnWriteArrayList transportListeners = new CopyOnWriteArrayList(); // Maps ConsumerIds to ActiveMQConsumer objects - private final ConcurrentHashMap dispatchers = new ConcurrentHashMap(); + private final ConcurrentHashMap dispatchers = new ConcurrentHashMap(); private final ConcurrentHashMap producers = new ConcurrentHashMap(); private final LongSequenceGenerator sessionIdGenerator = new LongSequenceGenerator(); private final SessionId connectionSessionId; @@ -194,7 +194,7 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon // Configure a single threaded executor who's core thread can timeout if // idle - asyncConnectionThread = new ThreadPoolExecutor(1, 1, 5, TimeUnit.SECONDS, new LinkedBlockingQueue(), new ThreadFactory() { + asyncConnectionThread = new ThreadPoolExecutor(1, 1, 5, TimeUnit.SECONDS, new LinkedBlockingQueue(), new ThreadFactory() { public Thread newThread(Runnable r) { Thread thread = new Thread(r, "AcitveMQ Connection Worker: " + transport); thread.setDaemon(true); @@ -290,7 +290,6 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException { checkClosedOrFailed(); ensureConnectionInfoSent(); - boolean doSessionAsync = alwaysSessionAsync || sessions.size() > 0 || transacted || acknowledgeMode == Session.CLIENT_ACKNOWLEDGE; return new ActiveMQSession(this, getNextSessionId(), transacted ? Session.SESSION_TRANSACTED : (acknowledgeMode == Session.SESSION_TRANSACTED ? Session.AUTO_ACKNOWLEDGE : acknowledgeMode), dispatchAsync, alwaysSessionAsync); } @@ -453,8 +452,8 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon checkClosedOrFailed(); ensureConnectionInfoSent(); if (started.compareAndSet(false, true)) { - for (Iterator i = sessions.iterator(); i.hasNext();) { - ActiveMQSession session = (ActiveMQSession)i.next(); + for (Iterator i = sessions.iterator(); i.hasNext();) { + ActiveMQSession session = i.next(); session.start(); } } @@ -494,8 +493,8 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon public void stop() throws JMSException { checkClosedOrFailed(); if (started.compareAndSet(true, false)) { - for (Iterator i = sessions.iterator(); i.hasNext();) { - ActiveMQSession s = (ActiveMQSession)i.next(); + for (Iterator i = sessions.iterator(); i.hasNext();) { + ActiveMQSession s = i.next(); s.stop(); } } @@ -560,20 +559,20 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon advisoryConsumer = null; } - for (Iterator i = this.sessions.iterator(); i.hasNext();) { - ActiveMQSession s = (ActiveMQSession)i.next(); + for (Iterator i = this.sessions.iterator(); i.hasNext();) { + ActiveMQSession s = i.next(); s.dispose(); } - for (Iterator i = this.connectionConsumers.iterator(); i.hasNext();) { - ActiveMQConnectionConsumer c = (ActiveMQConnectionConsumer)i.next(); + for (Iterator i = this.connectionConsumers.iterator(); i.hasNext();) { + ActiveMQConnectionConsumer c = i.next(); c.dispose(); } - for (Iterator i = this.inputStreams.iterator(); i.hasNext();) { - ActiveMQInputStream c = (ActiveMQInputStream)i.next(); + for (Iterator i = this.inputStreams.iterator(); i.hasNext();) { + ActiveMQInputStream c = i.next(); c.dispose(); } - for (Iterator i = this.outputStreams.iterator(); i.hasNext();) { - ActiveMQOutputStream c = (ActiveMQOutputStream)i.next(); + for (Iterator i = this.outputStreams.iterator(); i.hasNext();) { + ActiveMQOutputStream c = i.next(); c.dispose(); } @@ -691,7 +690,7 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon // Allows the options on the destination to configure the consumerInfo if (info.getDestination().getOptions() != null) { - HashMap options = new HashMap(info.getDestination().getOptions()); + Map options = new HashMap(info.getDestination().getOptions()); IntrospectionSupport.setProperties(this.info, options, "consumer."); } @@ -1076,7 +1075,7 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon // Allows the options on the destination to configure the consumerInfo if (info.getDestination().getOptions() != null) { - HashMap options = new HashMap(info.getDestination().getOptions()); + Map options = new HashMap(info.getDestination().getOptions()); IntrospectionSupport.setProperties(info, options, "consumer."); } @@ -1324,20 +1323,20 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon advisoryConsumer = null; } - for (Iterator i = this.sessions.iterator(); i.hasNext();) { - ActiveMQSession s = (ActiveMQSession)i.next(); + for (Iterator i = this.sessions.iterator(); i.hasNext();) { + ActiveMQSession s = i.next(); s.dispose(); } - for (Iterator i = this.connectionConsumers.iterator(); i.hasNext();) { - ActiveMQConnectionConsumer c = (ActiveMQConnectionConsumer)i.next(); + for (Iterator i = this.connectionConsumers.iterator(); i.hasNext();) { + ActiveMQConnectionConsumer c = i.next(); c.dispose(); } - for (Iterator i = this.inputStreams.iterator(); i.hasNext();) { - ActiveMQInputStream c = (ActiveMQInputStream)i.next(); + for (Iterator i = this.inputStreams.iterator(); i.hasNext();) { + ActiveMQInputStream c = i.next(); c.dispose(); } - for (Iterator i = this.outputStreams.iterator(); i.hasNext();) { - ActiveMQOutputStream c = (ActiveMQOutputStream)i.next(); + for (Iterator i = this.outputStreams.iterator(); i.hasNext();) { + ActiveMQOutputStream c = i.next(); c.dispose(); } @@ -1537,7 +1536,7 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon command.visit(new CommandVisitorAdapter() { @Override public Response processMessageDispatch(MessageDispatch md) throws Exception { - ActiveMQDispatcher dispatcher = (ActiveMQDispatcher)dispatchers.get(md.getConsumerId()); + ActiveMQDispatcher dispatcher = dispatchers.get(md.getConsumerId()); if (dispatcher != null) { // Copy in case a embedded broker is dispatching via // vm:// @@ -1616,8 +1615,8 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon } } - for (Iterator iter = transportListeners.iterator(); iter.hasNext();) { - TransportListener listener = (TransportListener)iter.next(); + for (Iterator iter = transportListeners.iterator(); iter.hasNext();) { + TransportListener listener = iter.next(); listener.onCommand(command); } } @@ -1660,8 +1659,8 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon ServiceSupport.dispose(ActiveMQConnection.this.transport); brokerInfoReceived.countDown(); - for (Iterator iter = transportListeners.iterator(); iter.hasNext();) { - TransportListener listener = (TransportListener)iter.next(); + for (Iterator iter = transportListeners.iterator(); iter.hasNext();) { + TransportListener listener = iter.next(); listener.onException(error); } } @@ -1669,23 +1668,23 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon } public void transportInterupted() { - for (Iterator i = this.sessions.iterator(); i.hasNext();) { - ActiveMQSession s = (ActiveMQSession)i.next(); + for (Iterator i = this.sessions.iterator(); i.hasNext();) { + ActiveMQSession s = i.next(); s.clearMessagesInProgress(); } - for (Iterator iter = transportListeners.iterator(); iter.hasNext();) { - TransportListener listener = (TransportListener)iter.next(); + for (Iterator iter = transportListeners.iterator(); iter.hasNext();) { + TransportListener listener = iter.next(); listener.transportInterupted(); } } public void transportResumed() { - for (Iterator iter = transportListeners.iterator(); iter.hasNext();) { - TransportListener listener = (TransportListener)iter.next(); + for (Iterator iter = transportListeners.iterator(); iter.hasNext();) { + TransportListener listener = iter.next(); listener.transportResumed(); } - for (Iterator i = this.sessions.iterator(); i.hasNext();) { - ActiveMQSession s = (ActiveMQSession)i.next(); + for (Iterator i = this.sessions.iterator(); i.hasNext();) { + ActiveMQSession s = i.next(); s.deliverAcks(); } } @@ -1726,8 +1725,8 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon checkClosedOrFailed(); - for (Iterator i = this.sessions.iterator(); i.hasNext();) { - ActiveMQSession s = (ActiveMQSession)i.next(); + for (Iterator i = this.sessions.iterator(); i.hasNext();) { + ActiveMQSession s = i.next(); if (s.isInUse(destination)) { throw new JMSException("A consumer is consuming from the temporary destination"); } @@ -1881,7 +1880,7 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon * {@link javax.jms.Message#setObjectProperty(String, Object)} * method */ - public OutputStream createOutputStream(Destination dest, Map streamProperties, int deliveryMode, int priority, long timeToLive) throws JMSException { + public OutputStream createOutputStream(Destination dest, Map streamProperties, int deliveryMode, int priority, long timeToLive) throws JMSException { checkClosedOrFailed(); ensureConnectionInfoSent(); return new ActiveMQOutputStream(this, createProducerId(), ActiveMQDestination.transform(dest), streamProperties, deliveryMode, priority, timeToLive); @@ -1910,7 +1909,7 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon checkClosedOrFailed(); RemoveSubscriptionInfo rsi = new RemoveSubscriptionInfo(); rsi.setConnectionId(getConnectionInfo().getConnectionId()); - rsi.setSubcriptionName(name); + rsi.setSubscriptionName(name); rsi.setClientId(getConnectionInfo().getClientId()); syncSendPacket(rsi); } @@ -1990,8 +1989,8 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon protected void onConnectionControl(ConnectionControl command) { if (command.isFaultTolerant()) { this.optimizeAcknowledge = false; - for (Iterator i = this.sessions.iterator(); i.hasNext();) { - ActiveMQSession s = (ActiveMQSession)i.next(); + for (Iterator i = this.sessions.iterator(); i.hasNext();) { + ActiveMQSession s = i.next(); s.setOptimizeAcknowledge(false); } } @@ -1999,13 +1998,13 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon protected void onConsumerControl(ConsumerControl command) { if (command.isClose()) { - for (Iterator i = this.sessions.iterator(); i.hasNext();) { - ActiveMQSession s = (ActiveMQSession)i.next(); + for (Iterator i = this.sessions.iterator(); i.hasNext();) { + ActiveMQSession s = i.next(); s.close(command.getConsumerId()); } } else { - for (Iterator i = this.sessions.iterator(); i.hasNext();) { - ActiveMQSession s = (ActiveMQSession)i.next(); + for (Iterator i = this.sessions.iterator(); i.hasNext();) { + ActiveMQSession s = i.next(); s.setPrefetchSize(command.getConsumerId(), command.getPrefetch()); } } diff --git a/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java b/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java index f9fb3b73c1..37245f3dc4 100755 --- a/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java @@ -18,6 +18,7 @@ package org.apache.activemq; import java.net.URI; import java.net.URISyntaxException; +import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.concurrent.Executor; @@ -550,10 +551,11 @@ public class ActiveMQConnectionFactory extends JNDIBaseStorable implements Conne setBrokerURL(temp); } - buildFromMap(properties); + Map p = new HashMap(properties); + buildFromMap(p); } - public boolean buildFromMap(Map properties) { + public boolean buildFromMap(Map properties) { boolean rc = false; ActiveMQPrefetchPolicy p = new ActiveMQPrefetchPolicy(); diff --git a/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionMetaData.java b/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionMetaData.java index 5884174975..b6a8522520 100755 --- a/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionMetaData.java +++ b/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionMetaData.java @@ -17,7 +17,7 @@ package org.apache.activemq; import java.util.Enumeration; -import java.util.Hashtable; +import java.util.Vector; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -137,12 +137,12 @@ public final class ActiveMQConnectionMetaData implements ConnectionMetaData { * @return an Enumeration of JMSX property names */ - public Enumeration getJMSXPropertyNames() { - Hashtable jmxProperties = new Hashtable(); - jmxProperties.put("JMSXGroupID", "1"); - jmxProperties.put("JMSXGroupSeq", "1"); - jmxProperties.put("JMSXDeliveryCount", "1"); - jmxProperties.put("JMSXProducerTXID", "1"); - return jmxProperties.keys(); + public Enumeration getJMSXPropertyNames() { + Vector jmxProperties = new Vector(); + jmxProperties.add("JMSXGroupID"); + jmxProperties.add("JMSXGroupSeq"); + jmxProperties.add("JMSXDeliveryCount"); + jmxProperties.add("JMSXProducerTXID"); + return jmxProperties.elements(); } } diff --git a/activemq-core/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java b/activemq-core/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java index 71386ea2c8..77df09e3fb 100755 --- a/activemq-core/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java +++ b/activemq-core/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java @@ -138,8 +138,10 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC * @param dispatchAsync * @throws JMSException */ - public ActiveMQMessageConsumer(ActiveMQSession session, ConsumerId consumerId, ActiveMQDestination dest, String name, String selector, int prefetch, - int maximumPendingMessageCount, boolean noLocal, boolean browser, boolean dispatchAsync) throws JMSException { + public ActiveMQMessageConsumer(ActiveMQSession session, ConsumerId consumerId, ActiveMQDestination dest, + String name, String selector, int prefetch, + int maximumPendingMessageCount, boolean noLocal, boolean browser, + boolean dispatchAsync) throws JMSException { if (dest == null) { throw new InvalidDestinationException("Don't understand null destinations"); } else if (dest.getPhysicalName() == null) { @@ -154,11 +156,13 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC String connectionID = session.connection.getConnectionInfo().getConnectionId().getValue(); if (physicalName.indexOf(connectionID) < 0) { - throw new InvalidDestinationException("Cannot use a Temporary destination from another Connection"); + throw new InvalidDestinationException( + "Cannot use a Temporary destination from another Connection"); } if (session.connection.isDeleted(dest)) { - throw new InvalidDestinationException("Cannot use a Temporary destination that has been deleted"); + throw new InvalidDestinationException( + "Cannot use a Temporary destination that has been deleted"); } } @@ -199,7 +203,8 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC } this.stats = new JMSConsumerStatsImpl(session.getSessionStats(), dest); - this.optimizeAcknowledge = session.connection.isOptimizeAcknowledge() && session.isAutoAcknowledge() && !info.isBrowser(); + this.optimizeAcknowledge = session.connection.isOptimizeAcknowledge() && session.isAutoAcknowledge() + && !info.isBrowser(); this.info.setOptimizedAcknowledge(this.optimizeAcknowledge); try { this.session.addConsumer(this); @@ -342,7 +347,8 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC public void setMessageListener(MessageListener listener) throws JMSException { checkClosed(); if (info.getPrefetchSize() == 0) { - throw new JMSException("Illegal prefetch size of zero. This setting is not supported for asynchronous consumers please set a value of at least 1"); + throw new JMSException( + "Illegal prefetch size of zero. This setting is not supported for asynchronous consumers please set a value of at least 1"); } this.messageListener = listener; if (listener != null) { @@ -709,15 +715,16 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC ackLater(md, MessageAck.DELIVERED_ACK_TYPE); } else { stats.onMessage(); - if( session.isTransacted() ) { + if (session.isTransacted()) { // Do nothing. - } else if(session.isAutoAcknowledge()) { + } else if (session.isAutoAcknowledge()) { if (!deliveredMessages.isEmpty()) { if (optimizeAcknowledge) { if (deliveryingAcknowledgements.compareAndSet(false, true)) { ackCounter++; if (ackCounter >= (info.getCurrentPrefetchSize() * .65)) { - MessageAck ack = new MessageAck(md, MessageAck.STANDARD_ACK_TYPE, deliveredMessages.size()); + MessageAck ack = new MessageAck(md, MessageAck.STANDARD_ACK_TYPE, + deliveredMessages.size()); session.asyncSendPacket(ack); ackCounter = 0; deliveredMessages.clear(); @@ -725,7 +732,8 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC deliveryingAcknowledgements.set(false); } } else { - MessageAck ack = new MessageAck(md, MessageAck.STANDARD_ACK_TYPE, deliveredMessages.size()); + MessageAck ack = new MessageAck(md, MessageAck.STANDARD_ACK_TYPE, deliveredMessages + .size()); session.asyncSendPacket(ack); deliveredMessages.clear(); } @@ -835,14 +843,15 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC } if (deliveredMessages.isEmpty()) { return; - } + } // Only increase the redlivery delay after the first redelivery.. if (rollbackCounter > 0) { redeliveryDelay = redeliveryPolicy.getRedeliveryDelay(redeliveryDelay); } rollbackCounter++; - if (redeliveryPolicy.getMaximumRedeliveries() != RedeliveryPolicy.NO_MAXIMUM_REDELIVERIES && rollbackCounter > redeliveryPolicy.getMaximumRedeliveries()) { + if (redeliveryPolicy.getMaximumRedeliveries() != RedeliveryPolicy.NO_MAXIMUM_REDELIVERIES + && rollbackCounter > redeliveryPolicy.getMaximumRedeliveries()) { // We need to NACK the messages so that they get sent to the // DLQ. // Acknowledge the last message. @@ -971,7 +980,8 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC } public String toString() { - return "ActiveMQMessageConsumer { value=" + info.getConsumerId() + ", started=" + started.get() + " }"; + return "ActiveMQMessageConsumer { value=" + info.getConsumerId() + ", started=" + started.get() + + " }"; } /** diff --git a/activemq-core/src/main/java/org/apache/activemq/ActiveMQMessageTransformation.java b/activemq-core/src/main/java/org/apache/activemq/ActiveMQMessageTransformation.java index 1b769e64c5..ac58028361 100755 --- a/activemq-core/src/main/java/org/apache/activemq/ActiveMQMessageTransformation.java +++ b/activemq-core/src/main/java/org/apache/activemq/ActiveMQMessageTransformation.java @@ -50,8 +50,11 @@ import org.apache.activemq.command.ActiveMQTopic; * * @version $Revision: 1.1 $ */ -public class ActiveMQMessageTransformation { +public final class ActiveMQMessageTransformation { + private ActiveMQMessageTransformation() { + } + /** * Creates a an available JMS message from another provider. * @@ -95,7 +98,7 @@ public class ActiveMQMessageTransformation { * message. * @throws JMSException if an error occurs */ - public static final ActiveMQMessage transformMessage(Message message, ActiveMQConnection connection) + public static ActiveMQMessage transformMessage(Message message, ActiveMQConnection connection) throws JMSException { if (message instanceof ActiveMQMessage) { return (ActiveMQMessage)message; diff --git a/activemq-core/src/main/java/org/apache/activemq/AdvisoryConsumer.java b/activemq-core/src/main/java/org/apache/activemq/AdvisoryConsumer.java index 3d43bae6f3..7f05ad933c 100755 --- a/activemq-core/src/main/java/org/apache/activemq/AdvisoryConsumer.java +++ b/activemq-core/src/main/java/org/apache/activemq/AdvisoryConsumer.java @@ -20,6 +20,7 @@ import javax.jms.JMSException; import org.apache.activemq.advisory.AdvisorySupport; import org.apache.activemq.command.ActiveMQDestination; +import org.apache.activemq.command.ActiveMQTempDestination; import org.apache.activemq.command.ConsumerId; import org.apache.activemq.command.ConsumerInfo; import org.apache.activemq.command.DataStructure; @@ -79,17 +80,24 @@ public class AdvisoryConsumer implements ActiveMQDispatcher { if (o != null && o.getClass() == DestinationInfo.class) { processDestinationInfo((DestinationInfo)o); } else { - connection.onAsyncException(new JMSException("Unexpected message was dispatched to the AdvisoryConsumer: " + md)); + connection.onAsyncException(new JMSException( + "Unexpected message was dispatched to the AdvisoryConsumer: " + + md)); } } private void processDestinationInfo(DestinationInfo dinfo) { ActiveMQDestination dest = dinfo.getDestination(); + if (!dest.isTemporary()) { + return; + } + + ActiveMQTempDestination tempDest = (ActiveMQTempDestination)dest; if (dinfo.getOperationType() == DestinationInfo.ADD_OPERATION_TYPE) { - connection.activeTempDestinations.put(dest, dest); + connection.activeTempDestinations.put(tempDest, tempDest); } else if (dinfo.getOperationType() == DestinationInfo.REMOVE_OPERATION_TYPE) { - connection.activeTempDestinations.remove(dest); + connection.activeTempDestinations.remove(tempDest); } } diff --git a/activemq-core/src/main/java/org/apache/activemq/StreamConnection.java b/activemq-core/src/main/java/org/apache/activemq/StreamConnection.java index 7983456f8f..ce240b49e3 100644 --- a/activemq-core/src/main/java/org/apache/activemq/StreamConnection.java +++ b/activemq-core/src/main/java/org/apache/activemq/StreamConnection.java @@ -50,7 +50,7 @@ public interface StreamConnection extends Connection { OutputStream createOutputStream(Destination dest) throws JMSException; - OutputStream createOutputStream(Destination dest, Map streamProperties, int deliveryMode, int priority, long timeToLive) throws JMSException; + OutputStream createOutputStream(Destination dest, Map streamProperties, int deliveryMode, int priority, long timeToLive) throws JMSException; /** * Unsubscribes a durable subscription that has been created by a client. diff --git a/activemq-core/src/main/java/org/apache/activemq/advisory/AdvisoryBroker.java b/activemq-core/src/main/java/org/apache/activemq/advisory/AdvisoryBroker.java index bdeb127156..a471c42e78 100755 --- a/activemq-core/src/main/java/org/apache/activemq/advisory/AdvisoryBroker.java +++ b/activemq-core/src/main/java/org/apache/activemq/advisory/AdvisoryBroker.java @@ -30,6 +30,7 @@ import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQMessage; import org.apache.activemq.command.ActiveMQTopic; import org.apache.activemq.command.Command; +import org.apache.activemq.command.ConnectionId; import org.apache.activemq.command.ConnectionInfo; import org.apache.activemq.command.ConsumerId; import org.apache.activemq.command.ConsumerInfo; @@ -53,10 +54,10 @@ public class AdvisoryBroker extends BrokerFilter { private static final Log LOG = LogFactory.getLog(AdvisoryBroker.class); private static final IdGenerator ID_GENERATOR = new IdGenerator(); - protected final ConcurrentHashMap connections = new ConcurrentHashMap(); - protected final ConcurrentHashMap consumers = new ConcurrentHashMap(); - protected final ConcurrentHashMap producers = new ConcurrentHashMap(); - protected final ConcurrentHashMap destinations = new ConcurrentHashMap(); + protected final ConcurrentHashMap connections = new ConcurrentHashMap(); + protected final ConcurrentHashMap consumers = new ConcurrentHashMap(); + protected final ConcurrentHashMap producers = new ConcurrentHashMap(); + protected final ConcurrentHashMap destinations = new ConcurrentHashMap(); protected final ProducerId advisoryProducerId = new ProducerId(); private final LongSequenceGenerator messageIdGenerator = new LongSequenceGenerator(); @@ -88,8 +89,8 @@ public class AdvisoryBroker extends BrokerFilter { // for this newly added consumer. if (AdvisorySupport.isConnectionAdvisoryTopic(info.getDestination())) { // Replay the connections. - for (Iterator iter = connections.values().iterator(); iter.hasNext();) { - ConnectionInfo value = (ConnectionInfo)iter.next(); + for (Iterator iter = connections.values().iterator(); iter.hasNext();) { + ConnectionInfo value = iter.next(); ActiveMQTopic topic = AdvisorySupport.getConnectionAdvisoryTopic(); fireAdvisory(context, topic, value, info.getConsumerId()); } @@ -100,8 +101,8 @@ public class AdvisoryBroker extends BrokerFilter { // for this newly added consumer. if (AdvisorySupport.isDestinationAdvisoryTopic(info.getDestination())) { // Replay the destinations. - for (Iterator iter = destinations.values().iterator(); iter.hasNext();) { - DestinationInfo value = (DestinationInfo)iter.next(); + for (Iterator iter = destinations.values().iterator(); iter.hasNext();) { + DestinationInfo value = iter.next(); ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(value.getDestination()); fireAdvisory(context, topic, value, info.getConsumerId()); } @@ -109,8 +110,8 @@ public class AdvisoryBroker extends BrokerFilter { // Replay the producers. if (AdvisorySupport.isProducerAdvisoryTopic(info.getDestination())) { - for (Iterator iter = producers.values().iterator(); iter.hasNext();) { - ProducerInfo value = (ProducerInfo)iter.next(); + for (Iterator iter = producers.values().iterator(); iter.hasNext();) { + ProducerInfo value = iter.next(); ActiveMQTopic topic = AdvisorySupport.getProducerAdvisoryTopic(value.getDestination()); fireProducerAdvisory(context, topic, value, info.getConsumerId()); } @@ -118,8 +119,8 @@ public class AdvisoryBroker extends BrokerFilter { // Replay the consumers. if (AdvisorySupport.isConsumerAdvisoryTopic(info.getDestination())) { - for (Iterator iter = consumers.values().iterator(); iter.hasNext();) { - ConsumerInfo value = (ConsumerInfo)iter.next(); + for (Iterator iter = consumers.values().iterator(); iter.hasNext();) { + ConsumerInfo value = iter.next(); ActiveMQTopic topic = AdvisorySupport.getConsumerAdvisoryTopic(value.getDestination()); fireConsumerAdvisory(context, topic, value, info.getConsumerId()); } @@ -163,7 +164,7 @@ public class AdvisoryBroker extends BrokerFilter { public void removeDestination(ConnectionContext context, ActiveMQDestination destination, long timeout) throws Exception { next.removeDestination(context, destination, timeout); - DestinationInfo info = (DestinationInfo)destinations.remove(destination); + DestinationInfo info = destinations.remove(destination); if (info != null) { info.setDestination(destination); info.setOperationType(DestinationInfo.REMOVE_OPERATION_TYPE); @@ -183,7 +184,7 @@ public class AdvisoryBroker extends BrokerFilter { public void removeDestinationInfo(ConnectionContext context, DestinationInfo destInfo) throws Exception { next.removeDestinationInfo(context, destInfo); - DestinationInfo info = (DestinationInfo)destinations.remove(destInfo.getDestination()); + DestinationInfo info = destinations.remove(destInfo.getDestination()); if (info != null) { info.setDestination(destInfo.getDestination()); diff --git a/activemq-core/src/main/java/org/apache/activemq/advisory/AdvisorySupport.java b/activemq-core/src/main/java/org/apache/activemq/advisory/AdvisorySupport.java index a5d928db83..6108a708e2 100755 --- a/activemq-core/src/main/java/org/apache/activemq/advisory/AdvisorySupport.java +++ b/activemq-core/src/main/java/org/apache/activemq/advisory/AdvisorySupport.java @@ -21,7 +21,7 @@ import javax.jms.Destination; import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQTopic; -public class AdvisorySupport { +public final class AdvisorySupport { public static final String ADVISORY_TOPIC_PREFIX = "ActiveMQ.Advisory."; public static final ActiveMQTopic CONNECTION_ADVISORY_TOPIC = new ActiveMQTopic(ADVISORY_TOPIC_PREFIX + "Connection"); @@ -45,6 +45,9 @@ public class AdvisorySupport { public static final ActiveMQTopic TEMP_DESTINATION_COMPOSITE_ADVISORY_TOPIC = new ActiveMQTopic(TEMP_QUEUE_ADVISORY_TOPIC + "," + TEMP_TOPIC_ADVISORY_TOPIC); private static final ActiveMQTopic AGENT_TOPIC_DESTINATION = new ActiveMQTopic(AGENT_TOPIC); + private AdvisorySupport() { + } + public static ActiveMQTopic getConnectionAdvisoryTopic() { return CONNECTION_ADVISORY_TOPIC; } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/BrokerBroadcaster.java b/activemq-core/src/main/java/org/apache/activemq/broker/BrokerBroadcaster.java index 02a33abe95..540148b35b 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/BrokerBroadcaster.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/BrokerBroadcaster.java @@ -228,19 +228,19 @@ public class BrokerBroadcaster extends BrokerFilter { } public synchronized void addListener(Broker broker) { - List tmp = getListenersAsList(); + List tmp = getListenersAsList(); tmp.add(broker); - listeners = (Broker[])tmp.toArray(new Broker[tmp.size()]); + listeners = tmp.toArray(new Broker[tmp.size()]); } public synchronized void removeListener(Broker broker) { - List tmp = getListenersAsList(); + List tmp = getListenersAsList(); tmp.remove(broker); - listeners = (Broker[])tmp.toArray(new Broker[tmp.size()]); + listeners = tmp.toArray(new Broker[tmp.size()]); } - protected List getListenersAsList() { - List tmp = new ArrayList(); + protected List getListenersAsList() { + List tmp = new ArrayList(); Broker brokers[] = getListeners(); for (int i = 0; i < brokers.length; i++) { tmp.add(brokers[i]); diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFactory.java b/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFactory.java index 6c5519ff05..4e41bc54dc 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFactory.java @@ -29,10 +29,13 @@ import org.apache.activemq.util.IOExceptionSupport; * * @version $Revision$ */ -public class BrokerFactory { +public final class BrokerFactory { private static final FactoryFinder BROKER_FACTORY_HANDLER_FINDER = new FactoryFinder("META-INF/services/org/apache/activemq/broker/"); + private BrokerFactory() { + } + public static BrokerFactoryHandler createBrokerFactoryHandler(String type) throws IOException { try { return (BrokerFactoryHandler)BROKER_FACTORY_HANDLER_FINDER.newInstance(type); diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFilter.java b/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFilter.java index ff03bbcf86..bf98e5c9a5 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFilter.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFilter.java @@ -61,7 +61,7 @@ public class BrokerFilter implements Broker { return next.getAdaptor(type); } - public Map getDestinationMap() { + public Map getDestinationMap() { return next.getDestinationMap(); } @@ -205,7 +205,7 @@ public class BrokerFilter implements Broker { return next.isStopped(); } - public Set getDurableDestinations() { + public Set getDurableDestinations() { return next.getDurableDestinations(); } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/BrokerRegistry.java b/activemq-core/src/main/java/org/apache/activemq/broker/BrokerRegistry.java index 912ff2c864..7a53366e00 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/BrokerRegistry.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/BrokerRegistry.java @@ -18,6 +18,8 @@ package org.apache.activemq.broker; import java.util.HashMap; import java.util.Iterator; +import java.util.Map; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -30,7 +32,7 @@ public class BrokerRegistry { private static final BrokerRegistry INSTANCE = new BrokerRegistry(); private final Object mutex = new Object(); - private final HashMap brokers = new HashMap(); + private final Map brokers = new HashMap(); public static BrokerRegistry getInstance() { return INSTANCE; diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/EmptyBroker.java b/activemq-core/src/main/java/org/apache/activemq/broker/EmptyBroker.java index f0522983ed..2e27c30063 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/EmptyBroker.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/EmptyBroker.java @@ -63,7 +63,8 @@ public class EmptyBroker implements Broker { return null; } - public Map getDestinationMap() { + @SuppressWarnings("unchecked") + public Map getDestinationMap() { return Collections.EMPTY_MAP; } @@ -198,7 +199,7 @@ public class EmptyBroker implements Broker { return false; } - public Set getDurableDestinations() { + public Set getDurableDestinations() { return null; } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/ErrorBroker.java b/activemq-core/src/main/java/org/apache/activemq/broker/ErrorBroker.java index a7660106dd..4d4587ba79 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/ErrorBroker.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/ErrorBroker.java @@ -55,7 +55,8 @@ public class ErrorBroker implements Broker { this.message = message; } - public Map getDestinationMap() { + @SuppressWarnings("unchecked") + public Map getDestinationMap() { return Collections.EMPTY_MAP; } @@ -203,7 +204,7 @@ public class ErrorBroker implements Broker { return true; } - public Set getDurableDestinations() { + public Set getDurableDestinations() { throw new BrokerStoppedException(this.message); } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/MutableBrokerFilter.java b/activemq-core/src/main/java/org/apache/activemq/broker/MutableBrokerFilter.java index c904db3b68..45adfa646f 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/MutableBrokerFilter.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/MutableBrokerFilter.java @@ -75,7 +75,7 @@ public class MutableBrokerFilter implements Broker { } } - public Map getDestinationMap() { + public Map getDestinationMap() { return getNext().getDestinationMap(); } @@ -215,7 +215,7 @@ public class MutableBrokerFilter implements Broker { return getNext().isStopped(); } - public Set getDurableDestinations() { + public Set getDurableDestinations() { return getNext().getDurableDestinations(); } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnection.java b/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnection.java index ac40eff26a..931bbd43a5 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnection.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnection.java @@ -83,6 +83,7 @@ import org.apache.activemq.state.TransactionState; import org.apache.activemq.thread.Task; import org.apache.activemq.thread.TaskRunner; import org.apache.activemq.thread.TaskRunnerFactory; +import org.apache.activemq.transaction.Transaction; import org.apache.activemq.transport.DefaultTransportListener; import org.apache.activemq.transport.ResponseCorrelator; import org.apache.activemq.transport.Transport; @@ -100,27 +101,31 @@ import org.apache.commons.logging.LogFactory; public class TransportConnection implements Service, Connection, Task, CommandVisitor { private static final Log LOG = LogFactory.getLog(TransportConnection.class); - private static final Log TRANSPORTLOG = LogFactory.getLog(TransportConnection.class.getName() + ".Transport"); + private static final Log TRANSPORTLOG = LogFactory.getLog(TransportConnection.class.getName() + + ".Transport"); private static final Log SERVICELOG = LogFactory.getLog(TransportConnection.class.getName() + ".Service"); + // Keeps track of the broker and connector that created this connection. protected final Broker broker; - private MasterBroker masterBroker; protected final TransportConnector connector; - private final Transport transport; - private MessageAuthorizationPolicy messageAuthorizationPolicy; // Keeps track of the state of the connections. // protected final ConcurrentHashMap localConnectionStates=new // ConcurrentHashMap(); protected final Map brokerConnectionStates; // The broker and wireformat info that was exchanged. protected BrokerInfo brokerInfo; + protected final List dispatchQueue = Collections.synchronizedList(new LinkedList()); + protected TaskRunner taskRunner; + protected final AtomicReference transportException = new AtomicReference(); + protected AtomicBoolean dispatchStopped = new AtomicBoolean(false); + + private MasterBroker masterBroker; + private final Transport transport; + private MessageAuthorizationPolicy messageAuthorizationPolicy; private WireFormatInfo wireFormatInfo; // Used to do async dispatch.. this should perhaps be pushed down into the // transport layer.. - protected final List dispatchQueue = Collections.synchronizedList(new LinkedList()); - protected TaskRunner taskRunner; - protected final AtomicReference transportException = new AtomicReference(); - private boolean inServiceException = false; + private boolean inServiceException; private ConnectionStatistics statistics = new ConnectionStatistics(); private boolean manageable; private boolean slow; @@ -140,7 +145,6 @@ public class TransportConnection implements Service, Connection, Task, CommandVi private final Map producerExchanges = new HashMap(); private final Map consumerExchanges = new HashMap(); private CountDownLatch dispatchStoppedLatch = new CountDownLatch(1); - protected AtomicBoolean dispatchStopped = new AtomicBoolean(false); private ConnectionContext context; private boolean networkConnection; private AtomicInteger protocolVersion = new AtomicInteger(CommandTypes.PROTOCOL_VERSION); @@ -193,7 +197,8 @@ public class TransportConnection implements Service, Connection, Task, CommandVi * @param taskRunnerFactory - can be null if you want direct dispatch to the * transport else commands are sent async. */ - public TransportConnection(TransportConnector connector, final Transport transport, Broker broker, TaskRunnerFactory taskRunnerFactory) { + public TransportConnection(TransportConnector connector, final Transport transport, Broker broker, + TaskRunnerFactory taskRunnerFactory) { this.connector = connector; this.broker = broker; RegionBroker rb = (RegionBroker)broker.getAdaptor(RegionBroker.class); @@ -264,7 +269,7 @@ public class TransportConnection implements Service, Connection, Task, CommandVi * error transmitted to the client before stopping it's transport. */ public void serviceException(Throwable e) { - + // are we a transport exception such as not being able to dispatch // synchronously to a transport if (e instanceof IOException) { @@ -275,7 +280,8 @@ public class TransportConnection implements Service, Connection, Task, CommandVi if (!disposed.get()) { if (SERVICELOG.isDebugEnabled()) { - SERVICELOG.debug("Broker has been stopped. Notifying client and closing his connection."); + SERVICELOG + .debug("Broker has been stopped. Notifying client and closing his connection."); } ConnectionError ce = new ConnectionError(); @@ -408,7 +414,8 @@ public class TransportConnection implements Service, Connection, Task, CommandVi } TransactionState transactionState = cs.getTransactionState(info.getTransactionId()); if (transactionState == null) { - throw new IllegalStateException("Cannot prepare a transaction that had not been started: " + info.getTransactionId()); + throw new IllegalStateException("Cannot prepare a transaction that had not been started: " + + info.getTransactionId()); } // Avoid dups. if (!transactionState.isPrepared()) { @@ -478,7 +485,8 @@ public class TransportConnection implements Service, Connection, Task, CommandVi return broker.messagePull(lookupConnectionState(pull.getConsumerId()).getContext(), pull); } - public Response processMessageDispatchNotification(MessageDispatchNotification notification) throws Exception { + public Response processMessageDispatchNotification(MessageDispatchNotification notification) + throws Exception { broker.processDispatchNotification(notification); return null; } @@ -507,7 +515,9 @@ public class TransportConnection implements Service, Connection, Task, CommandVi TransportConnectionState cs = lookupConnectionState(connectionId); SessionState ss = cs.getSessionState(sessionId); if (ss == null) { - throw new IllegalStateException("Cannot add a producer to a session that had not been registered: " + sessionId); + throw new IllegalStateException( + "Cannot add a producer to a session that had not been registered: " + + sessionId); } // Avoid replaying dup commands if (!ss.getProducerIds().contains(info.getProducerId())) { @@ -527,7 +537,9 @@ public class TransportConnection implements Service, Connection, Task, CommandVi TransportConnectionState cs = lookupConnectionState(connectionId); SessionState ss = cs.getSessionState(sessionId); if (ss == null) { - throw new IllegalStateException("Cannot remove a producer from a session that had not been registered: " + sessionId); + throw new IllegalStateException( + "Cannot remove a producer from a session that had not been registered: " + + sessionId); } ProducerState ps = ss.removeProducer(id); if (ps == null) { @@ -544,7 +556,9 @@ public class TransportConnection implements Service, Connection, Task, CommandVi TransportConnectionState cs = lookupConnectionState(connectionId); SessionState ss = cs.getSessionState(sessionId); if (ss == null) { - throw new IllegalStateException("Cannot add a consumer to a session that had not been registered: " + sessionId); + throw new IllegalStateException( + "Cannot add a consumer to a session that had not been registered: " + + sessionId); } // Avoid replaying dup commands if (!ss.getConsumerIds().contains(info.getConsumerId())) { @@ -564,7 +578,9 @@ public class TransportConnection implements Service, Connection, Task, CommandVi TransportConnectionState cs = lookupConnectionState(connectionId); SessionState ss = cs.getSessionState(sessionId); if (ss == null) { - throw new IllegalStateException("Cannot remove a consumer from a session that had not been registered: " + sessionId); + throw new IllegalStateException( + "Cannot remove a consumer from a session that had not been registered: " + + sessionId); } ConsumerState consumerState = ss.removeConsumer(id); if (consumerState == null) { @@ -644,7 +660,8 @@ public class TransportConnection implements Service, Connection, Task, CommandVi if (state.getConnection() != this) { LOG.debug("Killing previous stale connection: " + state.getConnection().getRemoteAddress()); state.getConnection().stop(); - LOG.debug("Connection " + getRemoteAddress() + " taking over previous connection: " + state.getConnection().getRemoteAddress()); + LOG.debug("Connection " + getRemoteAddress() + " taking over previous connection: " + + state.getConnection().getRemoteAddress()); state.setConnection(this); state.reset(info); } @@ -659,7 +676,7 @@ public class TransportConnection implements Service, Connection, Task, CommandVi context.setConnection(this); context.setBroker(broker); context.setConnector(connector); - context.setTransactions(new ConcurrentHashMap()); + context.setTransactions(new ConcurrentHashMap()); context.setClientId(clientId); context.setUserName(info.getUserName()); context.setConnectionId(info.getConnectionId()); @@ -767,7 +784,8 @@ public class TransportConnection implements Service, Connection, Task, CommandVi } protected void processDispatch(Command command) throws IOException { - final MessageDispatch messageDispatch = (MessageDispatch)(command.isMessageDispatch() ? command : null); + final MessageDispatch messageDispatch = (MessageDispatch)(command.isMessageDispatch() + ? command : null); try { if (!disposed.get()) { if (messageDispatch != null) { @@ -847,7 +865,8 @@ public class TransportConnection implements Service, Connection, Task, CommandVi transport.start(); if (taskRunnerFactory != null) { - taskRunner = taskRunnerFactory.createTaskRunner(this, "ActiveMQ Connection Dispatcher: " + getRemoteAddress()); + taskRunner = taskRunnerFactory.createTaskRunner(this, "ActiveMQ Connection Dispatcher: " + + getRemoteAddress()); } else { taskRunner = null; } @@ -931,8 +950,8 @@ public class TransportConnection implements Service, Connection, Task, CommandVi // Run the MessageDispatch callbacks so that message references get // cleaned up. - for (Iterator iter = dispatchQueue.iterator(); iter.hasNext();) { - Command command = (Command)iter.next(); + for (Iterator iter = dispatchQueue.iterator(); iter.hasNext();) { + Command command = iter.next(); if (command.isMessageDispatch()) { MessageDispatch md = (MessageDispatch)command; Runnable sub = md.getTransmitCallback(); @@ -1105,18 +1124,19 @@ public class TransportConnection implements Service, Connection, Task, CommandVi // We have been requested to create a two way pipe ... try { Properties properties = MarshallingSupport.stringToProperties(info.getNetworkProperties()); - Map props = new HashMap(properties); + Map props = createMap(properties); NetworkBridgeConfiguration config = new NetworkBridgeConfiguration(); IntrospectionSupport.setProperties(config, props, ""); config.setBrokerName(broker.getBrokerName()); URI uri = broker.getVmConnectorURI(); - HashMap map = new HashMap(URISupport.parseParamters(uri)); + HashMap map = new HashMap(URISupport.parseParamters(uri)); map.put("network", "true"); map.put("async", "false"); uri = URISupport.createURIWithQuery(uri, URISupport.createQueryString(map)); Transport localTransport = TransportFactory.connect(uri); Transport remoteBridgeTransport = new ResponseCorrelator(transport); - duplexBridge = NetworkBridgeFactory.createBridge(config, localTransport, remoteBridgeTransport); + duplexBridge = NetworkBridgeFactory.createBridge(config, localTransport, + remoteBridgeTransport); // now turn duplex off this side info.setDuplexConnection(false); duplexBridge.setCreatedByDuplex(true); @@ -1144,6 +1164,11 @@ public class TransportConnection implements Service, Connection, Task, CommandVi return null; } + @SuppressWarnings("unchecked") + private HashMap createMap(Properties properties) { + return new HashMap(properties); + } + protected void dispatch(Command command) throws IOException { try { setMarkedCandidate(true); @@ -1182,7 +1207,8 @@ public class TransportConnection implements Service, Connection, Task, CommandVi ProducerState producerState = ss.getProducerState(id); if (producerState != null && producerState.getInfo() != null) { ProducerInfo info = producerState.getInfo(); - result.setMutable(info.getDestination() == null || info.getDestination().isComposite()); + result.setMutable(info.getDestination() == null + || info.getDestination().isComposite()); } } producerExchanges.put(id, result); @@ -1213,7 +1239,7 @@ public class TransportConnection implements Service, Connection, Task, CommandVi if (cs != null) { ConsumerInfo info = cs.getInfo(); if (info != null) { - if (info.getDestination() != null && info.getDestination().isPattern()) { + if (info.getDestination() != null && info.getDestination().isPattern()) { result.setWildcard(true); } } @@ -1287,7 +1313,8 @@ public class TransportConnection implements Service, Connection, Task, CommandVi // // ///////////////////////////////////////////////////////////////// - protected TransportConnectionState registerConnectionState(ConnectionId connectionId, TransportConnectionState state) { + protected TransportConnectionState registerConnectionState(ConnectionId connectionId, + TransportConnectionState state) { TransportConnectionState rc = connectionState; connectionState = state; return rc; @@ -1310,7 +1337,9 @@ public class TransportConnection implements Service, Connection, Task, CommandVi protected TransportConnectionState lookupConnectionState(String connectionId) { TransportConnectionState cs = connectionState; if (cs == null) { - throw new IllegalStateException("Cannot lookup a connectionId for a connection that had not been registered: " + connectionId); + throw new IllegalStateException( + "Cannot lookup a connectionId for a connection that had not been registered: " + + connectionId); } return cs; } @@ -1318,7 +1347,9 @@ public class TransportConnection implements Service, Connection, Task, CommandVi protected TransportConnectionState lookupConnectionState(ConsumerId id) { TransportConnectionState cs = connectionState; if (cs == null) { - throw new IllegalStateException("Cannot lookup a consumer from a connection that had not been registered: " + id.getParentId().getParentId()); + throw new IllegalStateException( + "Cannot lookup a consumer from a connection that had not been registered: " + + id.getParentId().getParentId()); } return cs; } @@ -1326,7 +1357,9 @@ public class TransportConnection implements Service, Connection, Task, CommandVi protected TransportConnectionState lookupConnectionState(ProducerId id) { TransportConnectionState cs = connectionState; if (cs == null) { - throw new IllegalStateException("Cannot lookup a producer from a connection that had not been registered: " + id.getParentId().getParentId()); + throw new IllegalStateException( + "Cannot lookup a producer from a connection that had not been registered: " + + id.getParentId().getParentId()); } return cs; } @@ -1334,7 +1367,9 @@ public class TransportConnection implements Service, Connection, Task, CommandVi protected TransportConnectionState lookupConnectionState(SessionId id) { TransportConnectionState cs = connectionState; if (cs == null) { - throw new IllegalStateException("Cannot lookup a session from a connection that had not been registered: " + id.getParentId()); + throw new IllegalStateException( + "Cannot lookup a session from a connection that had not been registered: " + + id.getParentId()); } return cs; } @@ -1342,7 +1377,8 @@ public class TransportConnection implements Service, Connection, Task, CommandVi protected TransportConnectionState lookupConnectionState(ConnectionId connectionId) { TransportConnectionState cs = connectionState; if (cs == null) { - throw new IllegalStateException("Cannot lookup a connection that had not been registered: " + connectionId); + throw new IllegalStateException("Cannot lookup a connection that had not been registered: " + + connectionId); } return cs; } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/TransportStatusDetector.java b/activemq-core/src/main/java/org/apache/activemq/broker/TransportStatusDetector.java index 3992b289c2..41ad06ec1a 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/TransportStatusDetector.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/TransportStatusDetector.java @@ -34,7 +34,7 @@ import org.apache.commons.logging.LogFactory; public class TransportStatusDetector implements Service, Runnable { private static final Log LOG = LogFactory.getLog(TransportStatusDetector.class); private TransportConnector connector; - private Set collectionCandidates = new CopyOnWriteArraySet(); + private Set collectionCandidates = new CopyOnWriteArraySet(); private AtomicBoolean started = new AtomicBoolean(false); private Thread runner; private int sweepInterval = 5000; @@ -60,8 +60,8 @@ public class TransportStatusDetector implements Service, Runnable { } protected void doCollection() { - for (Iterator i = collectionCandidates.iterator(); i.hasNext();) { - TransportConnection tc = (TransportConnection)i.next(); + for (Iterator i = collectionCandidates.iterator(); i.hasNext();) { + TransportConnection tc = i.next(); if (tc.isMarkedCandidate()) { if (tc.isBlockedCandidate()) { collectionCandidates.remove(tc); diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/ft/MasterConnector.java b/activemq-core/src/main/java/org/apache/activemq/broker/ft/MasterConnector.java index 2909d2fb0c..edeb6ec5f5 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/ft/MasterConnector.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/ft/MasterConnector.java @@ -69,7 +69,7 @@ public class MasterConnector implements Service, BrokerServiceAware { private ConnectionInfo connectionInfo; private SessionInfo sessionInfo; private ProducerInfo producerInfo; - final AtomicBoolean masterActive = new AtomicBoolean(); + private final AtomicBoolean masterActive = new AtomicBoolean(); public MasterConnector() { } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java index a838809983..6810d49c53 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java @@ -196,7 +196,7 @@ public class BrokerView implements BrokerViewMBean { public void destroyDurableSubscriber(String clientId, String subscriberName) throws Exception { RemoveSubscriptionInfo info = new RemoveSubscriptionInfo(); info.setClientId(clientId); - info.setSubcriptionName(subscriberName); + info.setSubscriptionName(subscriberName); ConnectionContext context = new ConnectionContext(); context.setBroker(broker); context.setClientId(clientId); diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java index 1d5fce3224..33d76c519f 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java @@ -128,7 +128,7 @@ public class DestinationView implements DestinationViewMBean { public CompositeData[] browse(String selector) throws OpenDataException, InvalidSelectorException { Message[] messages = destination.browse(); - ArrayList c = new ArrayList(); + ArrayList c = new ArrayList(); MessageEvaluationContext ctx = new MessageEvaluationContext(); ctx.setDestination(destination.getActiveMQDestination()); @@ -159,7 +159,7 @@ public class DestinationView implements DestinationViewMBean { /** * Browses the current destination returning a list of messages */ - public List browseMessages() throws InvalidSelectorException { + public List browseMessages() throws InvalidSelectorException { return browseMessages(null); } @@ -167,9 +167,9 @@ public class DestinationView implements DestinationViewMBean { * Browses the current destination with the given selector returning a list * of messages */ - public List browseMessages(String selector) throws InvalidSelectorException { + public List browseMessages(String selector) throws InvalidSelectorException { Message[] messages = destination.browse(); - ArrayList answer = new ArrayList(); + ArrayList answer = new ArrayList(); MessageEvaluationContext ctx = new MessageEvaluationContext(); ctx.setDestination(destination.getActiveMQDestination()); diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DurableSubscriptionView.java b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DurableSubscriptionView.java index 2c01514a20..0dfc5cf1dd 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DurableSubscriptionView.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DurableSubscriptionView.java @@ -78,7 +78,7 @@ public class DurableSubscriptionView extends SubscriptionView implements Durable public void destroy() throws Exception { RemoveSubscriptionInfo info = new RemoveSubscriptionInfo(); info.setClientId(clientId); - info.setSubcriptionName(subscriptionName); + info.setSubscriptionName(subscriptionName); ConnectionContext context = new ConnectionContext(); context.setBroker(broker); context.setClientId(clientId); diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/InactiveDurableSubscriptionView.java b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/InactiveDurableSubscriptionView.java index cf426de942..ac9c25e120 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/InactiveDurableSubscriptionView.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/InactiveDurableSubscriptionView.java @@ -123,7 +123,7 @@ public class InactiveDurableSubscriptionView extends SubscriptionView implements public void destroy() throws Exception { RemoveSubscriptionInfo info = new RemoveSubscriptionInfo(); info.setClientId(clientId); - info.setSubcriptionName(subscriptionInfo.getSubscriptionName()); + info.setSubscriptionName(subscriptionInfo.getSubscriptionName()); ConnectionContext context = new ConnectionContext(); context.setBroker(broker); context.setClientId(clientId); diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagedRegionBroker.java b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagedRegionBroker.java index 7b77053cb2..97a42a72fd 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagedRegionBroker.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagedRegionBroker.java @@ -320,7 +320,7 @@ public class ManagedRegionBroker extends RegionBroker { SubscriptionKey subscriptionKey = new SubscriptionKey(view.getClientId(), view.getSubscriptionName()); SubscriptionInfo info = new SubscriptionInfo(); info.setClientId(subscriptionKey.getClientId()); - info.setSubcriptionName(subscriptionKey.getSubscriptionName()); + info.setSubscriptionName(subscriptionKey.getSubscriptionName()); info.setDestination(new ActiveMQTopic(view.getDestinationName())); addInactiveSubscription(subscriptionKey, info); } @@ -420,9 +420,6 @@ public class ManagedRegionBroker extends RegionBroker { throw new RuntimeException("Should not be called."); } - public void finished() { - } - public boolean hasSpace() { return true; } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractRegion.java b/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractRegion.java index c627a887f4..904ef36230 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractRegion.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractRegion.java @@ -243,7 +243,7 @@ public abstract class AbstractRegion implements Region { // inactive state for the // destination which has reduced memory usage. // - DestinationFilter destinationFilter = DestinationFilter.parseFilter(info.getDestination()); + DestinationFilter.parseFilter(info.getDestination()); Subscription sub = createSubscription(context, info); diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/region/DestinationFactoryImpl.java b/activemq-core/src/main/java/org/apache/activemq/broker/region/DestinationFactoryImpl.java index d908412e6f..f6b3d5c43e 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/region/DestinationFactoryImpl.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/region/DestinationFactoryImpl.java @@ -65,7 +65,7 @@ public class DestinationFactoryImpl extends DestinationFactory { this.broker = broker; } - public Set getDestinations() { + public Set getDestinations() { return persistenceAdapter.getDestinations(); } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/region/DurableTopicSubscription.java b/activemq-core/src/main/java/org/apache/activemq/broker/region/DurableTopicSubscription.java index 8710522cb2..fb4b0322f2 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/region/DurableTopicSubscription.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/region/DurableTopicSubscription.java @@ -23,10 +23,12 @@ import javax.jms.InvalidSelectorException; import org.apache.activemq.broker.Broker; import org.apache.activemq.broker.ConnectionContext; import org.apache.activemq.broker.region.cursors.StoreDurableSubscriberCursor; +import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ConsumerInfo; import org.apache.activemq.command.Message; import org.apache.activemq.command.MessageAck; import org.apache.activemq.command.MessageDispatch; +import org.apache.activemq.command.MessageId; import org.apache.activemq.memory.UsageListener; import org.apache.activemq.memory.UsageManager; import org.apache.activemq.util.SubscriptionKey; @@ -36,8 +38,8 @@ import org.apache.commons.logging.LogFactory; public class DurableTopicSubscription extends PrefetchSubscription implements UsageListener { private static final Log LOG = LogFactory.getLog(PrefetchSubscription.class); - private final ConcurrentHashMap redeliveredMessages = new ConcurrentHashMap(); - private final ConcurrentHashMap destinations = new ConcurrentHashMap(); + private final ConcurrentHashMap redeliveredMessages = new ConcurrentHashMap(); + private final ConcurrentHashMap destinations = new ConcurrentHashMap(); private final SubscriptionKey subscriptionKey; private final boolean keepDurableSubsActive; private final UsageManager usageManager; @@ -82,7 +84,7 @@ public class DurableTopicSubscription extends PrefetchSubscription implements Us this.context = context; this.info = info; if (!keepDurableSubsActive) { - for (Iterator iter = destinations.values().iterator(); iter.hasNext();) { + for (Iterator iter = destinations.values().iterator(); iter.hasNext();) { Topic topic = (Topic)iter.next(); topic.activate(context, this); } @@ -93,7 +95,7 @@ public class DurableTopicSubscription extends PrefetchSubscription implements Us // If nothing was in the persistent store, then try to use the // recovery policy. if (pending.isEmpty()) { - for (Iterator iter = destinations.values().iterator(); iter.hasNext();) { + for (Iterator iter = destinations.values().iterator(); iter.hasNext();) { Topic topic = (Topic)iter.next(); topic.recoverRetroactiveMessages(context, this); } @@ -110,7 +112,7 @@ public class DurableTopicSubscription extends PrefetchSubscription implements Us pending.stop(); } if (!keepDurableSubsActive) { - for (Iterator iter = destinations.values().iterator(); iter.hasNext();) { + for (Iterator iter = destinations.values().iterator(); iter.hasNext();) { Topic topic = (Topic)iter.next(); topic.deactivate(context, this); } @@ -118,7 +120,7 @@ public class DurableTopicSubscription extends PrefetchSubscription implements Us for (Iterator iter = dispatched.iterator(); iter.hasNext();) { // Mark the dispatched messages as redelivered for next time. MessageReference node = (MessageReference)iter.next(); - Integer count = (Integer)redeliveredMessages.get(node.getMessageId()); + Integer count = redeliveredMessages.get(node.getMessageId()); if (count != null) { redeliveredMessages.put(node.getMessageId(), Integer.valueOf(count.intValue() + 1)); } else { @@ -152,7 +154,7 @@ public class DurableTopicSubscription extends PrefetchSubscription implements Us protected MessageDispatch createMessageDispatch(MessageReference node, Message message) { MessageDispatch md = super.createMessageDispatch(node, message); - Integer count = (Integer)redeliveredMessages.get(node.getMessageId()); + Integer count = redeliveredMessages.get(node.getMessageId()); if (count != null) { md.setRedeliveryCounter(count.intValue()); } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/region/RegionBroker.java b/activemq-core/src/main/java/org/apache/activemq/broker/region/RegionBroker.java index afa724e4ef..7e0a7e4e4b 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/region/RegionBroker.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/region/RegionBroker.java @@ -114,8 +114,8 @@ public class RegionBroker implements Broker { tempTopicRegion = createTempTopicRegion(memoryManager, taskRunnerFactory, destinationFactory); } - public Map getDestinationMap() { - Map answer = getQueueRegion().getDestinationMap(); + public Map getDestinationMap() { + Map answer = getQueueRegion().getDestinationMap(); answer.putAll(getTopicRegion().getDestinationMap()); return answer; } @@ -174,10 +174,6 @@ public class RegionBroker implements Broker { return new QueueRegion(this, destinationStatistics, memoryManager, taskRunnerFactory, destinationFactory); } - private static PersistenceAdapter createDefaultPersistenceAdapter(UsageManager memoryManager) throws IOException { - return new MemoryPersistenceAdapter(); - } - public void start() throws Exception { ((TopicRegion)topicRegion).setKeepDurableSubsActive(keepDurableSubsActive); started = true; @@ -575,7 +571,7 @@ public class RegionBroker implements Broker { return !started; } - public Set getDurableDestinations() { + public Set getDurableDestinations() { return destinationFactory.getDestinations(); } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/region/TopicRegion.java b/activemq-core/src/main/java/org/apache/activemq/broker/region/TopicRegion.java index f712c28070..bace883d89 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/region/TopicRegion.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/region/TopicRegion.java @@ -276,10 +276,10 @@ public class TopicRegion extends AbstractRegion { return !info1.getDestination().equals(info2.getDestination()); } - protected Set getInactiveDestinations() { - Set inactiveDestinations = super.getInactiveDestinations(); - for (Iterator iter = inactiveDestinations.iterator(); iter.hasNext();) { - ActiveMQDestination dest = (ActiveMQDestination)iter.next(); + protected Set getInactiveDestinations() { + Set inactiveDestinations = super.getInactiveDestinations(); + for (Iterator iter = inactiveDestinations.iterator(); iter.hasNext();) { + ActiveMQDestination dest = iter.next(); if (!dest.isTopic()) { iter.remove(); } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursor.java b/activemq-core/src/main/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursor.java index 2558217e80..f5f1abb56f 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursor.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursor.java @@ -46,8 +46,8 @@ public class FilePendingMessageCursor extends AbstractPendingMessageCursor imple private Store store; private String name; - private LinkedList memoryList = new LinkedList(); - private ListContainer diskList; + private LinkedList memoryList = new LinkedList(); + private ListContainer diskList; private Iterator iter; private Destination regionDestination; private boolean iterating; @@ -105,7 +105,7 @@ public class FilePendingMessageCursor extends AbstractPendingMessageCursor imple public synchronized void destroy() { stop(); - for (Iterator i = memoryList.iterator(); i.hasNext();) { + for (Iterator i = memoryList.iterator(); i.hasNext();) { Message node = (Message)i.next(); node.decrementReferenceCount(); } @@ -115,15 +115,15 @@ public class FilePendingMessageCursor extends AbstractPendingMessageCursor imple } } - public synchronized LinkedList pageInList(int maxItems) { - LinkedList result = new LinkedList(); + public synchronized LinkedList pageInList(int maxItems) { + LinkedList result = new LinkedList(); int count = 0; - for (Iterator i = memoryList.iterator(); i.hasNext() && count < maxItems;) { + for (Iterator i = memoryList.iterator(); i.hasNext() && count < maxItems;) { result.add(i.next()); count++; } if (count < maxItems && !isDiskListEmpty()) { - for (Iterator i = getDiskList().iterator(); i.hasNext() && count < maxItems;) { + for (Iterator i = getDiskList().iterator(); i.hasNext() && count < maxItems;) { Message message = (Message)i.next(); message.setRegionDestination(regionDestination); message.incrementReferenceCount(); @@ -262,7 +262,7 @@ public class FilePendingMessageCursor extends AbstractPendingMessageCursor imple protected synchronized void flushToDisk() { if (!memoryList.isEmpty()) { while (!memoryList.isEmpty()) { - MessageReference node = (MessageReference)memoryList.removeFirst(); + MessageReference node = memoryList.removeFirst(); node.decrementReferenceCount(); getDiskList().addLast(node); } @@ -274,7 +274,7 @@ public class FilePendingMessageCursor extends AbstractPendingMessageCursor imple return diskList == null || diskList.isEmpty(); } - protected ListContainer getDiskList() { + protected ListContainer getDiskList() { if (diskList == null) { try { diskList = store.getListContainer(name, "TopicSubscription", true); diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/region/cursors/StoreQueueCursor.java b/activemq-core/src/main/java/org/apache/activemq/broker/region/cursors/StoreQueueCursor.java index 252c00fd20..083d0aab6b 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/region/cursors/StoreQueueCursor.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/region/cursors/StoreQueueCursor.java @@ -32,7 +32,7 @@ import org.apache.commons.logging.LogFactory; public class StoreQueueCursor extends AbstractPendingMessageCursor { private static final Log LOG = LogFactory.getLog(StoreQueueCursor.class); - private int pendingCount = 0; + private int pendingCount; private Queue queue; private Store tmpStore; private PendingMessageCursor nonPersistent; diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/region/group/SimpleMessageGroupMap.java b/activemq-core/src/main/java/org/apache/activemq/broker/region/group/SimpleMessageGroupMap.java index d0795310bc..7092b42784 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/region/group/SimpleMessageGroupMap.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/region/group/SimpleMessageGroupMap.java @@ -30,25 +30,25 @@ import org.apache.activemq.command.ConsumerId; * @version $Revision$ */ public class SimpleMessageGroupMap implements MessageGroupMap { - private Map map = new ConcurrentHashMap(); + private Map map = new ConcurrentHashMap(); public void put(String groupId, ConsumerId consumerId) { map.put(groupId, consumerId); } public ConsumerId get(String groupId) { - return (ConsumerId) map.get(groupId); + return map.get(groupId); } public ConsumerId removeGroup(String groupId) { - return (ConsumerId) map.remove(groupId); + return map.remove(groupId); } public MessageGroupSet removeConsumer(ConsumerId consumerId) { SimpleMessageGroupSet ownedGroups = new SimpleMessageGroupSet(); - for (Iterator iter = map.keySet().iterator(); iter.hasNext();) { - String group = (String) iter.next(); - ConsumerId owner = (ConsumerId) map.get(group); + for (Iterator iter = map.keySet().iterator(); iter.hasNext();) { + String group = iter.next(); + ConsumerId owner = map.get(group); if (owner.equals(consumerId)) { ownedGroups.add(group); iter.remove(); diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/region/group/SimpleMessageGroupSet.java b/activemq-core/src/main/java/org/apache/activemq/broker/region/group/SimpleMessageGroupSet.java index 7fc533b22a..bc8c2c75a6 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/region/group/SimpleMessageGroupSet.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/region/group/SimpleMessageGroupSet.java @@ -26,7 +26,7 @@ import java.util.Set; */ public class SimpleMessageGroupSet implements MessageGroupSet { - private Set set = new HashSet(); + private Set set = new HashSet(); public boolean contains(String groupID) { return set.contains(groupID); diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/DispatchPolicy.java b/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/DispatchPolicy.java index 06fd9ed8f2..3253a50f66 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/DispatchPolicy.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/DispatchPolicy.java @@ -19,6 +19,7 @@ package org.apache.activemq.broker.region.policy; import java.util.List; import org.apache.activemq.broker.region.MessageReference; +import org.apache.activemq.broker.region.Subscription; import org.apache.activemq.filter.MessageEvaluationContext; /** @@ -43,6 +44,6 @@ public interface DispatchPolicy { * * @return true if at least one consumer was dispatched or false if there are no active subscriptions that could be dispatched */ - boolean dispatch(MessageReference node, MessageEvaluationContext msgContext, List consumers) throws Exception; + boolean dispatch(MessageReference node, MessageEvaluationContext msgContext, List consumers) throws Exception; } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/LastImageSubscriptionRecoveryPolicy.java b/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/LastImageSubscriptionRecoveryPolicy.java index aa0871f1c5..d0b7177547 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/LastImageSubscriptionRecoveryPolicy.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/LastImageSubscriptionRecoveryPolicy.java @@ -57,12 +57,12 @@ public class LastImageSubscriptionRecoveryPolicy implements SubscriptionRecovery } public Message[] browse(ActiveMQDestination destination) throws Exception { - List result = new ArrayList(); + List result = new ArrayList(); DestinationFilter filter = DestinationFilter.parseFilter(destination); if (filter.matches(lastImage.getMessage().getDestination())) { result.add(lastImage.getMessage()); } - return (Message[])result.toArray(new Message[result.size()]); + return result.toArray(new Message[result.size()]); } public SubscriptionRecoveryPolicy copy() { diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/RoundRobinDispatchPolicy.java b/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/RoundRobinDispatchPolicy.java index 45e596bb74..aafe66b94b 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/RoundRobinDispatchPolicy.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/RoundRobinDispatchPolicy.java @@ -43,7 +43,7 @@ public class RoundRobinDispatchPolicy implements DispatchPolicy { * @see org.apache.activemq.broker.region.policy.DispatchPolicy#dispatch(org.apache.activemq.broker.region.MessageReference, * org.apache.activemq.filter.MessageEvaluationContext, java.util.List) */ - public boolean dispatch(MessageReference node, MessageEvaluationContext msgContext, List consumers) throws Exception { + public boolean dispatch(MessageReference node, MessageEvaluationContext msgContext, List consumers) throws Exception { // Big synch here so that only 1 message gets dispatched at a time. // Ensures @@ -54,8 +54,8 @@ public class RoundRobinDispatchPolicy implements DispatchPolicy { int count = 0; Subscription firstMatchingConsumer = null; - for (Iterator iter = consumers.iterator(); iter.hasNext();) { - Subscription sub = (Subscription)iter.next(); + for (Iterator iter = consumers.iterator(); iter.hasNext();) { + Subscription sub = iter.next(); // Only dispatch to interested subscriptions if (!sub.matches(node, msgContext)) { diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/TimedSubscriptionRecoveryPolicy.java b/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/TimedSubscriptionRecoveryPolicy.java index 154a41e4a8..144c0a4099 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/TimedSubscriptionRecoveryPolicy.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/TimedSubscriptionRecoveryPolicy.java @@ -45,7 +45,7 @@ public class TimedSubscriptionRecoveryPolicy implements SubscriptionRecoveryPoli // TODO: need to get a better synchronized linked list that has little // contention between enqueuing and dequeuing - private final List buffer = Collections.synchronizedList(new LinkedList()); + private final List buffer = Collections.synchronizedList(new LinkedList()); private volatile long lastGCRun = System.currentTimeMillis(); private long recoverDuration = 60 * 1000; // Buffer for 1 min. @@ -79,11 +79,10 @@ public class TimedSubscriptionRecoveryPolicy implements SubscriptionRecoveryPoli public void recover(ConnectionContext context, Topic topic, SubscriptionRecovery sub) throws Exception { // Re-dispatch the messages from the buffer. - ArrayList copy = new ArrayList(buffer); + ArrayList copy = new ArrayList(buffer); if (!copy.isEmpty()) { - MessageEvaluationContext msgContext = context.getMessageEvaluationContext(); - for (Iterator iter = copy.iterator(); iter.hasNext();) { - TimestampWrapper timestampWrapper = (TimestampWrapper)iter.next(); + for (Iterator iter = copy.iterator(); iter.hasNext();) { + TimestampWrapper timestampWrapper = iter.next(); MessageReference message = timestampWrapper.message; sub.addRecoveredMessage(context, message); } @@ -101,7 +100,7 @@ public class TimedSubscriptionRecoveryPolicy implements SubscriptionRecoveryPoli public void gc() { lastGCRun = System.currentTimeMillis(); while (buffer.size() > 0) { - TimestampWrapper timestampWrapper = (TimestampWrapper)buffer.get(0); + TimestampWrapper timestampWrapper = buffer.get(0); if (lastGCRun > timestampWrapper.timestamp + recoverDuration) { // GC it. buffer.remove(0); @@ -120,18 +119,18 @@ public class TimedSubscriptionRecoveryPolicy implements SubscriptionRecoveryPoli } public Message[] browse(ActiveMQDestination destination) throws Exception { - List result = new ArrayList(); - ArrayList copy = new ArrayList(buffer); + List result = new ArrayList(); + ArrayList copy = new ArrayList(buffer); DestinationFilter filter = DestinationFilter.parseFilter(destination); - for (Iterator iter = copy.iterator(); iter.hasNext();) { - TimestampWrapper timestampWrapper = (TimestampWrapper)iter.next(); + for (Iterator iter = copy.iterator(); iter.hasNext();) { + TimestampWrapper timestampWrapper = iter.next(); MessageReference ref = timestampWrapper.message; Message message = ref.getMessage(); if (filter.matches(message.getDestination())) { result.add(message); } } - return (Message[])result.toArray(new Message[result.size()]); + return result.toArray(new Message[result.size()]); } } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/view/ConnectionDotFileInterceptor.java b/activemq-core/src/main/java/org/apache/activemq/broker/view/ConnectionDotFileInterceptor.java index b34449451e..07e7a5d9d4 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/view/ConnectionDotFileInterceptor.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/view/ConnectionDotFileInterceptor.java @@ -58,7 +58,7 @@ public class ConnectionDotFileInterceptor extends DotFileInterceptorSupport { // until we have some MBeans for producers, lets do it all ourselves private Map producers = new HashMap(); - private Map producerDestinations = new HashMap(); + private Map> producerDestinations = new HashMap>(); private Object lock = new Object(); public ConnectionDotFileInterceptor(Broker next, String file, boolean redrawOnRemove) throws MalformedObjectNameException { @@ -267,7 +267,8 @@ public class ConnectionDotFileInterceptor extends DotFileInterceptorSupport { */ protected String asID(String name) { StringBuffer buffer = new StringBuffer(); - for (int i = 0, size = name.length(); i < size; i++) { + int size = name.length(); + for (int i = 0; i < size; i++) { char ch = name.charAt(i); if (Character.isLetterOrDigit(ch) || ch == '_') { buffer.append(ch); diff --git a/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java b/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java index 9dfd9444c2..fe9a511ccf 100755 --- a/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java +++ b/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java @@ -324,9 +324,10 @@ public abstract class ActiveMQDestination extends JNDIBaseStorable implements Da out.writeObject(options); } + @SuppressWarnings("unchecked") public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.setPhysicalName(in.readUTF()); - this.options = (Map)in.readObject(); + this.options = (Map)in.readObject(); } public String getDestinationTypeAsString() { diff --git a/activemq-core/src/main/java/org/apache/activemq/command/ControlCommand.java b/activemq-core/src/main/java/org/apache/activemq/command/ControlCommand.java index 43ee6f5200..68716b7b00 100644 --- a/activemq-core/src/main/java/org/apache/activemq/command/ControlCommand.java +++ b/activemq-core/src/main/java/org/apache/activemq/command/ControlCommand.java @@ -29,12 +29,12 @@ public class ControlCommand extends BaseCommand { public static final byte DATA_STRUCTURE_TYPE = CommandTypes.CONTROL_COMMAND; + private String command; + public byte getDataStructureType() { return DATA_STRUCTURE_TYPE; } - private String command; - /** * @openwire:property version=1 */ diff --git a/activemq-core/src/main/java/org/apache/activemq/command/DiscoveryEvent.java b/activemq-core/src/main/java/org/apache/activemq/command/DiscoveryEvent.java index 3322aa9071..659b78d326 100755 --- a/activemq-core/src/main/java/org/apache/activemq/command/DiscoveryEvent.java +++ b/activemq-core/src/main/java/org/apache/activemq/command/DiscoveryEvent.java @@ -26,10 +26,6 @@ public class DiscoveryEvent implements DataStructure { public static final byte DATA_STRUCTURE_TYPE = CommandTypes.DISCOVERY_EVENT; - public byte getDataStructureType() { - return DATA_STRUCTURE_TYPE; - } - protected String serviceName; protected String brokerName; @@ -40,6 +36,10 @@ public class DiscoveryEvent implements DataStructure { this.serviceName = serviceName; } + public byte getDataStructureType() { + return DATA_STRUCTURE_TYPE; + } + /** * @openwire:property version=1 */ diff --git a/activemq-core/src/main/java/org/apache/activemq/command/JournalTransaction.java b/activemq-core/src/main/java/org/apache/activemq/command/JournalTransaction.java index f3a6d72cf3..58192d2cbb 100755 --- a/activemq-core/src/main/java/org/apache/activemq/command/JournalTransaction.java +++ b/activemq-core/src/main/java/org/apache/activemq/command/JournalTransaction.java @@ -35,10 +35,6 @@ public class JournalTransaction implements DataStructure { public boolean wasPrepared; public TransactionId transactionId; - public byte getDataStructureType() { - return DATA_STRUCTURE_TYPE; - } - public JournalTransaction(byte type, TransactionId transactionId, boolean wasPrepared) { this.type = type; this.transactionId = transactionId; @@ -48,6 +44,10 @@ public class JournalTransaction implements DataStructure { public JournalTransaction() { } + public byte getDataStructureType() { + return DATA_STRUCTURE_TYPE; + } + /** * @openwire:property version=1 */ diff --git a/activemq-core/src/main/java/org/apache/activemq/command/RemoveInfo.java b/activemq-core/src/main/java/org/apache/activemq/command/RemoveInfo.java index a9d717168a..ed3f8e1d29 100755 --- a/activemq-core/src/main/java/org/apache/activemq/command/RemoveInfo.java +++ b/activemq-core/src/main/java/org/apache/activemq/command/RemoveInfo.java @@ -32,10 +32,6 @@ public class RemoveInfo extends BaseCommand { protected DataStructure objectId; - public byte getDataStructureType() { - return DATA_STRUCTURE_TYPE; - } - public RemoveInfo() { } @@ -43,6 +39,10 @@ public class RemoveInfo extends BaseCommand { this.objectId = objectId; } + public byte getDataStructureType() { + return DATA_STRUCTURE_TYPE; + } + /** * @openwire:property version=1 cache=true */ diff --git a/activemq-core/src/main/java/org/apache/activemq/filter/ConstantExpression.java b/activemq-core/src/main/java/org/apache/activemq/filter/ConstantExpression.java index eef49cbd79..f54d4e3da5 100755 --- a/activemq-core/src/main/java/org/apache/activemq/filter/ConstantExpression.java +++ b/activemq-core/src/main/java/org/apache/activemq/filter/ConstantExpression.java @@ -44,6 +44,10 @@ public class ConstantExpression implements Expression { private Object value; + public ConstantExpression(Object value) { + this.value = value; + } + public static ConstantExpression createFromDecimal(String text) { // Strip off the 'l' or 'L' if needed. @@ -89,10 +93,6 @@ public class ConstantExpression implements Expression { return new ConstantExpression(value); } - public ConstantExpression(Object value) { - this.value = value; - } - public Object evaluate(MessageEvaluationContext message) throws JMSException { return value; } diff --git a/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapNode.java b/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapNode.java index d433734871..281586311e 100755 --- a/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapNode.java +++ b/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapNode.java @@ -164,7 +164,8 @@ public class DestinationMapNode implements DestinationNode { public void removeAll(Set answer, String[] paths, int startIndex) { DestinationNode node = this; - for (int i = startIndex, size = paths.length; i < size && node != null; i++) { + int size = paths.length; + for (int i = startIndex; i < size && node != null; i++) { String path = paths[i]; if (path.equals(ANY_DESCENDENT)) { @@ -230,7 +231,8 @@ public class DestinationMapNode implements DestinationNode { public void appendMatchingValues(Set answer, String[] paths, int startIndex) { DestinationNode node = this; boolean couldMatchAny = true; - for (int i = startIndex, size = paths.length; i < size && node != null; i++) { + int size = paths.length; + for (int i = startIndex; i < size && node != null; i++) { String path = paths[i]; if (path.equals(ANY_DESCENDENT)) { answer.addAll(node.getDesendentValues()); diff --git a/activemq-core/src/main/java/org/apache/activemq/filter/DestinationPath.java b/activemq-core/src/main/java/org/apache/activemq/filter/DestinationPath.java index cd15d2b866..39f175c461 100755 --- a/activemq-core/src/main/java/org/apache/activemq/filter/DestinationPath.java +++ b/activemq-core/src/main/java/org/apache/activemq/filter/DestinationPath.java @@ -30,9 +30,12 @@ import org.apache.activemq.command.Message; * * @version $Revision: 1.3 $ */ -public class DestinationPath { +public final class DestinationPath { protected static final char SEPARATOR = '.'; + private DestinationPath() { + } + public static String[] getDestinationPaths(String subject) { List list = new ArrayList(); int previous = 0; diff --git a/activemq-core/src/main/java/org/apache/activemq/filter/PrefixDestinationFilter.java b/activemq-core/src/main/java/org/apache/activemq/filter/PrefixDestinationFilter.java index 74b75b0bdd..6366b71a57 100755 --- a/activemq-core/src/main/java/org/apache/activemq/filter/PrefixDestinationFilter.java +++ b/activemq-core/src/main/java/org/apache/activemq/filter/PrefixDestinationFilter.java @@ -42,7 +42,8 @@ public class PrefixDestinationFilter extends DestinationFilter { String[] path = DestinationPath.getDestinationPaths(destination.getPhysicalName()); int length = prefixes.length; if (path.length >= length) { - for (int i = 0, size = length - 1; i < size; i++) { + int size = length - 1; + for (int i = 0; i < size; i++) { if (!prefixes[i].equals(path[i])) { return false; } diff --git a/activemq-core/src/main/java/org/apache/activemq/filter/WildcardDestinationFilter.java b/activemq-core/src/main/java/org/apache/activemq/filter/WildcardDestinationFilter.java index b91b3af8fa..173e8562ac 100755 --- a/activemq-core/src/main/java/org/apache/activemq/filter/WildcardDestinationFilter.java +++ b/activemq-core/src/main/java/org/apache/activemq/filter/WildcardDestinationFilter.java @@ -48,7 +48,7 @@ public class WildcardDestinationFilter extends DestinationFilter { String[] path = DestinationPath.getDestinationPaths(destination); int length = prefixes.length; if (path.length == length) { - for (int i = 0, size = length; i < size; i++) { + for (int i = 0; i < length; i++) { String prefix = prefixes[i]; if (prefix != null && !prefix.equals(path[i])) { return false; diff --git a/activemq-core/src/main/java/org/apache/activemq/jndi/ActiveMQInitialContextFactory.java b/activemq-core/src/main/java/org/apache/activemq/jndi/ActiveMQInitialContextFactory.java index 2d3309b6cf..c47a96d50c 100755 --- a/activemq-core/src/main/java/org/apache/activemq/jndi/ActiveMQInitialContextFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/jndi/ActiveMQInitialContextFactory.java @@ -55,7 +55,7 @@ public class ActiveMQInitialContextFactory implements InitialContextFactory { public Context getInitialContext(Hashtable environment) throws NamingException { // lets create a factory - Map data = new ConcurrentHashMap(); + Map data = new ConcurrentHashMap(); String[] names = getConnectionFactoryNames(environment); for (int i = 0; i < names.length; i++) { ActiveMQConnectionFactory factory = null; @@ -120,7 +120,7 @@ public class ActiveMQInitialContextFactory implements InitialContextFactory { // Implementation methods // ------------------------------------------------------------------------- - protected ReadOnlyContext createContext(Hashtable environment, Map data) { + protected ReadOnlyContext createContext(Hashtable environment, Map data) { return new ReadOnlyContext(environment, data); } @@ -143,7 +143,7 @@ public class ActiveMQInitialContextFactory implements InitialContextFactory { protected String[] getConnectionFactoryNames(Map environment) { String factoryNames = (String)environment.get("connectionFactoryNames"); if (factoryNames != null) { - List list = new ArrayList(); + List list = new ArrayList(); for (StringTokenizer enumeration = new StringTokenizer(factoryNames, ","); enumeration.hasMoreTokens();) { list.add(enumeration.nextToken().trim()); } @@ -157,7 +157,7 @@ public class ActiveMQInitialContextFactory implements InitialContextFactory { return DEFAULT_CONNECTION_FACTORY_NAMES; } - protected void createQueues(Map data, Hashtable environment) { + protected void createQueues(Map data, Hashtable environment) { for (Iterator iter = environment.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry)iter.next(); String key = entry.getKey().toString(); @@ -168,7 +168,7 @@ public class ActiveMQInitialContextFactory implements InitialContextFactory { } } - protected void createTopics(Map data, Hashtable environment) { + protected void createTopics(Map data, Hashtable environment) { for (Iterator iter = environment.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry)iter.next(); String key = entry.getKey().toString(); diff --git a/activemq-core/src/main/java/org/apache/activemq/jndi/ReadOnlyContext.java b/activemq-core/src/main/java/org/apache/activemq/jndi/ReadOnlyContext.java index 7a31539fd9..7386b57371 100755 --- a/activemq-core/src/main/java/org/apache/activemq/jndi/ReadOnlyContext.java +++ b/activemq-core/src/main/java/org/apache/activemq/jndi/ReadOnlyContext.java @@ -59,6 +59,7 @@ import javax.naming.spi.NamingManager; * * @version $Revision: 1.2 $ $Date: 2005/08/27 03:52:39 $ */ +@SuppressWarnings("unchecked") public class ReadOnlyContext implements Context, Serializable { public static final String SEPARATOR = "/"; diff --git a/activemq-core/src/main/java/org/apache/activemq/kaha/StoreFactory.java b/activemq-core/src/main/java/org/apache/activemq/kaha/StoreFactory.java index 2ea9a7678a..5cae714bb6 100755 --- a/activemq-core/src/main/java/org/apache/activemq/kaha/StoreFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/kaha/StoreFactory.java @@ -25,7 +25,10 @@ import org.apache.activemq.kaha.impl.KahaStore; * * @version $Revision: 1.2 $ */ -public class StoreFactory { +public final class StoreFactory { + + private StoreFactory() { + } /** * open or create a Store diff --git a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java index 433ffee164..a470e410ac 100644 --- a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java +++ b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java @@ -53,8 +53,12 @@ import org.apache.commons.logging.LogFactory; public class KahaStore implements Store { private static final String PROPERTY_PREFIX = "org.apache.activemq.kaha.Store"; - private static final boolean BROKEN_FILE_LOCK = "true".equals(System.getProperty(PROPERTY_PREFIX + ".FileLockBroken", "false")); - private static final boolean DISABLE_LOCKING = "true".equals(System.getProperty(PROPERTY_PREFIX + ".DisableLocking", "false")); + private static final boolean BROKEN_FILE_LOCK = "true".equals(System.getProperty(PROPERTY_PREFIX + + ".FileLockBroken", + "false")); + private static final boolean DISABLE_LOCKING = "true".equals(System.getProperty(PROPERTY_PREFIX + + ".DisableLocking", + "false")); private static final Log LOG = LogFactory.getLog(KahaStore.class); @@ -73,7 +77,7 @@ public class KahaStore implements Store { private boolean useAsyncDataManager; private long maxDataFileLength = 1024 * 1024 * 32; private FileLock lock; - private boolean persistentIndex=true; + private boolean persistentIndex = true; private RandomAccessFile lockFile; public KahaStore(String name, String mode) throws IOException { @@ -196,7 +200,8 @@ public class KahaStore implements Store { return getMapContainer(id, containerName, persistentIndex); } - public synchronized MapContainer getMapContainer(Object id, String containerName, boolean persistentIndex) throws IOException { + public synchronized MapContainer getMapContainer(Object id, String containerName, boolean persistentIndex) + throws IOException { initialize(); ContainerId containerId = new ContainerId(); containerId.setKey(id); @@ -264,7 +269,8 @@ public class KahaStore implements Store { return getListContainer(id, containerName, persistentIndex); } - public synchronized ListContainer getListContainer(Object id, String containerName, boolean persistentIndex) throws IOException { + public synchronized ListContainer getListContainer(Object id, String containerName, + boolean persistentIndex) throws IOException { initialize(); ContainerId containerId = new ContainerId(); containerId.setKey(id); @@ -461,13 +467,15 @@ public class KahaStore implements Store { if (!BROKEN_FILE_LOCK) { lock = lockFile.getChannel().tryLock(); if (lock == null) { - throw new StoreLockedExcpetion("Kaha Store " + directory.getName() + " is already opened by another application"); + throw new StoreLockedExcpetion("Kaha Store " + directory.getName() + + " is already opened by another application"); } else { System.setProperty(key, new Date().toString()); } } } else { // already locked - throw new StoreLockedExcpetion("Kaha Store " + directory.getName() + " is already opened by this application."); + throw new StoreLockedExcpetion("Kaha Store " + directory.getName() + + " is already opened by this application."); } } } diff --git a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/BaseContainerImpl.java b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/BaseContainerImpl.java index 34a88f2482..e1f1b767a5 100644 --- a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/BaseContainerImpl.java +++ b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/BaseContainerImpl.java @@ -159,7 +159,7 @@ public abstract class BaseContainerImpl { protected final void doClear() { checkClosed(); loaded = true; - List indexList = new ArrayList(); + List indexList = new ArrayList(); try { init(); long nextItem = root.getNextItem(); @@ -172,7 +172,7 @@ public abstract class BaseContainerImpl { root.setNextItem(Item.POSITION_NOT_SET); storeIndex(root); for (int i = 0; i < indexList.size(); i++) { - IndexItem item = (IndexItem)indexList.get(i); + IndexItem item = indexList.get(i); dataManager.removeInterestInFile(item.getKeyFile()); dataManager.removeInterestInFile(item.getValueFile()); indexManager.freeIndex(item); diff --git a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerEntrySet.java b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerEntrySet.java index 67c1527a97..f9b5868e44 100644 --- a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerEntrySet.java +++ b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerEntrySet.java @@ -71,7 +71,7 @@ public class ContainerEntrySet extends ContainerCollectionSupport implements Set } public boolean retainAll(Collection c) { - List tmpList = new ArrayList(); + List tmpList = new ArrayList(); for (Iterator i = c.iterator(); i.hasNext();) { Object o = i.next(); if (!contains(o)) { @@ -79,7 +79,7 @@ public class ContainerEntrySet extends ContainerCollectionSupport implements Set } } boolean result = false; - for (Iterator i = tmpList.iterator(); i.hasNext();) { + for (Iterator i = tmpList.iterator(); i.hasNext();) { result |= remove(i.next()); } return result; @@ -99,8 +99,8 @@ public class ContainerEntrySet extends ContainerCollectionSupport implements Set container.clear(); } - protected Set buildEntrySet() { - Set set = new HashSet(); + protected Set buildEntrySet() { + Set set = new HashSet(); for (Iterator i = container.keySet().iterator(); i.hasNext();) { ContainerMapEntry entry = new ContainerMapEntry(container, i.next()); set.add(entry); diff --git a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerKeySet.java b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerKeySet.java index 543bd3f639..6a4b0a4e19 100644 --- a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerKeySet.java +++ b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerKeySet.java @@ -44,7 +44,7 @@ public class ContainerKeySet extends ContainerCollectionSupport implements Set { } public Object[] toArray() { - List list = new ArrayList(); + List list = new ArrayList(); IndexItem item = container.getInternalList().getRoot(); while ((item = container.getInternalList().getNextEntry(item)) != null) { list.add(container.getKey(item)); @@ -53,7 +53,7 @@ public class ContainerKeySet extends ContainerCollectionSupport implements Set { } public Object[] toArray(Object[] a) { - List list = new ArrayList(); + List list = new ArrayList(); IndexItem item = container.getInternalList().getRoot(); while ((item = container.getInternalList().getNextEntry(item)) != null) { list.add(container.getKey(item)); @@ -83,14 +83,14 @@ public class ContainerKeySet extends ContainerCollectionSupport implements Set { } public boolean retainAll(Collection c) { - List tmpList = new ArrayList(); + List tmpList = new ArrayList(); for (Iterator i = c.iterator(); i.hasNext();) { Object o = i.next(); if (!contains(o)) { tmpList.add(o); } } - for (Iterator i = tmpList.iterator(); i.hasNext();) { + for (Iterator i = tmpList.iterator(); i.hasNext();) { remove(i.next()); } return !tmpList.isEmpty(); diff --git a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerValueCollection.java b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerValueCollection.java index b68597f41b..1a36dd9d40 100644 --- a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerValueCollection.java +++ b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerValueCollection.java @@ -112,14 +112,14 @@ class ContainerValueCollection extends ContainerCollectionSupport implements Col } public boolean retainAll(Collection c) { - List tmpList = new ArrayList(); + List tmpList = new ArrayList(); for (Iterator i = c.iterator(); i.hasNext();) { Object o = i.next(); if (!contains(o)) { tmpList.add(o); } } - for (Iterator i = tmpList.iterator(); i.hasNext();) { + for (Iterator i = tmpList.iterator(); i.hasNext();) { remove(i.next()); } return !tmpList.isEmpty(); diff --git a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java index 3099ab240b..9aeda1f605 100644 --- a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java +++ b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java @@ -246,7 +246,7 @@ public class ListContainerImpl extends BaseContainerImpl implements ListContaine */ public synchronized Object[] toArray() { load(); - List tmp = new ArrayList(indexList.size()); + List tmp = new ArrayList(indexList.size()); IndexItem next = indexList.getFirst(); while (next != null) { Object value = getValue(next); @@ -263,7 +263,7 @@ public class ListContainerImpl extends BaseContainerImpl implements ListContaine */ public synchronized Object[] toArray(Object[] a) { load(); - List tmp = new ArrayList(indexList.size()); + List tmp = new ArrayList(indexList.size()); IndexItem next = indexList.getFirst(); while (next != null) { Object value = getValue(next); @@ -384,7 +384,7 @@ public class ListContainerImpl extends BaseContainerImpl implements ListContaine */ public synchronized boolean retainAll(Collection c) { load(); - List tmpList = new ArrayList(); + List tmpList = new ArrayList(); IndexItem next = indexList.getFirst(); while (next != null) { Object o = getValue(next); @@ -393,7 +393,7 @@ public class ListContainerImpl extends BaseContainerImpl implements ListContaine } next = indexList.getNextEntry(next); } - for (Iterator i = tmpList.iterator(); i.hasNext();) { + for (Iterator i = tmpList.iterator(); i.hasNext();) { remove(i.next()); } return !tmpList.isEmpty(); @@ -619,9 +619,9 @@ public class ListContainerImpl extends BaseContainerImpl implements ListContaine * * @see java.util.List#subList(int, int) */ - public synchronized List subList(int fromIndex, int toIndex) { + public synchronized List subList(int fromIndex, int toIndex) { load(); - List result = new ArrayList(); + List result = new ArrayList(); int count = fromIndex; IndexItem next = indexList.get(fromIndex); while (next != null && count++ < toIndex) { diff --git a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashBin.java b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashBin.java index efea443a34..f6353b7a60 100644 --- a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashBin.java +++ b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashBin.java @@ -251,15 +251,15 @@ class HashBin { return result; } - private int getInsertPageNo(int index) { - int result = index / maximumEntries; - return result; - } - - private int getOffset(int index) { - int result = index % maximumEntries; - return result; - } +// private int getInsertPageNo(int index) { +// int result = index / maximumEntries; +// return result; +// } +// +// private int getOffset(int index) { +// int result = index % maximumEntries; +// return result; +// } private void doOverFlow(int index) throws IOException { int pageNo = index / maximumEntries; diff --git a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreePage.java b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreePage.java index 3b43e477fc..5fda6f101f 100644 --- a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreePage.java +++ b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreePage.java @@ -34,8 +34,9 @@ import org.apache.commons.logging.LogFactory; * @version $Revision: 1.1.1.1 $ */ class TreePage { - private static final transient Log LOG = LogFactory.getLog(TreePage.class); + static final int PAGE_HEADER_SIZE = 18; + private static final transient Log LOG = LogFactory.getLog(TreePage.class); static enum Flavour { LESS, MORE @@ -193,7 +194,8 @@ class TreePage { void setParentId(long newId) throws IOException { if (newId == this.id) { - throw new IllegalStateException("Cannot set page as a child of itself " + this + " trying to set parentId = " + newId); + throw new IllegalStateException("Cannot set page as a child of itself " + this + + " trying to set parentId = " + newId); } this.parentId = newId; tree.writePage(this); @@ -362,7 +364,7 @@ class TreePage { newRoot.setLeaf(false); this.setParentId(newRoot.getId()); save(); // we are no longer root - need to save - we maybe - // looked up v. soon! + // looked up v. soon! TreePage rightPage = tree.createPage(newRoot.getId()); rightPage.setEntries(subList); rightPage.checkLeaf(); @@ -464,8 +466,8 @@ class TreePage { page.setLeaf(true); } insertTreeEntry(index, copy); - TreePage landed = null;// if we overflow - the page the - // replacement ends up on + // if we overflow - the page the replacement ends up on + TreePage landed = null; TreeEntry removed = null; if (isOverflowed()) { TreePage parent = getParent(); @@ -563,7 +565,8 @@ class TreePage { setLeaf(!result); } - private void checkParentIdForRemovedPageEntry(TreeEntry entry, long oldPageId, long newPageId) throws IOException { + private void checkParentIdForRemovedPageEntry(TreeEntry entry, long oldPageId, long newPageId) + throws IOException { TreePage page = tree.lookupPage(entry.getPrevPageId()); if (page != null && page.getParentId() == oldPageId) { page.setParentId(newPageId); diff --git a/activemq-core/src/main/java/org/apache/activemq/management/JMSConnectionStatsImpl.java b/activemq-core/src/main/java/org/apache/activemq/management/JMSConnectionStatsImpl.java index 273add152a..d13189598c 100755 --- a/activemq-core/src/main/java/org/apache/activemq/management/JMSConnectionStatsImpl.java +++ b/activemq-core/src/main/java/org/apache/activemq/management/JMSConnectionStatsImpl.java @@ -50,7 +50,8 @@ public class JMSConnectionStatsImpl extends StatsImpl { public void reset() { super.reset(); JMSSessionStatsImpl[] stats = getSessions(); - for (int i = 0, size = stats.length; i < size; i++) { + int size = stats.length; + for (int i = 0; i < size; i++) { stats[i].reset(); } } @@ -61,7 +62,8 @@ public class JMSConnectionStatsImpl extends StatsImpl { public void setEnabled(boolean enabled) { super.setEnabled(enabled); JMSSessionStatsImpl[] stats = getSessions(); - for (int i = 0, size = stats.length; i < size; i++) { + int size = stats.length; + for (int i = 0; i < size; i++) { stats[i].setEnabled(enabled); } diff --git a/activemq-core/src/main/java/org/apache/activemq/management/JMSSessionStatsImpl.java b/activemq-core/src/main/java/org/apache/activemq/management/JMSSessionStatsImpl.java index 03f44d706c..eeea9121b9 100755 --- a/activemq-core/src/main/java/org/apache/activemq/management/JMSSessionStatsImpl.java +++ b/activemq-core/src/main/java/org/apache/activemq/management/JMSSessionStatsImpl.java @@ -44,10 +44,14 @@ public class JMSSessionStatsImpl extends StatsImpl { this.messageCount = new CountStatisticImpl("messageCount", "Number of messages exchanged"); this.pendingMessageCount = new CountStatisticImpl("pendingMessageCount", "Number of pending messages"); this.expiredMessageCount = new CountStatisticImpl("expiredMessageCount", "Number of expired messages"); - this.messageWaitTime = new TimeStatisticImpl("messageWaitTime", "Time spent by a message before being delivered"); - this.durableSubscriptionCount = new CountStatisticImpl("durableSubscriptionCount", "The number of durable subscriptions"); - this.messageWaitTime = new TimeStatisticImpl("messageWaitTime", "Time spent by a message before being delivered"); - this.messageRateTime = new TimeStatisticImpl("messageRateTime", "Time taken to process a message (thoughtput rate)"); + this.messageWaitTime = new TimeStatisticImpl("messageWaitTime", + "Time spent by a message before being delivered"); + this.durableSubscriptionCount = new CountStatisticImpl("durableSubscriptionCount", + "The number of durable subscriptions"); + this.messageWaitTime = new TimeStatisticImpl("messageWaitTime", + "Time spent by a message before being delivered"); + this.messageRateTime = new TimeStatisticImpl("messageRateTime", + "Time taken to process a message (thoughtput rate)"); // lets add named stats addStatistic("messageCount", messageCount); @@ -85,11 +89,13 @@ public class JMSSessionStatsImpl extends StatsImpl { public void reset() { super.reset(); JMSConsumerStatsImpl[] cstats = getConsumers(); - for (int i = 0, size = cstats.length; i < size; i++) { + int size = cstats.length; + for (int i = 0; i < size; i++) { cstats[i].reset(); } JMSProducerStatsImpl[] pstats = getProducers(); - for (int i = 0, size = pstats.length; i < size; i++) { + size = pstats.length; + for (int i = 0; i < size; i++) { pstats[i].reset(); } } @@ -100,11 +106,13 @@ public class JMSSessionStatsImpl extends StatsImpl { public void setEnabled(boolean enabled) { super.setEnabled(enabled); JMSConsumerStatsImpl[] cstats = getConsumers(); - for (int i = 0, size = cstats.length; i < size; i++) { + int size = cstats.length; + for (int i = 0; i < size; i++) { cstats[i].setEnabled(enabled); } JMSProducerStatsImpl[] pstats = getProducers(); - for (int i = 0, size = pstats.length; i < size; i++) { + size = pstats.length; + for (int i = 0; i < size; i++) { pstats[i].setEnabled(enabled); } diff --git a/activemq-core/src/main/java/org/apache/activemq/management/JMSStatsImpl.java b/activemq-core/src/main/java/org/apache/activemq/management/JMSStatsImpl.java index 8146fb398e..af8a43d741 100755 --- a/activemq-core/src/main/java/org/apache/activemq/management/JMSStatsImpl.java +++ b/activemq-core/src/main/java/org/apache/activemq/management/JMSStatsImpl.java @@ -28,7 +28,7 @@ import org.apache.activemq.util.IndentPrinter; * @version $Revision: 1.2 $ */ public class JMSStatsImpl extends StatsImpl { - private List connections = new CopyOnWriteArrayList(); + private List connections = new CopyOnWriteArrayList(); public JMSStatsImpl() { } @@ -73,7 +73,8 @@ public class JMSStatsImpl extends StatsImpl { public void setEnabled(boolean enabled) { super.setEnabled(enabled); JMSConnectionStatsImpl[] stats = getConnections(); - for (int i = 0, size = stats.length; i < size; i++) { + int size = stats.length; + for (int i = 0; i < size; i++) { stats[i].setEnabled(enabled); } diff --git a/activemq-core/src/main/java/org/apache/activemq/management/StatisticImpl.java b/activemq-core/src/main/java/org/apache/activemq/management/StatisticImpl.java index 48a04018dc..19d89755c6 100755 --- a/activemq-core/src/main/java/org/apache/activemq/management/StatisticImpl.java +++ b/activemq-core/src/main/java/org/apache/activemq/management/StatisticImpl.java @@ -24,12 +24,14 @@ import javax.management.j2ee.statistics.Statistic; * @version $Revision: 1.2 $ */ public class StatisticImpl implements Statistic, Resettable { + + protected boolean enabled; + private String name; private String unit; private String description; private long startTime; private long lastSampleTime; - protected boolean enabled; public StatisticImpl(String name, String unit, String description) { this.name = name; diff --git a/activemq-core/src/main/java/org/apache/activemq/management/StatsImpl.java b/activemq-core/src/main/java/org/apache/activemq/management/StatsImpl.java index c9985e0e11..ebdd65c17d 100755 --- a/activemq-core/src/main/java/org/apache/activemq/management/StatsImpl.java +++ b/activemq-core/src/main/java/org/apache/activemq/management/StatsImpl.java @@ -29,7 +29,7 @@ public class StatsImpl extends StatisticImpl implements Stats, Resettable { private Map map; public StatsImpl() { - this(new HashMap()); + this(new HashMap()); } public StatsImpl(Map map) { @@ -39,7 +39,8 @@ public class StatsImpl extends StatisticImpl implements Stats, Resettable { public void reset() { Statistic[] stats = getStatistics(); - for (int i = 0, size = stats.length; i < size; i++) { + int size = stats.length; + for (int i = 0; i < size; i++) { Statistic stat = stats[i]; if (stat instanceof Resettable) { Resettable r = (Resettable)stat; diff --git a/activemq-core/src/main/java/org/apache/activemq/memory/LRUMap.java b/activemq-core/src/main/java/org/apache/activemq/memory/LRUMap.java index f320ecb695..a7ec32778c 100755 --- a/activemq-core/src/main/java/org/apache/activemq/memory/LRUMap.java +++ b/activemq-core/src/main/java/org/apache/activemq/memory/LRUMap.java @@ -25,10 +25,10 @@ import java.util.Map; * @version $Revision:$ */ public class LRUMap extends LinkedHashMap { - private static final long serialVersionUID = -9179676638408888162L; protected static final float DEFAULT_LOAD_FACTOR = (float) 0.75; protected static final int DEFAULT_INITIAL_CAPACITY = 5000; + private static final long serialVersionUID = -9179676638408888162L; private int maximumSize; diff --git a/activemq-core/src/main/java/org/apache/activemq/memory/MapCache.java b/activemq-core/src/main/java/org/apache/activemq/memory/MapCache.java index de8d66da5c..6d296d9f2f 100755 --- a/activemq-core/src/main/java/org/apache/activemq/memory/MapCache.java +++ b/activemq-core/src/main/java/org/apache/activemq/memory/MapCache.java @@ -31,7 +31,7 @@ public class MapCache implements Cache { protected final Map map; public MapCache() { - this(new ConcurrentHashMap()); + this(new ConcurrentHashMap()); } public MapCache(Map map) { diff --git a/activemq-core/src/main/java/org/apache/activemq/memory/buffer/MessageQueue.java b/activemq-core/src/main/java/org/apache/activemq/memory/buffer/MessageQueue.java index 7672ee1a55..8398d5a19a 100644 --- a/activemq-core/src/main/java/org/apache/activemq/memory/buffer/MessageQueue.java +++ b/activemq-core/src/main/java/org/apache/activemq/memory/buffer/MessageQueue.java @@ -34,7 +34,7 @@ import org.apache.activemq.command.Message; public class MessageQueue { private MessageBuffer buffer; - private LinkedList list = new LinkedList(); + private LinkedList list = new LinkedList(); private int size; private Object lock = new Object(); private int position; @@ -81,15 +81,15 @@ public class MessageQueue { /** * Returns a copy of the list */ - public List getList() { + public List getList() { synchronized (lock) { - return new ArrayList(list); + return new ArrayList(list); } } - public void appendMessages(List answer) { + public void appendMessages(List answer) { synchronized (lock) { - for (Iterator iter = list.iterator(); iter.hasNext();) { + for (Iterator iter = list.iterator(); iter.hasNext();) { answer.add(iter.next()); } } diff --git a/activemq-core/src/main/java/org/apache/activemq/memory/buffer/OrderBasedMessageBuffer.java b/activemq-core/src/main/java/org/apache/activemq/memory/buffer/OrderBasedMessageBuffer.java index 2a85c8dd75..091ec08651 100644 --- a/activemq-core/src/main/java/org/apache/activemq/memory/buffer/OrderBasedMessageBuffer.java +++ b/activemq-core/src/main/java/org/apache/activemq/memory/buffer/OrderBasedMessageBuffer.java @@ -28,7 +28,7 @@ import java.util.LinkedList; public class OrderBasedMessageBuffer implements MessageBuffer { private int limit = 100 * 64 * 1024; - private LinkedList list = new LinkedList(); + private LinkedList list = new LinkedList(); private int size; private Object lock = new Object(); @@ -63,7 +63,7 @@ public class OrderBasedMessageBuffer implements MessageBuffer { list.addLast(queue); size += delta; while (size > limit) { - MessageQueue biggest = (MessageQueue) list.removeFirst(); + MessageQueue biggest = list.removeFirst(); size -= biggest.evictMessage(); } } @@ -71,8 +71,8 @@ public class OrderBasedMessageBuffer implements MessageBuffer { public void clear() { synchronized (lock) { - for (Iterator iter = list.iterator(); iter.hasNext();) { - MessageQueue queue = (MessageQueue) iter.next(); + for (Iterator iter = list.iterator(); iter.hasNext();) { + MessageQueue queue = iter.next(); queue.clear(); } size = 0; diff --git a/activemq-core/src/main/java/org/apache/activemq/memory/buffer/SizeBasedMessageBuffer.java b/activemq-core/src/main/java/org/apache/activemq/memory/buffer/SizeBasedMessageBuffer.java index b266e634ff..49bf2f5296 100644 --- a/activemq-core/src/main/java/org/apache/activemq/memory/buffer/SizeBasedMessageBuffer.java +++ b/activemq-core/src/main/java/org/apache/activemq/memory/buffer/SizeBasedMessageBuffer.java @@ -28,7 +28,7 @@ import java.util.List; public class SizeBasedMessageBuffer implements MessageBuffer { private int limit = 100 * 64 * 1024; - private List bubbleList = new ArrayList(); + private List bubbleList = new ArrayList(); private int size; private Object lock = new Object(); @@ -69,7 +69,7 @@ public class SizeBasedMessageBuffer implements MessageBuffer { size += delta; while (size > limit) { - MessageQueue biggest = (MessageQueue)bubbleList.get(0); + MessageQueue biggest = bubbleList.get(0); size -= biggest.evictMessage(); bubbleDown(biggest, 0); @@ -79,8 +79,8 @@ public class SizeBasedMessageBuffer implements MessageBuffer { public void clear() { synchronized (lock) { - for (Iterator iter = bubbleList.iterator(); iter.hasNext();) { - MessageQueue queue = (MessageQueue)iter.next(); + for (Iterator iter = bubbleList.iterator(); iter.hasNext();) { + MessageQueue queue = iter.next(); queue.clear(); } size = 0; @@ -91,7 +91,7 @@ public class SizeBasedMessageBuffer implements MessageBuffer { // lets bubble up to head of queueif we need to int position = queue.getPosition(); while (--position >= 0) { - MessageQueue pivot = (MessageQueue)bubbleList.get(position); + MessageQueue pivot = bubbleList.get(position); if (pivot.getSize() < queueSize) { swap(position, pivot, position + 1, queue); } else { @@ -102,8 +102,9 @@ public class SizeBasedMessageBuffer implements MessageBuffer { protected void bubbleDown(MessageQueue biggest, int position) { int queueSize = biggest.getSize(); - for (int second = position + 1, end = bubbleList.size(); second < end; second++) { - MessageQueue pivot = (MessageQueue)bubbleList.get(second); + int end = bubbleList.size(); + for (int second = position + 1; second < end; second++) { + MessageQueue pivot = bubbleList.get(second); if (pivot.getSize() > queueSize) { swap(position, biggest, second, pivot); } else { diff --git a/activemq-core/src/main/java/org/apache/activemq/memory/list/DestinationBasedMessageList.java b/activemq-core/src/main/java/org/apache/activemq/memory/list/DestinationBasedMessageList.java index a812096f02..6e62609ae6 100644 --- a/activemq-core/src/main/java/org/apache/activemq/memory/list/DestinationBasedMessageList.java +++ b/activemq-core/src/main/java/org/apache/activemq/memory/list/DestinationBasedMessageList.java @@ -69,16 +69,16 @@ public class DestinationBasedMessageList implements MessageList { queue.add(node); } - public List getMessages(Subscription sub) { + public List getMessages(Subscription sub) { return getMessages(sub.getConsumerInfo().getDestination()); } - public List getMessages(ActiveMQDestination destination) { + public List getMessages(ActiveMQDestination destination) { Set set = null; synchronized (lock) { set = subscriptionIndex.get(destination); } - List answer = new ArrayList(); + List answer = new ArrayList(); for (Iterator iter = set.iterator(); iter.hasNext();) { MessageQueue queue = (MessageQueue) iter.next(); queue.appendMessages(answer); @@ -87,8 +87,8 @@ public class DestinationBasedMessageList implements MessageList { } public Message[] browse(ActiveMQDestination destination) { - List result = getMessages(destination); - return (Message[])result.toArray(new Message[result.size()]); + List result = getMessages(destination); + return result.toArray(new Message[result.size()]); } diff --git a/activemq-core/src/main/java/org/apache/activemq/memory/list/SimpleMessageList.java b/activemq-core/src/main/java/org/apache/activemq/memory/list/SimpleMessageList.java index 2ba65e6921..30d4339d21 100644 --- a/activemq-core/src/main/java/org/apache/activemq/memory/list/SimpleMessageList.java +++ b/activemq-core/src/main/java/org/apache/activemq/memory/list/SimpleMessageList.java @@ -38,7 +38,7 @@ import org.apache.commons.logging.LogFactory; */ public class SimpleMessageList implements MessageList { private static final Log LOG = LogFactory.getLog(SimpleMessageList.class); - private LinkedList list = new LinkedList(); + private LinkedList list = new LinkedList(); private int maximumSize = 100 * 64 * 1024; private int size; private Object lock = new Object(); @@ -56,22 +56,22 @@ public class SimpleMessageList implements MessageList { list.add(node); size += delta; while (size > maximumSize) { - MessageReference evicted = (MessageReference)list.removeFirst(); + MessageReference evicted = list.removeFirst(); size -= evicted.getMessageHardRef().getSize(); } } } - public List getMessages(ActiveMQDestination destination) { + public List getMessages(ActiveMQDestination destination) { return getList(); } public Message[] browse(ActiveMQDestination destination) { - List result = new ArrayList(); + List result = new ArrayList(); DestinationFilter filter = DestinationFilter.parseFilter(destination); synchronized (lock) { - for (Iterator i = list.iterator(); i.hasNext();) { - MessageReference ref = (MessageReference)i.next(); + for (Iterator i = list.iterator(); i.hasNext();) { + MessageReference ref = i.next(); Message msg; try { msg = ref.getMessage(); @@ -84,15 +84,15 @@ public class SimpleMessageList implements MessageList { } } - return (Message[])result.toArray(new Message[result.size()]); + return result.toArray(new Message[result.size()]); } /** * Returns a copy of the list */ - public List getList() { + public List getList() { synchronized (lock) { - return new ArrayList(list); + return new ArrayList(list); } } diff --git a/activemq-core/src/main/java/org/apache/activemq/network/DemandSubscription.java b/activemq-core/src/main/java/org/apache/activemq/network/DemandSubscription.java index 1667d33a0d..c2fdb2ce79 100644 --- a/activemq-core/src/main/java/org/apache/activemq/network/DemandSubscription.java +++ b/activemq-core/src/main/java/org/apache/activemq/network/DemandSubscription.java @@ -31,7 +31,7 @@ import org.apache.activemq.command.ConsumerInfo; public class DemandSubscription { private ConsumerInfo remoteInfo; private ConsumerInfo localInfo; - private Set remoteSubsIds = new CopyOnWriteArraySet(); + private Set remoteSubsIds = new CopyOnWriteArraySet(); private AtomicInteger dispatched = new AtomicInteger(0); DemandSubscription(ConsumerInfo info) { diff --git a/activemq-core/src/main/java/org/apache/activemq/network/NetworkBridgeFactory.java b/activemq-core/src/main/java/org/apache/activemq/network/NetworkBridgeFactory.java index 8b0f5179ea..4c070dbc05 100644 --- a/activemq-core/src/main/java/org/apache/activemq/network/NetworkBridgeFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/network/NetworkBridgeFactory.java @@ -23,8 +23,11 @@ import org.apache.activemq.transport.Transport; * * @version $Revision: 1.1 $ */ -public class NetworkBridgeFactory { +public final class NetworkBridgeFactory { + private NetworkBridgeFactory() { + } + /** * Create a network bridge * diff --git a/activemq-core/src/main/java/org/apache/activemq/openwire/CommandIdComparator.java b/activemq-core/src/main/java/org/apache/activemq/openwire/CommandIdComparator.java index 419fbd0f71..4a9947bc0b 100644 --- a/activemq-core/src/main/java/org/apache/activemq/openwire/CommandIdComparator.java +++ b/activemq-core/src/main/java/org/apache/activemq/openwire/CommandIdComparator.java @@ -25,14 +25,9 @@ import org.apache.activemq.command.Command; * * @version $Revision$ */ -public class CommandIdComparator implements Comparator { +public class CommandIdComparator implements Comparator { - public int compare(Object o1, Object o2) { - assert o1 instanceof Command; - assert o2 instanceof Command; - - Command c1 = (Command) o1; - Command c2 = (Command) o2; + public int compare(Command c1, Command c2) { return c1.getCommandId() - c2.getCommandId(); } diff --git a/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java b/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java index 5edab743a3..376cb64f11 100755 --- a/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java @@ -35,7 +35,7 @@ public class OpenWireFormatFactory implements WireFormatFactory { private boolean tcpNoDelayEnabled = true; private boolean cacheEnabled = true; private boolean tightEncodingEnabled = true; - private boolean sizePrefixDisabled = false; + private boolean sizePrefixDisabled; private long maxInactivityDuration = 30 * 1000; private int cacheSize = 1024; diff --git a/activemq-core/src/main/java/org/apache/activemq/openwire/v1/BaseDataStreamMarshaller.java b/activemq-core/src/main/java/org/apache/activemq/openwire/v1/BaseDataStreamMarshaller.java index 38d6127531..4d9392472f 100755 --- a/activemq-core/src/main/java/org/apache/activemq/openwire/v1/BaseDataStreamMarshaller.java +++ b/activemq-core/src/main/java/org/apache/activemq/openwire/v1/BaseDataStreamMarshaller.java @@ -282,14 +282,16 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { } } + @SuppressWarnings("deprecation") protected String tightUnmarshalString(DataInput dataIn, BooleanStream bs) throws IOException { if (bs.readBoolean()) { if (bs.readBoolean()) { int size = dataIn.readShort(); byte data[] = new byte[size]; dataIn.readFully(data); - return new String(data, 0); // Yes deprecated, but we know what - // we are doing. + // Yes deprecated, but we know what we are doing. + // This allows us to create a String from a ASCII byte array. (no UTF-8 decoding) + return new String(data, 0); } else { return dataIn.readUTF(); } @@ -305,7 +307,7 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { int strlen = value.length(); int utflen = 0; char[] charr = new char[strlen]; - int c, count = 0; + int c = 0; boolean isOnlyAscii = true; value.getChars(0, strlen, charr, 0); diff --git a/activemq-core/src/main/java/org/apache/activemq/openwire/v1/MarshallerFactory.java b/activemq-core/src/main/java/org/apache/activemq/openwire/v1/MarshallerFactory.java index f75098aaf6..6b4073872f 100755 --- a/activemq-core/src/main/java/org/apache/activemq/openwire/v1/MarshallerFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/openwire/v1/MarshallerFactory.java @@ -28,7 +28,7 @@ import org.apache.activemq.openwire.OpenWireFormat; * * @version $Revision$ */ -public class MarshallerFactory { +public final class MarshallerFactory { /** * Creates a Map of command type -> Marshallers @@ -92,6 +92,9 @@ public class MarshallerFactory { } + private MarshallerFactory() { + } + private static void add(DataStreamMarshaller dsm) { MARSHALLER[dsm.getDataStructureType()] = dsm; } diff --git a/activemq-core/src/main/java/org/apache/activemq/openwire/v2/BaseDataStreamMarshaller.java b/activemq-core/src/main/java/org/apache/activemq/openwire/v2/BaseDataStreamMarshaller.java index 6619b7e0c3..ace7f8727f 100755 --- a/activemq-core/src/main/java/org/apache/activemq/openwire/v2/BaseDataStreamMarshaller.java +++ b/activemq-core/src/main/java/org/apache/activemq/openwire/v2/BaseDataStreamMarshaller.java @@ -282,14 +282,16 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { } } + @SuppressWarnings("deprecation") protected String tightUnmarshalString(DataInput dataIn, BooleanStream bs) throws IOException { if (bs.readBoolean()) { if (bs.readBoolean()) { int size = dataIn.readShort(); byte data[] = new byte[size]; dataIn.readFully(data); - return new String(data, 0); // Yes deprecated, but we know what - // we are doing. + // Yes deprecated, but we know what we are doing. + // This allows us to create a String from a ASCII byte array. (no UTF-8 decoding) + return new String(data, 0); } else { return dataIn.readUTF(); } @@ -305,7 +307,7 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { int strlen = value.length(); int utflen = 0; char[] charr = new char[strlen]; - int c, count = 0; + int c = 0; boolean isOnlyAscii = true; value.getChars(0, strlen, charr, 0); diff --git a/activemq-core/src/main/java/org/apache/activemq/openwire/v2/MarshallerFactory.java b/activemq-core/src/main/java/org/apache/activemq/openwire/v2/MarshallerFactory.java index 4482f15f84..2853c1baca 100644 --- a/activemq-core/src/main/java/org/apache/activemq/openwire/v2/MarshallerFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/openwire/v2/MarshallerFactory.java @@ -31,7 +31,7 @@ import org.apache.activemq.openwire.OpenWireFormat; * * @version $Revision$ */ -public class MarshallerFactory { +public final class MarshallerFactory { /** * Creates a Map of command type -> Marshallers @@ -96,6 +96,9 @@ public class MarshallerFactory { } + private MarshallerFactory() { + } + private static void add(DataStreamMarshaller dsm) { MARSHALLER[dsm.getDataStructureType()] = dsm; } diff --git a/activemq-core/src/main/java/org/apache/activemq/openwire/v3/BaseDataStreamMarshaller.java b/activemq-core/src/main/java/org/apache/activemq/openwire/v3/BaseDataStreamMarshaller.java index 8970e1066a..0480a59132 100644 --- a/activemq-core/src/main/java/org/apache/activemq/openwire/v3/BaseDataStreamMarshaller.java +++ b/activemq-core/src/main/java/org/apache/activemq/openwire/v3/BaseDataStreamMarshaller.java @@ -35,7 +35,8 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { static { Constructor constructor = null; try { - constructor = StackTraceElement.class.getConstructor(new Class[] {String.class, String.class, String.class, int.class}); + constructor = StackTraceElement.class.getConstructor(new Class[] {String.class, String.class, + String.class, int.class}); } catch (Throwable e) { } STACK_TRACE_ELEMENT_CONSTRUCTOR = constructor; @@ -49,10 +50,12 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { return 0; } - public void tightMarshal2(OpenWireFormat wireFormat, Object o, DataOutput dataOut, BooleanStream bs) throws IOException { + public void tightMarshal2(OpenWireFormat wireFormat, Object o, DataOutput dataOut, BooleanStream bs) + throws IOException { } - public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn, BooleanStream bs) throws IOException { + public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn, BooleanStream bs) + throws IOException { } public int tightMarshalLong1(OpenWireFormat wireFormat, long o, BooleanStream bs) throws IOException { @@ -75,7 +78,8 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { } } - public void tightMarshalLong2(OpenWireFormat wireFormat, long o, DataOutput dataOut, BooleanStream bs) throws IOException { + public void tightMarshalLong2(OpenWireFormat wireFormat, long o, DataOutput dataOut, BooleanStream bs) + throws IOException { if (bs.readBoolean()) { if (bs.readBoolean()) { dataOut.writeLong(o); @@ -89,7 +93,8 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { } } - public long tightUnmarshalLong(OpenWireFormat wireFormat, DataInput dataIn, BooleanStream bs) throws IOException { + public long tightUnmarshalLong(OpenWireFormat wireFormat, DataInput dataIn, BooleanStream bs) + throws IOException { if (bs.readBoolean()) { if (bs.readBoolean()) { return dataIn.readLong(); @@ -117,19 +122,23 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { return answer & 0xffffffffL; } - protected DataStructure tightUnmarsalNestedObject(OpenWireFormat wireFormat, DataInput dataIn, BooleanStream bs) throws IOException { + protected DataStructure tightUnmarsalNestedObject(OpenWireFormat wireFormat, DataInput dataIn, + BooleanStream bs) throws IOException { return wireFormat.tightUnmarshalNestedObject(dataIn, bs); } - protected int tightMarshalNestedObject1(OpenWireFormat wireFormat, DataStructure o, BooleanStream bs) throws IOException { + protected int tightMarshalNestedObject1(OpenWireFormat wireFormat, DataStructure o, BooleanStream bs) + throws IOException { return wireFormat.tightMarshalNestedObject1(o, bs); } - protected void tightMarshalNestedObject2(OpenWireFormat wireFormat, DataStructure o, DataOutput dataOut, BooleanStream bs) throws IOException { + protected void tightMarshalNestedObject2(OpenWireFormat wireFormat, DataStructure o, DataOutput dataOut, + BooleanStream bs) throws IOException { wireFormat.tightMarshalNestedObject2(o, dataOut, bs); } - protected DataStructure tightUnmarsalCachedObject(OpenWireFormat wireFormat, DataInput dataIn, BooleanStream bs) throws IOException { + protected DataStructure tightUnmarsalCachedObject(OpenWireFormat wireFormat, DataInput dataIn, + BooleanStream bs) throws IOException { if (wireFormat.isCacheEnabled()) { if (bs.readBoolean()) { short index = dataIn.readShort(); @@ -145,7 +154,8 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { } } - protected int tightMarshalCachedObject1(OpenWireFormat wireFormat, DataStructure o, BooleanStream bs) throws IOException { + protected int tightMarshalCachedObject1(OpenWireFormat wireFormat, DataStructure o, BooleanStream bs) + throws IOException { if (wireFormat.isCacheEnabled()) { Short index = wireFormat.getMarshallCacheIndex(o); bs.writeBoolean(index == null); @@ -161,7 +171,8 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { } } - protected void tightMarshalCachedObject2(OpenWireFormat wireFormat, DataStructure o, DataOutput dataOut, BooleanStream bs) throws IOException { + protected void tightMarshalCachedObject2(OpenWireFormat wireFormat, DataStructure o, DataOutput dataOut, + BooleanStream bs) throws IOException { if (wireFormat.isCacheEnabled()) { Short index = wireFormat.getMarshallCacheIndex(o); if (bs.readBoolean()) { @@ -175,7 +186,8 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { } } - protected Throwable tightUnmarsalThrowable(OpenWireFormat wireFormat, DataInput dataIn, BooleanStream bs) throws IOException { + protected Throwable tightUnmarsalThrowable(OpenWireFormat wireFormat, DataInput dataIn, BooleanStream bs) + throws IOException { if (bs.readBoolean()) { String clazz = tightUnmarshalString(dataIn, bs); String message = tightUnmarshalString(dataIn, bs); @@ -185,10 +197,11 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { StackTraceElement ss[] = new StackTraceElement[dataIn.readShort()]; for (int i = 0; i < ss.length; i++) { try { - ss[i] = (StackTraceElement)STACK_TRACE_ELEMENT_CONSTRUCTOR.newInstance(new Object[] {tightUnmarshalString(dataIn, bs), - tightUnmarshalString(dataIn, bs), - tightUnmarshalString(dataIn, bs), - Integer.valueOf(dataIn.readInt())}); + ss[i] = (StackTraceElement)STACK_TRACE_ELEMENT_CONSTRUCTOR + .newInstance(new Object[] {tightUnmarshalString(dataIn, bs), + tightUnmarshalString(dataIn, bs), + tightUnmarshalString(dataIn, bs), + Integer.valueOf(dataIn.readInt())}); } catch (IOException e) { throw e; } catch (Throwable e) { @@ -223,7 +236,8 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { } } - protected int tightMarshalThrowable1(OpenWireFormat wireFormat, Throwable o, BooleanStream bs) throws IOException { + protected int tightMarshalThrowable1(OpenWireFormat wireFormat, Throwable o, BooleanStream bs) + throws IOException { if (o == null) { bs.writeBoolean(false); return 0; @@ -248,7 +262,8 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { } } - protected void tightMarshalThrowable2(OpenWireFormat wireFormat, Throwable o, DataOutput dataOut, BooleanStream bs) throws IOException { + protected void tightMarshalThrowable2(OpenWireFormat wireFormat, Throwable o, DataOutput dataOut, + BooleanStream bs) throws IOException { if (bs.readBoolean()) { tightMarshalString2(o.getClass().getName(), dataOut, bs); tightMarshalString2(o.getMessage(), dataOut, bs); @@ -267,14 +282,16 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { } } + @SuppressWarnings("deprecation") protected String tightUnmarshalString(DataInput dataIn, BooleanStream bs) throws IOException { if (bs.readBoolean()) { if (bs.readBoolean()) { int size = dataIn.readShort(); byte data[] = new byte[size]; dataIn.readFully(data); - return new String(data, 0); // Yes deprecated, but we know what - // we are doing. + // Yes deprecated, but we know what we are doing. + // This allows us to create a String from a ASCII byte array. (no UTF-8 decoding) + return new String(data, 0); } else { return dataIn.readUTF(); } @@ -290,7 +307,7 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { int strlen = value.length(); int utflen = 0; char[] charr = new char[strlen]; - int c, count = 0; + int c = 0; boolean isOnlyAscii = true; value.getChars(0, strlen, charr, 0); @@ -331,7 +348,8 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { } } - protected int tightMarshalObjectArray1(OpenWireFormat wireFormat, DataStructure[] objects, BooleanStream bs) throws IOException { + protected int tightMarshalObjectArray1(OpenWireFormat wireFormat, DataStructure[] objects, + BooleanStream bs) throws IOException { if (objects != null) { int rc = 0; bs.writeBoolean(true); @@ -346,7 +364,8 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { } } - protected void tightMarshalObjectArray2(OpenWireFormat wireFormat, DataStructure[] objects, DataOutput dataOut, BooleanStream bs) throws IOException { + protected void tightMarshalObjectArray2(OpenWireFormat wireFormat, DataStructure[] objects, + DataOutput dataOut, BooleanStream bs) throws IOException { if (bs.readBoolean()) { dataOut.writeShort(objects.length); for (int i = 0; i < objects.length; i++) { @@ -359,11 +378,13 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { return i; } - protected void tightMarshalConstByteArray2(byte[] data, DataOutput dataOut, BooleanStream bs, int i) throws IOException { + protected void tightMarshalConstByteArray2(byte[] data, DataOutput dataOut, BooleanStream bs, int i) + throws IOException { dataOut.write(data, 0, i); } - protected byte[] tightUnmarshalConstByteArray(DataInput dataIn, BooleanStream bs, int i) throws IOException { + protected byte[] tightUnmarshalConstByteArray(DataInput dataIn, BooleanStream bs, int i) + throws IOException { byte data[] = new byte[i]; dataIn.readFully(data); return data; @@ -378,7 +399,8 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { } } - protected void tightMarshalByteArray2(byte[] data, DataOutput dataOut, BooleanStream bs) throws IOException { + protected void tightMarshalByteArray2(byte[] data, DataOutput dataOut, BooleanStream bs) + throws IOException { if (bs.readBoolean()) { dataOut.writeInt(data.length); dataOut.write(data); @@ -404,7 +426,8 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { } } - protected void tightMarshalByteSequence2(ByteSequence data, DataOutput dataOut, BooleanStream bs) throws IOException { + protected void tightMarshalByteSequence2(ByteSequence data, DataOutput dataOut, BooleanStream bs) + throws IOException { if (bs.readBoolean()) { dataOut.writeInt(data.getLength()); dataOut.write(data.getData(), data.getOffset(), data.getLength()); @@ -440,15 +463,18 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { return dataIn.readLong(); } - protected DataStructure looseUnmarsalNestedObject(OpenWireFormat wireFormat, DataInput dataIn) throws IOException { + protected DataStructure looseUnmarsalNestedObject(OpenWireFormat wireFormat, DataInput dataIn) + throws IOException { return wireFormat.looseUnmarshalNestedObject(dataIn); } - protected void looseMarshalNestedObject(OpenWireFormat wireFormat, DataStructure o, DataOutput dataOut) throws IOException { + protected void looseMarshalNestedObject(OpenWireFormat wireFormat, DataStructure o, DataOutput dataOut) + throws IOException { wireFormat.looseMarshalNestedObject(o, dataOut); } - protected DataStructure looseUnmarsalCachedObject(OpenWireFormat wireFormat, DataInput dataIn) throws IOException { + protected DataStructure looseUnmarsalCachedObject(OpenWireFormat wireFormat, DataInput dataIn) + throws IOException { if (wireFormat.isCacheEnabled()) { if (dataIn.readBoolean()) { short index = dataIn.readShort(); @@ -464,7 +490,8 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { } } - protected void looseMarshalCachedObject(OpenWireFormat wireFormat, DataStructure o, DataOutput dataOut) throws IOException { + protected void looseMarshalCachedObject(OpenWireFormat wireFormat, DataStructure o, DataOutput dataOut) + throws IOException { if (wireFormat.isCacheEnabled()) { Short index = wireFormat.getMarshallCacheIndex(o); dataOut.writeBoolean(index == null); @@ -480,7 +507,8 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { } } - protected Throwable looseUnmarsalThrowable(OpenWireFormat wireFormat, DataInput dataIn) throws IOException { + protected Throwable looseUnmarsalThrowable(OpenWireFormat wireFormat, DataInput dataIn) + throws IOException { if (dataIn.readBoolean()) { String clazz = looseUnmarshalString(dataIn); String message = looseUnmarshalString(dataIn); @@ -490,8 +518,11 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { StackTraceElement ss[] = new StackTraceElement[dataIn.readShort()]; for (int i = 0; i < ss.length; i++) { try { - ss[i] = (StackTraceElement)STACK_TRACE_ELEMENT_CONSTRUCTOR.newInstance(new Object[] {looseUnmarshalString(dataIn), looseUnmarshalString(dataIn), - looseUnmarshalString(dataIn), Integer.valueOf(dataIn.readInt())}); + ss[i] = (StackTraceElement)STACK_TRACE_ELEMENT_CONSTRUCTOR + .newInstance(new Object[] {looseUnmarshalString(dataIn), + looseUnmarshalString(dataIn), + looseUnmarshalString(dataIn), + Integer.valueOf(dataIn.readInt())}); } catch (IOException e) { throw e; } catch (Throwable e) { @@ -516,7 +547,8 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { } } - protected void looseMarshalThrowable(OpenWireFormat wireFormat, Throwable o, DataOutput dataOut) throws IOException { + protected void looseMarshalThrowable(OpenWireFormat wireFormat, Throwable o, DataOutput dataOut) + throws IOException { dataOut.writeBoolean(o != null); if (o != null) { looseMarshalString(o.getClass().getName(), dataOut); @@ -551,7 +583,8 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { } } - protected void looseMarshalObjectArray(OpenWireFormat wireFormat, DataStructure[] objects, DataOutput dataOut) throws IOException { + protected void looseMarshalObjectArray(OpenWireFormat wireFormat, DataStructure[] objects, + DataOutput dataOut) throws IOException { dataOut.writeBoolean(objects != null); if (objects != null) { dataOut.writeShort(objects.length); @@ -561,7 +594,8 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { } } - protected void looseMarshalConstByteArray(OpenWireFormat wireFormat, byte[] data, DataOutput dataOut, int i) throws IOException { + protected void looseMarshalConstByteArray(OpenWireFormat wireFormat, byte[] data, DataOutput dataOut, + int i) throws IOException { dataOut.write(data, 0, i); } @@ -571,7 +605,8 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { return data; } - protected void looseMarshalByteArray(OpenWireFormat wireFormat, byte[] data, DataOutput dataOut) throws IOException { + protected void looseMarshalByteArray(OpenWireFormat wireFormat, byte[] data, DataOutput dataOut) + throws IOException { dataOut.writeBoolean(data != null); if (data != null) { dataOut.writeInt(data.length); @@ -589,7 +624,8 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller { return rc; } - protected void looseMarshalByteSequence(OpenWireFormat wireFormat, ByteSequence data, DataOutput dataOut) throws IOException { + protected void looseMarshalByteSequence(OpenWireFormat wireFormat, ByteSequence data, DataOutput dataOut) + throws IOException { dataOut.writeBoolean(data != null); if (data != null) { dataOut.writeInt(data.getLength()); diff --git a/activemq-core/src/main/java/org/apache/activemq/openwire/v3/MarshallerFactory.java b/activemq-core/src/main/java/org/apache/activemq/openwire/v3/MarshallerFactory.java index 772c7a0a2f..13c136d55c 100644 --- a/activemq-core/src/main/java/org/apache/activemq/openwire/v3/MarshallerFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/openwire/v3/MarshallerFactory.java @@ -31,7 +31,7 @@ import org.apache.activemq.openwire.OpenWireFormat; * * @version $Revision$ */ -public class MarshallerFactory { +public final class MarshallerFactory { /** * Creates a Map of command type -> Marshallers @@ -98,6 +98,9 @@ public class MarshallerFactory { } + private MarshallerFactory() { + } + private static void add(DataStreamMarshaller dsm) { MARSHALLER[dsm.getDataStructureType()] = dsm; } diff --git a/activemq-core/src/main/java/org/apache/activemq/pool/ConnectionPool.java b/activemq-core/src/main/java/org/apache/activemq/pool/ConnectionPool.java index 6bf4f290b9..c598dddbda 100644 --- a/activemq-core/src/main/java/org/apache/activemq/pool/ConnectionPool.java +++ b/activemq-core/src/main/java/org/apache/activemq/pool/ConnectionPool.java @@ -43,7 +43,7 @@ public class ConnectionPool { private TransactionManager transactionManager; private ActiveMQConnection connection; - private Map cache; + private Map cache; private AtomicBoolean started = new AtomicBoolean(false); private int referenceCount; private ObjectPoolFactory poolFactory; @@ -54,7 +54,7 @@ public class ConnectionPool { public ConnectionPool(ActiveMQConnection connection, ObjectPoolFactory poolFactory, TransactionManager transactionManager) { - this(connection, new HashMap(), poolFactory, transactionManager); + this(connection, new HashMap(), poolFactory, transactionManager); // Add a transport Listener so that we can notice if this connection // should be expired due to // a connection failure. @@ -76,7 +76,7 @@ public class ConnectionPool { }); } - public ConnectionPool(ActiveMQConnection connection, Map cache, ObjectPoolFactory poolFactory, + public ConnectionPool(ActiveMQConnection connection, Map cache, ObjectPoolFactory poolFactory, TransactionManager transactionManager) { this.connection = connection; this.cache = cache; @@ -102,7 +102,7 @@ public class ConnectionPool { ackMode = Session.SESSION_TRANSACTED; } SessionKey key = new SessionKey(transacted, ackMode); - SessionPool pool = (SessionPool)cache.get(key); + SessionPool pool = cache.get(key); if (pool == null) { pool = new SessionPool(this, key, poolFactory.createPool()); cache.put(key, pool); @@ -129,9 +129,9 @@ public class ConnectionPool { public synchronized void close() { if (connection != null) { try { - Iterator i = cache.values().iterator(); + Iterator i = cache.values().iterator(); while (i.hasNext()) { - SessionPool pool = (SessionPool)i.next(); + SessionPool pool = i.next(); i.remove(); try { pool.close(); diff --git a/activemq-core/src/main/java/org/apache/activemq/pool/PooledConnectionFactory.java b/activemq-core/src/main/java/org/apache/activemq/pool/PooledConnectionFactory.java index b29c2bf6bd..17e46fb085 100644 --- a/activemq-core/src/main/java/org/apache/activemq/pool/PooledConnectionFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/pool/PooledConnectionFactory.java @@ -47,7 +47,7 @@ import org.apache.commons.pool.impl.GenericObjectPoolFactory; */ public class PooledConnectionFactory implements ConnectionFactory, Service { private ConnectionFactory connectionFactory; - private Map cache = new HashMap(); + private Map> cache = new HashMap>(); private ObjectPoolFactory poolFactory; private int maximumActive = 500; private int maxConnections = 1; @@ -87,16 +87,16 @@ public class PooledConnectionFactory implements ConnectionFactory, Service { public synchronized Connection createConnection(String userName, String password) throws JMSException { ConnectionKey key = new ConnectionKey(userName, password); - LinkedList pools = (LinkedList)cache.get(key); + LinkedList pools = cache.get(key); if (pools == null) { - pools = new LinkedList(); + pools = new LinkedList(); cache.put(key, pools); } ConnectionPool connection = null; if (pools.size() == maxConnections) { - connection = (ConnectionPool)pools.removeFirst(); + connection = pools.removeFirst(); } // Now.. we might get a connection, but it might be that we need to @@ -138,8 +138,8 @@ public class PooledConnectionFactory implements ConnectionFactory, Service { } public void stop() throws Exception { - for (Iterator iter = cache.values().iterator(); iter.hasNext();) { - LinkedList list = (LinkedList)iter.next(); + for (Iterator> iter = cache.values().iterator(); iter.hasNext();) { + LinkedList list = iter.next(); for (Iterator i = list.iterator(); i.hasNext();) { ConnectionPool connection = (ConnectionPool)i.next(); connection.close(); diff --git a/activemq-core/src/main/java/org/apache/activemq/pool/PooledSession.java b/activemq-core/src/main/java/org/apache/activemq/pool/PooledSession.java index 1556138e63..e3b4f95263 100644 --- a/activemq-core/src/main/java/org/apache/activemq/pool/PooledSession.java +++ b/activemq-core/src/main/java/org/apache/activemq/pool/PooledSession.java @@ -63,10 +63,10 @@ public class PooledSession implements TopicSession, QueueSession { private ActiveMQQueueSender queueSender; private ActiveMQTopicPublisher topicPublisher; private boolean transactional = true; - private boolean ignoreClose = false; + private boolean ignoreClose; - private final CopyOnWriteArrayList consumers = new CopyOnWriteArrayList(); - private final CopyOnWriteArrayList browsers = new CopyOnWriteArrayList(); + private final CopyOnWriteArrayList consumers = new CopyOnWriteArrayList(); + private final CopyOnWriteArrayList browsers = new CopyOnWriteArrayList(); public PooledSession(ActiveMQSession aSession, SessionPool sessionPool) { this.session = aSession; @@ -90,14 +90,14 @@ public class PooledSession implements TopicSession, QueueSession { getSession().setMessageListener(null); // Close any consumers and browsers that may have been created. - for (Iterator iter = consumers.iterator(); iter.hasNext();) { - MessageConsumer consumer = (MessageConsumer)iter.next(); + for (Iterator iter = consumers.iterator(); iter.hasNext();) { + MessageConsumer consumer = iter.next(); consumer.close(); } consumers.clear(); - for (Iterator iter = browsers.iterator(); iter.hasNext();) { - QueueBrowser browser = (QueueBrowser)iter.next(); + for (Iterator iter = browsers.iterator(); iter.hasNext();) { + QueueBrowser browser = iter.next(); browser.close(); } browsers.clear(); diff --git a/activemq-core/src/main/java/org/apache/activemq/proxy/ProxyConnector.java b/activemq-core/src/main/java/org/apache/activemq/proxy/ProxyConnector.java index dee313cb3d..228fa2e667 100644 --- a/activemq-core/src/main/java/org/apache/activemq/proxy/ProxyConnector.java +++ b/activemq-core/src/main/java/org/apache/activemq/proxy/ProxyConnector.java @@ -46,8 +46,7 @@ public class ProxyConnector implements Service { private URI remote; private URI localUri; private String name; - - CopyOnWriteArrayList connections = new CopyOnWriteArrayList(); + private CopyOnWriteArrayList connections = new CopyOnWriteArrayList(); public void start() throws Exception { @@ -77,9 +76,9 @@ public class ProxyConnector implements Service { if (this.server != null) { ss.stop(this.server); } - for (Iterator iter = connections.iterator(); iter.hasNext();) { + for (Iterator iter = connections.iterator(); iter.hasNext();) { LOG.info("Connector stopped: Stopping proxy."); - ss.stop((Service)iter.next()); + ss.stop(iter.next()); } ss.throwFirstException(); LOG.info("Proxy Connector " + getName() + " Stopped"); diff --git a/activemq-core/src/main/java/org/apache/activemq/security/AuthorizationBroker.java b/activemq-core/src/main/java/org/apache/activemq/security/AuthorizationBroker.java index 2b0fb2f4b9..02723b1ecf 100644 --- a/activemq-core/src/main/java/org/apache/activemq/security/AuthorizationBroker.java +++ b/activemq-core/src/main/java/org/apache/activemq/security/AuthorizationBroker.java @@ -54,7 +54,7 @@ public class AuthorizationBroker extends BrokerFilter implements SecurityAdminMB // if(!((ActiveMQTempDestination)destination).getConnectionId().equals(context.getConnectionId().getValue()) // ) { if (!securityContext.isBrokerContext()) { - Set allowedACLs = null; + Set allowedACLs = null; if (!destination.isTemporary()) { allowedACLs = authorizationMap.getAdminACLs(destination); } else { @@ -77,7 +77,7 @@ public class AuthorizationBroker extends BrokerFilter implements SecurityAdminMB if (securityContext == null) { throw new SecurityException("User is not authenticated."); } - Set allowedACLs = null; + Set allowedACLs = null; if (!destination.isTemporary()) { allowedACLs = authorizationMap.getAdminACLs(destination); } else { @@ -96,7 +96,7 @@ public class AuthorizationBroker extends BrokerFilter implements SecurityAdminMB if (subject == null) { throw new SecurityException("User is not authenticated."); } - Set allowedACLs = null; + Set allowedACLs = null; if (!info.getDestination().isTemporary()) { allowedACLs = authorizationMap.getReadACLs(info.getDestination()); } else { @@ -140,7 +140,7 @@ public class AuthorizationBroker extends BrokerFilter implements SecurityAdminMB } if (info.getDestination() != null) { - Set allowedACLs = null; + Set allowedACLs = null; if (!info.getDestination().isTemporary()) { allowedACLs = authorizationMap.getWriteACLs(info.getDestination()); } else { @@ -162,7 +162,7 @@ public class AuthorizationBroker extends BrokerFilter implements SecurityAdminMB } if (!subject.getAuthorizedWriteDests().contains(messageSend.getDestination())) { - Set allowedACLs = null; + Set allowedACLs = null; if (!messageSend.getDestination().isTemporary()) { allowedACLs = authorizationMap.getWriteACLs(messageSend.getDestination()); } else { diff --git a/activemq-core/src/main/java/org/apache/activemq/security/AuthorizationEntry.java b/activemq-core/src/main/java/org/apache/activemq/security/AuthorizationEntry.java index 39cd0039e0..e7b60c5d41 100644 --- a/activemq-core/src/main/java/org/apache/activemq/security/AuthorizationEntry.java +++ b/activemq-core/src/main/java/org/apache/activemq/security/AuthorizationEntry.java @@ -35,13 +35,13 @@ import org.apache.activemq.filter.DestinationMapEntry; */ public class AuthorizationEntry extends DestinationMapEntry { - private Set readACLs = Collections.EMPTY_SET; - private Set writeACLs = Collections.EMPTY_SET; - private Set adminACLs = Collections.EMPTY_SET; + private Set readACLs = emptySet(); + private Set writeACLs = emptySet(); + private Set adminACLs = emptySet(); - private String adminRoles = null; - private String readRoles = null; - private String writeRoles = null; + private String adminRoles; + private String readRoles; + private String writeRoles; private String groupClass = "org.apache.activemq.jaas.GroupPrincipal"; @@ -49,31 +49,36 @@ public class AuthorizationEntry extends DestinationMapEntry { return groupClass; } + @SuppressWarnings("unchecked") + private Set emptySet() { + return Collections.EMPTY_SET; + } + public void setGroupClass(String groupClass) { this.groupClass = groupClass; } - public Set getAdminACLs() { + public Set getAdminACLs() { return adminACLs; } - public void setAdminACLs(Set adminACLs) { + public void setAdminACLs(Set adminACLs) { this.adminACLs = adminACLs; } - public Set getReadACLs() { + public Set getReadACLs() { return readACLs; } - public void setReadACLs(Set readACLs) { + public void setReadACLs(Set readACLs) { this.readACLs = readACLs; } - public Set getWriteACLs() { + public Set getWriteACLs() { return writeACLs; } - public void setWriteACLs(Set writeACLs) { + public void setWriteACLs(Set writeACLs) { this.writeACLs = writeACLs; } @@ -100,8 +105,8 @@ public class AuthorizationEntry extends DestinationMapEntry { setWriteACLs(parseACLs(writeRoles)); } - protected Set parseACLs(String roles) throws Exception { - Set answer = new HashSet(); + protected Set parseACLs(String roles) throws Exception { + Set answer = new HashSet(); StringTokenizer iter = new StringTokenizer(roles, ","); while (iter.hasMoreTokens()) { String name = iter.nextToken().trim(); diff --git a/activemq-core/src/main/java/org/apache/activemq/security/AuthorizationMap.java b/activemq-core/src/main/java/org/apache/activemq/security/AuthorizationMap.java index 9f7ea266c3..2a1ddaf626 100644 --- a/activemq-core/src/main/java/org/apache/activemq/security/AuthorizationMap.java +++ b/activemq-core/src/main/java/org/apache/activemq/security/AuthorizationMap.java @@ -28,33 +28,33 @@ public interface AuthorizationMap { /** * Returns the set of all ACLs capable of administering temp destination */ - Set getTempDestinationAdminACLs(); + Set getTempDestinationAdminACLs(); /** * Returns the set of all ACLs capable of reading from temp destination */ - Set getTempDestinationReadACLs(); + Set getTempDestinationReadACLs(); /** * Returns the set of all ACLs capable of writing to temp destination */ - Set getTempDestinationWriteACLs(); + Set getTempDestinationWriteACLs(); /** * Returns the set of all ACLs capable of administering the given * destination */ - Set getAdminACLs(ActiveMQDestination destination); + Set getAdminACLs(ActiveMQDestination destination); /** * Returns the set of all ACLs capable of reading (consuming from) the given * destination */ - Set getReadACLs(ActiveMQDestination destination); + Set getReadACLs(ActiveMQDestination destination); /** * Returns the set of all ACLs capable of writing to the given destination */ - Set getWriteACLs(ActiveMQDestination destination); + Set getWriteACLs(ActiveMQDestination destination); } diff --git a/activemq-core/src/main/java/org/apache/activemq/security/DefaultAuthorizationMap.java b/activemq-core/src/main/java/org/apache/activemq/security/DefaultAuthorizationMap.java index 4d25dce64e..60da06a063 100644 --- a/activemq-core/src/main/java/org/apache/activemq/security/DefaultAuthorizationMap.java +++ b/activemq-core/src/main/java/org/apache/activemq/security/DefaultAuthorizationMap.java @@ -55,7 +55,7 @@ public class DefaultAuthorizationMap extends DestinationMap implements Authoriza return this.tempDestinationAuthorizationEntry; } - public Set getTempDestinationAdminACLs() { + public Set getTempDestinationAdminACLs() { if (tempDestinationAuthorizationEntry != null) { return tempDestinationAuthorizationEntry.getAdminACLs(); } else { @@ -63,7 +63,7 @@ public class DefaultAuthorizationMap extends DestinationMap implements Authoriza } } - public Set getTempDestinationReadACLs() { + public Set getTempDestinationReadACLs() { if (tempDestinationAuthorizationEntry != null) { return tempDestinationAuthorizationEntry.getReadACLs(); } else { @@ -71,7 +71,7 @@ public class DefaultAuthorizationMap extends DestinationMap implements Authoriza } } - public Set getTempDestinationWriteACLs() { + public Set getTempDestinationWriteACLs() { if (tempDestinationAuthorizationEntry != null) { return tempDestinationAuthorizationEntry.getWriteACLs(); } else { @@ -79,36 +79,36 @@ public class DefaultAuthorizationMap extends DestinationMap implements Authoriza } } - public Set getAdminACLs(ActiveMQDestination destination) { - Set entries = getAllEntries(destination); - Set answer = new HashSet(); + public Set getAdminACLs(ActiveMQDestination destination) { + Set entries = getAllEntries(destination); + Set answer = new HashSet(); // now lets go through each entry adding individual - for (Iterator iter = entries.iterator(); iter.hasNext();) { - AuthorizationEntry entry = (AuthorizationEntry)iter.next(); + for (Iterator iter = entries.iterator(); iter.hasNext();) { + AuthorizationEntry entry = iter.next(); answer.addAll(entry.getAdminACLs()); } return answer; } - public Set getReadACLs(ActiveMQDestination destination) { - Set entries = getAllEntries(destination); - Set answer = new HashSet(); + public Set getReadACLs(ActiveMQDestination destination) { + Set entries = getAllEntries(destination); + Set answer = new HashSet(); // now lets go through each entry adding individual - for (Iterator iter = entries.iterator(); iter.hasNext();) { - AuthorizationEntry entry = (AuthorizationEntry)iter.next(); + for (Iterator iter = entries.iterator(); iter.hasNext();) { + AuthorizationEntry entry = iter.next(); answer.addAll(entry.getReadACLs()); } return answer; } - public Set getWriteACLs(ActiveMQDestination destination) { - Set entries = getAllEntries(destination); - Set answer = new HashSet(); + public Set getWriteACLs(ActiveMQDestination destination) { + Set entries = getAllEntries(destination); + Set answer = new HashSet(); // now lets go through each entry adding individual - for (Iterator iter = entries.iterator(); iter.hasNext();) { - AuthorizationEntry entry = (AuthorizationEntry)iter.next(); + for (Iterator iter = entries.iterator(); iter.hasNext();) { + AuthorizationEntry entry = iter.next(); answer.addAll(entry.getWriteACLs()); } return answer; @@ -139,12 +139,12 @@ public class DefaultAuthorizationMap extends DestinationMap implements Authoriza this.defaultEntry = defaultEntry; } - protected Class getEntryClass() { + protected Class getEntryClass() { return AuthorizationEntry.class; } - protected Set getAllEntries(ActiveMQDestination destination) { - Set entries = get(destination); + protected Set getAllEntries(ActiveMQDestination destination) { + Set entries = get(destination); if (defaultEntry != null) { entries.add(defaultEntry); } diff --git a/activemq-core/src/main/java/org/apache/activemq/security/JaasAuthenticationBroker.java b/activemq-core/src/main/java/org/apache/activemq/security/JaasAuthenticationBroker.java index 18cdc2d9ce..aeab9942d2 100644 --- a/activemq-core/src/main/java/org/apache/activemq/security/JaasAuthenticationBroker.java +++ b/activemq-core/src/main/java/org/apache/activemq/security/JaasAuthenticationBroker.java @@ -16,6 +16,7 @@ */ package org.apache.activemq.security; +import java.security.Principal; import java.util.Iterator; import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; @@ -37,7 +38,7 @@ import org.apache.activemq.jaas.JassCredentialCallbackHandler; public class JaasAuthenticationBroker extends BrokerFilter { private final String jassConfiguration; - private final CopyOnWriteArrayList securityContexts = new CopyOnWriteArrayList(); + private final CopyOnWriteArrayList securityContexts = new CopyOnWriteArrayList(); public JaasAuthenticationBroker(Broker next, String jassConfiguration) { super(next); @@ -53,7 +54,7 @@ public class JaasAuthenticationBroker extends BrokerFilter { this.subject = subject; } - public Set getPrincipals() { + public Set getPrincipals() { return subject.getPrincipals(); } @@ -102,8 +103,8 @@ public class JaasAuthenticationBroker extends BrokerFilter { * Refresh all the logged into users. */ public void refresh() { - for (Iterator iter = securityContexts.iterator(); iter.hasNext();) { - SecurityContext sc = (SecurityContext)iter.next(); + for (Iterator iter = securityContexts.iterator(); iter.hasNext();) { + SecurityContext sc = iter.next(); sc.getAuthorizedReadDests().clear(); sc.getAuthorizedWriteDests().clear(); } diff --git a/activemq-core/src/main/java/org/apache/activemq/security/JaasCertificateSecurityContext.java b/activemq-core/src/main/java/org/apache/activemq/security/JaasCertificateSecurityContext.java index c589255c34..abf246a3f1 100644 --- a/activemq-core/src/main/java/org/apache/activemq/security/JaasCertificateSecurityContext.java +++ b/activemq-core/src/main/java/org/apache/activemq/security/JaasCertificateSecurityContext.java @@ -17,6 +17,7 @@ package org.apache.activemq.security; +import java.security.Principal; import java.security.cert.X509Certificate; import java.util.Set; @@ -38,7 +39,7 @@ public class JaasCertificateSecurityContext extends SecurityContext { this.certs = certs; } - public Set getPrincipals() { + public Set getPrincipals() { return subject.getPrincipals(); } diff --git a/activemq-core/src/main/java/org/apache/activemq/security/LDAPAuthorizationMap.java b/activemq-core/src/main/java/org/apache/activemq/security/LDAPAuthorizationMap.java index 6d035de702..647602eeb1 100755 --- a/activemq-core/src/main/java/org/apache/activemq/security/LDAPAuthorizationMap.java +++ b/activemq-core/src/main/java/org/apache/activemq/security/LDAPAuthorizationMap.java @@ -47,8 +47,6 @@ import org.apache.commons.logging.LogFactory; */ public class LDAPAuthorizationMap implements AuthorizationMap { - private static Log log = LogFactory.getLog(LDAPLoginModule.class); - public static final String INITIAL_CONTEXT_FACTORY = "initialContextFactory"; public static final String CONNECTION_URL = "connectionURL"; public static final String CONNECTION_USERNAME = "connectionUsername"; @@ -68,6 +66,8 @@ public class LDAPAuthorizationMap implements AuthorizationMap { public static final String WRITE_BASE = "writeBAse"; public static final String WRITE_ATTRIBUTE = "writeAttribute"; + private static final Log LOG = LogFactory.getLog(LDAPLoginModule.class); + private String initialContextFactory; private String connectionURL; private String connectionUsername; @@ -135,31 +135,30 @@ public class LDAPAuthorizationMap implements AuthorizationMap { queueSearchSubtreeBool = Boolean.valueOf(queueSearchSubtree).booleanValue(); } - public Set getTempDestinationAdminACLs() { - // TODO insert implementation - - return null; - } - - public Set getTempDestinationReadACLs() { + public Set getTempDestinationAdminACLs() { // TODO insert implementation return null; } - public Set getTempDestinationWriteACLs() { + public Set getTempDestinationReadACLs() { // TODO insert implementation return null; } - public Set getAdminACLs(ActiveMQDestination destination) { + public Set getTempDestinationWriteACLs() { + // TODO insert implementation + return null; + } + + public Set getAdminACLs(ActiveMQDestination destination) { return getACLs(destination, adminBase, adminAttribute); } - public Set getReadACLs(ActiveMQDestination destination) { + public Set getReadACLs(ActiveMQDestination destination) { return getACLs(destination, readBase, readAttribute); } - public Set getWriteACLs(ActiveMQDestination destination) { + public Set getWriteACLs(ActiveMQDestination destination) { return getACLs(destination, writeBase, writeAttribute); } @@ -304,12 +303,12 @@ public class LDAPAuthorizationMap implements AuthorizationMap { // Implementation methods // ------------------------------------------------------------------------- - protected Set getACLs(ActiveMQDestination destination, String roleBase, String roleAttribute) { + protected Set getACLs(ActiveMQDestination destination, String roleBase, String roleAttribute) { try { context = open(); } catch (NamingException e) { - log.error(e); - return new HashSet(); + LOG.error(e); + return new HashSet(); } // if ((destination.getDestinationType() & @@ -340,8 +339,8 @@ public class LDAPAuthorizationMap implements AuthorizationMap { constraints.setReturningAttributes(new String[] {roleAttribute}); try { - Set roles = new HashSet(); - Set acls = new HashSet(); + Set roles = new HashSet(); + Set acls = new HashSet(); NamingEnumeration results = context.search(destinationBase, roleBase, constraints); while (results.hasMore()) { SearchResult result = (SearchResult)results.next(); @@ -351,23 +350,23 @@ public class LDAPAuthorizationMap implements AuthorizationMap { } acls = addAttributeValues(roleAttribute, attrs, acls); } - for (Iterator iter = acls.iterator(); iter.hasNext();) { - String roleName = (String)iter.next(); + for (Iterator iter = acls.iterator(); iter.hasNext();) { + String roleName = iter.next(); roles.add(new GroupPrincipal(roleName)); } return roles; } catch (NamingException e) { - log.error(e); - return new HashSet(); + LOG.error(e); + return new HashSet(); } } - protected Set addAttributeValues(String attrId, Attributes attrs, Set values) throws NamingException { + protected Set addAttributeValues(String attrId, Attributes attrs, Set values) throws NamingException { if (attrId == null || attrs == null) { return values; } if (values == null) { - values = new HashSet(); + values = new HashSet(); } Attribute attr = attrs.get(attrId); if (attr == null) { @@ -387,7 +386,7 @@ public class LDAPAuthorizationMap implements AuthorizationMap { } try { - Hashtable env = new Hashtable(); + Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory); if (connectionUsername != null || !"".equals(connectionUsername)) { env.put(Context.SECURITY_PRINCIPAL, connectionUsername); @@ -401,7 +400,7 @@ public class LDAPAuthorizationMap implements AuthorizationMap { context = new InitialDirContext(env); } catch (NamingException e) { - log.error(e); + LOG.error(e); throw e; } return context; diff --git a/activemq-core/src/main/java/org/apache/activemq/security/SecurityContext.java b/activemq-core/src/main/java/org/apache/activemq/security/SecurityContext.java index 9632c6ce81..40f8057f21 100644 --- a/activemq-core/src/main/java/org/apache/activemq/security/SecurityContext.java +++ b/activemq-core/src/main/java/org/apache/activemq/security/SecurityContext.java @@ -21,6 +21,8 @@ import java.util.HashSet; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import org.apache.activemq.command.ActiveMQDestination; + /** * Used to cache up authorizations so that subsequent requests are faster. * @@ -34,37 +36,38 @@ public abstract class SecurityContext { return true; } - public Set getPrincipals() { + @SuppressWarnings("unchecked") + public Set getPrincipals() { return Collections.EMPTY_SET; } }; final String userName; - final ConcurrentHashMap authorizedReadDests = new ConcurrentHashMap(); - final ConcurrentHashMap authorizedWriteDests = new ConcurrentHashMap(); + final ConcurrentHashMap authorizedReadDests = new ConcurrentHashMap(); + final ConcurrentHashMap authorizedWriteDests = new ConcurrentHashMap(); public SecurityContext(String userName) { this.userName = userName; } - public boolean isInOneOf(Set allowedPrincipals) { - HashSet set = new HashSet(getPrincipals()); + public boolean isInOneOf(Set allowedPrincipals) { + HashSet set = new HashSet(getPrincipals()); set.retainAll(allowedPrincipals); return set.size() > 0; } - public abstract Set getPrincipals(); + public abstract Set getPrincipals(); public String getUserName() { return userName; } - public ConcurrentHashMap getAuthorizedReadDests() { + public ConcurrentHashMap getAuthorizedReadDests() { return authorizedReadDests; } - public ConcurrentHashMap getAuthorizedWriteDests() { + public ConcurrentHashMap getAuthorizedWriteDests() { return authorizedWriteDests; } diff --git a/activemq-core/src/main/java/org/apache/activemq/security/SimpleAuthenticationBroker.java b/activemq-core/src/main/java/org/apache/activemq/security/SimpleAuthenticationBroker.java index cb149569b8..b687412c11 100644 --- a/activemq-core/src/main/java/org/apache/activemq/security/SimpleAuthenticationBroker.java +++ b/activemq-core/src/main/java/org/apache/activemq/security/SimpleAuthenticationBroker.java @@ -54,7 +54,7 @@ public class SimpleAuthenticationBroker extends BrokerFilter { final Set groups = (Set)userGroups.get(info.getUserName()); SecurityContext s = new SecurityContext(info.getUserName()) { - public Set getPrincipals() { + public Set getPrincipals() { return groups; } }; diff --git a/activemq-core/src/main/java/org/apache/activemq/security/SimpleAuthorizationMap.java b/activemq-core/src/main/java/org/apache/activemq/security/SimpleAuthorizationMap.java index 6904af7553..d3d0056eff 100644 --- a/activemq-core/src/main/java/org/apache/activemq/security/SimpleAuthorizationMap.java +++ b/activemq-core/src/main/java/org/apache/activemq/security/SimpleAuthorizationMap.java @@ -63,7 +63,7 @@ public class SimpleAuthorizationMap implements AuthorizationMap { return this.tempDestinationAuthorizationEntry; } - public Set getTempDestinationAdminACLs() { + public Set getTempDestinationAdminACLs() { if (tempDestinationAuthorizationEntry != null) { return tempDestinationAuthorizationEntry.getAdminACLs(); } else { @@ -71,7 +71,7 @@ public class SimpleAuthorizationMap implements AuthorizationMap { } } - public Set getTempDestinationReadACLs() { + public Set getTempDestinationReadACLs() { if (tempDestinationAuthorizationEntry != null) { return tempDestinationAuthorizationEntry.getReadACLs(); } else { @@ -79,7 +79,7 @@ public class SimpleAuthorizationMap implements AuthorizationMap { } } - public Set getTempDestinationWriteACLs() { + public Set getTempDestinationWriteACLs() { if (tempDestinationAuthorizationEntry != null) { return tempDestinationAuthorizationEntry.getWriteACLs(); } else { @@ -87,15 +87,18 @@ public class SimpleAuthorizationMap implements AuthorizationMap { } } - public Set getAdminACLs(ActiveMQDestination destination) { + @SuppressWarnings("unchecked") + public Set getAdminACLs(ActiveMQDestination destination) { return adminACLs.get(destination); } - public Set getReadACLs(ActiveMQDestination destination) { + @SuppressWarnings("unchecked") + public Set getReadACLs(ActiveMQDestination destination) { return readACLs.get(destination); } - public Set getWriteACLs(ActiveMQDestination destination) { + @SuppressWarnings("unchecked") + public Set getWriteACLs(ActiveMQDestination destination) { return writeACLs.get(destination); } diff --git a/activemq-core/src/main/java/org/apache/activemq/state/ProducerState.java b/activemq-core/src/main/java/org/apache/activemq/state/ProducerState.java index 07ee9fea82..f63368ba09 100755 --- a/activemq-core/src/main/java/org/apache/activemq/state/ProducerState.java +++ b/activemq-core/src/main/java/org/apache/activemq/state/ProducerState.java @@ -21,7 +21,6 @@ import org.apache.activemq.command.ProducerInfo; public class ProducerState { final ProducerInfo info; - private long lastSequenceId = -1; public ProducerState(ProducerInfo info) { this.info = info; diff --git a/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQTopicMessageStore.java b/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQTopicMessageStore.java index bcdf528581..62d27c2bfa 100644 --- a/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQTopicMessageStore.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQTopicMessageStore.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.io.InterruptedIOException; import java.util.HashMap; import java.util.Iterator; +import java.util.Map; import org.apache.activemq.broker.ConnectionContext; import org.apache.activemq.command.ActiveMQTopic; @@ -45,7 +46,7 @@ public class AMQTopicMessageStore extends AMQMessageStore implements TopicMessag private static final Log LOG = LogFactory.getLog(AMQTopicMessageStore.class); private TopicReferenceStore topicReferenceStore; - private HashMap ackedLastAckLocations = new HashMap(); + private Map ackedLastAckLocations = new HashMap(); public AMQTopicMessageStore(AMQPersistenceAdapter adapter, TopicReferenceStore topicReferenceStore, ActiveMQTopic destinationName) { super(adapter, topicReferenceStore, destinationName); @@ -157,7 +158,7 @@ public class AMQTopicMessageStore extends AMQMessageStore implements TopicMessag @Override protected Location doAsyncWrite() throws IOException { - final HashMap cpAckedLastAckLocations; + final Map cpAckedLastAckLocations; // swap out the hash maps.. synchronized (this) { cpAckedLastAckLocations = this.ackedLastAckLocations; diff --git a/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQTx.java b/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQTx.java index dfb0e88855..dcab20a861 100644 --- a/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQTx.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQTx.java @@ -19,6 +19,8 @@ package org.apache.activemq.store.amq; import java.util.ArrayList; import java.util.Iterator; +import java.util.List; + import org.apache.activemq.command.JournalTopicAck; import org.apache.activemq.command.Message; import org.apache.activemq.command.MessageAck; @@ -34,7 +36,7 @@ import org.apache.activemq.kaha.impl.async.Location; public class AMQTx { private final Location location; - private ArrayList operations = new ArrayList(); + private List operations = new ArrayList(); public AMQTx(Location location) { this.location = location; @@ -56,7 +58,7 @@ public class AMQTx { } public Message[] getMessages() { - ArrayList list = new ArrayList(); + List list = new ArrayList(); for (Iterator iter = operations.iterator(); iter.hasNext();) { AMQTxOperation op = iter.next(); if (op.getOperationType() == AMQTxOperation.ADD_OPERATION_TYPE) { @@ -69,7 +71,7 @@ public class AMQTx { } public MessageAck[] getAcks() { - ArrayList list = new ArrayList(); + List list = new ArrayList(); for (Iterator iter = operations.iterator(); iter.hasNext();) { AMQTxOperation op = iter.next(); if (op.getOperationType() == AMQTxOperation.REMOVE_OPERATION_TYPE) { @@ -88,11 +90,11 @@ public class AMQTx { return this.location; } - public ArrayList getOperations() { + public List getOperations() { return operations; } - public void setOperations(ArrayList operations) { + public void setOperations(List operations) { this.operations = operations; } } diff --git a/activemq-core/src/main/java/org/apache/activemq/store/amq/RecoveryListenerAdapter.java b/activemq-core/src/main/java/org/apache/activemq/store/amq/RecoveryListenerAdapter.java index 4a5edd2eb2..bb7af38c36 100644 --- a/activemq-core/src/main/java/org/apache/activemq/store/amq/RecoveryListenerAdapter.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/amq/RecoveryListenerAdapter.java @@ -28,7 +28,7 @@ final class RecoveryListenerAdapter implements MessageRecoveryListener { private static final Log LOG = LogFactory.getLog(RecoveryListenerAdapter.class); private final MessageStore store; private final MessageRecoveryListener listener; - private int count = 0; + private int count; private MessageId lastRecovered; RecoveryListenerAdapter(MessageStore store, MessageRecoveryListener listener) { diff --git a/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCAdapter.java b/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCAdapter.java index a93c316353..e12ab5a69d 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCAdapter.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCAdapter.java @@ -68,7 +68,7 @@ public interface JDBCAdapter { long doGetLastMessageBrokerSequenceId(TransactionContext c) throws SQLException, IOException; - Set doGetDestinations(TransactionContext c) throws SQLException, IOException; + Set doGetDestinations(TransactionContext c) throws SQLException, IOException; void setUseExternalMessageReferences(boolean useExternalMessageReferences); diff --git a/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java b/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java index e10f91ec92..ca12022c8e 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java @@ -31,6 +31,7 @@ import javax.sql.DataSource; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerServiceAware; import org.apache.activemq.broker.ConnectionContext; +import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQTopic; import org.apache.activemq.memory.UsageManager; @@ -76,7 +77,7 @@ public class JDBCPersistenceAdapter extends DataSourceSupport implements Persist private int cleanupPeriod = 1000 * 60 * 5; private boolean useExternalMessageReferences; private boolean useDatabaseLock = true; - private int lockKeepAlivePeriod = 0; + private int lockKeepAlivePeriod; private DatabaseLocker databaseLocker; private boolean createTablesOnStartup = true; @@ -88,17 +89,17 @@ public class JDBCPersistenceAdapter extends DataSourceSupport implements Persist this.wireFormat = wireFormat; } - public Set getDestinations() { + public Set getDestinations() { // Get a connection and insert the message into the DB. TransactionContext c = null; try { c = getTransactionContext(); return getAdapter().doGetDestinations(c); } catch (IOException e) { - return Collections.EMPTY_SET; + return emptyDestinationSet(); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); - return Collections.EMPTY_SET; + return emptyDestinationSet(); } finally { if (c != null) { try { @@ -109,6 +110,11 @@ public class JDBCPersistenceAdapter extends DataSourceSupport implements Persist } } + @SuppressWarnings("unchecked") + private Set emptyDestinationSet() { + return Collections.EMPTY_SET; + } + public MessageStore createQueueMessageStore(ActiveMQQueue destination) throws IOException { MessageStore rc = new JDBCMessageStore(this, getAdapter(), wireFormat, destination); if (transactionStore != null) { diff --git a/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCTopicMessageStore.java b/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCTopicMessageStore.java index 34ba54be0d..2daa612703 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCTopicMessageStore.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCTopicMessageStore.java @@ -38,7 +38,7 @@ import org.apache.activemq.wireformat.WireFormat; */ public class JDBCTopicMessageStore extends JDBCMessageStore implements TopicMessageStore { - private Map subscriberLastMessageMap = new ConcurrentHashMap(); + private Map subscriberLastMessageMap = new ConcurrentHashMap(); public JDBCTopicMessageStore(JDBCPersistenceAdapter persistenceAdapter, JDBCAdapter adapter, WireFormat wireFormat, ActiveMQTopic topic) { super(persistenceAdapter, adapter, wireFormat, topic); @@ -89,7 +89,7 @@ public class JDBCTopicMessageStore extends JDBCMessageStore implements TopicMess throws Exception { TransactionContext c = persistenceAdapter.getTransactionContext(); String subcriberId = getSubscriptionKey(clientId, subscriptionName); - AtomicLong last = (AtomicLong)subscriberLastMessageMap.get(subcriberId); + AtomicLong last = subscriberLastMessageMap.get(subcriberId); if (last == null) { long lastAcked = adapter.doGetLastAckedDurableSubscriberMessageId(c, destination, clientId, subscriptionName); last = new AtomicLong(lastAcked); diff --git a/activemq-core/src/main/java/org/apache/activemq/store/jdbc/Statements.java b/activemq-core/src/main/java/org/apache/activemq/store/jdbc/Statements.java index c056543ddc..265408c352 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/jdbc/Statements.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/jdbc/Statements.java @@ -24,20 +24,18 @@ package org.apache.activemq.store.jdbc; */ public class Statements { - private String tablePrefix = ""; protected String messageTableName = "ACTIVEMQ_MSGS"; protected String durableSubAcksTableName = "ACTIVEMQ_ACKS"; protected String lockTableName = "ACTIVEMQ_LOCK"; - protected String binaryDataType = "BLOB"; protected String containerNameDataType = "VARCHAR(250)"; protected String msgIdDataType = "VARCHAR(250)"; protected String sequenceDataType = "INTEGER"; protected String longDataType = "BIGINT"; protected String stringIdDataType = "VARCHAR(250)"; + protected boolean useExternalMessageReferences; - protected boolean useExternalMessageReferences = false; - + private String tablePrefix = ""; private String addMessageStatement; private String updateMessageStatement; private String removeMessageStatment; @@ -96,7 +94,7 @@ public class Statements { public String[] getDropSchemaStatements() { if (dropSchemaStatements == null) { dropSchemaStatements = new String[] {"DROP TABLE " + getFullAckTableName() + "", - "DROP TABLE " + getFullMessageTableName() + "",}; + "DROP TABLE " + getFullMessageTableName() + ""}; } return dropSchemaStatements; } diff --git a/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/DefaultJDBCAdapter.java b/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/DefaultJDBCAdapter.java index c2eae01d16..69f89ea9f4 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/DefaultJDBCAdapter.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/DefaultJDBCAdapter.java @@ -90,7 +90,7 @@ public class DefaultJDBCAdapter implements JDBCAdapter { // created already. try { LOG.debug("Executing SQL: " + createStatments[i]); - boolean rc = s.execute(createStatments[i]); + s.execute(createStatments[i]); } catch (SQLException e) { if (alreadyExists) { LOG.debug("Could not create JDBC tables; The message table already existed." @@ -122,7 +122,7 @@ public class DefaultJDBCAdapter implements JDBCAdapter { // This will fail usually since the tables will be // created already. try { - boolean rc = s.execute(dropStatments[i]); + s.execute(dropStatments[i]); } catch (SQLException e) { LOG.warn("Could not drop JDBC tables; they may not exist." + " Failure was: " + dropStatments[i] + " Message: " + e.getMessage() + " SQLState: " @@ -515,7 +515,7 @@ public class DefaultJDBCAdapter implements JDBCAdapter { s = c.getConnection().prepareStatement(statements.getFindAllDurableSubsStatement()); s.setString(1, destination.getQualifiedName()); rs = s.executeQuery(); - ArrayList rc = new ArrayList(); + ArrayList rc = new ArrayList(); while (rs.next()) { SubscriptionInfo subscription = new SubscriptionInfo(); subscription.setDestination(destination); @@ -526,7 +526,7 @@ public class DefaultJDBCAdapter implements JDBCAdapter { .createDestination(rs.getString(4), ActiveMQDestination.QUEUE_TYPE)); rc.add(subscription); } - return (SubscriptionInfo[])rc.toArray(new SubscriptionInfo[rc.size()]); + return rc.toArray(new SubscriptionInfo[rc.size()]); } finally { close(rs); close(s); @@ -616,17 +616,15 @@ public class DefaultJDBCAdapter implements JDBCAdapter { } } - public Set doGetDestinations(TransactionContext c) throws SQLException, IOException { - HashSet rc = new HashSet(); + public Set doGetDestinations(TransactionContext c) throws SQLException, IOException { + HashSet rc = new HashSet(); PreparedStatement s = null; ResultSet rs = null; try { s = c.getConnection().prepareStatement(statements.getFindAllDestinationsStatement()); rs = s.executeQuery(); while (rs.next()) { - rc - .add(ActiveMQDestination.createDestination(rs.getString(1), - ActiveMQDestination.QUEUE_TYPE)); + rc.add(ActiveMQDestination.createDestination(rs.getString(1), ActiveMQDestination.QUEUE_TYPE)); } } finally { close(rs); diff --git a/activemq-core/src/main/java/org/apache/activemq/store/journal/JournalMessageStore.java b/activemq-core/src/main/java/org/apache/activemq/store/journal/JournalMessageStore.java index e46c05d5fe..fc09cbe2d8 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/journal/JournalMessageStore.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/journal/JournalMessageStore.java @@ -234,6 +234,7 @@ public class JournalMessageStore implements MessageStore { * @return * @throws IOException */ + @SuppressWarnings("unchecked") public RecordLocation checkpoint(final Callback postCheckpointTest) throws IOException { final List cpRemovedMessageLocations; diff --git a/activemq-core/src/main/java/org/apache/activemq/store/journal/JournalPersistenceAdapter.java b/activemq-core/src/main/java/org/apache/activemq/store/journal/JournalPersistenceAdapter.java index 5afc168a9e..3aed5c939b 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/journal/JournalPersistenceAdapter.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/journal/JournalPersistenceAdapter.java @@ -86,12 +86,12 @@ public class JournalPersistenceAdapter implements PersistenceAdapter, JournalEve private final WireFormat wireFormat = new OpenWireFormat(); - private final ConcurrentHashMap queues = new ConcurrentHashMap(); - private final ConcurrentHashMap topics = new ConcurrentHashMap(); + private final ConcurrentHashMap queues = new ConcurrentHashMap(); + private final ConcurrentHashMap topics = new ConcurrentHashMap(); private UsageManager usageManager; - long checkpointInterval = 1000 * 60 * 5; - long lastCheckpointRequest = System.currentTimeMillis(); + private long checkpointInterval = 1000 * 60 * 5; + private long lastCheckpointRequest = System.currentTimeMillis(); private long lastCleanup = System.currentTimeMillis(); private int maxCheckpointWorkers = 10; private int maxCheckpointMessageAddSize = 1024 * 1024; @@ -107,20 +107,6 @@ public class JournalPersistenceAdapter implements PersistenceAdapter, JournalEve private final Runnable periodicCheckpointTask = createPeriodicCheckpointTask(); - final Runnable createPeriodicCheckpointTask() { - return new Runnable() { - public void run() { - long lastTime = 0; - synchronized (this) { - lastTime = lastCheckpointRequest; - } - if (System.currentTimeMillis() > lastTime + checkpointInterval) { - checkpoint(false, true); - } - } - }; - } - public JournalPersistenceAdapter(Journal journal, PersistenceAdapter longTermPersistence, TaskRunnerFactory taskRunnerFactory) throws IOException { this.journal = journal; @@ -135,6 +121,20 @@ public class JournalPersistenceAdapter implements PersistenceAdapter, JournalEve this.longTermPersistence = longTermPersistence; } + final Runnable createPeriodicCheckpointTask() { + return new Runnable() { + public void run() { + long lastTime = 0; + synchronized (this) { + lastTime = lastCheckpointRequest; + } + if (System.currentTimeMillis() > lastTime + checkpointInterval) { + checkpoint(false, true); + } + } + }; + } + /** * @param usageManager The UsageManager that is controlling the * destination's memory usage. @@ -144,8 +144,8 @@ public class JournalPersistenceAdapter implements PersistenceAdapter, JournalEve longTermPersistence.setUsageManager(usageManager); } - public Set getDestinations() { - Set destinations = new HashSet(longTermPersistence.getDestinations()); + public Set getDestinations() { + Set destinations = new HashSet(longTermPersistence.getDestinations()); destinations.addAll(queues.keySet()); destinations.addAll(topics.keySet()); return destinations; @@ -160,7 +160,7 @@ public class JournalPersistenceAdapter implements PersistenceAdapter, JournalEve } public MessageStore createQueueMessageStore(ActiveMQQueue destination) throws IOException { - JournalMessageStore store = (JournalMessageStore)queues.get(destination); + JournalMessageStore store = queues.get(destination); if (store == null) { MessageStore checkpointStore = longTermPersistence.createQueueMessageStore(destination); store = new JournalMessageStore(this, checkpointStore, destination); @@ -170,7 +170,7 @@ public class JournalPersistenceAdapter implements PersistenceAdapter, JournalEve } public TopicMessageStore createTopicMessageStore(ActiveMQTopic destinationName) throws IOException { - JournalTopicMessageStore store = (JournalTopicMessageStore)topics.get(destinationName); + JournalTopicMessageStore store = topics.get(destinationName); if (store == null) { TopicMessageStore checkpointStore = longTermPersistence.createTopicMessageStore(destinationName); store = new JournalTopicMessageStore(this, checkpointStore, destinationName); @@ -204,7 +204,7 @@ public class JournalPersistenceAdapter implements PersistenceAdapter, JournalEve return; } - checkpointExecutor = new ThreadPoolExecutor(maxCheckpointWorkers, maxCheckpointWorkers, 30, TimeUnit.SECONDS, new LinkedBlockingQueue(), new ThreadFactory() { + checkpointExecutor = new ThreadPoolExecutor(maxCheckpointWorkers, maxCheckpointWorkers, 30, TimeUnit.SECONDS, new LinkedBlockingQueue(), new ThreadFactory() { public Thread newThread(Runnable runable) { Thread t = new Thread(runable, "Journal checkpoint worker"); t.setPriority(7); @@ -343,7 +343,7 @@ public class JournalPersistenceAdapter implements PersistenceAdapter, JournalEve LOG.debug("Checkpoint started."); RecordLocation newMark = null; - ArrayList futureTasks = new ArrayList(queues.size() + topics.size()); + ArrayList> futureTasks = new ArrayList>(queues.size() + topics.size()); // // We do many partial checkpoints (fullCheckpoint==false) to move @@ -357,12 +357,12 @@ public class JournalPersistenceAdapter implements PersistenceAdapter, JournalEve // checkpoint queues on the fullCheckpoint cycles. // if (fullCheckpoint) { - Iterator iterator = queues.values().iterator(); + Iterator iterator = queues.values().iterator(); while (iterator.hasNext()) { try { - final JournalMessageStore ms = (JournalMessageStore)iterator.next(); - FutureTask task = new FutureTask(new Callable() { - public Object call() throws Exception { + final JournalMessageStore ms = iterator.next(); + FutureTask task = new FutureTask(new Callable() { + public RecordLocation call() throws Exception { return ms.checkpoint(); } }); @@ -374,12 +374,12 @@ public class JournalPersistenceAdapter implements PersistenceAdapter, JournalEve } } - Iterator iterator = topics.values().iterator(); + Iterator iterator = topics.values().iterator(); while (iterator.hasNext()) { try { - final JournalTopicMessageStore ms = (JournalTopicMessageStore)iterator.next(); - FutureTask task = new FutureTask(new Callable() { - public Object call() throws Exception { + final JournalTopicMessageStore ms = iterator.next(); + FutureTask task = new FutureTask(new Callable() { + public RecordLocation call() throws Exception { return ms.checkpoint(); } }); @@ -391,9 +391,9 @@ public class JournalPersistenceAdapter implements PersistenceAdapter, JournalEve } try { - for (Iterator iter = futureTasks.iterator(); iter.hasNext();) { - FutureTask ft = (FutureTask)iter.next(); - RecordLocation mark = (RecordLocation)ft.get(); + for (Iterator> iter = futureTasks.iterator(); iter.hasNext();) { + FutureTask ft = iter.next(); + RecordLocation mark = ft.get(); // We only set a newMark on full checkpoints. if (fullCheckpoint) { if (mark != null && (newMark == null || newMark.compareTo(mark) < 0)) { diff --git a/activemq-core/src/main/java/org/apache/activemq/store/journal/JournalPersistenceAdapterFactory.java b/activemq-core/src/main/java/org/apache/activemq/store/journal/JournalPersistenceAdapterFactory.java index 62f30eddb9..d13d915325 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/journal/JournalPersistenceAdapterFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/journal/JournalPersistenceAdapterFactory.java @@ -48,9 +48,9 @@ public class JournalPersistenceAdapterFactory extends DataSourceSupport implemen private TaskRunnerFactory taskRunnerFactory; private Journal journal; private boolean useJournal = true; - private boolean useQuickJournal = false; + private boolean useQuickJournal; private File journalArchiveDirectory; - private boolean failIfJournalIsLocked = false; + private boolean failIfJournalIsLocked; private int journalThreadPriority = Thread.MAX_PRIORITY; private JDBCPersistenceAdapter jdbcPersistenceAdapter = new JDBCPersistenceAdapter(); diff --git a/activemq-core/src/main/java/org/apache/activemq/store/journal/JournalTopicMessageStore.java b/activemq-core/src/main/java/org/apache/activemq/store/journal/JournalTopicMessageStore.java index f4a4822439..86d6616058 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/journal/JournalTopicMessageStore.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/journal/JournalTopicMessageStore.java @@ -45,7 +45,7 @@ public class JournalTopicMessageStore extends JournalMessageStore implements Top private static final Log LOG = LogFactory.getLog(JournalTopicMessageStore.class); private TopicMessageStore longTermStore; - private HashMap ackedLastAckLocations = new HashMap(); + private HashMap ackedLastAckLocations = new HashMap(); public JournalTopicMessageStore(JournalPersistenceAdapter adapter, TopicMessageStore checkpointStore, ActiveMQTopic destinationName) { @@ -160,22 +160,22 @@ public class JournalTopicMessageStore extends JournalMessageStore implements Top public RecordLocation checkpoint() throws IOException { - final HashMap cpAckedLastAckLocations; + final HashMap cpAckedLastAckLocations; // swap out the hash maps.. synchronized (this) { cpAckedLastAckLocations = this.ackedLastAckLocations; - this.ackedLastAckLocations = new HashMap(); + this.ackedLastAckLocations = new HashMap(); } return super.checkpoint(new Callback() { public void execute() throws Exception { // Checkpoint the acknowledged messages. - Iterator iterator = cpAckedLastAckLocations.keySet().iterator(); + Iterator iterator = cpAckedLastAckLocations.keySet().iterator(); while (iterator.hasNext()) { - SubscriptionKey subscriptionKey = (SubscriptionKey)iterator.next(); - MessageId identity = (MessageId)cpAckedLastAckLocations.get(subscriptionKey); + SubscriptionKey subscriptionKey = iterator.next(); + MessageId identity = cpAckedLastAckLocations.get(subscriptionKey); longTermStore.acknowledge(transactionTemplate.getContext(), subscriptionKey.clientId, subscriptionKey.subscriptionName, identity); } diff --git a/activemq-core/src/main/java/org/apache/activemq/store/journal/JournalTransactionStore.java b/activemq-core/src/main/java/org/apache/activemq/store/journal/JournalTransactionStore.java index 6f61881853..fe6f30bf60 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/journal/JournalTransactionStore.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/journal/JournalTransactionStore.java @@ -40,8 +40,8 @@ import org.apache.activemq.store.TransactionStore; public class JournalTransactionStore implements TransactionStore { private final JournalPersistenceAdapter peristenceAdapter; - Map inflightTransactions = new LinkedHashMap(); - Map preparedTransactions = new LinkedHashMap(); + private Map inflightTransactions = new LinkedHashMap(); + private Map preparedTransactions = new LinkedHashMap(); private boolean doingRecover; public static class TxOperation { @@ -70,7 +70,7 @@ public class JournalTransactionStore implements TransactionStore { public static class Tx { private final RecordLocation location; - private ArrayList operations = new ArrayList(); + private ArrayList operations = new ArrayList(); public Tx(RecordLocation location) { this.location = location; @@ -89,9 +89,9 @@ public class JournalTransactionStore implements TransactionStore { } public Message[] getMessages() { - ArrayList list = new ArrayList(); - for (Iterator iter = operations.iterator(); iter.hasNext();) { - TxOperation op = (TxOperation)iter.next(); + ArrayList list = new ArrayList(); + for (Iterator iter = operations.iterator(); iter.hasNext();) { + TxOperation op = iter.next(); if (op.operationType == TxOperation.ADD_OPERATION_TYPE) { list.add(op.data); } @@ -102,9 +102,9 @@ public class JournalTransactionStore implements TransactionStore { } public MessageAck[] getAcks() { - ArrayList list = new ArrayList(); - for (Iterator iter = operations.iterator(); iter.hasNext();) { - TxOperation op = (TxOperation)iter.next(); + ArrayList list = new ArrayList(); + for (Iterator iter = operations.iterator(); iter.hasNext();) { + TxOperation op = iter.next(); if (op.operationType == TxOperation.REMOVE_OPERATION_TYPE) { list.add(op.data); } @@ -114,7 +114,7 @@ public class JournalTransactionStore implements TransactionStore { return rc; } - public ArrayList getOperations() { + public ArrayList getOperations() { return operations; } @@ -131,7 +131,7 @@ public class JournalTransactionStore implements TransactionStore { public void prepare(TransactionId txid) throws IOException { Tx tx = null; synchronized (inflightTransactions) { - tx = (Tx)inflightTransactions.remove(txid); + tx = inflightTransactions.remove(txid); } if (tx == null) { return; @@ -150,7 +150,7 @@ public class JournalTransactionStore implements TransactionStore { public void replayPrepare(TransactionId txid) throws IOException { Tx tx = null; synchronized (inflightTransactions) { - tx = (Tx)inflightTransactions.remove(txid); + tx = inflightTransactions.remove(txid); } if (tx == null) { return; @@ -163,7 +163,7 @@ public class JournalTransactionStore implements TransactionStore { public Tx getTx(Object txid, RecordLocation location) { Tx tx = null; synchronized (inflightTransactions) { - tx = (Tx)inflightTransactions.get(txid); + tx = inflightTransactions.get(txid); } if (tx == null) { tx = new Tx(location); @@ -180,11 +180,11 @@ public class JournalTransactionStore implements TransactionStore { Tx tx; if (wasPrepared) { synchronized (preparedTransactions) { - tx = (Tx)preparedTransactions.remove(txid); + tx = preparedTransactions.remove(txid); } } else { synchronized (inflightTransactions) { - tx = (Tx)inflightTransactions.remove(txid); + tx = inflightTransactions.remove(txid); } } if (tx == null) { @@ -206,11 +206,11 @@ public class JournalTransactionStore implements TransactionStore { public Tx replayCommit(TransactionId txid, boolean wasPrepared) throws IOException { if (wasPrepared) { synchronized (preparedTransactions) { - return (Tx)preparedTransactions.remove(txid); + return preparedTransactions.remove(txid); } } else { synchronized (inflightTransactions) { - return (Tx)inflightTransactions.remove(txid); + return inflightTransactions.remove(txid); } } } @@ -222,11 +222,11 @@ public class JournalTransactionStore implements TransactionStore { public void rollback(TransactionId txid) throws IOException { Tx tx = null; synchronized (inflightTransactions) { - tx = (Tx)inflightTransactions.remove(txid); + tx = inflightTransactions.remove(txid); } if (tx != null) { synchronized (preparedTransactions) { - tx = (Tx)preparedTransactions.remove(txid); + tx = preparedTransactions.remove(txid); } } if (tx != null) { @@ -269,13 +269,13 @@ public class JournalTransactionStore implements TransactionStore { } this.doingRecover = true; try { - Map txs = null; + Map txs = null; synchronized (preparedTransactions) { - txs = new LinkedHashMap(preparedTransactions); + txs = new LinkedHashMap(preparedTransactions); } - for (Iterator iter = txs.keySet().iterator(); iter.hasNext();) { - Object txid = (Object)iter.next(); - Tx tx = (Tx)txs.get(txid); + for (Iterator iter = txs.keySet().iterator(); iter.hasNext();) { + Object txid = iter.next(); + Tx tx = txs.get(txid); listener.recover((XATransactionId)txid, tx.getMessages(), tx.getAcks()); } } finally { @@ -316,8 +316,8 @@ public class JournalTransactionStore implements TransactionStore { // roll over active tx records. RecordLocation rc = null; synchronized (inflightTransactions) { - for (Iterator iter = inflightTransactions.values().iterator(); iter.hasNext();) { - Tx tx = (Tx)iter.next(); + for (Iterator iter = inflightTransactions.values().iterator(); iter.hasNext();) { + Tx tx = iter.next(); RecordLocation location = tx.location; if (rc == null || rc.compareTo(location) < 0) { rc = location; @@ -325,8 +325,8 @@ public class JournalTransactionStore implements TransactionStore { } } synchronized (preparedTransactions) { - for (Iterator iter = preparedTransactions.values().iterator(); iter.hasNext();) { - Tx tx = (Tx)iter.next(); + for (Iterator iter = preparedTransactions.values().iterator(); iter.hasNext();) { + Tx tx = iter.next(); RecordLocation location = tx.location; if (rc == null || rc.compareTo(location) < 0) { rc = location; diff --git a/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaMessageStore.java b/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaMessageStore.java index c0037bad47..f66935936f 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaMessageStore.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaMessageStore.java @@ -38,7 +38,7 @@ public class KahaMessageStore implements MessageStore { protected final ActiveMQDestination destination; protected final MapContainer messageContainer; - protected StoreEntry batchEntry = null; + protected StoreEntry batchEntry; public KahaMessageStore(MapContainer container, ActiveMQDestination destination) throws IOException { diff --git a/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaPersistenceAdapter.java b/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaPersistenceAdapter.java index cb1ea12fef..a586f05b4f 100644 --- a/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaPersistenceAdapter.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaPersistenceAdapter.java @@ -50,19 +50,20 @@ import org.apache.commons.logging.LogFactory; /** * @org.apache.xbean.XBean - * * @version $Revision: 1.4 $ */ public class KahaPersistenceAdapter implements PersistenceAdapter { private static final int STORE_LOCKED_WAIT_DELAY = 10 * 1000; private static final Log LOG = LogFactory.getLog(KahaPersistenceAdapter.class); - static final String PREPARED_TRANSACTIONS_NAME = "PreparedTransactions"; - KahaTransactionStore transactionStore; - ConcurrentHashMap topics = new ConcurrentHashMap(); - ConcurrentHashMap queues = new ConcurrentHashMap(); - ConcurrentHashMap messageStores = new ConcurrentHashMap(); + private static final String PREPARED_TRANSACTIONS_NAME = "PreparedTransactions"; + protected OpenWireFormat wireFormat = new OpenWireFormat(); + protected KahaTransactionStore transactionStore; + protected ConcurrentHashMap topics = new ConcurrentHashMap(); + protected ConcurrentHashMap queues = new ConcurrentHashMap(); + protected ConcurrentHashMap messageStores = new ConcurrentHashMap(); + private long maxDataFileLength = 32 * 1024 * 1024; private File directory; private String brokerName; @@ -198,10 +199,10 @@ public class KahaPersistenceAdapter implements PersistenceAdapter { return container; } - protected MapContainer getSubsMapContainer(Object id, String containerName) + protected MapContainer getSubsMapContainer(Object id, String containerName) throws IOException { Store store = getStore(); - MapContainer container = store.getMapContainer(id, containerName); + MapContainer container = store.getMapContainer(id, containerName); container.setKeyMarshaller(Store.STRING_MARSHALLER); container.setValueMarshaller(createMessageMarshaller()); container.load(); @@ -236,7 +237,6 @@ public class KahaPersistenceAdapter implements PersistenceAdapter { /** * @param maxDataFileLength the maxDataFileLength to set - * * @org.apache.xbean.Property propertyEditor="org.apache.activemq.util.MemoryPropertyEditor" */ public void setMaxDataFileLength(long maxDataFileLength) { diff --git a/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaReferenceStore.java b/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaReferenceStore.java index 338cfdbbb6..c0865d4168 100644 --- a/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaReferenceStore.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaReferenceStore.java @@ -33,10 +33,10 @@ public class KahaReferenceStore implements ReferenceStore { protected final ActiveMQDestination destination; protected final MapContainer messageContainer; protected KahaReferenceStoreAdapter adapter; - private StoreEntry batchEntry = null; - private String lastBatchId = null; + private StoreEntry batchEntry; + private String lastBatchId; - public KahaReferenceStore(KahaReferenceStoreAdapter adapter, MapContainer container, + public KahaReferenceStore(KahaReferenceStoreAdapter adapter, MapContainer container, ActiveMQDestination destination) throws IOException { this.adapter = adapter; this.messageContainer = container; diff --git a/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaReferenceStoreAdapter.java b/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaReferenceStoreAdapter.java index 99c9e350cc..092cad175e 100644 --- a/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaReferenceStoreAdapter.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaReferenceStoreAdapter.java @@ -53,9 +53,9 @@ public class KahaReferenceStoreAdapter extends KahaPersistenceAdapter implements private static final String RECORD_REFERENCES = "record-references"; private static final String TRANSACTIONS = "transactions-state"; private MapContainer stateMap; - private MapContainer preparedTransactions; + private MapContainer preparedTransactions; private Map recordReferences = new HashMap(); - private ListContainer durableSubscribers; + private ListContainer durableSubscribers; private boolean storeValid; private Store stateStore; @@ -130,9 +130,8 @@ public class KahaReferenceStoreAdapter extends KahaPersistenceAdapter implements if (rc == null) { Store store = getStore(); MapContainer messageContainer = getMapReferenceContainer(destination, "topic-data"); - MapContainer subsContainer = getSubsMapContainer(destination.toString() + "-Subscriptions", - "blob"); - ListContainer ackContainer = store.getListContainer(destination.toString(), "topic-acks"); + MapContainer subsContainer = getSubsMapContainer(destination.toString() + "-Subscriptions", "blob"); + ListContainer ackContainer = store.getListContainer(destination.toString(), "topic-acks"); ackContainer.setMarshaller(new TopicSubAckMarshaller()); rc = new KahaTopicReferenceStore(store, this, messageContainer, ackContainer, subsContainer, destination); @@ -212,8 +211,8 @@ public class KahaReferenceStoreAdapter extends KahaPersistenceAdapter implements * @see org.apache.activemq.store.ReferenceStoreAdapter#recoverState() */ public void recoverState() throws IOException { - for (Iterator i = durableSubscribers.iterator(); i.hasNext();) { - SubscriptionInfo info = (SubscriptionInfo)i.next(); + for (Iterator i = durableSubscribers.iterator(); i.hasNext();) { + SubscriptionInfo info = i.next(); TopicReferenceStore ts = createTopicReferenceStore((ActiveMQTopic)info.getDestination()); ts.addSubsciption(info, false); } @@ -222,9 +221,9 @@ public class KahaReferenceStoreAdapter extends KahaPersistenceAdapter implements public Map retrievePreparedState() throws IOException { Map result = new HashMap(); preparedTransactions.load(); - for (Iterator i = preparedTransactions.keySet().iterator(); i.hasNext();) { - TransactionId key = (TransactionId)i.next(); - AMQTx value = (AMQTx)preparedTransactions.get(key); + for (Iterator i = preparedTransactions.keySet().iterator(); i.hasNext();) { + TransactionId key = i.next(); + AMQTx value = preparedTransactions.get(key); result.put(key, value); } return result; diff --git a/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaTopicMessageStore.java b/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaTopicMessageStore.java index ce477657d8..61a45affe2 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaTopicMessageStore.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaTopicMessageStore.java @@ -39,19 +39,19 @@ import org.apache.activemq.store.TopicMessageStore; public class KahaTopicMessageStore extends KahaMessageStore implements TopicMessageStore { protected ListContainer ackContainer; - private Map subscriberContainer; + protected Map subscriberMessages = new ConcurrentHashMap(); + private Map subscriberContainer; private Store store; - protected Map subscriberMessages = new ConcurrentHashMap(); - public KahaTopicMessageStore(Store store, MapContainer messageContainer, - ListContainer ackContainer, MapContainer subsContainer, + public KahaTopicMessageStore(Store store, MapContainer messageContainer, + ListContainer ackContainer, MapContainer subsContainer, ActiveMQDestination destination) throws IOException { super(messageContainer, destination); this.store = store; this.ackContainer = ackContainer; subscriberContainer = subsContainer; // load all the Ack containers - for (Iterator i = subscriberContainer.keySet().iterator(); i.hasNext();) { + for (Iterator i = subscriberContainer.keySet().iterator(); i.hasNext();) { Object key = i.next(); addSubscriberMessageContainer(key); } @@ -67,8 +67,8 @@ public class KahaTopicMessageStore extends KahaMessageStore implements TopicMess tsa.setCount(subscriberCount); tsa.setMessageEntry(messageEntry); StoreEntry ackEntry = ackContainer.placeLast(tsa); - for (Iterator i = subscriberMessages.values().iterator(); i.hasNext();) { - TopicSubContainer container = (TopicSubContainer)i.next(); + for (Iterator i = subscriberMessages.values().iterator(); i.hasNext();) { + TopicSubContainer container = i.next(); ConsumerMessageRef ref = new ConsumerMessageRef(); ref.setAckEntry(ackEntry); ref.setMessageEntry(messageEntry); @@ -81,14 +81,14 @@ public class KahaTopicMessageStore extends KahaMessageStore implements TopicMess public synchronized void acknowledge(ConnectionContext context, String clientId, String subscriptionName, MessageId messageId) throws IOException { String subcriberId = getSubscriptionKey(clientId, subscriptionName); - TopicSubContainer container = (TopicSubContainer)subscriberMessages.get(subcriberId); + TopicSubContainer container = subscriberMessages.get(subcriberId); if (container != null) { ConsumerMessageRef ref = container.remove(messageId); if (container.isEmpty()) { container.reset(); } if (ref != null) { - TopicSubAck tsa = (TopicSubAck)ackContainer.get(ref.getAckEntry()); + TopicSubAck tsa = ackContainer.get(ref.getAckEntry()); if (tsa != null) { if (tsa.decrementCount() <= 0) { StoreEntry entry = ref.getAckEntry(); @@ -106,7 +106,7 @@ public class KahaTopicMessageStore extends KahaMessageStore implements TopicMess } public SubscriptionInfo lookupSubscription(String clientId, String subscriptionName) throws IOException { - return (SubscriptionInfo)subscriberContainer.get(getSubscriptionKey(clientId, subscriptionName)); + return subscriberContainer.get(getSubscriptionKey(clientId, subscriptionName)); } public synchronized void addSubsciption(SubscriptionInfo info, boolean retroactive) throws IOException { @@ -136,7 +136,7 @@ public class KahaTopicMessageStore extends KahaMessageStore implements TopicMess public void recoverSubscription(String clientId, String subscriptionName, MessageRecoveryListener listener) throws Exception { String key = getSubscriptionKey(clientId, subscriptionName); - TopicSubContainer container = (TopicSubContainer)subscriberMessages.get(key); + TopicSubContainer container = subscriberMessages.get(key); if (container != null) { for (Iterator i = container.iterator(); i.hasNext();) { ConsumerMessageRef ref = (ConsumerMessageRef)i.next(); @@ -153,7 +153,7 @@ public class KahaTopicMessageStore extends KahaMessageStore implements TopicMess public void recoverNextMessages(String clientId, String subscriptionName, int maxReturned, MessageRecoveryListener listener) throws Exception { String key = getSubscriptionKey(clientId, subscriptionName); - TopicSubContainer container = (TopicSubContainer)subscriberMessages.get(key); + TopicSubContainer container = subscriberMessages.get(key); if (container != null) { int count = 0; StoreEntry entry = container.getBatchEntry(); @@ -190,7 +190,7 @@ public class KahaTopicMessageStore extends KahaMessageStore implements TopicMess } public SubscriptionInfo[] getAllSubscriptions() throws IOException { - return (SubscriptionInfo[])subscriberContainer.values() + return subscriberContainer.values() .toArray(new SubscriptionInfo[subscriberContainer.size()]); } @@ -211,11 +211,11 @@ public class KahaTopicMessageStore extends KahaMessageStore implements TopicMess protected void removeSubscriberMessageContainer(Object key) throws IOException { subscriberContainer.remove(key); - TopicSubContainer container = (TopicSubContainer)subscriberMessages.remove(key); + TopicSubContainer container = subscriberMessages.remove(key); for (Iterator i = container.iterator(); i.hasNext();) { ConsumerMessageRef ref = (ConsumerMessageRef)i.next(); if (ref != null) { - TopicSubAck tsa = (TopicSubAck)ackContainer.get(ref.getAckEntry()); + TopicSubAck tsa = ackContainer.get(ref.getAckEntry()); if (tsa != null) { if (tsa.decrementCount() <= 0) { ackContainer.remove(ref.getAckEntry()); @@ -231,7 +231,7 @@ public class KahaTopicMessageStore extends KahaMessageStore implements TopicMess public int getMessageCount(String clientId, String subscriberName) throws IOException { String key = getSubscriptionKey(clientId, subscriberName); - TopicSubContainer container = (TopicSubContainer)subscriberMessages.get(key); + TopicSubContainer container = subscriberMessages.get(key); return container != null ? container.size() : 0; } @@ -243,15 +243,15 @@ public class KahaTopicMessageStore extends KahaMessageStore implements TopicMess public synchronized void removeAllMessages(ConnectionContext context) throws IOException { messageContainer.clear(); ackContainer.clear(); - for (Iterator i = subscriberMessages.values().iterator(); i.hasNext();) { - TopicSubContainer container = (TopicSubContainer)i.next(); + for (Iterator i = subscriberMessages.values().iterator(); i.hasNext();) { + TopicSubContainer container = i.next(); container.clear(); } } public synchronized void resetBatching(String clientId, String subscriptionName) { String key = getSubscriptionKey(clientId, subscriptionName); - TopicSubContainer topicSubContainer = (TopicSubContainer)subscriberMessages.get(key); + TopicSubContainer topicSubContainer = subscriberMessages.get(key); if (topicSubContainer != null) { topicSubContainer.reset(); } diff --git a/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaTopicReferenceStore.java b/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaTopicReferenceStore.java index 5af8420aa4..04c0e90c99 100644 --- a/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaTopicReferenceStore.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaTopicReferenceStore.java @@ -37,21 +37,21 @@ import org.apache.activemq.store.TopicReferenceStore; public class KahaTopicReferenceStore extends KahaReferenceStore implements TopicReferenceStore { protected ListContainer ackContainer; - private Map subscriberContainer; + protected Map subscriberMessages = new ConcurrentHashMap(); + private Map subscriberContainer; private Store store; - protected Map subscriberMessages = new ConcurrentHashMap(); public KahaTopicReferenceStore(Store store, KahaReferenceStoreAdapter adapter, - MapContainer messageContainer, ListContainer ackContainer, - MapContainer subsContainer, ActiveMQDestination destination) + MapContainer messageContainer, ListContainer ackContainer, + MapContainer subsContainer, ActiveMQDestination destination) throws IOException { super(adapter, messageContainer, destination); this.store = store; this.ackContainer = ackContainer; subscriberContainer = subsContainer; // load all the Ack containers - for (Iterator i = subscriberContainer.keySet().iterator(); i.hasNext();) { - String key = (String)i.next(); + for (Iterator i = subscriberContainer.keySet().iterator(); i.hasNext();) { + String key = i.next(); addSubscriberMessageContainer(key); } } @@ -79,8 +79,8 @@ public class KahaTopicReferenceStore extends KahaReferenceStore implements Topic tsa.setCount(subscriberCount); tsa.setMessageEntry(messageEntry); final StoreEntry ackEntry = ackContainer.placeLast(tsa); - for (final Iterator i = subscriberMessages.values().iterator(); i.hasNext();) { - final TopicSubContainer container = (TopicSubContainer)i.next(); + for (final Iterator i = subscriberMessages.values().iterator(); i.hasNext();) { + final TopicSubContainer container = i.next(); final ConsumerMessageRef ref = new ConsumerMessageRef(); ref.setAckEntry(ackEntry); ref.setMessageEntry(messageEntry); @@ -100,9 +100,9 @@ public class KahaTopicReferenceStore extends KahaReferenceStore implements Topic public void addReferenceFileIdsInUse() { for (StoreEntry entry = ackContainer.getFirst(); entry != null; entry = ackContainer.getNext(entry)) { - TopicSubAck subAck = (TopicSubAck)ackContainer.get(entry); + TopicSubAck subAck = ackContainer.get(entry); if (subAck.getCount() > 0) { - ReferenceRecord rr = (ReferenceRecord)messageContainer.getValue(subAck.getMessageEntry()); + ReferenceRecord rr = messageContainer.getValue(subAck.getMessageEntry()); addInterest(rr); } } @@ -121,11 +121,11 @@ public class KahaTopicReferenceStore extends KahaReferenceStore implements Topic MessageId messageId) throws IOException { String key = getSubscriptionKey(clientId, subscriptionName); - TopicSubContainer container = (TopicSubContainer)subscriberMessages.get(key); + TopicSubContainer container = subscriberMessages.get(key); if (container != null) { ConsumerMessageRef ref = container.remove(messageId); if (ref != null) { - TopicSubAck tsa = (TopicSubAck)ackContainer.get(ref.getAckEntry()); + TopicSubAck tsa = ackContainer.get(ref.getAckEntry()); if (tsa != null) { if (tsa.decrementCount() <= 0) { StoreEntry entry = ref.getAckEntry(); @@ -179,24 +179,24 @@ public class KahaTopicReferenceStore extends KahaReferenceStore implements Topic } public SubscriptionInfo[] getAllSubscriptions() throws IOException { - return (SubscriptionInfo[])subscriberContainer.values() + return subscriberContainer.values() .toArray(new SubscriptionInfo[subscriberContainer.size()]); } public int getMessageCount(String clientId, String subscriberName) throws IOException { String key = getSubscriptionKey(clientId, subscriberName); - TopicSubContainer container = (TopicSubContainer)subscriberMessages.get(key); + TopicSubContainer container = subscriberMessages.get(key); return container != null ? container.size() : 0; } public SubscriptionInfo lookupSubscription(String clientId, String subscriptionName) throws IOException { - return (SubscriptionInfo)subscriberContainer.get(getSubscriptionKey(clientId, subscriptionName)); + return subscriberContainer.get(getSubscriptionKey(clientId, subscriptionName)); } public synchronized void recoverNextMessages(String clientId, String subscriptionName, int maxReturned, MessageRecoveryListener listener) throws Exception { String key = getSubscriptionKey(clientId, subscriptionName); - TopicSubContainer container = (TopicSubContainer)subscriberMessages.get(key); + TopicSubContainer container = subscriberMessages.get(key); if (container != null) { int count = 0; StoreEntry entry = container.getBatchEntry(); @@ -230,7 +230,7 @@ public class KahaTopicReferenceStore extends KahaReferenceStore implements Topic public void recoverSubscription(String clientId, String subscriptionName, MessageRecoveryListener listener) throws Exception { String key = getSubscriptionKey(clientId, subscriptionName); - TopicSubContainer container = (TopicSubContainer)subscriberMessages.get(key); + TopicSubContainer container = subscriberMessages.get(key); if (container != null) { for (Iterator i = container.iterator(); i.hasNext();) { ConsumerMessageRef ref = (ConsumerMessageRef)i.next(); @@ -246,7 +246,7 @@ public class KahaTopicReferenceStore extends KahaReferenceStore implements Topic public synchronized void resetBatching(String clientId, String subscriptionName) { String key = getSubscriptionKey(clientId, subscriptionName); - TopicSubContainer topicSubContainer = (TopicSubContainer)subscriberMessages.get(key); + TopicSubContainer topicSubContainer = subscriberMessages.get(key); if (topicSubContainer != null) { topicSubContainer.reset(); } @@ -254,11 +254,11 @@ public class KahaTopicReferenceStore extends KahaReferenceStore implements Topic protected void removeSubscriberMessageContainer(String key) throws IOException { subscriberContainer.remove(key); - TopicSubContainer container = (TopicSubContainer)subscriberMessages.remove(key); + TopicSubContainer container = subscriberMessages.remove(key); for (Iterator i = container.iterator(); i.hasNext();) { ConsumerMessageRef ref = (ConsumerMessageRef)i.next(); if (ref != null) { - TopicSubAck tsa = (TopicSubAck)ackContainer.get(ref.getAckEntry()); + TopicSubAck tsa = ackContainer.get(ref.getAckEntry()); if (tsa != null) { if (tsa.decrementCount() <= 0) { ackContainer.remove(ref.getAckEntry()); diff --git a/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaTransaction.java b/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaTransaction.java index 28116dd3e6..464b185d50 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaTransaction.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaTransaction.java @@ -33,8 +33,7 @@ import org.apache.commons.logging.LogFactory; * @version $Revision: 1.4 $ */ class KahaTransaction { - private static final Log LOG = LogFactory.getLog(KahaTransaction.class); - protected List list = new ArrayList(); + protected List list = new ArrayList(); void add(KahaMessageStore store, BaseCommand command) { TxCommand tx = new TxCommand(); @@ -44,27 +43,27 @@ class KahaTransaction { } Message[] getMessages() { - List result = new ArrayList(); + List result = new ArrayList(); for (int i = 0; i < list.size(); i++) { - TxCommand command = (TxCommand)list.get(i); + TxCommand command = list.get(i); if (command.isAdd()) { result.add(command.getCommand()); } } Message[] messages = new Message[result.size()]; - return (Message[])result.toArray(messages); + return result.toArray(messages); } MessageAck[] getAcks() { - List result = new ArrayList(); + List result = new ArrayList(); for (int i = 0; i < list.size(); i++) { - TxCommand command = (TxCommand)list.get(i); + TxCommand command = list.get(i); if (command.isRemove()) { result.add(command.getCommand()); } } MessageAck[] acks = new MessageAck[result.size()]; - return (MessageAck[])result.toArray(acks); + return result.toArray(acks); } void prepare() { @@ -79,14 +78,14 @@ class KahaTransaction { */ void commit(KahaTransactionStore transactionStore) throws IOException { for (int i = 0; i < list.size(); i++) { - TxCommand command = (TxCommand)list.get(i); + TxCommand command = list.get(i); MessageStore ms = transactionStore.getStoreById(command.getMessageStoreKey()); if (command.isAdd()) { ms.addMessage(null, (Message)command.getCommand()); } } for (int i = 0; i < list.size(); i++) { - TxCommand command = (TxCommand)list.get(i); + TxCommand command = list.get(i); MessageStore ms = transactionStore.getStoreById(command.getMessageStoreKey()); if (command.isRemove()) { ms.removeMessage(null, (MessageAck)command.getCommand()); @@ -94,11 +93,11 @@ class KahaTransaction { } } - List getList() { - return new ArrayList(list); + List getList() { + return new ArrayList(list); } - void setList(List list) { + void setList(List list) { this.list = list; } } diff --git a/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/TopicSubAck.java b/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/TopicSubAck.java index b97faa303b..24619f1201 100644 --- a/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/TopicSubAck.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/TopicSubAck.java @@ -25,7 +25,7 @@ import org.apache.activemq.kaha.StoreEntry; */ public class TopicSubAck { - private int count = 0; + private int count; private StoreEntry messageEntry; /** diff --git a/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryMessageStore.java b/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryMessageStore.java index 8a7541b342..9cee250cbe 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryMessageStore.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryMessageStore.java @@ -41,14 +41,14 @@ import org.apache.activemq.store.MessageStore; public class MemoryMessageStore implements MessageStore { protected final ActiveMQDestination destination; - protected final Map messageTable; + protected final Map messageTable; protected MessageId lastBatchId; public MemoryMessageStore(ActiveMQDestination destination) { - this(destination, new LinkedHashMap()); + this(destination, new LinkedHashMap()); } - public MemoryMessageStore(ActiveMQDestination destination, Map messageTable) { + public MemoryMessageStore(ActiveMQDestination destination, Map messageTable) { this.destination = destination; this.messageTable = Collections.synchronizedMap(messageTable); } @@ -68,7 +68,7 @@ public class MemoryMessageStore implements MessageStore { // } public Message getMessage(MessageId identity) throws IOException { - return (Message)messageTable.get(identity); + return messageTable.get(identity); } // public String getMessageReference(MessageId identity) throws IOException{ @@ -92,8 +92,8 @@ public class MemoryMessageStore implements MessageStore { // the message table is a synchronizedMap - so just have to synchronize // here synchronized (messageTable) { - for (Iterator iter = messageTable.values().iterator(); iter.hasNext();) { - Object msg = (Object)iter.next(); + for (Iterator iter = messageTable.values().iterator(); iter.hasNext();) { + Object msg = iter.next(); if (msg.getClass() == MessageId.class) { listener.recoverMessageReference((MessageId)msg); } else { diff --git a/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryPersistenceAdapter.java b/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryPersistenceAdapter.java index 42284d1324..c9e763a264 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryPersistenceAdapter.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryPersistenceAdapter.java @@ -24,6 +24,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.apache.activemq.broker.ConnectionContext; +import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQTopic; import org.apache.activemq.memory.UsageManager; @@ -42,16 +43,16 @@ public class MemoryPersistenceAdapter implements PersistenceAdapter { private static final Log LOG = LogFactory.getLog(MemoryPersistenceAdapter.class); MemoryTransactionStore transactionStore; - ConcurrentHashMap topics = new ConcurrentHashMap(); - ConcurrentHashMap queues = new ConcurrentHashMap(); + ConcurrentHashMap topics = new ConcurrentHashMap(); + ConcurrentHashMap queues = new ConcurrentHashMap(); private boolean useExternalMessageReferences; - public Set getDestinations() { - Set rc = new HashSet(queues.size() + topics.size()); - for (Iterator iter = queues.keySet().iterator(); iter.hasNext();) { + public Set getDestinations() { + Set rc = new HashSet(queues.size() + topics.size()); + for (Iterator iter = queues.keySet().iterator(); iter.hasNext();) { rc.add(iter.next()); } - for (Iterator iter = topics.keySet().iterator(); iter.hasNext();) { + for (Iterator iter = topics.keySet().iterator(); iter.hasNext();) { rc.add(iter.next()); } return rc; @@ -62,7 +63,7 @@ public class MemoryPersistenceAdapter implements PersistenceAdapter { } public MessageStore createQueueMessageStore(ActiveMQQueue destination) throws IOException { - MessageStore rc = (MessageStore)queues.get(destination); + MessageStore rc = queues.get(destination); if (rc == null) { rc = new MemoryMessageStore(destination); if (transactionStore != null) { @@ -74,7 +75,7 @@ public class MemoryPersistenceAdapter implements PersistenceAdapter { } public TopicMessageStore createTopicMessageStore(ActiveMQTopic destination) throws IOException { - TopicMessageStore rc = (TopicMessageStore)topics.get(destination); + TopicMessageStore rc = topics.get(destination); if (rc == null) { rc = new MemoryTopicMessageStore(destination); if (transactionStore != null) { @@ -112,13 +113,13 @@ public class MemoryPersistenceAdapter implements PersistenceAdapter { } public void deleteAllMessages() throws IOException { - for (Iterator iter = topics.values().iterator(); iter.hasNext();) { + for (Iterator iter = topics.values().iterator(); iter.hasNext();) { MemoryMessageStore store = asMemoryMessageStore(iter.next()); if (store != null) { store.delete(); } } - for (Iterator iter = queues.values().iterator(); iter.hasNext();) { + for (Iterator iter = queues.values().iterator(); iter.hasNext();) { MemoryMessageStore store = asMemoryMessageStore(iter.next()); if (store != null) { store.delete(); diff --git a/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryTopicMessageStore.java b/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryTopicMessageStore.java index cca1f3f9e0..14702f5057 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryTopicMessageStore.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryTopicMessageStore.java @@ -37,41 +37,45 @@ import org.apache.activemq.util.SubscriptionKey; */ public class MemoryTopicMessageStore extends MemoryMessageStore implements TopicMessageStore { - private Map subscriberDatabase; - private Map topicSubMap; + private Map subscriberDatabase; + private Map topicSubMap; public MemoryTopicMessageStore(ActiveMQDestination destination) { - this(destination, new LRUCache(100, 100, 0.75f, false), makeMap()); + this(destination, new LRUCache(100, 100, 0.75f, false), makeSubscriptionInfoMap()); } - protected static Map makeMap() { - return Collections.synchronizedMap(new HashMap()); - } - - public MemoryTopicMessageStore(ActiveMQDestination destination, Map messageTable, Map subscriberDatabase) { + public MemoryTopicMessageStore(ActiveMQDestination destination, Map messageTable, Map subscriberDatabase) { super(destination, messageTable); this.subscriberDatabase = subscriberDatabase; - this.topicSubMap = makeMap(); + this.topicSubMap = makeSubMap(); + } + + protected static Map makeSubscriptionInfoMap() { + return Collections.synchronizedMap(new HashMap()); + } + + protected static Map makeSubMap() { + return Collections.synchronizedMap(new HashMap()); } public synchronized void addMessage(ConnectionContext context, Message message) throws IOException { super.addMessage(context, message); - for (Iterator i = topicSubMap.values().iterator(); i.hasNext();) { - MemoryTopicSub sub = (MemoryTopicSub)i.next(); + for (Iterator i = topicSubMap.values().iterator(); i.hasNext();) { + MemoryTopicSub sub = i.next(); sub.addMessage(message.getMessageId(), message); } } public synchronized void acknowledge(ConnectionContext context, String clientId, String subscriptionName, MessageId messageId) throws IOException { SubscriptionKey key = new SubscriptionKey(clientId, subscriptionName); - MemoryTopicSub sub = (MemoryTopicSub)topicSubMap.get(key); + MemoryTopicSub sub = topicSubMap.get(key); if (sub != null) { sub.removeMessage(messageId); } } public SubscriptionInfo lookupSubscription(String clientId, String subscriptionName) throws IOException { - return (SubscriptionInfo)subscriberDatabase.get(new SubscriptionKey(clientId, subscriptionName)); + return subscriberDatabase.get(new SubscriptionKey(clientId, subscriptionName)); } public synchronized void addSubsciption(SubscriptionInfo info, boolean retroactive) throws IOException { @@ -94,7 +98,7 @@ public class MemoryTopicMessageStore extends MemoryMessageStore implements Topic } public void recoverSubscription(String clientId, String subscriptionName, MessageRecoveryListener listener) throws Exception { - MemoryTopicSub sub = (MemoryTopicSub)topicSubMap.get(new SubscriptionKey(clientId, subscriptionName)); + MemoryTopicSub sub = topicSubMap.get(new SubscriptionKey(clientId, subscriptionName)); if (sub != null) { sub.recoverSubscription(listener); } @@ -107,12 +111,12 @@ public class MemoryTopicMessageStore extends MemoryMessageStore implements Topic } public SubscriptionInfo[] getAllSubscriptions() throws IOException { - return (SubscriptionInfo[])subscriberDatabase.values().toArray(new SubscriptionInfo[subscriberDatabase.size()]); + return subscriberDatabase.values().toArray(new SubscriptionInfo[subscriberDatabase.size()]); } public synchronized int getMessageCount(String clientId, String subscriberName) throws IOException { int result = 0; - MemoryTopicSub sub = (MemoryTopicSub)topicSubMap.get(new SubscriptionKey(clientId, subscriberName)); + MemoryTopicSub sub = topicSubMap.get(new SubscriptionKey(clientId, subscriberName)); if (sub != null) { result = sub.size(); } @@ -120,14 +124,14 @@ public class MemoryTopicMessageStore extends MemoryMessageStore implements Topic } public void recoverNextMessages(String clientId, String subscriptionName, int maxReturned, MessageRecoveryListener listener) throws Exception { - MemoryTopicSub sub = (MemoryTopicSub)topicSubMap.get(new SubscriptionKey(clientId, subscriptionName)); + MemoryTopicSub sub = topicSubMap.get(new SubscriptionKey(clientId, subscriptionName)); if (sub != null) { sub.recoverNextMessages(maxReturned, listener); } } public void resetBatching(String clientId, String subscriptionName) { - MemoryTopicSub sub = (MemoryTopicSub)topicSubMap.get(new SubscriptionKey(clientId, subscriptionName)); + MemoryTopicSub sub = topicSubMap.get(new SubscriptionKey(clientId, subscriptionName)); if (sub != null) { sub.resetBatching(); } diff --git a/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryTopicSub.java b/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryTopicSub.java index ab8860921c..931432f6d8 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryTopicSub.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryTopicSub.java @@ -31,7 +31,7 @@ import org.apache.activemq.store.MessageRecoveryListener; */ class MemoryTopicSub { - private Map map = new LinkedHashMap(); + private Map map = new LinkedHashMap(); private MessageId lastBatch; void addMessage(MessageId id, Message message) { diff --git a/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryTransactionStore.java b/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryTransactionStore.java index f7a82dfaed..987bcf4557 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryTransactionStore.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/memory/MemoryTransactionStore.java @@ -43,16 +43,16 @@ import org.apache.activemq.store.TransactionStore; */ public class MemoryTransactionStore implements TransactionStore { - ConcurrentHashMap inflightTransactions = new ConcurrentHashMap(); + ConcurrentHashMap inflightTransactions = new ConcurrentHashMap(); - ConcurrentHashMap preparedTransactions = new ConcurrentHashMap(); + ConcurrentHashMap preparedTransactions = new ConcurrentHashMap(); private boolean doingRecover; public static class Tx { - private ArrayList messages = new ArrayList(); + private ArrayList messages = new ArrayList(); - private ArrayList acks = new ArrayList(); + private ArrayList acks = new ArrayList(); public void add(AddMessageCommand msg) { messages.add(msg); @@ -65,8 +65,8 @@ public class MemoryTransactionStore implements TransactionStore { public Message[] getMessages() { Message rc[] = new Message[messages.size()]; int count = 0; - for (Iterator iter = messages.iterator(); iter.hasNext();) { - AddMessageCommand cmd = (AddMessageCommand)iter.next(); + for (Iterator iter = messages.iterator(); iter.hasNext();) { + AddMessageCommand cmd = iter.next(); rc[count++] = cmd.getMessage(); } return rc; @@ -75,8 +75,8 @@ public class MemoryTransactionStore implements TransactionStore { public MessageAck[] getAcks() { MessageAck rc[] = new MessageAck[acks.size()]; int count = 0; - for (Iterator iter = acks.iterator(); iter.hasNext();) { - RemoveMessageCommand cmd = (RemoveMessageCommand)iter.next(); + for (Iterator iter = acks.iterator(); iter.hasNext();) { + RemoveMessageCommand cmd = iter.next(); rc[count++] = cmd.getMessageAck(); } return rc; @@ -87,13 +87,13 @@ public class MemoryTransactionStore implements TransactionStore { */ public void commit() throws IOException { // Do all the message adds. - for (Iterator iter = messages.iterator(); iter.hasNext();) { - AddMessageCommand cmd = (AddMessageCommand)iter.next(); + for (Iterator iter = messages.iterator(); iter.hasNext();) { + AddMessageCommand cmd = iter.next(); cmd.run(); } // And removes.. - for (Iterator iter = acks.iterator(); iter.hasNext();) { - RemoveMessageCommand cmd = (RemoveMessageCommand)iter.next(); + for (Iterator iter = acks.iterator(); iter.hasNext();) { + RemoveMessageCommand cmd = iter.next(); cmd.run(); } } @@ -139,7 +139,7 @@ public class MemoryTransactionStore implements TransactionStore { * @see org.apache.activemq.store.TransactionStore#prepare(TransactionId) */ public void prepare(TransactionId txid) { - Tx tx = (Tx)inflightTransactions.remove(txid); + Tx tx = inflightTransactions.remove(txid); if (tx == null) { return; } @@ -147,7 +147,7 @@ public class MemoryTransactionStore implements TransactionStore { } public Tx getTx(Object txid) { - Tx tx = (Tx)inflightTransactions.get(txid); + Tx tx = inflightTransactions.get(txid); if (tx == null) { tx = new Tx(); inflightTransactions.put(txid, tx); @@ -163,9 +163,9 @@ public class MemoryTransactionStore implements TransactionStore { Tx tx; if (wasPrepared) { - tx = (Tx)preparedTransactions.remove(txid); + tx = preparedTransactions.remove(txid); } else { - tx = (Tx)inflightTransactions.remove(txid); + tx = inflightTransactions.remove(txid); } if (tx == null) { @@ -194,9 +194,9 @@ public class MemoryTransactionStore implements TransactionStore { inflightTransactions.clear(); this.doingRecover = true; try { - for (Iterator iter = preparedTransactions.keySet().iterator(); iter.hasNext();) { - Object txid = (Object)iter.next(); - Tx tx = (Tx)preparedTransactions.get(txid); + for (Iterator iter = preparedTransactions.keySet().iterator(); iter.hasNext();) { + Object txid = iter.next(); + Tx tx = preparedTransactions.get(txid); listener.recover((XATransactionId)txid, tx.getMessages(), tx.getAcks()); } } finally { diff --git a/activemq-core/src/main/java/org/apache/activemq/thread/DefaultThreadPools.java b/activemq-core/src/main/java/org/apache/activemq/thread/DefaultThreadPools.java index 1ed747f63d..d3969f1da0 100755 --- a/activemq-core/src/main/java/org/apache/activemq/thread/DefaultThreadPools.java +++ b/activemq-core/src/main/java/org/apache/activemq/thread/DefaultThreadPools.java @@ -24,7 +24,7 @@ import java.util.concurrent.ThreadFactory; * * @version $Revision$ */ -public class DefaultThreadPools { +public final class DefaultThreadPools { private static final Executor DEFAULT_POOL; static { @@ -35,10 +35,12 @@ public class DefaultThreadPools { return thread; } }); - } - + } private static final TaskRunnerFactory DEFAULT_TASK_RUNNER_FACTORY = new TaskRunnerFactory(); + private DefaultThreadPools() { + } + public static Executor getDefaultPool() { return DEFAULT_POOL; } diff --git a/activemq-core/src/main/java/org/apache/activemq/thread/Scheduler.java b/activemq-core/src/main/java/org/apache/activemq/thread/Scheduler.java index d94c55b59b..e050674c3d 100755 --- a/activemq-core/src/main/java/org/apache/activemq/thread/Scheduler.java +++ b/activemq-core/src/main/java/org/apache/activemq/thread/Scheduler.java @@ -26,27 +26,35 @@ import java.util.concurrent.TimeUnit; /** * @version $Revision$ */ -public class Scheduler { +public final class Scheduler { - public static final ScheduledThreadPoolExecutor CLOCK_DAEMON = new ScheduledThreadPoolExecutor(5, new ThreadFactory() { - public Thread newThread(Runnable runnable) { - Thread thread = new Thread(runnable, "ActiveMQ Scheduler"); - thread.setDaemon(true); - return thread; - } - }); + public static final ScheduledThreadPoolExecutor CLOCK_DAEMON = new ScheduledThreadPoolExecutor(5, createThreadFactory()); static { CLOCK_DAEMON.setKeepAliveTime(5, TimeUnit.SECONDS); } - private static final HashMap CLOCK_TICKETS = new HashMap(); + private static final HashMap CLOCK_TICKETS = new HashMap(); + + private Scheduler() { + } + + private static ThreadFactory createThreadFactory() { + return new ThreadFactory() { + public Thread newThread(Runnable runnable) { + Thread thread = new Thread(runnable, "ActiveMQ Scheduler"); + thread.setDaemon(true); + return thread; + } + }; + } public static synchronized void executePeriodically(final Runnable task, long period) { - ScheduledFuture ticket = CLOCK_DAEMON.scheduleAtFixedRate(task, period, period, TimeUnit.MILLISECONDS); + ScheduledFuture ticket = CLOCK_DAEMON + .scheduleAtFixedRate(task, period, period, TimeUnit.MILLISECONDS); CLOCK_TICKETS.put(task, ticket); } public static synchronized void cancel(Runnable task) { - ScheduledFuture ticket = (ScheduledFuture)CLOCK_TICKETS.remove(task); + ScheduledFuture ticket = CLOCK_TICKETS.remove(task); if (ticket != null) { ticket.cancel(false); if (ticket instanceof Runnable) { diff --git a/activemq-core/src/main/java/org/apache/activemq/thread/TaskRunnerFactory.java b/activemq-core/src/main/java/org/apache/activemq/thread/TaskRunnerFactory.java index 70c8f9b288..73b96d65dc 100755 --- a/activemq-core/src/main/java/org/apache/activemq/thread/TaskRunnerFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/thread/TaskRunnerFactory.java @@ -76,7 +76,7 @@ public class TaskRunnerFactory { } protected ExecutorService createDefaultExecutor() { - ThreadPoolExecutor rc = new ThreadPoolExecutor(1, Integer.MAX_VALUE, 10, TimeUnit.SECONDS, new SynchronousQueue(), new ThreadFactory() { + ThreadPoolExecutor rc = new ThreadPoolExecutor(1, Integer.MAX_VALUE, 10, TimeUnit.SECONDS, new SynchronousQueue(), new ThreadFactory() { public Thread newThread(Runnable runnable) { Thread thread = new Thread(runnable, name); thread.setDaemon(daemon); diff --git a/activemq-core/src/main/java/org/apache/activemq/thread/Valve.java b/activemq-core/src/main/java/org/apache/activemq/thread/Valve.java index d3139c6364..abb2716a0f 100755 --- a/activemq-core/src/main/java/org/apache/activemq/thread/Valve.java +++ b/activemq-core/src/main/java/org/apache/activemq/thread/Valve.java @@ -26,8 +26,8 @@ public final class Valve { private final Object mutex = new Object(); private boolean on; - private int turningOff = 0; - private int usage = 0; + private int turningOff; + private int usage; public Valve(boolean on) { this.on = on; diff --git a/activemq-core/src/main/java/org/apache/activemq/transaction/Transaction.java b/activemq-core/src/main/java/org/apache/activemq/transaction/Transaction.java index b57532eccd..cd2bbe3439 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transaction/Transaction.java +++ b/activemq-core/src/main/java/org/apache/activemq/transaction/Transaction.java @@ -37,7 +37,7 @@ public abstract class Transaction { public static final byte PREPARED_STATE = 2; // can go to: 3 public static final byte FINISHED_STATE = 3; - private ArrayList synchronizations = new ArrayList(); + private ArrayList synchronizations = new ArrayList(); private byte state = START_STATE; public byte getState() { @@ -81,15 +81,15 @@ public abstract class Transaction { } protected void fireAfterCommit() throws Exception { - for (Iterator iter = synchronizations.iterator(); iter.hasNext();) { - Synchronization s = (Synchronization)iter.next(); + for (Iterator iter = synchronizations.iterator(); iter.hasNext();) { + Synchronization s = iter.next(); s.afterCommit(); } } public void fireAfterRollback() throws Exception { - for (Iterator iter = synchronizations.iterator(); iter.hasNext();) { - Synchronization s = (Synchronization)iter.next(); + for (Iterator iter = synchronizations.iterator(); iter.hasNext();) { + Synchronization s = iter.next(); s.afterRollback(); } } diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/FutureResponse.java b/activemq-core/src/main/java/org/apache/activemq/transport/FutureResponse.java index d16ff1ee9d..b529743191 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/FutureResponse.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/FutureResponse.java @@ -29,7 +29,7 @@ public class FutureResponse { private static final Log LOG = LogFactory.getLog(FutureResponse.class); private final ResponseCallback responseCallback; - private final ArrayBlockingQueue responseSlot = new ArrayBlockingQueue(1); + private final ArrayBlockingQueue responseSlot = new ArrayBlockingQueue(1); public FutureResponse(ResponseCallback responseCallback) { this.responseCallback = responseCallback; @@ -37,7 +37,7 @@ public class FutureResponse { public Response getResult() throws IOException { try { - return (Response)responseSlot.take(); + return responseSlot.take(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); if (LOG.isDebugEnabled()) { @@ -49,7 +49,7 @@ public class FutureResponse { public Response getResult(int timeout) throws IOException { try { - return (Response)responseSlot.poll(timeout, TimeUnit.MILLISECONDS); + return responseSlot.poll(timeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { throw new InterruptedIOException("Interrupted."); } diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/ResponseCorrelator.java b/activemq-core/src/main/java/org/apache/activemq/transport/ResponseCorrelator.java index 51ada4e955..0e4ac667f7 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/ResponseCorrelator.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/ResponseCorrelator.java @@ -39,7 +39,7 @@ import org.apache.commons.logging.LogFactory; public class ResponseCorrelator extends TransportFilter { private static final Log LOG = LogFactory.getLog(ResponseCorrelator.class); - private final Map requestMap = new HashMap(); + private final Map requestMap = new HashMap(); private IntSequenceGenerator sequenceGenerator; private final boolean debug = LOG.isDebugEnabled(); @@ -87,7 +87,7 @@ public class ResponseCorrelator extends TransportFilter { Response response = (Response)command; FutureResponse future = null; synchronized (requestMap) { - future = (FutureResponse)requestMap.remove(Integer.valueOf(response.getCorrelationId())); + future = requestMap.remove(Integer.valueOf(response.getCorrelationId())); } if (future != null) { future.set(response); @@ -107,10 +107,10 @@ public class ResponseCorrelator extends TransportFilter { */ public void onException(IOException error) { // Copy and Clear the request Map - ArrayList requests = new ArrayList(requestMap.values()); + ArrayList requests = new ArrayList(requestMap.values()); requestMap.clear(); - for (Iterator iter = requests.iterator(); iter.hasNext();) { - FutureResponse fr = (FutureResponse)iter.next(); + for (Iterator iter = requests.iterator(); iter.hasNext();) { + FutureResponse fr = iter.next(); fr.set(new ExceptionResponse(error)); } super.onException(error); diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/Transport.java b/activemq-core/src/main/java/org/apache/activemq/transport/Transport.java index 01c51c64ce..ff3ce08fc2 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/Transport.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/Transport.java @@ -122,7 +122,7 @@ public interface Transport extends Service { * @param target * @return the target */ - Object narrow(Class target); + T narrow(Class target); /** * @return the remote address for this connection diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/TransportFactory.java b/activemq-core/src/main/java/org/apache/activemq/transport/TransportFactory.java index 43b8faed52..ee692df9a2 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/TransportFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/TransportFactory.java @@ -37,7 +37,7 @@ public abstract class TransportFactory { private static final FactoryFinder TRANSPORT_FACTORY_FINDER = new FactoryFinder("META-INF/services/org/apache/activemq/transport/"); private static final FactoryFinder WIREFORMAT_FACTORY_FINDER = new FactoryFinder("META-INF/services/org/apache/activemq/wireformat/"); - private static final ConcurrentHashMap TRANSPORT_FACTORYS = new ConcurrentHashMap(); + private static final ConcurrentHashMap TRANSPORT_FACTORYS = new ConcurrentHashMap(); public abstract TransportServer doBind(String brokerId, URI location) throws IOException; @@ -108,7 +108,7 @@ public abstract class TransportFactory { public Transport doConnect(URI location) throws Exception { try { - Map options = new HashMap(URISupport.parseParamters(location)); + Map options = new HashMap(URISupport.parseParamters(location)); WireFormat wf = createWireFormat(options); Transport transport = createTransport(location, wf); Transport rc = configure(transport, wf, options); @@ -123,7 +123,7 @@ public abstract class TransportFactory { public Transport doCompositeConnect(URI location) throws Exception { try { - Map options = new HashMap(URISupport.parseParamters(location)); + Map options = new HashMap(URISupport.parseParamters(location)); WireFormat wf = createWireFormat(options); Transport transport = createTransport(location, wf); Transport rc = compositeConfigure(transport, wf, options); @@ -157,7 +157,7 @@ public abstract class TransportFactory { if (scheme == null) { throw new IOException("Transport not scheme specified: [" + location + "]"); } - TransportFactory tf = (TransportFactory)TRANSPORT_FACTORYS.get(scheme); + TransportFactory tf = TRANSPORT_FACTORYS.get(scheme); if (tf == null) { // Try to load if from a META-INF property. try { @@ -170,13 +170,13 @@ public abstract class TransportFactory { return tf; } - protected WireFormat createWireFormat(Map options) throws IOException { + protected WireFormat createWireFormat(Map options) throws IOException { WireFormatFactory factory = createWireFormatFactory(options); WireFormat format = factory.createWireFormat(); return format; } - protected WireFormatFactory createWireFormatFactory(Map options) throws IOException { + protected WireFormatFactory createWireFormatFactory(Map options) throws IOException { String wireFormat = (String)options.get("wireFormat"); if (wireFormat == null) { wireFormat = getDefaultWireFormatType(); diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/TransportFilter.java b/activemq-core/src/main/java/org/apache/activemq/transport/TransportFilter.java index 8330a980bd..1a08d37884 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/TransportFilter.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/TransportFilter.java @@ -106,9 +106,9 @@ public class TransportFilter implements TransportListener, Transport { transportListener.transportResumed(); } - public Object narrow(Class target) { + public T narrow(Class target) { if (target.isAssignableFrom(getClass())) { - return this; + return target.cast(this); } return next.narrow(target); } diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/TransportLogger.java b/activemq-core/src/main/java/org/apache/activemq/transport/TransportLogger.java index af8900ad60..873ddcf3a5 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/TransportLogger.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/TransportLogger.java @@ -33,15 +33,15 @@ public class TransportLogger extends TransportFilter { this(next, LogFactory.getLog(TransportLogger.class.getName() + ".Connection:" + getNextId())); } - private static synchronized int getNextId() { - return ++lastId; - } - public TransportLogger(Transport next, Log log) { super(next); this.log = log; } + private static synchronized int getNextId() { + return ++lastId; + } + public Object request(Object command) throws IOException { log.debug("SENDING REQUEST: " + command); Object rc = super.request(command); diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/TransportServerThreadSupport.java b/activemq-core/src/main/java/org/apache/activemq/transport/TransportServerThreadSupport.java index 5cc34a9930..012e7a90b6 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/TransportServerThreadSupport.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/TransportServerThreadSupport.java @@ -35,8 +35,8 @@ public abstract class TransportServerThreadSupport extends TransportServerSuppor private boolean daemon = true; private boolean joinOnStop = true; private Thread runner; - // should be a multiple of 128k - private long stackSize = 0; + // should be a multiple of 128k + private long stackSize; public TransportServerThreadSupport() { } diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/TransportSupport.java b/activemq-core/src/main/java/org/apache/activemq/transport/TransportSupport.java index aaed6f3362..14b052d953 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/TransportSupport.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/TransportSupport.java @@ -54,10 +54,10 @@ public abstract class TransportSupport extends ServiceSupport implements Transpo * @param target * @return 'this' if assignable */ - public Object narrow(Class target) { + public T narrow(Class target) { boolean assignableFrom = target.isAssignableFrom(getClass()); if (assignableFrom) { - return this; + return target.cast(this); } return null; } diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/TransportThreadSupport.java b/activemq-core/src/main/java/org/apache/activemq/transport/TransportThreadSupport.java index 411a82c7cd..cd4f7df423 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/TransportThreadSupport.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/TransportThreadSupport.java @@ -24,10 +24,10 @@ package org.apache.activemq.transport; */ public abstract class TransportThreadSupport extends TransportSupport implements Runnable { - private boolean daemon = false; + private boolean daemon; private Thread runner; // should be a multiple of 128k - private long stackSize = 0; + private long stackSize; public boolean isDaemon() { return daemon; diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/discovery/DiscoveryAgentFactory.java b/activemq-core/src/main/java/org/apache/activemq/transport/discovery/DiscoveryAgentFactory.java index 7e0a803e2b..75183e2643 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/discovery/DiscoveryAgentFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/discovery/DiscoveryAgentFactory.java @@ -26,7 +26,7 @@ import org.apache.activemq.util.IOExceptionSupport; public abstract class DiscoveryAgentFactory { private static final FactoryFinder DISCOVERY_AGENT_FINDER = new FactoryFinder("META-INF/services/org/apache/activemq/transport/discoveryagent/"); - private static final ConcurrentHashMap DISCOVERY_AGENT_FACTORYS = new ConcurrentHashMap(); + private static final ConcurrentHashMap DISCOVERY_AGENT_FACTORYS = new ConcurrentHashMap(); /** * @param uri @@ -38,7 +38,7 @@ public abstract class DiscoveryAgentFactory { if (scheme == null) { throw new IOException("DiscoveryAgent scheme not specified: [" + uri + "]"); } - DiscoveryAgentFactory daf = (DiscoveryAgentFactory)DISCOVERY_AGENT_FACTORYS.get(scheme); + DiscoveryAgentFactory daf = DISCOVERY_AGENT_FACTORYS.get(scheme); if (daf == null) { // Try to load if from a META-INF property. try { diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/discovery/DiscoveryTransport.java b/activemq-core/src/main/java/org/apache/activemq/transport/discovery/DiscoveryTransport.java index b771fc31da..7cbcd6e25a 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/discovery/DiscoveryTransport.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/discovery/DiscoveryTransport.java @@ -39,7 +39,7 @@ public class DiscoveryTransport extends TransportFilter implements DiscoveryList private final CompositeTransport next; private DiscoveryAgent discoveryAgent; - private final ConcurrentHashMap serviceURIs = new ConcurrentHashMap(); + private final ConcurrentHashMap serviceURIs = new ConcurrentHashMap(); public DiscoveryTransport(CompositeTransport next) { super(next); @@ -79,7 +79,7 @@ public class DiscoveryTransport extends TransportFilter implements DiscoveryList } public void onServiceRemove(DiscoveryEvent event) { - URI uri = (URI)serviceURIs.get(event.getServiceName()); + URI uri = serviceURIs.get(event.getServiceName()); if (uri != null) { next.remove(new URI[] {uri}); } diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/discovery/DiscoveryTransportFactory.java b/activemq-core/src/main/java/org/apache/activemq/transport/discovery/DiscoveryTransportFactory.java index c1bc0e88f2..37978874fe 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/discovery/DiscoveryTransportFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/discovery/DiscoveryTransportFactory.java @@ -33,7 +33,7 @@ import org.apache.activemq.util.URISupport.CompositeData; public class DiscoveryTransportFactory extends FailoverTransportFactory { public Transport createTransport(CompositeData compositData) throws IOException { - Map parameters = new HashMap(compositData.getParameters()); + Map parameters = new HashMap(compositData.getParameters()); DiscoveryTransport transport = new DiscoveryTransport(createTransport(parameters)); DiscoveryAgent discoveryAgent = DiscoveryAgentFactory.createDiscoveryAgent(compositData.getComponents()[0]); diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/discovery/multicast/MulticastDiscoveryAgent.java b/activemq-core/src/main/java/org/apache/activemq/transport/discovery/multicast/MulticastDiscoveryAgent.java index 18a74f2f33..0096944216 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/discovery/multicast/MulticastDiscoveryAgent.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/discovery/multicast/MulticastDiscoveryAgent.java @@ -47,8 +47,9 @@ import org.apache.commons.logging.LogFactory; * @version $Revision$ */ public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable { - private static final Log LOG = LogFactory.getLog(MulticastDiscoveryAgent.class); + public static final String DEFAULT_DISCOVERY_URI_STRING = "multicast://239.255.2.3:6155"; + private static final Log LOG = LogFactory.getLog(MulticastDiscoveryAgent.class); private static final String TYPE_SUFFIX = "ActiveMQ-4."; private static final String ALIVE = "alive."; private static final String DEAD = "dead."; @@ -60,7 +61,7 @@ public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable { private long initialReconnectDelay = 1000 * 5; private long maxReconnectDelay = 1000 * 30; private long backOffMultiplier = 2; - private boolean useExponentialBackOff = false; + private boolean useExponentialBackOff; private int maxReconnectAttempts; class RemoteBrokerData { @@ -156,8 +157,8 @@ public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable { } private int timeToLive = 1; - private boolean loopBackMode = false; - private Map brokersByService = new ConcurrentHashMap(); + private boolean loopBackMode; + private Map brokersByService = new ConcurrentHashMap(); private String group = "default"; private String brokerName; private URI discoveryURI; @@ -168,11 +169,11 @@ public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable { private MulticastSocket mcast; private Thread runner; private long keepAliveInterval = DEFAULT_IDLE_TIME; - private long lastAdvertizeTime = 0; + private long lastAdvertizeTime; private AtomicBoolean started = new AtomicBoolean(false); private boolean reportAdvertizeFailed = true; - private final Executor executor = new ThreadPoolExecutor(1, 1, 30, TimeUnit.SECONDS, new LinkedBlockingQueue(), new ThreadFactory() { + private final Executor executor = new ThreadPoolExecutor(1, 1, 30, TimeUnit.SECONDS, new LinkedBlockingQueue(), new ThreadFactory() { public Thread newThread(Runnable runable) { Thread t = new Thread(runable, "Multicast Discovery Agent Notifier"); t.setDaemon(true); @@ -421,7 +422,7 @@ public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable { private void processAlive(String brokerName, String service) { if (selfService == null || !service.equals(selfService)) { - RemoteBrokerData data = (RemoteBrokerData)brokersByService.get(service); + RemoteBrokerData data = brokersByService.get(service); if (data == null) { data = new RemoteBrokerData(brokerName, service); brokersByService.put(service, data); @@ -440,7 +441,7 @@ public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable { private void processDead(String brokerName, String service) { if (!service.equals(selfService)) { - RemoteBrokerData data = (RemoteBrokerData)brokersByService.remove(service); + RemoteBrokerData data = brokersByService.remove(service); if (data != null && !data.isFailed()) { fireServiceRemovedEvent(data); } @@ -449,8 +450,8 @@ public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable { private void doExpireOldServices() { long expireTime = System.currentTimeMillis() - (keepAliveInterval * HEARTBEAT_MISS_BEFORE_DEATH); - for (Iterator i = brokersByService.values().iterator(); i.hasNext();) { - RemoteBrokerData data = (RemoteBrokerData)i.next(); + for (Iterator i = brokersByService.values().iterator(); i.hasNext();) { + RemoteBrokerData data = i.next(); if (data.getLastHeartBeat() < expireTime) { processDead(brokerName, data.service); } @@ -468,7 +469,7 @@ public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable { } public void serviceFailed(DiscoveryEvent event) throws IOException { - RemoteBrokerData data = (RemoteBrokerData)brokersByService.get(event.getServiceName()); + RemoteBrokerData data = brokersByService.get(event.getServiceName()); if (data != null && data.markFailed()) { fireServiceRemovedEvent(data); } diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/discovery/rendezvous/JmDNSFactory.java b/activemq-core/src/main/java/org/apache/activemq/transport/discovery/rendezvous/JmDNSFactory.java index aa703e2181..f189a77496 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/discovery/rendezvous/JmDNSFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/discovery/rendezvous/JmDNSFactory.java @@ -24,7 +24,7 @@ import java.util.concurrent.atomic.AtomicInteger; import javax.jmdns.JmDNS; -public class JmDNSFactory { +public final class JmDNSFactory { static Map registry = new HashMap(); @@ -33,6 +33,9 @@ public class JmDNSFactory { JmDNS jmDNS; } + private JmDNSFactory() { + } + static synchronized JmDNS create(final InetAddress address) throws IOException { UsageTracker tracker = registry.get(address); if (tracker == null) { diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/discovery/rendezvous/RendezvousDiscoveryAgent.java b/activemq-core/src/main/java/org/apache/activemq/transport/discovery/rendezvous/RendezvousDiscoveryAgent.java index 1affd54eb7..2a4c80d74c 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/discovery/rendezvous/RendezvousDiscoveryAgent.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/discovery/rendezvous/RendezvousDiscoveryAgent.java @@ -51,12 +51,12 @@ public class RendezvousDiscoveryAgent implements DiscoveryAgent, ServiceListener private JmDNS jmdns; private InetAddress localAddress; private String localhost; - private int weight = 0; - private int priority = 0; + private int weight; + private int priority; private DiscoveryListener listener; private String group = "default"; - private final CopyOnWriteArrayList serviceInfos = new CopyOnWriteArrayList(); + private final CopyOnWriteArrayList serviceInfos = new CopyOnWriteArrayList(); // DiscoveryAgent interface // ------------------------------------------------------------------------- @@ -83,8 +83,8 @@ public class RendezvousDiscoveryAgent implements DiscoveryAgent, ServiceListener public void stop() { if (jmdns != null) { - for (Iterator iter = serviceInfos.iterator(); iter.hasNext();) { - ServiceInfo si = (ServiceInfo)iter.next(); + for (Iterator iter = serviceInfos.iterator(); iter.hasNext();) { + ServiceInfo si = iter.next(); jmdns.unregisterService(si); } diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/discovery/simple/SimpleDiscoveryAgent.java b/activemq-core/src/main/java/org/apache/activemq/transport/discovery/simple/SimpleDiscoveryAgent.java index 389d00dab6..087e59f003 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/discovery/simple/SimpleDiscoveryAgent.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/discovery/simple/SimpleDiscoveryAgent.java @@ -35,14 +35,13 @@ public class SimpleDiscoveryAgent implements DiscoveryAgent { private long initialReconnectDelay = 1000; private long maxReconnectDelay = 1000 * 30; private long backOffMultiplier = 2; - private boolean useExponentialBackOff = false; + private boolean useExponentialBackOff; private int maxReconnectAttempts; private final Object sleepMutex = new Object(); private long minConnectTime = 500; - private DiscoveryListener listener; - String services[] = new String[] {}; - String group = "DEFAULT"; + private String services[] = new String[] {}; + private String group = "DEFAULT"; private final AtomicBoolean running = new AtomicBoolean(false); class SimpleDiscoveryEvent extends DiscoveryEvent { diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java b/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java index 2f90eb3cb6..2c152790e9 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java @@ -56,12 +56,12 @@ public class FailoverTransport implements CompositeTransport { private TransportListener transportListener; private boolean disposed; - private final CopyOnWriteArrayList uris = new CopyOnWriteArrayList(); + private final CopyOnWriteArrayList uris = new CopyOnWriteArrayList(); private final Object reconnectMutex = new Object(); private final Object sleepMutex = new Object(); private final ConnectionStateTracker stateTracker = new ConnectionStateTracker(); - private final ConcurrentHashMap requestMap = new ConcurrentHashMap(); + private final ConcurrentHashMap requestMap = new ConcurrentHashMap(); private URI connectedTransportURI; private Transport connectedTransport; @@ -81,61 +81,6 @@ public class FailoverTransport implements CompositeTransport { private final TransportListener myTransportListener = createTransportListener(); - TransportListener createTransportListener() { - return new TransportListener() { - public void onCommand(Object o) { - Command command = (Command)o; - if (command == null) { - return; - } - if (command.isResponse()) { - Object object = requestMap.remove(Integer.valueOf(((Response)command).getCorrelationId())); - if (object != null && object.getClass() == Tracked.class) { - ((Tracked)object).onResponses(); - } - } - if (!initialized) { - if (command.isBrokerInfo()) { - BrokerInfo info = (BrokerInfo)command; - BrokerInfo[] peers = info.getPeerBrokerInfos(); - if (peers != null) { - for (int i = 0; i < peers.length; i++) { - String brokerString = peers[i].getBrokerURL(); - add(brokerString); - } - } - initialized = true; - } - - } - if (transportListener != null) { - transportListener.onCommand(command); - } - } - - public void onException(IOException error) { - try { - handleTransportFailure(error); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - transportListener.onException(new InterruptedIOException()); - } - } - - public void transportInterupted() { - if (transportListener != null) { - transportListener.transportInterupted(); - } - } - - public void transportResumed() { - if (transportListener != null) { - transportListener.transportResumed(); - } - } - }; - } - public FailoverTransport() throws InterruptedIOException { stateTracker.setTrackTransactions(true); @@ -155,14 +100,14 @@ public class FailoverTransport implements CompositeTransport { if (connectedTransport != null || disposed || connectionFailure != null) { return false; } else { - ArrayList connectList = getConnectList(); + ArrayList connectList = getConnectList(); if (connectList.isEmpty()) { failure = new IOException("No uris available to connect to."); } else { if (!useExponentialBackOff) { reconnectDelay = initialReconnectDelay; } - Iterator iter = connectList.iterator(); + Iterator iter = connectList.iterator(); for (int i = 0; iter.hasNext() && connectedTransport == null && !disposed; i++) { URI uri = (URI)iter.next(); try { @@ -227,6 +172,62 @@ public class FailoverTransport implements CompositeTransport { }, "ActiveMQ Failover Worker: " + System.identityHashCode(this)); } + TransportListener createTransportListener() { + return new TransportListener() { + public void onCommand(Object o) { + Command command = (Command)o; + if (command == null) { + return; + } + if (command.isResponse()) { + Object object = requestMap.remove(Integer.valueOf(((Response)command).getCorrelationId())); + if (object != null && object.getClass() == Tracked.class) { + ((Tracked)object).onResponses(); + } + } + if (!initialized) { + if (command.isBrokerInfo()) { + BrokerInfo info = (BrokerInfo)command; + BrokerInfo[] peers = info.getPeerBrokerInfos(); + if (peers != null) { + for (int i = 0; i < peers.length; i++) { + String brokerString = peers[i].getBrokerURL(); + add(brokerString); + } + } + initialized = true; + } + + } + if (transportListener != null) { + transportListener.onCommand(command); + } + } + + public void onException(IOException error) { + try { + handleTransportFailure(error); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + transportListener.onException(new InterruptedIOException()); + } + } + + public void transportInterupted() { + if (transportListener != null) { + transportListener.transportInterupted(); + } + } + + public void transportResumed() { + if (transportListener != null) { + transportListener.transportResumed(); + } + } + }; + } + + final void handleTransportFailure(IOException e) throws InterruptedException { if (transportListener != null) { transportListener.transportInterupted(); @@ -481,8 +482,8 @@ public class FailoverTransport implements CompositeTransport { } } - private ArrayList getConnectList() { - ArrayList l = new ArrayList(uris); + private ArrayList getConnectList() { + ArrayList l = new ArrayList(uris); if (randomize) { // Randomly, reorder the list by random swapping Random r = new Random(); @@ -505,10 +506,10 @@ public class FailoverTransport implements CompositeTransport { this.transportListener = commandListener; } - public Object narrow(Class target) { + public T narrow(Class target) { if (target.isAssignableFrom(getClass())) { - return this; + return target.cast(this); } synchronized (reconnectMutex) { if (connectedTransport != null) { @@ -522,8 +523,8 @@ public class FailoverTransport implements CompositeTransport { protected void restoreTransport(Transport t) throws Exception, IOException { t.start(); stateTracker.restore(t); - for (Iterator iter2 = requestMap.values().iterator(); iter2.hasNext();) { - Command command = (Command)iter2.next(); + for (Iterator iter2 = requestMap.values().iterator(); iter2.hasNext();) { + Command command = iter2.next(); t.oneway(command); } } diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/fanout/FanoutTransport.java b/activemq-core/src/main/java/org/apache/activemq/transport/fanout/FanoutTransport.java index d19e139e51..2ba9071b3c 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/fanout/FanoutTransport.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/fanout/FanoutTransport.java @@ -59,13 +59,13 @@ public class FanoutTransport implements CompositeTransport { private final Object reconnectMutex = new Object(); private final ConnectionStateTracker stateTracker = new ConnectionStateTracker(); - private final ConcurrentHashMap requestMap = new ConcurrentHashMap(); + private final ConcurrentHashMap requestMap = new ConcurrentHashMap(); private final TaskRunner reconnectTask; private boolean started; - private ArrayList transports = new ArrayList(); - private int connectedCount = 0; + private ArrayList transports = new ArrayList(); + private int connectedCount; private int minAckCount = 2; @@ -109,7 +109,7 @@ public class FanoutTransport implements CompositeTransport { Command command = (Command)o; if (command.isResponse()) { Integer id = new Integer(((Response)command).getCorrelationId()); - RequestCounter rc = (RequestCounter)requestMap.get(id); + RequestCounter rc = requestMap.get(id); if (rc != null) { if (rc.ackCount.decrementAndGet() <= 0) { requestMap.remove(id); @@ -179,12 +179,12 @@ public class FanoutTransport implements CompositeTransport { } else { // Try to connect them up. - Iterator iter = transports.iterator(); + Iterator iter = transports.iterator(); for (int i = 0; iter.hasNext() && !disposed; i++) { long now = System.currentTimeMillis(); - FanoutTransportHandler fanoutHandler = (FanoutTransportHandler)iter.next(); + FanoutTransportHandler fanoutHandler = iter.next(); if (fanoutHandler.transport != null) { continue; } @@ -269,8 +269,8 @@ public class FanoutTransport implements CompositeTransport { return; } started = true; - for (Iterator iter = transports.iterator(); iter.hasNext();) { - FanoutTransportHandler th = (FanoutTransportHandler)iter.next(); + for (Iterator iter = transports.iterator(); iter.hasNext();) { + FanoutTransportHandler th = iter.next(); if (th.transport != null) { restoreTransport(th); } @@ -288,8 +288,8 @@ public class FanoutTransport implements CompositeTransport { started = false; disposed = true; - for (Iterator iter = transports.iterator(); iter.hasNext();) { - FanoutTransportHandler th = (FanoutTransportHandler)iter.next(); + for (Iterator iter = transports.iterator(); iter.hasNext();) { + FanoutTransportHandler th = iter.next(); if (th.transport != null) { ss.stop(th.transport); } @@ -376,8 +376,8 @@ public class FanoutTransport implements CompositeTransport { // Send the message. if (fanout) { - for (Iterator iter = transports.iterator(); iter.hasNext();) { - FanoutTransportHandler th = (FanoutTransportHandler)iter.next(); + for (Iterator iter = transports.iterator(); iter.hasNext();) { + FanoutTransportHandler th = iter.next(); if (th.transport != null) { try { th.transport.oneway(command); @@ -447,17 +447,17 @@ public class FanoutTransport implements CompositeTransport { this.transportListener = commandListener; } - public Object narrow(Class target) { + public T narrow(Class target) { if (target.isAssignableFrom(getClass())) { - return this; + return target.cast(this); } synchronized (reconnectMutex) { - for (Iterator iter = transports.iterator(); iter.hasNext();) { - FanoutTransportHandler th = (FanoutTransportHandler)iter.next(); + for (Iterator iter = transports.iterator(); iter.hasNext();) { + FanoutTransportHandler th = iter.next(); if (th.transport != null) { - Object rc = th.transport.narrow(target); + T rc = th.transport.narrow(target); if (rc != null) { return rc; } @@ -473,8 +473,8 @@ public class FanoutTransport implements CompositeTransport { th.transport.start(); stateTracker.setRestoreConsumers(th.transport == primary); stateTracker.restore(th.transport); - for (Iterator iter2 = requestMap.values().iterator(); iter2.hasNext();) { - RequestCounter rc = (RequestCounter)iter2.next(); + for (Iterator iter2 = requestMap.values().iterator(); iter2.hasNext();) { + RequestCounter rc = iter2.next(); th.transport.oneway(rc.command); } } @@ -486,8 +486,8 @@ public class FanoutTransport implements CompositeTransport { URI uri = uris[i]; boolean match = false; - for (Iterator iter = transports.iterator(); iter.hasNext();) { - FanoutTransportHandler th = (FanoutTransportHandler)iter.next(); + for (Iterator iter = transports.iterator(); iter.hasNext();) { + FanoutTransportHandler th = iter.next(); if (th.uri.equals(uri)) { match = true; break; @@ -509,9 +509,8 @@ public class FanoutTransport implements CompositeTransport { for (int i = 0; i < uris.length; i++) { URI uri = uris[i]; - boolean match = false; - for (Iterator iter = transports.iterator(); iter.hasNext();) { - FanoutTransportHandler th = (FanoutTransportHandler)iter.next(); + for (Iterator iter = transports.iterator(); iter.hasNext();) { + FanoutTransportHandler th = iter.next(); if (th.uri.equals(uri)) { if (th.transport != null) { ServiceSupport.dispose(th.transport); diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/fanout/FanoutTransportFactory.java b/activemq-core/src/main/java/org/apache/activemq/transport/fanout/FanoutTransportFactory.java index 56e832cf97..40c738291e 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/fanout/FanoutTransportFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/fanout/FanoutTransportFactory.java @@ -64,7 +64,7 @@ public class FanoutTransportFactory extends TransportFactory { public Transport createTransport(URI location) throws IOException, URISyntaxException { CompositeData compositData = URISupport.parseComposite(location); - Map parameters = new HashMap(compositData.getParameters()); + Map parameters = new HashMap(compositData.getParameters()); DiscoveryTransport transport = new DiscoveryTransport(createTransport(parameters)); DiscoveryAgent discoveryAgent = DiscoveryAgentFactory.createDiscoveryAgent(compositData.getComponents()[0]); diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/mock/MockTransport.java b/activemq-core/src/main/java/org/apache/activemq/transport/mock/MockTransport.java index ea2edd35c9..a113a79193 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/mock/MockTransport.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/mock/MockTransport.java @@ -111,9 +111,9 @@ public class MockTransport extends DefaultTransportListener implements Transport getTransportListener().onException(error); } - public Object narrow(Class target) { + public T narrow(Class target) { if (target.isAssignableFrom(getClass())) { - return this; + return target.cast(this); } return getNext().narrow(target); } diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/multicast/MulticastDatagramHeaderMarshaller.java b/activemq-core/src/main/java/org/apache/activemq/transport/multicast/MulticastDatagramHeaderMarshaller.java index 80c7eaf47f..2f5b7bca35 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/multicast/MulticastDatagramHeaderMarshaller.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/multicast/MulticastDatagramHeaderMarshaller.java @@ -30,11 +30,9 @@ import org.apache.activemq.transport.udp.DatagramHeaderMarshaller; */ public class MulticastDatagramHeaderMarshaller extends DatagramHeaderMarshaller { - private final String localUri; private final byte[] localUriAsBytes; public MulticastDatagramHeaderMarshaller(String localUri) { - this.localUri = localUri; this.localUriAsBytes = localUri.getBytes(); } diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/multicast/MulticastTransport.java b/activemq-core/src/main/java/org/apache/activemq/transport/multicast/MulticastTransport.java index ff262eed96..063f2dc5f7 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/multicast/MulticastTransport.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/multicast/MulticastTransport.java @@ -50,7 +50,7 @@ public class MulticastTransport extends UdpTransport { private InetAddress mcastAddress; private int mcastPort; private int timeToLive = 1; - private boolean loopBackMode = false; + private boolean loopBackMode; private long keepAliveInterval = DEFAULT_IDLE_TIME; public MulticastTransport(OpenWireFormat wireFormat, URI remoteLocation) throws UnknownHostException, IOException { diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/peer/PeerTransportFactory.java b/activemq-core/src/main/java/org/apache/activemq/transport/peer/PeerTransportFactory.java index c243b60366..e2190fac51 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/peer/PeerTransportFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/peer/PeerTransportFactory.java @@ -69,7 +69,7 @@ public class PeerTransportFactory extends TransportFactory { broker = ID_GENERATOR.generateSanitizedId(); } - final Map brokerOptions = new HashMap(URISupport.parseParamters(location)); + final Map brokerOptions = new HashMap(URISupport.parseParamters(location)); if (!brokerOptions.containsKey("persistent")) { brokerOptions.put("persistent", "false"); } diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/reliable/DefaultReplayBuffer.java b/activemq-core/src/main/java/org/apache/activemq/transport/reliable/DefaultReplayBuffer.java index 6ae7568295..69bf345d7d 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/reliable/DefaultReplayBuffer.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/reliable/DefaultReplayBuffer.java @@ -33,7 +33,7 @@ public class DefaultReplayBuffer implements ReplayBuffer { private final int size; private ReplayBufferListener listener; - private Map map; + private Map map; private int lowestCommandId = 1; private Object lock = new Object(); @@ -77,8 +77,8 @@ public class DefaultReplayBuffer implements ReplayBuffer { } } - protected Map createMap(int maximumSize) { - return new HashMap(maximumSize); + protected Map createMap(int maximumSize) { + return new HashMap(maximumSize); } protected void onEvictedBuffer(int commandId, Object buffer) { diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/reliable/ReliableTransport.java b/activemq-core/src/main/java/org/apache/activemq/transport/reliable/ReliableTransport.java index f484edaf54..4e3ef907bc 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/reliable/ReliableTransport.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/reliable/ReliableTransport.java @@ -41,7 +41,7 @@ public class ReliableTransport extends ResponseCorrelator { private static final Log LOG = LogFactory.getLog(ReliableTransport.class); private ReplayStrategy replayStrategy; - private SortedSet commands = new TreeSet(new CommandIdComparator()); + private SortedSet commands = new TreeSet(new CommandIdComparator()); private int expectedCounter = 1; private int replayBufferCommandCount = 50; private int requestTimeout = 2000; @@ -123,7 +123,7 @@ public class ReliableTransport extends ResponseCorrelator { int nextCounter = actualCounter; boolean empty = commands.isEmpty(); if (!empty) { - Command nextAvailable = (Command)commands.first(); + Command nextAvailable = commands.first(); nextCounter = nextAvailable.getCommandId(); } @@ -144,7 +144,7 @@ public class ReliableTransport extends ResponseCorrelator { if (!empty) { // lets see if the first item in the set is the next // expected - command = (Command)commands.first(); + command = commands.first(); valid = expectedCounter == command.getCommandId(); if (valid) { commands.remove(command); @@ -165,7 +165,7 @@ public class ReliableTransport extends ResponseCorrelator { if (valid) { // lets see if the first item in the set is the next // expected - command = (Command)commands.first(); + command = commands.first(); valid = expectedCounter == command.getCommandId(); if (valid) { commands.remove(command); diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/FrameTranslator.java b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/FrameTranslator.java index b6a96ae161..4315a78dba 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/FrameTranslator.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/FrameTranslator.java @@ -75,9 +75,11 @@ public interface FrameTranslator { } // now lets add all the message headers - final Map properties = message.getProperties(); + final Map properties = message.getProperties(); if (properties != null) { - headers.putAll(properties); + for (Map.Entry prop : properties.entrySet()) { + headers.put(prop.getKey(), "" + prop.getValue()); + } } } diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java index 4257e99bb5..64623aee71 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java @@ -56,7 +56,7 @@ public class LegacyFrameTranslator implements FrameTranslator { public StompFrame convertMessage(ActiveMQMessage message) throws IOException, JMSException { StompFrame command = new StompFrame(); command.setAction(Stomp.Responses.MESSAGE); - Map headers = new HashMap(25); + Map headers = new HashMap(25); command.setHeaders(headers); FrameTranslator.Helper.copyStandardHeadersFromMessageToFrame(message, command, this); diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompFrame.java b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompFrame.java index b0da225c9e..cded7fd5d1 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompFrame.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompFrame.java @@ -37,10 +37,10 @@ public class StompFrame implements Command { private static final byte[] NO_DATA = new byte[] {}; private String action; - private Map headers = new HashMap(); + private Map headers = new HashMap(); private byte[] content = NO_DATA; - public StompFrame(String command, Map headers, byte[] data) { + public StompFrame(String command, Map headers, byte[] data) { this.action = command; this.headers = headers; this.content = data; @@ -65,11 +65,11 @@ public class StompFrame implements Command { this.content = data; } - public Map getHeaders() { + public Map getHeaders() { return headers; } - public void setHeaders(Map headers) { + public void setHeaders(Map headers) { this.headers = headers; } diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompSubscription.java b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompSubscription.java index 253858807b..a8e4d8f628 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompSubscription.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompSubscription.java @@ -45,7 +45,7 @@ public class StompSubscription { private final String subscriptionId; private final ConsumerInfo consumerInfo; - private final LinkedHashMap dispatchedMessage = new LinkedHashMap(); + private final LinkedHashMap dispatchedMessage = new LinkedHashMap(); private String ackMode = AUTO_ACK; private ActiveMQDestination destination; diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompWireFormat.java b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompWireFormat.java index f7d8c9e60a..b58a3b132c 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompWireFormat.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompWireFormat.java @@ -103,7 +103,7 @@ public class StompWireFormat implements WireFormat { } // Parse the headers - HashMap headers = new HashMap(25); + HashMap headers = new HashMap(25); while (true) { String line = readLine(in, MAX_HEADER_LENGTH, "The maximum header length was exceeded"); if (line != null && line.trim().length() > 0) { @@ -127,7 +127,7 @@ public class StompWireFormat implements WireFormat { // Read in the data part. byte[] data = NO_DATA; - String contentLength = (String)headers.get(Stomp.Headers.CONTENT_LENGTH); + String contentLength = headers.get(Stomp.Headers.CONTENT_LENGTH); if (contentLength != null) { // Bless the client, he's telling us how much data to read in. diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportFactory.java b/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportFactory.java index 0987d8a521..218d3838b4 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportFactory.java @@ -75,13 +75,13 @@ public class SslTransportFactory extends TcpTransportFactory { */ public TransportServer doBind(String brokerId, final URI location) throws IOException { try { - Map options = new HashMap(URISupport.parseParamters(location)); + Map options = new HashMap(URISupport.parseParamters(location)); ServerSocketFactory serverSocketFactory = createServerSocketFactory(); SslTransportServer server = new SslTransportServer(this, location, (SSLServerSocketFactory)serverSocketFactory); server.setWireFormatFactory(createWireFormatFactory(options)); IntrospectionSupport.setProperties(server, options); - Map transportOptions = IntrospectionSupport.extractProperties(options, "transport."); + Map transportOptions = IntrospectionSupport.extractProperties(options, "transport."); server.setTransportOption(transportOptions); server.bind(); @@ -99,7 +99,7 @@ public class SslTransportFactory extends TcpTransportFactory { SslTransport sslTransport = (SslTransport)transport.narrow(SslTransport.class); IntrospectionSupport.setProperties(sslTransport, options); - Map socketOptions = IntrospectionSupport.extractProperties(options, "socket."); + Map socketOptions = IntrospectionSupport.extractProperties(options, "socket."); sslTransport.setSocketOptions(socketOptions); diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportServer.java b/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportServer.java index 41a2bd4c79..93f482b18c 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportServer.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportServer.java @@ -40,10 +40,10 @@ import org.apache.activemq.wireformat.WireFormat; public class SslTransportServer extends TcpTransportServer { // Specifies if sockets created from this server should needClientAuth. - private boolean needClientAuth = false; + private boolean needClientAuth; // Specifies if sockets created from this server should wantClientAuth. - private boolean wantClientAuth = false; + private boolean wantClientAuth; /** diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpBufferedOutputStream.java b/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpBufferedOutputStream.java index 8f1b9453ae..dc6c4779e6 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpBufferedOutputStream.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpBufferedOutputStream.java @@ -33,7 +33,6 @@ public class TcpBufferedOutputStream extends FilterOutputStream { private byte[] buffer; private int bufferlen; private int count; - private boolean closed; /** * Constructor @@ -115,18 +114,6 @@ public class TcpBufferedOutputStream extends FilterOutputStream { */ public void close() throws IOException { super.close(); - closed = true; - } - - /** - * Checks that the stream has not been closed - * - * @throws IOException - */ - private void checkClosed() throws IOException { - if (closed) { - throw new EOFException("Cannot write to the stream any more it has already been closed"); - } } } diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java b/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java index 153306260b..8e65ab7cf9 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java @@ -56,7 +56,7 @@ public class TcpTransport extends TransportThreadSupport implements Transport, S protected final WireFormat wireFormat; protected int connectionTimeout = 30000; - protected int soTimeout = 0; + protected int soTimeout; protected int socketBufferSize = 64 * 1024; protected int ioBufferSize = 8 * 1024; protected Socket socket; @@ -68,7 +68,7 @@ public class TcpTransport extends TransportThreadSupport implements Transport, S protected SocketFactory socketFactory; protected final AtomicReference stoppedLatch = new AtomicReference(); - private Map socketOptions; + private Map socketOptions; private Boolean keepAlive; private Boolean tcpNoDelay; @@ -82,7 +82,8 @@ public class TcpTransport extends TransportThreadSupport implements Transport, S * @throws IOException * @throws UnknownHostException */ - public TcpTransport(WireFormat wireFormat, SocketFactory socketFactory, URI remoteLocation, URI localLocation) throws UnknownHostException, IOException { + public TcpTransport(WireFormat wireFormat, SocketFactory socketFactory, URI remoteLocation, + URI localLocation) throws UnknownHostException, IOException { this.wireFormat = wireFormat; this.socketFactory = socketFactory; try { @@ -313,7 +314,8 @@ public class TcpTransport extends TransportThreadSupport implements Transport, S InetSocketAddress remoteAddress = null; if (localLocation != null) { - localAddress = new InetSocketAddress(InetAddress.getByName(localLocation.getHost()), localLocation.getPort()); + localAddress = new InetSocketAddress(InetAddress.getByName(localLocation.getHost()), + localLocation.getPort()); } if (remoteLocation != null) { @@ -341,7 +343,8 @@ public class TcpTransport extends TransportThreadSupport implements Transport, S // For SSL sockets.. you can't create an unconnected socket :( // This means the timout option are not supported either. if (localAddress != null) { - socket = socketFactory.createSocket(remoteAddress.getAddress(), remoteAddress.getPort(), localAddress.getAddress(), localAddress.getPort()); + socket = socketFactory.createSocket(remoteAddress.getAddress(), remoteAddress.getPort(), + localAddress.getAddress(), localAddress.getPort()); } else { socket = socketFactory.createSocket(remoteAddress.getAddress(), remoteAddress.getPort()); } @@ -392,8 +395,8 @@ public class TcpTransport extends TransportThreadSupport implements Transport, S } } - public void setSocketOptions(Map socketOptions) { - this.socketOptions = new HashMap(socketOptions); + public void setSocketOptions(Map socketOptions) { + this.socketOptions = new HashMap(socketOptions); } public String getRemoteAddress() { diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportFactory.java b/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportFactory.java index ba842dcab6..162e9fa980 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportFactory.java @@ -45,13 +45,13 @@ public class TcpTransportFactory extends TransportFactory { public TransportServer doBind(String brokerId, final URI location) throws IOException { try { - Map options = new HashMap(URISupport.parseParamters(location)); + Map options = new HashMap(URISupport.parseParamters(location)); ServerSocketFactory serverSocketFactory = createServerSocketFactory(); TcpTransportServer server = createTcpTransportServer(location, serverSocketFactory); server.setWireFormatFactory(createWireFormatFactory(options)); IntrospectionSupport.setProperties(server, options); - Map transportOptions = IntrospectionSupport.extractProperties(options, "transport."); + Map transportOptions = IntrospectionSupport.extractProperties(options, "transport."); server.setTransportOption(transportOptions); server.bind(); @@ -80,7 +80,7 @@ public class TcpTransportFactory extends TransportFactory { TcpTransport tcpTransport = (TcpTransport)transport.narrow(TcpTransport.class); IntrospectionSupport.setProperties(tcpTransport, options); - Map socketOptions = IntrospectionSupport.extractProperties(options, "socket."); + Map socketOptions = IntrospectionSupport.extractProperties(options, "socket."); tcpTransport.setSocketOptions(socketOptions); if (tcpTransport.isTrace()) { diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportServer.java b/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportServer.java index 084a566389..644a92911f 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportServer.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportServer.java @@ -58,7 +58,7 @@ public class TcpTransportServer extends TransportServerThreadSupport { protected long maxInactivityDuration = 30000; protected int minmumWireFormatVersion; protected boolean trace; - protected Map transportOptions; + protected Map transportOptions; protected final ServerSocketFactory serverSocketFactory; public TcpTransportServer(TcpTransportFactory transportFactory, URI location, ServerSocketFactory serverSocketFactory) throws IOException, URISyntaxException { @@ -159,7 +159,7 @@ public class TcpTransportServer extends TransportServerThreadSupport { if (isStopped() || getAcceptListener() == null) { socket.close(); } else { - HashMap options = new HashMap(); + HashMap options = new HashMap(); options.put("maxInactivityDuration", Long.valueOf(maxInactivityDuration)); options.put("minmumWireFormatVersion", Integer.valueOf(minmumWireFormatVersion)); options.put("trace", Boolean.valueOf(trace)); @@ -228,7 +228,7 @@ public class TcpTransportServer extends TransportServerThreadSupport { return (InetSocketAddress)serverSocket.getLocalSocketAddress(); } - public void setTransportOption(Map transportOptions) { + public void setTransportOption(Map transportOptions) { this.transportOptions = transportOptions; } } diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/udp/CommandDatagramChannel.java b/activemq-core/src/main/java/org/apache/activemq/transport/udp/CommandDatagramChannel.java index dc097a4695..06c6619b48 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/udp/CommandDatagramChannel.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/udp/CommandDatagramChannel.java @@ -126,7 +126,8 @@ public class CommandDatagramChannel extends CommandChannelSupport { // lets split the command up into chunks int offset = 0; boolean lastFragment = false; - for (int fragment = 0, length = data.length; !lastFragment; fragment++) { + int length = data.length; + for (int fragment = 0; !lastFragment; fragment++) { // write the header if (fragment > 0) { writeBuffer = bufferPool.borrowBuffer(); diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/udp/CommandDatagramSocket.java b/activemq-core/src/main/java/org/apache/activemq/transport/udp/CommandDatagramSocket.java index dfb87e4b06..f6fe85b74a 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/udp/CommandDatagramSocket.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/udp/CommandDatagramSocket.java @@ -104,7 +104,8 @@ public class CommandDatagramSocket extends CommandChannelSupport { // lets split the command up into chunks byte[] data = writeBuffer.toByteArray(); boolean lastFragment = false; - for (int fragment = 0, length = data.length; !lastFragment; fragment++) { + int length = data.length; + for (int fragment = 0; !lastFragment; fragment++) { writeBuffer = createByteArrayOutputStream(); headerMarshaller.writeHeader(command, dataOut); diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/udp/DatagramHeaderMarshaller.java b/activemq-core/src/main/java/org/apache/activemq/transport/udp/DatagramHeaderMarshaller.java index 72c82ac571..58d7c61b1c 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/udp/DatagramHeaderMarshaller.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/udp/DatagramHeaderMarshaller.java @@ -37,7 +37,7 @@ public class DatagramHeaderMarshaller { // TODO for large dynamic networks // we may want to evict endpoints that disconnect // from a transport - e.g. for multicast - private Map endpoints = new HashMap(); + private Map endpoints = new HashMap(); /** * Reads any header if applicable and then creates an endpoint object @@ -71,7 +71,7 @@ public class DatagramHeaderMarshaller { * */ protected Endpoint getEndpoint(SocketAddress address) { - Endpoint endpoint = (Endpoint) endpoints.get(address); + Endpoint endpoint = endpoints.get(address); if (endpoint == null) { endpoint = createEndpoint(address); endpoints.put(address, endpoint); diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/udp/DefaultBufferPool.java b/activemq-core/src/main/java/org/apache/activemq/transport/udp/DefaultBufferPool.java index 50d5e4b208..090ea5471f 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/udp/DefaultBufferPool.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/udp/DefaultBufferPool.java @@ -28,7 +28,7 @@ import java.util.List; */ public class DefaultBufferPool extends SimpleBufferPool implements ByteBufferPool { - private List buffers = new ArrayList(); + private List buffers = new ArrayList(); private Object lock = new Object(); public DefaultBufferPool() { @@ -43,7 +43,7 @@ public class DefaultBufferPool extends SimpleBufferPool implements ByteBufferPoo synchronized (lock) { int size = buffers.size(); if (size > 0) { - return (ByteBuffer) buffers.remove(size - 1); + return buffers.remove(size - 1); } } return createBuffer(); diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/udp/UdpTransport.java b/activemq-core/src/main/java/org/apache/activemq/transport/udp/UdpTransport.java index 2fc45e0389..c3f3536d3e 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/udp/UdpTransport.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/udp/UdpTransport.java @@ -64,11 +64,11 @@ public class UdpTransport extends TransportThreadSupport implements Transport, S private SocketAddress targetAddress; private SocketAddress originalTargetAddress; private DatagramChannel channel; - private boolean trace = false; + private boolean trace; private boolean useLocalHost = true; private int port; private int minmumWireFormatVersion; - private String description = null; + private String description; private IntSequenceGenerator sequenceGenerator; private boolean replayEnabled = true; diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/udp/UdpTransportFactory.java b/activemq-core/src/main/java/org/apache/activemq/transport/udp/UdpTransportFactory.java index 0ca7685364..e1b1e420f9 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/udp/UdpTransportFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/udp/UdpTransportFactory.java @@ -44,7 +44,7 @@ public class UdpTransportFactory extends TransportFactory { public TransportServer doBind(String brokerId, final URI location) throws IOException { try { - Map options = new HashMap(URISupport.parseParamters(location)); + Map options = new HashMap(URISupport.parseParamters(location)); if (options.containsKey("port")) { throw new IllegalArgumentException("The port property cannot be specified on a UDP server transport - please use the port in the URI syntax"); } diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/udp/UdpTransportServer.java b/activemq-core/src/main/java/org/apache/activemq/transport/udp/UdpTransportServer.java index e439ab3c3a..8bd5291584 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/udp/UdpTransportServer.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/udp/UdpTransportServer.java @@ -52,7 +52,7 @@ public class UdpTransportServer extends TransportServerSupport { private ReplayStrategy replayStrategy; private Transport configuredTransport; private boolean usingWireFormatNegotiation; - private Map transports = new HashMap(); + private Map transports = new HashMap(); public UdpTransportServer(URI connectURI, UdpTransport serverTransport, Transport configuredTransport, ReplayStrategy replayStrategy) { super(connectURI); @@ -108,7 +108,7 @@ public class UdpTransportServer extends TransportServerSupport { } Transport transport = null; synchronized (transports) { - transport = (Transport)transports.get(endpoint); + transport = transports.get(endpoint); if (transport == null) { if (usingWireFormatNegotiation && !command.isWireFormatInfo()) { LOG.error("Received inbound server communication from: " + command.getFrom() + " expecting WireFormatInfo but was command: " + command); @@ -146,7 +146,7 @@ public class UdpTransportServer extends TransportServerSupport { final UdpTransport transport = new UdpTransport(connectionWireFormat, address); final ReliableTransport reliableTransport = new ReliableTransport(transport, transport); - Replayer replayer = reliableTransport.getReplayer(); + reliableTransport.getReplayer(); reliableTransport.setReplayStrategy(replayStrategy); // Joiner must be on outside as the inbound messages must be processed diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransport.java b/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransport.java index 2a44469a6c..7e1bc0c568 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransport.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransport.java @@ -41,7 +41,6 @@ import org.apache.commons.logging.LogFactory; */ public class VMTransport implements Transport, Task { - private static final Log LOG = LogFactory.getLog(VMTransport.class); private static final AtomicLong NEXT_ID = new AtomicLong(0); private static final TaskRunnerFactory TASK_RUNNER_FACTORY = new TaskRunnerFactory("VMTransport", Thread.NORM_PRIORITY, true, 1000); protected VMTransport peer; @@ -51,7 +50,7 @@ public class VMTransport implements Transport, Task { protected boolean network; protected boolean async = true; protected int asyncQueueDepth = 2000; - protected LinkedBlockingQueue messageQueue; + protected LinkedBlockingQueue messageQueue; protected boolean started; protected final URI location; protected final long id; @@ -139,10 +138,10 @@ public class VMTransport implements Transport, Task { } } - private LinkedBlockingQueue getMessageQueue() { + private LinkedBlockingQueue getMessageQueue() { synchronized (mutex) { if (messageQueue == null) { - messageQueue = new LinkedBlockingQueue(this.asyncQueueDepth); + messageQueue = new LinkedBlockingQueue(this.asyncQueueDepth); } return messageQueue; } @@ -182,9 +181,9 @@ public class VMTransport implements Transport, Task { } } - public Object narrow(Class target) { + public T narrow(Class target) { if (target.isAssignableFrom(getClass())) { - return this; + return target.cast(this); } return null; } @@ -228,7 +227,7 @@ public class VMTransport implements Transport, Task { } } - LinkedBlockingQueue mq = getMessageQueue(); + LinkedBlockingQueue mq = getMessageQueue(); final Command command = (Command)mq.poll(); if (command != null) { tl.onCommand(command); diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransportFactory.java b/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransportFactory.java index 7013ea245e..1c0a85bd2d 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransportFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransportFactory.java @@ -42,9 +42,9 @@ import org.apache.commons.logging.LogFactory; public class VMTransportFactory extends TransportFactory { - public static final ConcurrentHashMap BROKERS = new ConcurrentHashMap(); - public static final ConcurrentHashMap CONNECTORS = new ConcurrentHashMap(); - public static final ConcurrentHashMap SERVERS = new ConcurrentHashMap(); + public static final ConcurrentHashMap BROKERS = new ConcurrentHashMap(); + public static final ConcurrentHashMap CONNECTORS = new ConcurrentHashMap(); + public static final ConcurrentHashMap SERVERS = new ConcurrentHashMap(); private static final Log LOG = LogFactory.getLog(VMTransportFactory.class); BrokerFactoryHandler brokerFactoryHandler; @@ -56,7 +56,7 @@ public class VMTransportFactory extends TransportFactory { public Transport doCompositeConnect(URI location) throws Exception { URI brokerURI; String host; - Map options; + Map options; boolean create = true; CompositeData data = URISupport.parseComposite(location); if (data.getComponents().length == 1 && "broker".equals(data.getComponents()[0].getScheme())) { @@ -96,7 +96,7 @@ public class VMTransportFactory extends TransportFactory { if (host == null) { host = "localhost"; } - VMTransportServer server = (VMTransportServer)SERVERS.get(host); + VMTransportServer server = SERVERS.get(host); // validate the broker is still active if (!validateBroker(host) || server == null) { BrokerService broker = null; @@ -123,7 +123,7 @@ public class VMTransportFactory extends TransportFactory { BROKERS.put(host, broker); } - server = (VMTransportServer)SERVERS.get(host); + server = SERVERS.get(host); if (server == null) { server = (VMTransportServer)bind(location, true); TransportConnector connector = new TransportConnector(broker.getBroker(), server); @@ -140,7 +140,7 @@ public class VMTransportFactory extends TransportFactory { IntrospectionSupport.setProperties(vmtransport, options); Transport transport = vmtransport; if (vmtransport.isMarshal()) { - HashMap optionsCopy = new HashMap(options); + Map optionsCopy = new HashMap(options); transport = new MarshallingTransportFilter(transport, createWireFormat(options), createWireFormat(optionsCopy)); } @@ -174,11 +174,11 @@ public class VMTransportFactory extends TransportFactory { public static void stopped(VMTransportServer server) { String host = server.getBindURI().getHost(); SERVERS.remove(host); - TransportConnector connector = (TransportConnector)CONNECTORS.remove(host); + TransportConnector connector = CONNECTORS.remove(host); if (connector != null) { LOG.debug("Shutting down VM connectors for broker: " + host); ServiceSupport.dispose(connector); - BrokerService broker = (BrokerService)BROKERS.remove(host); + BrokerService broker = BROKERS.remove(host); if (broker != null) { ServiceSupport.dispose(broker); } @@ -187,11 +187,11 @@ public class VMTransportFactory extends TransportFactory { public static void stopped(String host) { SERVERS.remove(host); - TransportConnector connector = (TransportConnector)CONNECTORS.remove(host); + TransportConnector connector = CONNECTORS.remove(host); if (connector != null) { LOG.debug("Shutting down VM connectors for broker: " + host); ServiceSupport.dispose(connector); - BrokerService broker = (BrokerService)BROKERS.remove(host); + BrokerService broker = BROKERS.remove(host); if (broker != null) { ServiceSupport.dispose(broker); } @@ -210,7 +210,7 @@ public class VMTransportFactory extends TransportFactory { boolean result = true; if (BROKERS.containsKey(host) || SERVERS.containsKey(host) || CONNECTORS.containsKey(host)) { // check the broker is still in the BrokerRegistry - TransportConnector connector = (TransportConnector)CONNECTORS.get(host); + TransportConnector connector = CONNECTORS.get(host); if (BrokerRegistry.getInstance().lookup(host) == null || (connector != null && connector.getBroker().isStopped())) { result = false; diff --git a/activemq-core/src/main/java/org/apache/activemq/util/BrokerSupport.java b/activemq-core/src/main/java/org/apache/activemq/util/BrokerSupport.java index 11d518efdb..28813550d1 100644 --- a/activemq-core/src/main/java/org/apache/activemq/util/BrokerSupport.java +++ b/activemq-core/src/main/java/org/apache/activemq/util/BrokerSupport.java @@ -23,8 +23,11 @@ import org.apache.activemq.command.Message; import org.apache.activemq.command.ProducerInfo; import org.apache.activemq.state.ProducerState; -public class BrokerSupport { +public final class BrokerSupport { + private BrokerSupport() { + } + /** * @param context * @param message diff --git a/activemq-core/src/main/java/org/apache/activemq/util/ByteSequenceData.java b/activemq-core/src/main/java/org/apache/activemq/util/ByteSequenceData.java index e65243b66a..1b8a40a6c1 100644 --- a/activemq-core/src/main/java/org/apache/activemq/util/ByteSequenceData.java +++ b/activemq-core/src/main/java/org/apache/activemq/util/ByteSequenceData.java @@ -23,6 +23,9 @@ import java.io.IOException; */ public final class ByteSequenceData { + private ByteSequenceData() { + } + public static byte[] toByteArray(ByteSequence packet) { if (packet.offset == 0 && packet.length == packet.data.length) { return packet.data; diff --git a/activemq-core/src/main/java/org/apache/activemq/util/DataByteArrayInputStream.java b/activemq-core/src/main/java/org/apache/activemq/util/DataByteArrayInputStream.java index 48509a332e..32a58594c0 100755 --- a/activemq-core/src/main/java/org/apache/activemq/util/DataByteArrayInputStream.java +++ b/activemq-core/src/main/java/org/apache/activemq/util/DataByteArrayInputStream.java @@ -252,7 +252,9 @@ public final class DataByteArrayInputStream extends InputStream implements DataI public String readUTF() throws IOException { int length = readUnsignedShort(); char[] characters = new char[length]; - int c, c2, c3; + int c; + int c2; + int c3; int count = 0; int total = pos + length; while (pos < total) { diff --git a/activemq-core/src/main/java/org/apache/activemq/util/DataByteArrayOutputStream.java b/activemq-core/src/main/java/org/apache/activemq/util/DataByteArrayOutputStream.java index 0a1f84d615..e2a8053634 100755 --- a/activemq-core/src/main/java/org/apache/activemq/util/DataByteArrayOutputStream.java +++ b/activemq-core/src/main/java/org/apache/activemq/util/DataByteArrayOutputStream.java @@ -216,7 +216,7 @@ public final class DataByteArrayOutputStream extends OutputStream implements Dat encodedsize += 2; } } - if (encodedsize > 65535){ + if (encodedsize > 65535) { throw new UTFDataFormatException("encoded string too long: " + encodedsize + " bytes"); } ensureEnoughBuffer(pos + encodedsize + 2); diff --git a/activemq-core/src/main/java/org/apache/activemq/util/FactoryFinder.java b/activemq-core/src/main/java/org/apache/activemq/util/FactoryFinder.java index 434f399f1c..50009f4e93 100644 --- a/activemq-core/src/main/java/org/apache/activemq/util/FactoryFinder.java +++ b/activemq-core/src/main/java/org/apache/activemq/util/FactoryFinder.java @@ -25,7 +25,7 @@ import java.util.concurrent.ConcurrentHashMap; public class FactoryFinder { private final String path; - private final ConcurrentHashMap classMap = new ConcurrentHashMap(); + private final ConcurrentHashMap classMap = new ConcurrentHashMap(); public FactoryFinder(String path) { this.path = path; @@ -47,7 +47,7 @@ public class FactoryFinder { propertyPrefix = ""; } - Class clazz = (Class)classMap.get(propertyPrefix + key); + Class clazz = classMap.get(propertyPrefix + key); if (clazz == null) { clazz = newInstance(doFindFactoryProperies(key), propertyPrefix); classMap.put(propertyPrefix + key, clazz); diff --git a/activemq-core/src/main/java/org/apache/activemq/util/HexSupport.java b/activemq-core/src/main/java/org/apache/activemq/util/HexSupport.java index 589b3c84a1..aa1ff95254 100755 --- a/activemq-core/src/main/java/org/apache/activemq/util/HexSupport.java +++ b/activemq-core/src/main/java/org/apache/activemq/util/HexSupport.java @@ -21,7 +21,7 @@ package org.apache.activemq.util; * * @version $Revision: 1.2 $ */ -public class HexSupport { +public final class HexSupport { private static final String[] HEX_TABLE = new String[]{ "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f", @@ -42,6 +42,9 @@ public class HexSupport { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff", }; + private HexSupport() { + } + /** * @param hex * @return diff --git a/activemq-core/src/main/java/org/apache/activemq/util/IOExceptionSupport.java b/activemq-core/src/main/java/org/apache/activemq/util/IOExceptionSupport.java index ee0cc4b5ec..ed0925f05d 100755 --- a/activemq-core/src/main/java/org/apache/activemq/util/IOExceptionSupport.java +++ b/activemq-core/src/main/java/org/apache/activemq/util/IOExceptionSupport.java @@ -20,6 +20,9 @@ import java.io.IOException; public final class IOExceptionSupport { + private IOExceptionSupport() { + } + public static IOException create(String msg, Throwable cause) { IOException exception = new IOException(msg); exception.initCause(cause); @@ -31,7 +34,7 @@ public final class IOExceptionSupport { exception.initCause(cause); return exception; } - + public static IOException create(Throwable cause) { IOException exception = new IOException(cause.getMessage()); exception.initCause(cause); @@ -43,5 +46,5 @@ public final class IOExceptionSupport { exception.initCause(cause); return exception; } - + } diff --git a/activemq-core/src/main/java/org/apache/activemq/util/IOHelper.java b/activemq-core/src/main/java/org/apache/activemq/util/IOHelper.java index 47899274b2..5bf91e290b 100644 --- a/activemq-core/src/main/java/org/apache/activemq/util/IOHelper.java +++ b/activemq-core/src/main/java/org/apache/activemq/util/IOHelper.java @@ -19,7 +19,10 @@ package org.apache.activemq.util; /** * @version $Revision$ */ -public class IOHelper { +public final class IOHelper { + + private IOHelper() { + } public static String getDefaultDataDirectory() { return getDefaultDirectoryPrefix() + "activemq-data"; diff --git a/activemq-core/src/main/java/org/apache/activemq/util/IdGenerator.java b/activemq-core/src/main/java/org/apache/activemq/util/IdGenerator.java index 0f1dcf7d1d..df9be31e22 100755 --- a/activemq-core/src/main/java/org/apache/activemq/util/IdGenerator.java +++ b/activemq-core/src/main/java/org/apache/activemq/util/IdGenerator.java @@ -63,6 +63,19 @@ public class IdGenerator { UNIQUE_STUB = stub; } + /** + * Construct an IdGenerator + */ + public IdGenerator(String prefix) { + synchronized (UNIQUE_STUB) { + this.seed = prefix + UNIQUE_STUB + (instanceCount++) + ":"; + } + } + + public IdGenerator() { + this("ID:" + hostName); + } + /** * As we have to find the hostname as a side-affect of generating a unique * stub, we allow it's easy retrevial here @@ -74,19 +87,6 @@ public class IdGenerator { return hostName; } - /** - * Construct an IdGenerator - */ - - public IdGenerator(String prefix) { - synchronized (UNIQUE_STUB) { - this.seed = prefix + UNIQUE_STUB + (instanceCount++) + ":"; - } - } - - public IdGenerator() { - this("ID:" + hostName); - } /** * Generate a unqiue id diff --git a/activemq-core/src/main/java/org/apache/activemq/util/IntrospectionSupport.java b/activemq-core/src/main/java/org/apache/activemq/util/IntrospectionSupport.java index b04ea81ecc..0f55dab764 100755 --- a/activemq-core/src/main/java/org/apache/activemq/util/IntrospectionSupport.java +++ b/activemq-core/src/main/java/org/apache/activemq/util/IntrospectionSupport.java @@ -33,7 +33,10 @@ import java.util.Set; import org.apache.activemq.command.ActiveMQDestination; -public class IntrospectionSupport { +public final class IntrospectionSupport { + + private IntrospectionSupport() { + } public static boolean getProperties(Object target, Map props, String optionPrefix) { @@ -92,8 +95,8 @@ public class IntrospectionSupport { throw new IllegalArgumentException("props was null."); } - for (Iterator iter = props.keySet().iterator(); iter.hasNext();) { - String name = (String)iter.next(); + for (Iterator iter = props.keySet().iterator(); iter.hasNext();) { + String name = iter.next(); if (name.startsWith(optionPrefix)) { Object value = props.get(name); name = name.substring(optionPrefix.length()); @@ -106,12 +109,12 @@ public class IntrospectionSupport { return rc; } - public static Map extractProperties(Map props, String optionPrefix) { + public static Map extractProperties(Map props, String optionPrefix) { if (props == null) { throw new IllegalArgumentException("props was null."); } - HashMap rc = new HashMap(props.size()); + HashMap rc = new HashMap(props.size()); for (Iterator iter = props.keySet().iterator(); iter.hasNext();) { String name = (String)iter.next(); @@ -225,7 +228,7 @@ public class IntrospectionSupport { } public static String toString(Object target, Class stopClass) { - LinkedHashMap map = new LinkedHashMap(); + LinkedHashMap map = new LinkedHashMap(); addFields(target, target.getClass(), stopClass, map); StringBuffer buffer = new StringBuffer(simpleName(target.getClass())); buffer.append(" {"); @@ -264,7 +267,7 @@ public class IntrospectionSupport { return name; } - private static void addFields(Object target, Class startClass, Class stopClass, LinkedHashMap map) { + private static void addFields(Object target, Class startClass, Class stopClass, LinkedHashMap map) { if (startClass != stopClass) { addFields(target, startClass.getSuperclass(), stopClass, map); @@ -273,7 +276,8 @@ public class IntrospectionSupport { Field[] fields = startClass.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; - if (Modifier.isStatic(field.getModifiers()) || Modifier.isTransient(field.getModifiers()) || Modifier.isPrivate(field.getModifiers())) { + if (Modifier.isStatic(field.getModifiers()) || Modifier.isTransient(field.getModifiers()) + || Modifier.isPrivate(field.getModifiers())) { continue; } diff --git a/activemq-core/src/main/java/org/apache/activemq/util/JMSExceptionSupport.java b/activemq-core/src/main/java/org/apache/activemq/util/JMSExceptionSupport.java index cf9f8e1580..9382362792 100755 --- a/activemq-core/src/main/java/org/apache/activemq/util/JMSExceptionSupport.java +++ b/activemq-core/src/main/java/org/apache/activemq/util/JMSExceptionSupport.java @@ -22,6 +22,9 @@ import javax.jms.MessageFormatException; public final class JMSExceptionSupport { + private JMSExceptionSupport() { + } + public static JMSException create(String msg, Throwable cause) { JMSException exception = new JMSException(msg); exception.initCause(cause); diff --git a/activemq-core/src/main/java/org/apache/activemq/util/JMXSupport.java b/activemq-core/src/main/java/org/apache/activemq/util/JMXSupport.java index 6a9688f9ad..03cd457bed 100755 --- a/activemq-core/src/main/java/org/apache/activemq/util/JMXSupport.java +++ b/activemq-core/src/main/java/org/apache/activemq/util/JMXSupport.java @@ -16,9 +16,13 @@ */ package org.apache.activemq.util; -public class JMXSupport { +public final class JMXSupport { + + private JMXSupport() { + } + public static String encodeObjectNamePart(String part) { - //return ObjectName.quote(part); + // return ObjectName.quote(part); String answer = part.replaceAll("[\\:\\,\\'\\\"]", "_"); answer = answer.replaceAll("\\?", "&qe;"); answer = answer.replaceAll("=", "&"); diff --git a/activemq-core/src/main/java/org/apache/activemq/util/MapHelper.java b/activemq-core/src/main/java/org/apache/activemq/util/MapHelper.java index da54442563..46b0a9f5d1 100755 --- a/activemq-core/src/main/java/org/apache/activemq/util/MapHelper.java +++ b/activemq-core/src/main/java/org/apache/activemq/util/MapHelper.java @@ -23,7 +23,11 @@ import java.util.Map; * * @version $Revision$ */ -public class MapHelper { +public final class MapHelper { + + private MapHelper() { + } + /** * Extracts the value from the map and coerces to a String */ diff --git a/activemq-core/src/main/java/org/apache/activemq/util/TypeConversionSupport.java b/activemq-core/src/main/java/org/apache/activemq/util/TypeConversionSupport.java index 943cec88a8..4e350b9e1b 100755 --- a/activemq-core/src/main/java/org/apache/activemq/util/TypeConversionSupport.java +++ b/activemq-core/src/main/java/org/apache/activemq/util/TypeConversionSupport.java @@ -21,7 +21,7 @@ import java.util.HashMap; import org.apache.activemq.command.ActiveMQDestination; -public class TypeConversionSupport { +public final class TypeConversionSupport { static class ConversionKey { final Class from; @@ -35,7 +35,7 @@ public class TypeConversionSupport { } public boolean equals(Object o) { - ConversionKey x = (ConversionKey) o; + ConversionKey x = (ConversionKey)o; return x.from == from && x.to == to; } @@ -48,7 +48,7 @@ public class TypeConversionSupport { Object convert(Object value); } - private static final HashMap CONVERSION_MAP = new HashMap(); + private static final HashMap CONVERSION_MAP = new HashMap(); static { Converter toStringConverter = new Converter() { public Object convert(Object value) { @@ -65,43 +65,43 @@ public class TypeConversionSupport { CONVERSION_MAP.put(new ConversionKey(String.class, Boolean.class), new Converter() { public Object convert(Object value) { - return Boolean.valueOf((String) value); + return Boolean.valueOf((String)value); } }); CONVERSION_MAP.put(new ConversionKey(String.class, Byte.class), new Converter() { public Object convert(Object value) { - return Byte.valueOf((String) value); + return Byte.valueOf((String)value); } }); CONVERSION_MAP.put(new ConversionKey(String.class, Short.class), new Converter() { public Object convert(Object value) { - return Short.valueOf((String) value); + return Short.valueOf((String)value); } }); CONVERSION_MAP.put(new ConversionKey(String.class, Integer.class), new Converter() { public Object convert(Object value) { - return Integer.valueOf((String) value); + return Integer.valueOf((String)value); } }); CONVERSION_MAP.put(new ConversionKey(String.class, Long.class), new Converter() { public Object convert(Object value) { - return Long.valueOf((String) value); + return Long.valueOf((String)value); } }); CONVERSION_MAP.put(new ConversionKey(String.class, Float.class), new Converter() { public Object convert(Object value) { - return Float.valueOf((String) value); + return Float.valueOf((String)value); } }); CONVERSION_MAP.put(new ConversionKey(String.class, Double.class), new Converter() { public Object convert(Object value) { - return Double.valueOf((String) value); + return Double.valueOf((String)value); } }); Converter longConverter = new Converter() { public Object convert(Object value) { - return Long.valueOf(((Number) value).longValue()); + return Long.valueOf(((Number)value).longValue()); } }; CONVERSION_MAP.put(new ConversionKey(Byte.class, Long.class), longConverter); @@ -109,13 +109,13 @@ public class TypeConversionSupport { CONVERSION_MAP.put(new ConversionKey(Integer.class, Long.class), longConverter); CONVERSION_MAP.put(new ConversionKey(Date.class, Long.class), new Converter() { public Object convert(Object value) { - return Long.valueOf(((Date) value).getTime()); + return Long.valueOf(((Date)value).getTime()); } }); Converter intConverter = new Converter() { public Object convert(Object value) { - return Integer.valueOf(((Number) value).intValue()); + return Integer.valueOf(((Number)value).intValue()); } }; CONVERSION_MAP.put(new ConversionKey(Byte.class, Integer.class), intConverter); @@ -123,22 +123,25 @@ public class TypeConversionSupport { CONVERSION_MAP.put(new ConversionKey(Byte.class, Short.class), new Converter() { public Object convert(Object value) { - return Short.valueOf(((Number) value).shortValue()); + return Short.valueOf(((Number)value).shortValue()); } }); - + CONVERSION_MAP.put(new ConversionKey(Float.class, Double.class), new Converter() { public Object convert(Object value) { - return new Double(((Number) value).doubleValue()); + return new Double(((Number)value).doubleValue()); } }); CONVERSION_MAP.put(new ConversionKey(String.class, ActiveMQDestination.class), new Converter() { public Object convert(Object value) { - return ActiveMQDestination.createDestination((String) value, ActiveMQDestination.QUEUE_TYPE); + return ActiveMQDestination.createDestination((String)value, ActiveMQDestination.QUEUE_TYPE); } }); } + private TypeConversionSupport() { + } + public static Object convert(Object value, Class clazz) { assert value != null && clazz != null; @@ -147,7 +150,7 @@ public class TypeConversionSupport { return value; } - Converter c = (Converter) CONVERSION_MAP.get(new ConversionKey(value.getClass(), clazz)); + Converter c = CONVERSION_MAP.get(new ConversionKey(value.getClass(), clazz)); if (c == null) { return null; } diff --git a/activemq-core/src/main/java/org/apache/activemq/util/URISupport.java b/activemq-core/src/main/java/org/apache/activemq/util/URISupport.java index 94dd99b5f0..0a77a0eb38 100755 --- a/activemq-core/src/main/java/org/apache/activemq/util/URISupport.java +++ b/activemq-core/src/main/java/org/apache/activemq/util/URISupport.java @@ -123,8 +123,13 @@ public class URISupport { } } - public static Map parseParamters(URI uri) throws URISyntaxException { - return uri.getQuery() == null ? Collections.EMPTY_MAP : parseQuery(stripPrefix(uri.getQuery(), "?")); + public static Map parseParamters(URI uri) throws URISyntaxException { + return uri.getQuery() == null ? emptyMap() : parseQuery(stripPrefix(uri.getQuery(), "?")); + } + + @SuppressWarnings("unchecked") + private static Map emptyMap() { + return Collections.EMPTY_MAP; } /** @@ -138,7 +143,8 @@ public class URISupport { * Creates a URI with the given query */ public static URI createURIWithQuery(URI uri, String query) throws URISyntaxException { - return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), query, uri.getFragment()); + return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), + query, uri.getFragment()); } public static CompositeData parseComposite(URI uri) throws URISyntaxException { @@ -202,7 +208,7 @@ public class URISupport { if (params.length() > 0) { rc.path = stripPrefix(params, "/"); } - rc.parameters = Collections.EMPTY_MAP; + rc.parameters = emptyMap(); } } @@ -296,7 +302,8 @@ public class URISupport { } public static URI changeScheme(URI bindAddr, String scheme) throws URISyntaxException { - return new URI(scheme, bindAddr.getUserInfo(), bindAddr.getHost(), bindAddr.getPort(), bindAddr.getPath(), bindAddr.getQuery(), bindAddr.getFragment()); + return new URI(scheme, bindAddr.getUserInfo(), bindAddr.getHost(), bindAddr.getPort(), bindAddr + .getPath(), bindAddr.getQuery(), bindAddr.getFragment()); } public static boolean checkParenthesis(String str) { diff --git a/activemq-core/src/main/java/org/apache/activemq/xbean/BrokerFactoryBean.java b/activemq-core/src/main/java/org/apache/activemq/xbean/BrokerFactoryBean.java index 9022a4fbf0..8e1d7c6d63 100644 --- a/activemq-core/src/main/java/org/apache/activemq/xbean/BrokerFactoryBean.java +++ b/activemq-core/src/main/java/org/apache/activemq/xbean/BrokerFactoryBean.java @@ -41,7 +41,6 @@ import org.springframework.core.io.Resource; * @version $Revision: 1.1 $ */ public class BrokerFactoryBean implements FactoryBean, InitializingBean, DisposableBean, ApplicationContextAware { - private static final Log LOG = LogFactory.getLog(BrokerFactoryBean.class); static { PropertyEditorManager.registerEditor(URI.class, URIEditor.class); diff --git a/activemq-core/src/main/java/org/apache/activemq/xbean/PooledBrokerFactoryBean.java b/activemq-core/src/main/java/org/apache/activemq/xbean/PooledBrokerFactoryBean.java index 77bf82a83d..bb6dec807a 100644 --- a/activemq-core/src/main/java/org/apache/activemq/xbean/PooledBrokerFactoryBean.java +++ b/activemq-core/src/main/java/org/apache/activemq/xbean/PooledBrokerFactoryBean.java @@ -34,7 +34,7 @@ import org.springframework.core.io.Resource; */ public class PooledBrokerFactoryBean implements FactoryBean, InitializingBean, DisposableBean { - static final HashMap SHARED_BROKER_MAP = new HashMap(); + static final HashMap SHARED_BROKER_MAP = new HashMap(); private boolean start; private Resource config; @@ -46,7 +46,7 @@ public class PooledBrokerFactoryBean implements FactoryBean, InitializingBean, D public void afterPropertiesSet() throws Exception { synchronized (SHARED_BROKER_MAP) { - SharedBroker sharedBroker = (SharedBroker)SHARED_BROKER_MAP.get(config.getFilename()); + SharedBroker sharedBroker = SHARED_BROKER_MAP.get(config.getFilename()); if (sharedBroker == null) { sharedBroker = new SharedBroker(); sharedBroker.factory = new BrokerFactoryBean(); @@ -61,7 +61,7 @@ public class PooledBrokerFactoryBean implements FactoryBean, InitializingBean, D public void destroy() throws Exception { synchronized (SHARED_BROKER_MAP) { - SharedBroker sharedBroker = (SharedBroker)SHARED_BROKER_MAP.get(config.getFilename()); + SharedBroker sharedBroker = SHARED_BROKER_MAP.get(config.getFilename()); if (sharedBroker != null) { sharedBroker.refCount--; if (sharedBroker.refCount == 0) { @@ -78,7 +78,7 @@ public class PooledBrokerFactoryBean implements FactoryBean, InitializingBean, D public Object getObject() throws Exception { synchronized (SHARED_BROKER_MAP) { - SharedBroker sharedBroker = (SharedBroker)SHARED_BROKER_MAP.get(config.getFilename()); + SharedBroker sharedBroker = SHARED_BROKER_MAP.get(config.getFilename()); if (sharedBroker != null) { return sharedBroker.factory.getObject(); } @@ -86,7 +86,7 @@ public class PooledBrokerFactoryBean implements FactoryBean, InitializingBean, D return null; } - public Class getObjectType() { + public Class getObjectType() { return BrokerService.class; } diff --git a/activemq-core/src/test/java/org/apache/activemq/AMQDeadlockTest3.java b/activemq-core/src/test/java/org/apache/activemq/AMQDeadlockTest3.java index 1d15b21aa0..810bdf303a 100644 --- a/activemq-core/src/test/java/org/apache/activemq/AMQDeadlockTest3.java +++ b/activemq-core/src/test/java/org/apache/activemq/AMQDeadlockTest3.java @@ -18,6 +18,7 @@ package org.apache.activemq; import java.net.URI; import java.util.ArrayList; +import java.util.List; import java.util.Random; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; @@ -241,7 +242,7 @@ public class AMQDeadlockTest3 extends TestCase { memoryManager.setLimit(5000000); brokerService.setMemoryManager(memoryManager); - final ArrayList policyEntries = new ArrayList(); + final List policyEntries = new ArrayList(); final PolicyEntry entry = new PolicyEntry(); entry.setQueue(">"); diff --git a/activemq-core/src/test/java/org/apache/activemq/ActiveMQMessageAuditTest.java b/activemq-core/src/test/java/org/apache/activemq/ActiveMQMessageAuditTest.java index d240bc0aae..8dca9b0251 100755 --- a/activemq-core/src/test/java/org/apache/activemq/ActiveMQMessageAuditTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/ActiveMQMessageAuditTest.java @@ -32,6 +32,16 @@ import org.apache.activemq.util.IdGenerator; */ public class ActiveMQMessageAuditTest extends TestCase { + + /** + * Constructor for ActiveMQMessageAuditTest. + * + * @param name + */ + public ActiveMQMessageAuditTest(String name) { + super(name); + } + public static void main(String[] args) { } @@ -43,15 +53,6 @@ public class ActiveMQMessageAuditTest extends TestCase { super.tearDown(); } - /** - * Constructor for ActiveMQMessageAuditTest. - * - * @param arg0 - */ - public ActiveMQMessageAuditTest(String arg0) { - super(arg0); - } - /** * test case for isDuplicate */ diff --git a/activemq-core/src/test/java/org/apache/activemq/CombinationTestSupport.java b/activemq-core/src/test/java/org/apache/activemq/CombinationTestSupport.java index 7b1d0ed943..8178186396 100755 --- a/activemq-core/src/test/java/org/apache/activemq/CombinationTestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/CombinationTestSupport.java @@ -62,22 +62,22 @@ public abstract class CombinationTestSupport extends AutoFailTestSupport { private static final Log LOG = LogFactory.getLog(CombinationTestSupport.class); - private HashMap comboOptions = new HashMap(); + private HashMap comboOptions = new HashMap(); private boolean combosEvaluated; private Map options; static class ComboOption { final String attribute; - final LinkedHashSet values = new LinkedHashSet(); + final LinkedHashSet values = new LinkedHashSet(); - public ComboOption(String attribute, Collection options) { + public ComboOption(String attribute, Collection options) { this.attribute = attribute; this.values.addAll(options); } } public void addCombinationValues(String attribute, Object[] options) { - ComboOption co = (ComboOption)this.comboOptions.get(attribute); + ComboOption co = this.comboOptions.get(attribute); if (co == null) { this.comboOptions.put(attribute, new ComboOption(attribute, Arrays.asList(options))); } else { @@ -129,20 +129,20 @@ public abstract class CombinationTestSupport extends AutoFailTestSupport { } try { - ArrayList expandedOptions = new ArrayList(); - expandCombinations(new ArrayList(comboOptions.values()), expandedOptions); + ArrayList> expandedOptions = new ArrayList>(); + expandCombinations(new ArrayList(comboOptions.values()), expandedOptions); if (expandedOptions.isEmpty()) { combosEvaluated = true; return new CombinationTestSupport[] {this}; } else { - ArrayList result = new ArrayList(); + ArrayList result = new ArrayList(); // Run the test case for each possible combination - for (Iterator iter = expandedOptions.iterator(); iter.hasNext();) { + for (Iterator> iter = expandedOptions.iterator(); iter.hasNext();) { CombinationTestSupport combo = (CombinationTestSupport)TestSuite.createTest(getClass(), name); combo.combosEvaluated = true; - combo.setOptions((Map)iter.next()); + combo.setOptions(iter.next()); result.add(combo); } @@ -157,23 +157,23 @@ public abstract class CombinationTestSupport extends AutoFailTestSupport { } - private void expandCombinations(List optionsLeft, List expandedCombos) { + private void expandCombinations(List optionsLeft, List> expandedCombos) { if (!optionsLeft.isEmpty()) { - HashMap map; + HashMap map; if (comboOptions.size() == optionsLeft.size()) { - map = new HashMap(); + map = new HashMap(); expandedCombos.add(map); } else { - map = (HashMap)expandedCombos.get(expandedCombos.size() - 1); + map = expandedCombos.get(expandedCombos.size() - 1); } - LinkedList l = new LinkedList(optionsLeft); - ComboOption comboOption = (ComboOption)l.removeLast(); + LinkedList l = new LinkedList(optionsLeft); + ComboOption comboOption = l.removeLast(); int i = 0; - for (Iterator iter = comboOption.values.iterator(); iter.hasNext();) { - Object value = (Object)iter.next(); + for (Iterator iter = comboOption.values.iterator(); iter.hasNext();) { + Object value = iter.next(); if (i != 0) { - map = new HashMap(map); + map = new HashMap(map); expandedCombos.add(map); } map.put(comboOption.attribute, value); @@ -183,10 +183,10 @@ public abstract class CombinationTestSupport extends AutoFailTestSupport { } } - public static Test suite(Class clazz) { + public static Test suite(Class clazz) { TestSuite suite = new TestSuite(); - ArrayList names = new ArrayList(); + ArrayList names = new ArrayList(); Method[] methods = clazz.getMethods(); for (int i = 0; i < methods.length; i++) { String name = methods[i].getName(); diff --git a/activemq-core/src/test/java/org/apache/activemq/ConnectionCleanupTest.java b/activemq-core/src/test/java/org/apache/activemq/ConnectionCleanupTest.java index ba639dd5b3..a9edb6f0fd 100755 --- a/activemq-core/src/test/java/org/apache/activemq/ConnectionCleanupTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/ConnectionCleanupTest.java @@ -46,7 +46,7 @@ public class ConnectionCleanupTest extends TestCase { public void testChangeClientID() throws JMSException { connection.setClientID("test"); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + connection.createSession(false, Session.AUTO_ACKNOWLEDGE); try { connection.setClientID("test"); diff --git a/activemq-core/src/test/java/org/apache/activemq/EmbeddedBrokerTestSupport.java b/activemq-core/src/test/java/org/apache/activemq/EmbeddedBrokerTestSupport.java index 57c99f6ec7..0ece680979 100644 --- a/activemq-core/src/test/java/org/apache/activemq/EmbeddedBrokerTestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/EmbeddedBrokerTestSupport.java @@ -37,8 +37,6 @@ import org.springframework.jms.core.JmsTemplate; */ public abstract class EmbeddedBrokerTestSupport extends TestCase { - private static final Log LOG = LogFactory.getLog(EmbeddedBrokerTestSupport.class); - protected BrokerService broker; // protected String bindAddress = "tcp://localhost:61616"; protected String bindAddress = "vm://localhost"; diff --git a/activemq-core/src/test/java/org/apache/activemq/JMSConsumerTest.java b/activemq-core/src/test/java/org/apache/activemq/JMSConsumerTest.java index 606704ca7b..8294e6309d 100755 --- a/activemq-core/src/test/java/org/apache/activemq/JMSConsumerTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/JMSConsumerTest.java @@ -33,6 +33,8 @@ import javax.jms.Topic; import junit.framework.Test; import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQQueue; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * Test cases used to test the JMS message consumer. @@ -41,7 +43,7 @@ import org.apache.activemq.command.ActiveMQQueue; */ public class JMSConsumerTest extends JmsTestSupport { - private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(JMSConsumerTest.class); + private static final Log LOG = LogFactory.getLog(JMSConsumerTest.class); public ActiveMQDestination destination; public int deliveryMode; @@ -487,7 +489,7 @@ public class JMSConsumerTest extends JmsTestSupport { ActiveMQConnection connection2 = (ActiveMQConnection)factory.createConnection(); connections.add(connection2); Session session2 = connection2.createSession(true, 0); - MessageConsumer consumer2 = session2.createConsumer(destination); + session2.createConsumer(destination); // Only pick up the 2nd messages. Message message2 = consumer.receive(1000); diff --git a/activemq-core/src/test/java/org/apache/activemq/JMSDurableTopicRedeliverTest.java b/activemq-core/src/test/java/org/apache/activemq/JMSDurableTopicRedeliverTest.java index c4a91243a3..25bb533d0e 100755 --- a/activemq-core/src/test/java/org/apache/activemq/JMSDurableTopicRedeliverTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/JMSDurableTopicRedeliverTest.java @@ -20,12 +20,15 @@ import javax.jms.Message; import javax.jms.Session; import javax.jms.TextMessage; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + /** * @version $Revision: 1.4 $ */ public class JMSDurableTopicRedeliverTest extends JmsTopicRedeliverTest { - private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(JMSDurableTopicRedeliverTest.class); + private static final Log LOG = LogFactory.getLog(JMSDurableTopicRedeliverTest.class); protected void setUp() throws Exception { durable = true; diff --git a/activemq-core/src/test/java/org/apache/activemq/JMSExclusiveConsumerTest.java b/activemq-core/src/test/java/org/apache/activemq/JMSExclusiveConsumerTest.java index f4ce875aa3..127df50af4 100644 --- a/activemq-core/src/test/java/org/apache/activemq/JMSExclusiveConsumerTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/JMSExclusiveConsumerTest.java @@ -23,7 +23,6 @@ import javax.jms.MessageProducer; import javax.jms.Session; import junit.framework.Test; - import org.apache.activemq.command.ActiveMQQueue; /** @@ -33,6 +32,8 @@ import org.apache.activemq.command.ActiveMQQueue; */ public class JMSExclusiveConsumerTest extends JmsTestSupport { + public int deliveryMode; + public static Test suite() { return suite(JMSExclusiveConsumerTest.class); } @@ -41,8 +42,6 @@ public class JMSExclusiveConsumerTest extends JmsTestSupport { junit.textui.TestRunner.run(suite()); } - public int deliveryMode; - public void initCombosForTestRoundRobinDispatchOnNonExclusive() { addCombinationValues("deliveryMode", new Object[] {Integer.valueOf(DeliveryMode.NON_PERSISTENT), Integer.valueOf(DeliveryMode.PERSISTENT)}); } diff --git a/activemq-core/src/test/java/org/apache/activemq/JMSMessageTest.java b/activemq-core/src/test/java/org/apache/activemq/JMSMessageTest.java index 4cd4d805dc..55c69fda16 100755 --- a/activemq-core/src/test/java/org/apache/activemq/JMSMessageTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/JMSMessageTest.java @@ -258,18 +258,19 @@ public class JMSMessageTest extends JmsTestSupport { static class ForeignMessage implements TextMessage { + public int deliveryMode; + private String messageId; private long timestamp; private String correlationId; private Destination replyTo; private Destination destination; - public int deliveryMode; private boolean redelivered; private String type; private long expiration; private int priority; private String text; - HashMap props = new HashMap(); + private HashMap props = new HashMap(); public String getJMSMessageID() throws JMSException { return messageId; @@ -402,7 +403,7 @@ public class JMSMessageTest extends JmsTestSupport { } public Enumeration getPropertyNames() throws JMSException { - return new Vector(props.keySet()).elements(); + return new Vector(props.keySet()).elements(); } public void setBooleanProperty(String arg0, boolean arg1) throws JMSException { diff --git a/activemq-core/src/test/java/org/apache/activemq/JMSUsecaseTest.java b/activemq-core/src/test/java/org/apache/activemq/JMSUsecaseTest.java index e682d689aa..9f4ca87682 100755 --- a/activemq-core/src/test/java/org/apache/activemq/JMSUsecaseTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/JMSUsecaseTest.java @@ -34,6 +34,12 @@ import org.apache.activemq.command.ActiveMQMessage; public class JMSUsecaseTest extends JmsTestSupport { + public ActiveMQDestination destination; + public int deliveryMode; + public int prefetch; + public byte destinationType; + public boolean durableConsumer; + public static Test suite() { return suite(JMSUsecaseTest.class); } @@ -42,12 +48,6 @@ public class JMSUsecaseTest extends JmsTestSupport { junit.textui.TestRunner.run(suite()); } - public ActiveMQDestination destination; - public int deliveryMode; - public int prefetch; - public byte destinationType; - public boolean durableConsumer; - public void initCombosForTestQueueBrowser() { addCombinationValues("deliveryMode", new Object[] {Integer.valueOf(DeliveryMode.NON_PERSISTENT), Integer.valueOf(DeliveryMode.PERSISTENT)}); addCombinationValues("destinationType", new Object[] {Byte.valueOf(ActiveMQDestination.QUEUE_TYPE), Byte.valueOf(ActiveMQDestination.TEMP_QUEUE_TYPE)}); diff --git a/activemq-core/src/test/java/org/apache/activemq/JmsBenchmark.java b/activemq-core/src/test/java/org/apache/activemq/JmsBenchmark.java index ca5d60fa62..ebcb844c93 100755 --- a/activemq-core/src/test/java/org/apache/activemq/JmsBenchmark.java +++ b/activemq-core/src/test/java/org/apache/activemq/JmsBenchmark.java @@ -176,7 +176,6 @@ public class JmsBenchmark extends JmsTestSupport { LOG.info("Starting sample: " + SAMPLES + " each lasting " + (SAMPLE_DURATION / 1000.0f) + " seconds"); - long now = System.currentTimeMillis(); for (int i = 0; i < SAMPLES; i++) { long start = System.currentTimeMillis(); diff --git a/activemq-core/src/test/java/org/apache/activemq/JmsCreateConsumerInOnMessageTest.java b/activemq-core/src/test/java/org/apache/activemq/JmsCreateConsumerInOnMessageTest.java index b62f658f3e..c7e86ee210 100755 --- a/activemq-core/src/test/java/org/apache/activemq/JmsCreateConsumerInOnMessageTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/JmsCreateConsumerInOnMessageTest.java @@ -87,7 +87,7 @@ public class JmsCreateConsumerInOnMessageTest extends TestSupport implements Mes public void onMessage(Message message) { try { testConsumer = consumerSession.createConsumer(topic); - MessageProducer anotherProducer = consumerSession.createProducer(topic); + consumerSession.createProducer(topic); synchronized (lock) { lock.notify(); } diff --git a/activemq-core/src/test/java/org/apache/activemq/JmsDurableTopicSendReceiveTest.java b/activemq-core/src/test/java/org/apache/activemq/JmsDurableTopicSendReceiveTest.java index 7b2c58e1ad..479cdbc165 100755 --- a/activemq-core/src/test/java/org/apache/activemq/JmsDurableTopicSendReceiveTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/JmsDurableTopicSendReceiveTest.java @@ -26,12 +26,14 @@ import javax.jms.TextMessage; import javax.jms.Topic; import org.apache.activemq.test.JmsTopicSendReceiveTest; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * @version $Revision: 1.5 $ */ public class JmsDurableTopicSendReceiveTest extends JmsTopicSendReceiveTest { - private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(JmsDurableTopicSendReceiveTest.class); + private static final Log LOG = LogFactory.getLog(JmsDurableTopicSendReceiveTest.class); protected Connection connection2; protected Session session2; diff --git a/activemq-core/src/test/java/org/apache/activemq/JmsDurableTopicWildcardSendReceiveTest.java b/activemq-core/src/test/java/org/apache/activemq/JmsDurableTopicWildcardSendReceiveTest.java index 438c0559c7..50e06743cb 100755 --- a/activemq-core/src/test/java/org/apache/activemq/JmsDurableTopicWildcardSendReceiveTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/JmsDurableTopicWildcardSendReceiveTest.java @@ -20,14 +20,14 @@ import javax.jms.DeliveryMode; import org.apache.activemq.test.JmsTopicSendReceiveTest; - /** * @version $Revision: 1.2 $ */ public class JmsDurableTopicWildcardSendReceiveTest extends JmsTopicSendReceiveTest { /** - * Sets up a test with a topic destination, durable suscriber and persistent delivery mode. + * Sets up a test with a topic destination, durable suscriber and persistent + * delivery mode. * * @see junit.framework.TestCase#setUp() */ @@ -37,18 +37,18 @@ public class JmsDurableTopicWildcardSendReceiveTest extends JmsTopicSendReceiveT deliveryMode = DeliveryMode.PERSISTENT; super.setUp(); } - + /** - * Returns the consumer subject. + * Returns the consumer subject. */ - protected String getConsumerSubject(){ + protected String getConsumerSubject() { return "FOO.>"; } - + /** - * Returns the producer subject. + * Returns the producer subject. */ - protected String getProducerSubject(){ + protected String getProducerSubject() { return "FOO.BAR.HUMBUG"; } } diff --git a/activemq-core/src/test/java/org/apache/activemq/JmsMultipleClientsTestSupport.java b/activemq-core/src/test/java/org/apache/activemq/JmsMultipleClientsTestSupport.java index 2b509d1ee4..d41e01b4b2 100644 --- a/activemq-core/src/test/java/org/apache/activemq/JmsMultipleClientsTestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/JmsMultipleClientsTestSupport.java @@ -51,9 +51,8 @@ import org.apache.activemq.util.MessageIdList; * @version $Revision$ */ public class JmsMultipleClientsTestSupport extends CombinationTestSupport { - private AtomicInteger producerLock; - protected Map consumers = new HashMap(); // Map of consumer with messages + protected Map consumers = new HashMap(); // Map of consumer with messages // received protected int consumerCount = 1; protected int producerCount = 1; @@ -67,9 +66,11 @@ public class JmsMultipleClientsTestSupport extends CombinationTestSupport { protected BrokerService broker; protected Destination destination; - protected List connections = Collections.synchronizedList(new ArrayList()); + protected List connections = Collections.synchronizedList(new ArrayList()); protected MessageIdList allMessagesList = new MessageIdList(); + private AtomicInteger producerLock; + protected void startProducers(Destination dest, int msgCount) throws Exception { startProducers(createConnectionFactory(), dest, msgCount); } @@ -219,8 +220,8 @@ public class JmsMultipleClientsTestSupport extends CombinationTestSupport { } protected void tearDown() throws Exception { - for (Iterator iter = connections.iterator(); iter.hasNext();) { - Connection conn = (Connection)iter.next(); + for (Iterator iter = connections.iterator(); iter.hasNext();) { + Connection conn = iter.next(); try { conn.close(); } catch (Throwable e) { @@ -236,35 +237,35 @@ public class JmsMultipleClientsTestSupport extends CombinationTestSupport { * Some helpful assertions for multiple consumers. */ protected void assertConsumerReceivedAtLeastXMessages(MessageConsumer consumer, int msgCount) { - MessageIdList messageIdList = (MessageIdList)consumers.get(consumer); + MessageIdList messageIdList = consumers.get(consumer); messageIdList.assertAtLeastMessagesReceived(msgCount); } protected void assertConsumerReceivedAtMostXMessages(MessageConsumer consumer, int msgCount) { - MessageIdList messageIdList = (MessageIdList)consumers.get(consumer); + MessageIdList messageIdList = consumers.get(consumer); messageIdList.assertAtMostMessagesReceived(msgCount); } protected void assertConsumerReceivedXMessages(MessageConsumer consumer, int msgCount) { - MessageIdList messageIdList = (MessageIdList)consumers.get(consumer); + MessageIdList messageIdList = consumers.get(consumer); messageIdList.assertMessagesReceivedNoWait(msgCount); } protected void assertEachConsumerReceivedAtLeastXMessages(int msgCount) { - for (Iterator i = consumers.keySet().iterator(); i.hasNext();) { - assertConsumerReceivedAtLeastXMessages((MessageConsumer)i.next(), msgCount); + for (Iterator i = consumers.keySet().iterator(); i.hasNext();) { + assertConsumerReceivedAtLeastXMessages(i.next(), msgCount); } } protected void assertEachConsumerReceivedAtMostXMessages(int msgCount) { - for (Iterator i = consumers.keySet().iterator(); i.hasNext();) { - assertConsumerReceivedAtMostXMessages((MessageConsumer)i.next(), msgCount); + for (Iterator i = consumers.keySet().iterator(); i.hasNext();) { + assertConsumerReceivedAtMostXMessages(i.next(), msgCount); } } protected void assertEachConsumerReceivedXMessages(int msgCount) { - for (Iterator i = consumers.keySet().iterator(); i.hasNext();) { - assertConsumerReceivedXMessages((MessageConsumer)i.next(), msgCount); + for (Iterator i = consumers.keySet().iterator(); i.hasNext();) { + assertConsumerReceivedXMessages(i.next(), msgCount); } } @@ -273,8 +274,8 @@ public class JmsMultipleClientsTestSupport extends CombinationTestSupport { // now lets count the individual messages received int totalMsg = 0; - for (Iterator i = consumers.keySet().iterator(); i.hasNext();) { - MessageIdList messageIdList = (MessageIdList)consumers.get(i.next()); + for (Iterator i = consumers.keySet().iterator(); i.hasNext();) { + MessageIdList messageIdList = consumers.get(i.next()); totalMsg += messageIdList.getMessageCount(); } assertEquals("Total of consumers message count", msgCount, totalMsg); diff --git a/activemq-core/src/test/java/org/apache/activemq/JmsQueueSendReceiveTwoConnectionsStartBeforeBrokerTest.java b/activemq-core/src/test/java/org/apache/activemq/JmsQueueSendReceiveTwoConnectionsStartBeforeBrokerTest.java index 22d312dbca..95795a3026 100644 --- a/activemq-core/src/test/java/org/apache/activemq/JmsQueueSendReceiveTwoConnectionsStartBeforeBrokerTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/JmsQueueSendReceiveTwoConnectionsStartBeforeBrokerTest.java @@ -29,7 +29,7 @@ import org.apache.commons.logging.LogFactory; public class JmsQueueSendReceiveTwoConnectionsStartBeforeBrokerTest extends JmsQueueSendReceiveTwoConnectionsTest { private static final Log LOG = LogFactory.getLog(JmsQueueSendReceiveTwoConnectionsStartBeforeBrokerTest.class); - private Queue errors = new ConcurrentLinkedQueue(); + private Queue errors = new ConcurrentLinkedQueue(); private int delayBeforeStartingBroker = 1000; private BrokerService broker; @@ -77,7 +77,7 @@ public class JmsQueueSendReceiveTwoConnectionsStartBeforeBrokerTest extends JmsQ broker.stop(); } if (!errors.isEmpty()) { - Exception e = (Exception)errors.remove(); + Exception e = errors.remove(); throw e; } } diff --git a/activemq-core/src/test/java/org/apache/activemq/JmsQueueSendReceiveTwoConnectionsTest.java b/activemq-core/src/test/java/org/apache/activemq/JmsQueueSendReceiveTwoConnectionsTest.java index 53eb1ef03c..12662dfa5e 100755 --- a/activemq-core/src/test/java/org/apache/activemq/JmsQueueSendReceiveTwoConnectionsTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/JmsQueueSendReceiveTwoConnectionsTest.java @@ -25,8 +25,6 @@ import org.apache.commons.logging.LogFactory; */ public class JmsQueueSendReceiveTwoConnectionsTest extends JmsTopicSendReceiveWithTwoConnectionsTest { - private static final Log LOG = LogFactory.getLog(JmsQueueSendReceiveTwoConnectionsTest.class); - /** * Set up the test with a queue and using two connections. * diff --git a/activemq-core/src/test/java/org/apache/activemq/JmsQueueTransactionTest.java b/activemq-core/src/test/java/org/apache/activemq/JmsQueueTransactionTest.java index c0b5b25ab8..d523008585 100755 --- a/activemq-core/src/test/java/org/apache/activemq/JmsQueueTransactionTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/JmsQueueTransactionTest.java @@ -28,12 +28,14 @@ import javax.jms.Session; import javax.jms.TextMessage; import org.apache.activemq.test.JmsResourceProvider; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * @version $Revision: 1.2 $ */ public class JmsQueueTransactionTest extends JmsTransactionTestSupport { - private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(JmsQueueTransactionTest.class); + private static final Log LOG = LogFactory.getLog(JmsQueueTransactionTest.class); /** * @see org.apache.activemq.JmsTransactionTestSupport#getJmsResourceProvider() @@ -65,7 +67,7 @@ public class JmsQueueTransactionTest extends JmsTransactionTestSupport { LOG.info("Sent 0: " + outbound[0]); LOG.info("Sent 1: " + outbound[1]); - ArrayList messages = new ArrayList(); + ArrayList messages = new ArrayList(); Message message = consumer.receive(1000); assertEquals(outbound[0], message); diff --git a/activemq-core/src/test/java/org/apache/activemq/JmsSendReceiveTestSupport.java b/activemq-core/src/test/java/org/apache/activemq/JmsSendReceiveTestSupport.java index 2448c78ffb..59b05fd708 100755 --- a/activemq-core/src/test/java/org/apache/activemq/JmsSendReceiveTestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/JmsSendReceiveTestSupport.java @@ -33,11 +33,14 @@ import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.TextMessage; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + /** * @version $Revision: 1.7 $ */ public class JmsSendReceiveTestSupport extends TestSupport implements MessageListener { - private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(JmsSendReceiveTestSupport.class); + private static final Log LOG = LogFactory.getLog(JmsSendReceiveTestSupport.class); protected int messageCount = 100; protected String[] data; @@ -46,7 +49,7 @@ public class JmsSendReceiveTestSupport extends TestSupport implements MessageLis protected MessageProducer producer; protected Destination consumerDestination; protected Destination producerDestination; - protected List messages = createConcurrentList(); + protected List messages = createConcurrentList(); protected boolean topic = true; protected boolean durable; protected int deliveryMode = DeliveryMode.PERSISTENT; @@ -118,12 +121,12 @@ public class JmsSendReceiveTestSupport extends TestSupport implements MessageLis * @param receivedMessages - list of received messages. * @throws JMSException */ - protected void assertMessagesReceivedAreValid(List receivedMessages) throws JMSException { - List copyOfMessages = Arrays.asList(receivedMessages.toArray()); + protected void assertMessagesReceivedAreValid(List receivedMessages) throws JMSException { + List copyOfMessages = Arrays.asList(receivedMessages.toArray()); int counter = 0; if (data.length != copyOfMessages.size()) { - for (Iterator iter = copyOfMessages.iterator(); iter.hasNext();) { + for (Iterator iter = copyOfMessages.iterator(); iter.hasNext();) { TextMessage message = (TextMessage)iter.next(); if (LOG.isInfoEnabled()) { LOG.info("<== " + counter++ + " = " + message.getText()); @@ -187,7 +190,7 @@ public class JmsSendReceiveTestSupport extends TestSupport implements MessageLis * @param message - message to be consumed. * @param messageList -list of consumed messages. */ - protected void consumeMessage(Message message, List messageList) { + protected void consumeMessage(Message message, List messageList) { if (verbose) { if (LOG.isDebugEnabled()) { LOG.info("Received message: " + message); @@ -208,8 +211,8 @@ public class JmsSendReceiveTestSupport extends TestSupport implements MessageLis * * @return List */ - protected List createConcurrentList() { - return Collections.synchronizedList(new ArrayList()); + protected List createConcurrentList() { + return Collections.synchronizedList(new ArrayList()); } /** diff --git a/activemq-core/src/test/java/org/apache/activemq/JmsSendReceiveWithMessageExpirationTest.java b/activemq-core/src/test/java/org/apache/activemq/JmsSendReceiveWithMessageExpirationTest.java index 03d6ae222f..cbb893d8a6 100644 --- a/activemq-core/src/test/java/org/apache/activemq/JmsSendReceiveWithMessageExpirationTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/JmsSendReceiveWithMessageExpirationTest.java @@ -28,12 +28,15 @@ import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.Topic; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + /** * */ public class JmsSendReceiveWithMessageExpirationTest extends TestSupport { - private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(JmsSendReceiveWithMessageExpirationTest.class); + private static final Log LOG = LogFactory.getLog(JmsSendReceiveWithMessageExpirationTest.class); protected int messageCount = 100; protected String[] data; diff --git a/activemq-core/src/test/java/org/apache/activemq/JmsTestSupport.java b/activemq-core/src/test/java/org/apache/activemq/JmsTestSupport.java index 8a86c22a0a..dac0189287 100755 --- a/activemq-core/src/test/java/org/apache/activemq/JmsTestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/JmsTestSupport.java @@ -50,7 +50,7 @@ public class JmsTestSupport extends CombinationTestSupport { protected ActiveMQConnection connection; protected BrokerService broker; - protected List connections = Collections.synchronizedList(new ArrayList()); + protected List connections = Collections.synchronizedList(new ArrayList()); // ///////////////////////////////////////////////////////////////// // diff --git a/activemq-core/src/test/java/org/apache/activemq/JmsTopicRedeliverTest.java b/activemq-core/src/test/java/org/apache/activemq/JmsTopicRedeliverTest.java index 2c20121a84..6dcc9420c4 100755 --- a/activemq-core/src/test/java/org/apache/activemq/JmsTopicRedeliverTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/JmsTopicRedeliverTest.java @@ -26,12 +26,15 @@ import javax.jms.Session; import javax.jms.TextMessage; import javax.jms.Topic; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + /** * @version $Revision: 1.4 $ */ public class JmsTopicRedeliverTest extends TestSupport { - private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(JmsTopicRedeliverTest.class); + private static final Log LOG = LogFactory.getLog(JmsTopicRedeliverTest.class); protected Connection connection; protected Session session; diff --git a/activemq-core/src/test/java/org/apache/activemq/JmsTopicRequestReplyTest.java b/activemq-core/src/test/java/org/apache/activemq/JmsTopicRequestReplyTest.java index 9f8f87ea62..f44c905370 100755 --- a/activemq-core/src/test/java/org/apache/activemq/JmsTopicRequestReplyTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/JmsTopicRequestReplyTest.java @@ -37,16 +37,16 @@ import org.apache.commons.logging.LogFactory; * @version $Revision: 1.3 $ */ public class JmsTopicRequestReplyTest extends TestSupport implements MessageListener { - private final Log log = LogFactory.getLog(getClass()); + private static final Log LOG = LogFactory.getLog(JmsTopicRequestReplyTest.class); + protected boolean useAsyncConsume; private Connection serverConnection; private Connection clientConnection; private MessageProducer replyProducer; private Session serverSession; private Destination requestDestination; - private List failures = new Vector(); + private List failures = new Vector(); private boolean dynamicallyCreateProducer; - protected boolean useAsyncConsume; private String clientSideClientID; public void testSendAndReceive() throws Exception { @@ -67,7 +67,7 @@ public class JmsTopicRequestReplyTest extends TestSupport implements MessageList // replyDestination); // assertEquals("clientID from the temporary destination must be the // same", clientSideClientID, value); - log.info("Both the clientID and destination clientID match properly: " + clientSideClientID); + LOG.info("Both the clientID and destination clientID match properly: " + clientSideClientID); /* build queues */ MessageProducer requestProducer = session.createProducer(requestDestination); @@ -78,15 +78,15 @@ public class JmsTopicRequestReplyTest extends TestSupport implements MessageList requestMessage.setJMSReplyTo(replyDestination); requestProducer.send(requestMessage); - log.info("Sent request."); - log.info(requestMessage.toString()); + LOG.info("Sent request."); + LOG.info(requestMessage.toString()); Message msg = replyConsumer.receive(5000); if (msg instanceof TextMessage) { TextMessage replyMessage = (TextMessage)msg; - log.info("Received reply."); - log.info(replyMessage.toString()); + LOG.info("Received reply."); + LOG.info(replyMessage.toString()); assertEquals("Wrong message content", "Hello: Olivier", replyMessage.getText()); } else { fail("Should have received a reply by now"); @@ -107,8 +107,8 @@ public class JmsTopicRequestReplyTest extends TestSupport implements MessageList try { TextMessage requestMessage = (TextMessage)message; - log.info("Received request."); - log.info(requestMessage.toString()); + LOG.info("Received request."); + LOG.info(requestMessage.toString()); Destination replyDestination = requestMessage.getJMSReplyTo(); @@ -130,8 +130,8 @@ public class JmsTopicRequestReplyTest extends TestSupport implements MessageList replyProducer.send(replyDestination, replyMessage); } - log.info("Sent reply."); - log.info(replyMessage.toString()); + LOG.info("Sent reply."); + LOG.info(replyMessage.toString()); } catch (JMSException e) { onException(e); } @@ -146,7 +146,7 @@ public class JmsTopicRequestReplyTest extends TestSupport implements MessageList if (message != null) { onMessage(message); } else { - log.error("No message received"); + LOG.error("No message received"); } } catch (JMSException e) { onException(e); @@ -188,7 +188,7 @@ public class JmsTopicRequestReplyTest extends TestSupport implements MessageList } protected void onException(JMSException e) { - log.info("Caught: " + e); + LOG.info("Caught: " + e); e.printStackTrace(); failures.add(e); } diff --git a/activemq-core/src/test/java/org/apache/activemq/JmsTopicSelectorTest.java b/activemq-core/src/test/java/org/apache/activemq/JmsTopicSelectorTest.java index b7f084b85d..7337a67171 100755 --- a/activemq-core/src/test/java/org/apache/activemq/JmsTopicSelectorTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/JmsTopicSelectorTest.java @@ -28,11 +28,14 @@ import javax.jms.Session; import javax.jms.TextMessage; import javax.jms.Topic; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + /** * @version $Revision: 1.2 $ */ public class JmsTopicSelectorTest extends TestSupport { - private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(JmsTopicSelectorTest.class); + private static final Log LOG = LogFactory.getLog(JmsTopicSelectorTest.class); protected Connection connection; protected Session session; diff --git a/activemq-core/src/test/java/org/apache/activemq/JmsTopicSendReceiveTest.java b/activemq-core/src/test/java/org/apache/activemq/JmsTopicSendReceiveTest.java index 13fa4b6b5f..da06892d26 100755 --- a/activemq-core/src/test/java/org/apache/activemq/JmsTopicSendReceiveTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/JmsTopicSendReceiveTest.java @@ -23,11 +23,14 @@ import javax.jms.MessageConsumer; import javax.jms.Session; import javax.jms.Topic; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + /** * @version $Revision: 1.3 $ */ public class JmsTopicSendReceiveTest extends JmsSendReceiveTestSupport { - private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(JmsTopicSendReceiveTest.class); + private static final Log LOG = LogFactory.getLog(JmsTopicSendReceiveTest.class); protected Connection connection; diff --git a/activemq-core/src/test/java/org/apache/activemq/JmsTransactionTestSupport.java b/activemq-core/src/test/java/org/apache/activemq/JmsTransactionTestSupport.java index 9c6e037011..25b4d972ed 100755 --- a/activemq-core/src/test/java/org/apache/activemq/JmsTransactionTestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/JmsTransactionTestSupport.java @@ -20,6 +20,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; + import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.Destination; @@ -31,17 +32,20 @@ import javax.jms.MessageProducer; import javax.jms.ObjectMessage; import javax.jms.Session; import javax.jms.TextMessage; + import org.apache.activemq.broker.BrokerFactory; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.test.JmsResourceProvider; import org.apache.activemq.test.TestSupport; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * @version $Revision: 1.9 $ */ public abstract class JmsTransactionTestSupport extends TestSupport implements MessageListener { - private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(JmsTransactionTestSupport.class); + private static final Log LOG = LogFactory.getLog(JmsTransactionTestSupport.class); private static final int MESSAGE_COUNT = 5; private static final String MESSAGE_TEXT = "message"; @@ -52,16 +56,15 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M protected MessageProducer producer; protected JmsResourceProvider resourceProvider; protected Destination destination; - - // for message listener test - private List unackMessages = new ArrayList(MESSAGE_COUNT); - private List ackMessages = new ArrayList(MESSAGE_COUNT); - private boolean resendPhase; protected int batchCount = 10; protected int batchSize = 20; - protected BrokerService broker; + // for message listener test + private List unackMessages = new ArrayList(MESSAGE_COUNT); + private List ackMessages = new ArrayList(MESSAGE_COUNT); + private boolean resendPhase; + public JmsTransactionTestSupport() { super(); } @@ -164,7 +167,7 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M session.commit(); // receives the first message - ArrayList messages = new ArrayList(); + ArrayList messages = new ArrayList(); LOG.info("About to consume message 1"); Message message = consumer.receive(1000); messages.add(message); @@ -207,7 +210,7 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M session.commit(); // receives the first message - ArrayList messages = new ArrayList(); + ArrayList messages = new ArrayList(); LOG.info("About to consume message 1"); Message message = consumer.receive(1000); messages.add(message); @@ -251,7 +254,7 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M session.commit(); // receives the first message - ArrayList messages = new ArrayList(); + ArrayList messages = new ArrayList(); LOG.info("About to consume message 1"); Message message = consumer.receive(1000); messages.add(message); @@ -292,7 +295,7 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M LOG.info("Sent 0: " + outbound[0]); LOG.info("Sent 1: " + outbound[1]); - ArrayList messages = new ArrayList(); + ArrayList messages = new ArrayList(); Message message = consumer.receive(1000); messages.add(message); assertEquals(outbound[0], message); @@ -338,7 +341,7 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M LOG.info("Sent 0: " + outbound[0]); LOG.info("Sent 1: " + outbound[1]); - ArrayList messages = new ArrayList(); + ArrayList messages = new ArrayList(); Message message = consumer.receive(1000); assertEquals(outbound[0], message); @@ -470,7 +473,7 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M } public void testChangeMutableObjectInObjectMessageThenRollback() throws Exception { - ArrayList list = new ArrayList(); + ArrayList list = new ArrayList(); list.add("First"); Message outbound = session.createObjectMessage(list); outbound.setStringProperty("foo", "abc"); @@ -481,7 +484,7 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M LOG.info("About to consume message 1"); Message message = consumer.receive(5000); - List body = assertReceivedObjectMessageWithListBody(message); + List body = assertReceivedObjectMessageWithListBody(message); // now lets try mutate it try { @@ -495,18 +498,19 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M session.rollback(); message = consumer.receive(5000); - List secondBody = assertReceivedObjectMessageWithListBody(message); + List secondBody = assertReceivedObjectMessageWithListBody(message); assertNotSame("Second call should return a different body", secondBody, body); session.commit(); } - protected List assertReceivedObjectMessageWithListBody(Message message) throws JMSException { + @SuppressWarnings("unchecked") + protected List assertReceivedObjectMessageWithListBody(Message message) throws JMSException { assertNotNull("Should have received a message!", message); assertEquals("foo header", "abc", message.getStringProperty("foo")); assertTrue("Should be an object message but was: " + message, message instanceof ObjectMessage); ObjectMessage objectMessage = (ObjectMessage)message; - List body = (List)objectMessage.getObject(); + List body = (List)objectMessage.getObject(); LOG.info("Received body: " + body); assertEquals("Size of list should be 1", 1, body.size()); diff --git a/activemq-core/src/test/java/org/apache/activemq/LargeMessageTestSupport.java b/activemq-core/src/test/java/org/apache/activemq/LargeMessageTestSupport.java index deeb8319cc..57f256c83b 100755 --- a/activemq-core/src/test/java/org/apache/activemq/LargeMessageTestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/LargeMessageTestSupport.java @@ -35,6 +35,8 @@ import org.apache.activemq.command.ActiveMQMessage; import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQTopic; import org.apache.activemq.util.IdGenerator; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * @version $Revision: 1.4 $ @@ -44,7 +46,7 @@ public class LargeMessageTestSupport extends ClientTestSupport implements Messag protected static final int LARGE_MESSAGE_SIZE = 128 * 1024; protected static final int MESSAGE_COUNT = 100; - private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(LargeMessageTestSupport.class); + private static final Log LOG = LogFactory.getLog(LargeMessageTestSupport.class); protected Connection producerConnection; protected Connection consumerConnection; diff --git a/activemq-core/src/test/java/org/apache/activemq/LargeStreamletTest.java b/activemq-core/src/test/java/org/apache/activemq/LargeStreamletTest.java index c3ed6dd702..2abf0385ab 100644 --- a/activemq-core/src/test/java/org/apache/activemq/LargeStreamletTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/LargeStreamletTest.java @@ -58,16 +58,13 @@ public final class LargeStreamletTest extends TestCase { private static final int BUFFER_SIZE = 1 * 1024; private static final int MESSAGE_COUNT = 10 * 1024; - private AtomicInteger totalRead = new AtomicInteger(); - - private AtomicInteger totalWritten = new AtomicInteger(); - - private AtomicBoolean stopThreads = new AtomicBoolean(false); - protected Exception writerException; - protected Exception readerException; + private AtomicInteger totalRead = new AtomicInteger(); + private AtomicInteger totalWritten = new AtomicInteger(); + private AtomicBoolean stopThreads = new AtomicBoolean(false); + public void testStreamlets() throws Exception { final ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(BROKER_URL); diff --git a/activemq-core/src/test/java/org/apache/activemq/LoadTestBurnIn.java b/activemq-core/src/test/java/org/apache/activemq/LoadTestBurnIn.java index 6d1328f3db..257110e046 100644 --- a/activemq-core/src/test/java/org/apache/activemq/LoadTestBurnIn.java +++ b/activemq-core/src/test/java/org/apache/activemq/LoadTestBurnIn.java @@ -51,6 +51,13 @@ import org.apache.commons.logging.LogFactory; public class LoadTestBurnIn extends JmsTestSupport { private static final transient Log LOG = LogFactory.getLog(LoadTestBurnIn.class); + public ActiveMQDestination destination; + public int deliveryMode; + public byte destinationType; + public boolean durableConsumer; + public int messageCount = 50000; + public int messageSize = 1024; + public static Test suite() { return suite(LoadTestBurnIn.class); } @@ -85,14 +92,6 @@ public class LoadTestBurnIn extends JmsTestSupport { .getServer().getConnectURI()); } - public ActiveMQDestination destination; - public int deliveryMode; - public byte destinationType; - public boolean durableConsumer; - - public int messageCount = 50000; - public int messageSize = 1024; - public void initCombosForTestSendReceive() { addCombinationValues("deliveryMode", new Object[] {Integer.valueOf(DeliveryMode.NON_PERSISTENT), Integer.valueOf(DeliveryMode.PERSISTENT)}); diff --git a/activemq-core/src/test/java/org/apache/activemq/MessageListenerRedeliveryTest.java b/activemq-core/src/test/java/org/apache/activemq/MessageListenerRedeliveryTest.java index 0e04731f45..00673dbaa7 100644 --- a/activemq-core/src/test/java/org/apache/activemq/MessageListenerRedeliveryTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/MessageListenerRedeliveryTest.java @@ -34,7 +34,7 @@ import org.apache.commons.logging.LogFactory; public class MessageListenerRedeliveryTest extends TestCase { - private Log log = LogFactory.getLog(getClass()); + private static final Log LOG = LogFactory.getLog(MessageListenerRedeliveryTest.class); private Connection connection; @@ -68,9 +68,9 @@ public class MessageListenerRedeliveryTest extends TestCase { } private class TestMessageListener implements MessageListener { - private Session session; public int counter; + private Session session; public TestMessageListener(Session session) { this.session = session; @@ -78,18 +78,18 @@ public class MessageListenerRedeliveryTest extends TestCase { public void onMessage(Message message) { try { - log.info("Message Received: " + message); + LOG.info("Message Received: " + message); counter++; if (counter <= 4) { - log.info("Message Rollback."); + LOG.info("Message Rollback."); session.rollback(); } else { - log.info("Message Commit."); + LOG.info("Message Commit."); message.acknowledge(); session.commit(); } } catch (JMSException e) { - log.error("Error when rolling back transaction"); + LOG.error("Error when rolling back transaction"); } } } diff --git a/activemq-core/src/test/java/org/apache/activemq/SpringTestSupport.java b/activemq-core/src/test/java/org/apache/activemq/SpringTestSupport.java index e2c189206d..8249bbd443 100755 --- a/activemq-core/src/test/java/org/apache/activemq/SpringTestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/SpringTestSupport.java @@ -33,8 +33,6 @@ import org.springframework.context.support.AbstractApplicationContext; */ public abstract class SpringTestSupport extends TestCase { - protected final Log log = LogFactory.getLog(getClass()); - protected AbstractApplicationContext context; protected void setUp() throws Exception { @@ -58,7 +56,7 @@ public abstract class SpringTestSupport extends TestCase { } protected void assertSetEquals(String description, Object[] expected, Set actual) { - Set expectedSet = new HashSet(); + Set expectedSet = new HashSet(); expectedSet.addAll(Arrays.asList(expected)); assertEquals(description, expectedSet, actual); } diff --git a/activemq-core/src/test/java/org/apache/activemq/TestSupport.java b/activemq-core/src/test/java/org/apache/activemq/TestSupport.java index c5599afe4e..d59bd21564 100755 --- a/activemq-core/src/test/java/org/apache/activemq/TestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/TestSupport.java @@ -38,7 +38,6 @@ import org.apache.commons.logging.LogFactory; */ public class TestSupport extends TestCase { - protected Log log = LogFactory.getLog(getClass()); protected ActiveMQConnectionFactory connectionFactory; protected boolean topic = true; diff --git a/activemq-core/src/test/java/org/apache/activemq/ZeroPrefetchConsumerTest.java b/activemq-core/src/test/java/org/apache/activemq/ZeroPrefetchConsumerTest.java index 0d7fea80e0..2d29a1e2ca 100644 --- a/activemq-core/src/test/java/org/apache/activemq/ZeroPrefetchConsumerTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/ZeroPrefetchConsumerTest.java @@ -90,8 +90,8 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport { } // now lets receive it MessageConsumer consumer = session.createConsumer(queue); - // noinspection UNUSED_SYMBOL - MessageConsumer idleConsumer = session.createConsumer(queue); + + session.createConsumer(queue); TextMessage answer = (TextMessage)consumer.receive(5000); assertEquals("Should have received a message!", answer.getText(), "Msg1"); if (transacted) { diff --git a/activemq-core/src/test/java/org/apache/activemq/advisory/ConsumerListenerTest.java b/activemq-core/src/test/java/org/apache/activemq/advisory/ConsumerListenerTest.java index be7cca01e1..12d463875e 100644 --- a/activemq-core/src/test/java/org/apache/activemq/advisory/ConsumerListenerTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/advisory/ConsumerListenerTest.java @@ -43,7 +43,7 @@ public class ConsumerListenerTest extends EmbeddedBrokerTestSupport implements C protected Session consumerSession2; protected int consumerCounter; protected ConsumerEventSource consumerEventSource; - protected BlockingQueue eventQueue = new ArrayBlockingQueue(1000); + protected BlockingQueue eventQueue = new ArrayBlockingQueue(1000); private Connection connection; public void testConsumerEvents() throws Exception { @@ -131,7 +131,7 @@ public class ConsumerListenerTest extends EmbeddedBrokerTestSupport implements C } protected ConsumerEvent waitForConsumerEvent() throws InterruptedException { - ConsumerEvent answer = (ConsumerEvent)eventQueue.poll(100000, TimeUnit.MILLISECONDS); + ConsumerEvent answer = eventQueue.poll(100000, TimeUnit.MILLISECONDS); assertTrue("Should have received a consumer event!", answer != null); return answer; } diff --git a/activemq-core/src/test/java/org/apache/activemq/advisory/ProducerListenerTest.java b/activemq-core/src/test/java/org/apache/activemq/advisory/ProducerListenerTest.java index 6cbab6b75a..7e7079490e 100644 --- a/activemq-core/src/test/java/org/apache/activemq/advisory/ProducerListenerTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/advisory/ProducerListenerTest.java @@ -40,7 +40,7 @@ public class ProducerListenerTest extends EmbeddedBrokerTestSupport implements P protected Session consumerSession2; protected int consumerCounter; protected ProducerEventSource producerEventSource; - protected BlockingQueue eventQueue = new ArrayBlockingQueue(1000); + protected BlockingQueue eventQueue = new ArrayBlockingQueue(1000); private Connection connection; public void testProducerEvents() throws Exception { @@ -123,7 +123,7 @@ public class ProducerListenerTest extends EmbeddedBrokerTestSupport implements P } protected ProducerEvent waitForProducerEvent() throws InterruptedException { - ProducerEvent answer = (ProducerEvent)eventQueue.poll(100000, TimeUnit.MILLISECONDS); + ProducerEvent answer = eventQueue.poll(100000, TimeUnit.MILLISECONDS); assertTrue("Should have received a consumer event!", answer != null); return answer; } diff --git a/activemq-core/src/test/java/org/apache/activemq/advisory/TempDestDeleteTest.java b/activemq-core/src/test/java/org/apache/activemq/advisory/TempDestDeleteTest.java index 2225377aea..17c8f5d9a4 100644 --- a/activemq-core/src/test/java/org/apache/activemq/advisory/TempDestDeleteTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/advisory/TempDestDeleteTest.java @@ -44,9 +44,9 @@ public class TempDestDeleteTest extends EmbeddedBrokerTestSupport implements Con protected int consumerCounter; protected ConsumerEventSource topicConsumerEventSource; + protected BlockingQueue eventQueue = new ArrayBlockingQueue(1000); + private ConsumerEventSource queueConsumerEventSource; - - protected BlockingQueue eventQueue = new ArrayBlockingQueue(1000); private Connection connection; private Session session; private ActiveMQTempTopic tempTopic; @@ -141,7 +141,7 @@ public class TempDestDeleteTest extends EmbeddedBrokerTestSupport implements Con } protected ConsumerEvent waitForConsumerEvent() throws InterruptedException { - ConsumerEvent answer = (ConsumerEvent)eventQueue.poll(1000, TimeUnit.MILLISECONDS); + ConsumerEvent answer = eventQueue.poll(1000, TimeUnit.MILLISECONDS); assertTrue("Should have received a consumer event!", answer != null); return answer; } diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/BrokerTest.java b/activemq-core/src/test/java/org/apache/activemq/broker/BrokerTest.java index f73ddf9193..52352427a2 100755 --- a/activemq-core/src/test/java/org/apache/activemq/broker/BrokerTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/BrokerTest.java @@ -17,6 +17,7 @@ package org.apache.activemq.broker; import java.util.ArrayList; +import java.util.List; import java.util.concurrent.TimeUnit; import javax.jms.DeliveryMode; @@ -145,7 +146,7 @@ public class BrokerTest extends BrokerTestSupport { connection2.send(sessionInfo2); connection2.request(consumerInfo2); - ArrayList messages = new ArrayList(); + List messages = new ArrayList(); for (int i = 0; i < 4; i++) { Message m1 = receiveMessage(connection1); @@ -154,7 +155,7 @@ public class BrokerTest extends BrokerTestSupport { } for (int i = 0; i < 4; i++) { - Message m1 = (Message)messages.get(i); + Message m1 = messages.get(i); Message m2 = receiveMessage(connection2); assertNotNull("m2 is null for index: " + i, m2); assertEquals(m1.getMessageId(), m2.getMessageId()); diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/BrokerTestSupport.java b/activemq-core/src/test/java/org/apache/activemq/broker/BrokerTestSupport.java index e4f3f67861..54437db3ea 100755 --- a/activemq-core/src/test/java/org/apache/activemq/broker/BrokerTestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/BrokerTestSupport.java @@ -64,9 +64,6 @@ public class BrokerTestSupport extends CombinationTestSupport { */ public static final boolean FAST_NO_MESSAGE_LEFT_ASSERT = System.getProperty("FAST_NO_MESSAGE_LEFT_ASSERT", "true").equals("true"); - private static final Log LOG = LogFactory.getLog(BrokerTestSupport.class); - - protected RegionBroker regionBroker; protected BrokerService broker; protected long idGenerator; @@ -199,7 +196,6 @@ public class BrokerTestSupport extends CombinationTestSupport { } protected XATransactionId createXATransaction(SessionInfo info) throws IOException { - long id = txGenerator; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream os = new DataOutputStream(baos); os.writeLong(++txGenerator); @@ -247,7 +243,7 @@ public class BrokerTestSupport extends CombinationTestSupport { consumerInfo.setBrowser(true); connection.send(consumerInfo); - ArrayList skipped = new ArrayList(); + ArrayList skipped = new ArrayList(); // Now get the messages. Object m = connection.getDispatchQueue().poll(maxWait, TimeUnit.MILLISECONDS); @@ -267,7 +263,7 @@ public class BrokerTestSupport extends CombinationTestSupport { m = connection.getDispatchQueue().poll(maxWait, TimeUnit.MILLISECONDS); } - for (Iterator iter = skipped.iterator(); iter.hasNext();) { + for (Iterator iter = skipped.iterator(); iter.hasNext();) { connection.getDispatchQueue().put(iter.next()); } diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/Main.java b/activemq-core/src/test/java/org/apache/activemq/broker/Main.java index 463efc94cb..952308c9ef 100644 --- a/activemq-core/src/test/java/org/apache/activemq/broker/Main.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/Main.java @@ -31,17 +31,16 @@ import org.apache.activemq.demo.DefaultQueueSender; * * @version $Revision$ */ -public class Main { +public final class Main { protected static boolean createConsumers; + private Main() { + } + /** * @param args */ public static void main(String[] args) { - String brokerURI = "broker:(tcp://localhost:61616,stomp://localhost:61613)?persistent=false&useJmx=true"; - if (args.length > 0) { - brokerURI = args[0]; - } try { // TODO - this seems to break interceptors for some reason // BrokerService broker = BrokerFactory.createBroker(new @@ -71,10 +70,10 @@ public class Main { Connection connection = new ActiveMQConnectionFactory().createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - MessageConsumer consumer1 = session.createConsumer(new ActiveMQQueue("Orders.IBM")); - MessageConsumer consumer2 = session.createConsumer(new ActiveMQQueue("Orders.MSFT"), "price > 100"); + session.createConsumer(new ActiveMQQueue("Orders.IBM")); + session.createConsumer(new ActiveMQQueue("Orders.MSFT"), "price > 100"); Session session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - MessageConsumer consumer3 = session2.createConsumer(new ActiveMQQueue("Orders.MSFT"), "price > 200"); + session2.createConsumer(new ActiveMQQueue("Orders.MSFT"), "price > 200"); } else { // Lets wait for the broker broker.waitUntilStopped(); diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/MarshallingBrokerTest.java b/activemq-core/src/test/java/org/apache/activemq/broker/MarshallingBrokerTest.java index 1217232495..d9580e6926 100755 --- a/activemq-core/src/test/java/org/apache/activemq/broker/MarshallingBrokerTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/MarshallingBrokerTest.java @@ -41,7 +41,7 @@ public class MarshallingBrokerTest extends BrokerTest { OpenWireFormat wf2 = new OpenWireFormat(); wf2.setCacheEnabled(true); - addCombinationValues("wireFormat", new Object[] {wf1, wf2,}); + addCombinationValues("wireFormat", new Object[] {wf1, wf2, }); } protected StubConnection createConnection() throws Exception { diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/MessageExpirationTest.java b/activemq-core/src/test/java/org/apache/activemq/broker/MessageExpirationTest.java index df7c6c56c9..44eea54d39 100644 --- a/activemq-core/src/test/java/org/apache/activemq/broker/MessageExpirationTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/MessageExpirationTest.java @@ -49,7 +49,7 @@ public class MessageExpirationTest extends BrokerTestSupport { public void initCombosForTestMessagesWaitingForUssageDecreaseExpire() { addCombinationValues("deliveryMode", new Object[] {Integer.valueOf(DeliveryMode.NON_PERSISTENT), Integer.valueOf(DeliveryMode.PERSISTENT)}); addCombinationValues("destinationType", new Object[] {Byte.valueOf(ActiveMQDestination.TEMP_QUEUE_TYPE), Byte.valueOf(ActiveMQDestination.TEMP_TOPIC_TYPE), - Byte.valueOf(ActiveMQDestination.QUEUE_TYPE), Byte.valueOf(ActiveMQDestination.TOPIC_TYPE),}); + Byte.valueOf(ActiveMQDestination.QUEUE_TYPE), Byte.valueOf(ActiveMQDestination.TOPIC_TYPE)}); } @Override @@ -148,7 +148,7 @@ public class MessageExpirationTest extends BrokerTestSupport { * DeliveryMode.PERSISTENT test combination for now. */ public void initCombosForTestMessagesInLongTransactionExpire() { - addCombinationValues("deliveryMode", new Object[] {Integer.valueOf(DeliveryMode.NON_PERSISTENT),}); + addCombinationValues("deliveryMode", new Object[] {Integer.valueOf(DeliveryMode.NON_PERSISTENT)}); addCombinationValues("destinationType", new Object[] {Byte.valueOf(ActiveMQDestination.QUEUE_TYPE), Byte.valueOf(ActiveMQDestination.TOPIC_TYPE), Byte.valueOf(ActiveMQDestination.TEMP_QUEUE_TYPE), Byte.valueOf(ActiveMQDestination.TEMP_TOPIC_TYPE)}); } diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/ProgressPrinter.java b/activemq-core/src/test/java/org/apache/activemq/broker/ProgressPrinter.java index 707248d9c0..dcf4b6e614 100755 --- a/activemq-core/src/test/java/org/apache/activemq/broker/ProgressPrinter.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/ProgressPrinter.java @@ -21,8 +21,8 @@ public class ProgressPrinter { private final long total; private final long interval; - long percentDone; - long counter; + private long percentDone; + private long counter; public ProgressPrinter(long total, long interval) { this.total = total; diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/StubBroker.java b/activemq-core/src/test/java/org/apache/activemq/broker/StubBroker.java index 88fe04aa16..f098c1c022 100644 --- a/activemq-core/src/test/java/org/apache/activemq/broker/StubBroker.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/StubBroker.java @@ -45,8 +45,8 @@ import org.apache.activemq.command.TransactionId; import org.apache.activemq.kaha.Store; public class StubBroker implements Broker { - public LinkedList addConnectionData = new LinkedList(); - public LinkedList removeConnectionData = new LinkedList(); + public LinkedList addConnectionData = new LinkedList(); + public LinkedList removeConnectionData = new LinkedList(); public class AddConnectionData { public final ConnectionContext connectionContext; @@ -124,7 +124,7 @@ public class StubBroker implements Broker { return null; } - public Set getDurableDestinations() { + public Set getDurableDestinations() { return null; } @@ -190,7 +190,7 @@ public class StubBroker implements Broker { public void gc() { } - public Map getDestinationMap() { + public Map getDestinationMap() { return null; } diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/StubConnection.java b/activemq-core/src/test/java/org/apache/activemq/broker/StubConnection.java index a3d7df2dda..4363f17fb4 100755 --- a/activemq-core/src/test/java/org/apache/activemq/broker/StubConnection.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/StubConnection.java @@ -34,14 +34,10 @@ import org.apache.activemq.util.ServiceSupport; public class StubConnection implements Service { - private final BlockingQueue dispatchQueue = new LinkedBlockingQueue(); + private final BlockingQueue dispatchQueue = new LinkedBlockingQueue(); private Connection connection; private Transport transport; - boolean shuttingDown; - - protected void dispatch(Object command) throws InterruptedException, IOException { - dispatchQueue.put(command); - } + private boolean shuttingDown; public StubConnection(BrokerService broker) throws Exception { this(TransportFactory.connect(broker.getVmConnectorURI())); @@ -74,7 +70,11 @@ public class StubConnection implements Service { transport.start(); } - public BlockingQueue getDispatchQueue() { + protected void dispatch(Object command) throws InterruptedException, IOException { + dispatchQueue.put(command); + } + + public BlockingQueue getDispatchQueue() { return dispatchQueue; } diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/policy/DeadLetterTest.java b/activemq-core/src/test/java/org/apache/activemq/broker/policy/DeadLetterTest.java index d88c2d2eee..403434f9bb 100644 --- a/activemq-core/src/test/java/org/apache/activemq/broker/policy/DeadLetterTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/policy/DeadLetterTest.java @@ -23,12 +23,15 @@ import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.RedeliveryPolicy; import org.apache.activemq.command.ActiveMQQueue; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * * @version $Revision$ */ public class DeadLetterTest extends DeadLetterTestSupport { + private static final Log LOG = LogFactory.getLog(DeadLetterTest.class); private int rollbackCount; @@ -37,7 +40,7 @@ public class DeadLetterTest extends DeadLetterTestSupport { ActiveMQConnection amqConnection = (ActiveMQConnection) connection; rollbackCount = amqConnection.getRedeliveryPolicy().getMaximumRedeliveries() + 1; - log.info("Will redeliver messages: " + rollbackCount + " times"); + LOG.info("Will redeliver messages: " + rollbackCount + " times"); makeConsumer(); makeDlqConsumer(); @@ -64,7 +67,7 @@ public class DeadLetterTest extends DeadLetterTestSupport { session.rollback(); } - log.info("Rolled back: " + rollbackCount + " times"); + LOG.info("Rolled back: " + rollbackCount + " times"); } protected void setUp() throws Exception { diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/policy/DeadLetterTestSupport.java b/activemq-core/src/test/java/org/apache/activemq/broker/policy/DeadLetterTestSupport.java index 6d97f594f6..48906f5c4b 100755 --- a/activemq-core/src/test/java/org/apache/activemq/broker/policy/DeadLetterTestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/policy/DeadLetterTestSupport.java @@ -29,11 +29,14 @@ import javax.jms.Topic; import org.apache.activemq.TestSupport; import org.apache.activemq.broker.BrokerService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * @version $Revision$ */ public abstract class DeadLetterTestSupport extends TestSupport { + private static final Log LOG = LogFactory.getLog(DeadLetterTestSupport.class); protected int messageCount = 10; protected long timeToLive; @@ -80,7 +83,7 @@ public abstract class DeadLetterTestSupport extends TestSupport { protected void makeConsumer() throws JMSException { Destination destination = getDestination(); - log.info("Consuming from: " + destination); + LOG.info("Consuming from: " + destination); if (durableSubscriber) { consumer = session.createDurableSubscriber((Topic)destination, destination.toString()); } else { @@ -91,7 +94,7 @@ public abstract class DeadLetterTestSupport extends TestSupport { protected void makeDlqConsumer() throws JMSException { dlqDestination = createDlqDestination(); - log.info("Consuming from dead letter on: " + dlqDestination); + LOG.info("Consuming from dead letter on: " + dlqDestination); dlqConsumer = session.createConsumer(dlqDestination); } @@ -101,7 +104,7 @@ public abstract class DeadLetterTestSupport extends TestSupport { producer.setDeliveryMode(deliveryMode); producer.setTimeToLive(timeToLive); - log.info("Sending " + messageCount + " messages to: " + getDestination()); + LOG.info("Sending " + messageCount + " messages to: " + getDestination()); for (int i = 0; i < messageCount; i++) { Message message = createMessage(session, i); producer.send(message); @@ -117,7 +120,7 @@ public abstract class DeadLetterTestSupport extends TestSupport { } protected void assertMessage(Message message, int i) throws Exception { - log.info("Received message: " + message); + LOG.info("Received message: " + message); assertNotNull("No message received for index: " + i, message); assertTrue("Should be a TextMessage not: " + message, message instanceof TextMessage); TextMessage textMessage = (TextMessage)message; diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/policy/IndividualDeadLetterViaXmlTest.java b/activemq-core/src/test/java/org/apache/activemq/broker/policy/IndividualDeadLetterViaXmlTest.java index ca52abc2ad..72553089bf 100644 --- a/activemq-core/src/test/java/org/apache/activemq/broker/policy/IndividualDeadLetterViaXmlTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/policy/IndividualDeadLetterViaXmlTest.java @@ -21,6 +21,8 @@ import javax.jms.Destination; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.xbean.BrokerFactoryBean; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.core.io.ClassPathResource; /** @@ -28,6 +30,7 @@ import org.springframework.core.io.ClassPathResource; * @version $Revision$ */ public class IndividualDeadLetterViaXmlTest extends DeadLetterTest { + private static final Log LOG = LogFactory.getLog(IndividualDeadLetterViaXmlTest.class); protected BrokerService createBroker() throws Exception { @@ -39,7 +42,7 @@ public class IndividualDeadLetterViaXmlTest extends DeadLetterTest { protected Destination createDlqDestination() { String queueName = "Test.DLQ." + getClass().getName() + "." + getName(); - log.info("Using queue name: " + queueName); + LOG.info("Using queue name: " + queueName); return new ActiveMQQueue(queueName); } } diff --git a/activemq-core/src/test/java/org/apache/activemq/bugs/CraigsBugTest.java b/activemq-core/src/test/java/org/apache/activemq/bugs/CraigsBugTest.java index ac23f2a371..a059278ecd 100644 --- a/activemq-core/src/test/java/org/apache/activemq/bugs/CraigsBugTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/bugs/CraigsBugTest.java @@ -41,7 +41,7 @@ public class CraigsBugTest extends EmbeddedBrokerTestSupport { try { Session session = conn.createSession(false, 1); MessageConsumer consumer = session.createConsumer(queue, null); - Message msg = consumer.receive(1000); + consumer.receive(1000); } catch (JMSException e) { e.printStackTrace(); } diff --git a/activemq-core/src/test/java/org/apache/activemq/bugs/MessageSender.java b/activemq-core/src/test/java/org/apache/activemq/bugs/MessageSender.java index e6d0c782fa..903a476ece 100644 --- a/activemq-core/src/test/java/org/apache/activemq/bugs/MessageSender.java +++ b/activemq-core/src/test/java/org/apache/activemq/bugs/MessageSender.java @@ -1,3 +1,19 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.apache.activemq.bugs; import javax.jms.Connection; @@ -9,7 +25,7 @@ public class MessageSender { private MessageProducer producer; private Session session; - public MessageSender(String queueName,Connection connection, boolean useTransactedSession) throws Exception { + public MessageSender(String queueName, Connection connection, boolean useTransactedSession) throws Exception { session = useTransactedSession ? connection.createSession(true, Session.SESSION_TRANSACTED) : connection.createSession(false, Session.AUTO_ACKNOWLEDGE); producer = session.createProducer(session.createQueue(queueName)); } diff --git a/activemq-core/src/test/java/org/apache/activemq/bugs/Receiver.java b/activemq-core/src/test/java/org/apache/activemq/bugs/Receiver.java index 0233c2dfd9..b1872df208 100644 --- a/activemq-core/src/test/java/org/apache/activemq/bugs/Receiver.java +++ b/activemq-core/src/test/java/org/apache/activemq/bugs/Receiver.java @@ -1,5 +1,21 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.apache.activemq.bugs; public interface Receiver { - public void receive(String s) throws Exception; + void receive(String s) throws Exception; } diff --git a/activemq-core/src/test/java/org/apache/activemq/bugs/TransactionNotStartedErrorTest.java b/activemq-core/src/test/java/org/apache/activemq/bugs/TransactionNotStartedErrorTest.java index 9f8137cf1f..bc54382d02 100644 --- a/activemq-core/src/test/java/org/apache/activemq/bugs/TransactionNotStartedErrorTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/bugs/TransactionNotStartedErrorTest.java @@ -1,5 +1,4 @@ /** - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. @@ -7,7 +6,7 @@ * (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 + * 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, @@ -22,282 +21,266 @@ import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageConsumer; import javax.jms.MessageListener; - import javax.jms.ObjectMessage; import javax.jms.Session; -import junit.framework.TestCase; +import junit.framework.TestCase; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.broker.BrokerService; -import org.apache.activemq.bugs.Receiver; -import org.apache.activemq.bugs.MessageSender; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /* - * simulate message flow which cause the following exception - * in the broker (exception logged by client) - *

- * 2007-07-24 13:51:23,624 com.easynet.halo.Halo ERROR (LoggingErrorHandler.java: 23) JMS failure - * javax.jms.JMSException: Transaction 'TX:ID:dmt-53625-1185281414694-1:0:344' has not been started. - * at org.apache.activemq.broker.TransactionBroker.getTransaction(TransactionBroker.java:230) - * - * - * This appears to be consistent in a MacBook. Haven't been able to replicate it on Windows though + * simulate message flow which cause the following exception in the broker + * (exception logged by client)

2007-07-24 13:51:23,624 + * com.easynet.halo.Halo ERROR (LoggingErrorHandler.java: 23) JMS failure + * javax.jms.JMSException: Transaction 'TX:ID:dmt-53625-1185281414694-1:0:344' + * has not been started. at + * org.apache.activemq.broker.TransactionBroker.getTransaction(TransactionBroker.java:230) + * This appears to be consistent in a MacBook. Haven't been able to replicate it + * on Windows though */ public class TransactionNotStartedErrorTest extends TestCase { - private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory - .getLog(TransactionNotStartedErrorTest.class); - private String hectorToHalo = "hectorToHalo"; - private String xenaToHalo = "xenaToHalo"; - private String troyToHalo = "troyToHalo"; + private static final Log LOG = LogFactory.getLog(TransactionNotStartedErrorTest.class); + + private static int counter = 500; - private String haloToHector = "haloToHector"; - private String haloToXena = "haloToXena"; - private String haloToTroy = "haloToTroy"; + private static int hectorToHaloCtr; + private static int xenaToHaloCtr; + private static int troyToHaloCtr; - private static int counter = 500; + private static int haloToHectorCtr; + private static int haloToXenaCtr; + private static int haloToTroyCtr; - private static int hectorToHaloCtr = 0; - private static int xenaToHaloCtr = 0; - private static int troyToHaloCtr = 0; + private String hectorToHalo = "hectorToHalo"; + private String xenaToHalo = "xenaToHalo"; + private String troyToHalo = "troyToHalo"; - private static int haloToHectorCtr = 0; - private static int haloToXenaCtr = 0; - private static int haloToTroyCtr = 0; + private String haloToHector = "haloToHector"; + private String haloToXena = "haloToXena"; + private String haloToTroy = "haloToTroy"; - private BrokerService broker; - private Connection hectorConnection; - private Connection xenaConnection; - private Connection troyConnection; - private Connection haloConnection; + private BrokerService broker; - private final Object lock = new Object(); + private Connection hectorConnection; + private Connection xenaConnection; + private Connection troyConnection; + private Connection haloConnection; - public Connection createConnection() throws JMSException { - ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory( - "tcp://localhost:61616"); - return factory.createConnection(); - } + private final Object lock = new Object(); - public Session createSession(Connection connection, boolean transacted) - throws JMSException { - return connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE); - } + public Connection createConnection() throws JMSException { + ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616"); + return factory.createConnection(); + } - public void startBroker() throws Exception { - broker = new BrokerService(); - broker.setDeleteAllMessagesOnStartup(true); - broker.setPersistent(true); - broker.setUseJmx(true); - broker.addConnector("tcp://localhost:61616").setName("Default"); - broker.start(); - log.info("Starting broker.."); - } + public Session createSession(Connection connection, boolean transacted) throws JMSException { + return connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE); + } - public void tearDown() throws Exception { - hectorConnection.close(); - xenaConnection.close(); - troyConnection.close(); - haloConnection.close(); - broker.stop(); - } + public void startBroker() throws Exception { + broker = new BrokerService(); + broker.setDeleteAllMessagesOnStartup(true); + broker.setPersistent(true); + broker.setUseJmx(true); + broker.addConnector("tcp://localhost:61616").setName("Default"); + broker.start(); + LOG.info("Starting broker.."); + } - public void testTransactionNotStartedError() throws Exception { - startBroker(); - hectorConnection = createConnection(); - Thread hectorThread = buildProducer(hectorConnection, hectorToHalo); - Receiver hHectorReceiver = new Receiver() { - public void receive(String s) throws Exception { - haloToHectorCtr++; - if (haloToHectorCtr >= counter) { - synchronized (lock) { - lock.notifyAll(); - } - } - } - }; - buildReceiver(hectorConnection, haloToHector, false, hHectorReceiver); + public void tearDown() throws Exception { + hectorConnection.close(); + xenaConnection.close(); + troyConnection.close(); + haloConnection.close(); + broker.stop(); + } - troyConnection = createConnection(); - Thread troyThread = buildProducer(troyConnection, troyToHalo); - Receiver hTroyReceiver = new Receiver() { - public void receive(String s) throws Exception { - haloToTroyCtr++; - if (haloToTroyCtr >= counter) { - synchronized (lock) { - lock.notifyAll(); - } - } - } - }; - buildReceiver(hectorConnection, haloToTroy, false, hTroyReceiver); + public void testTransactionNotStartedError() throws Exception { + startBroker(); + hectorConnection = createConnection(); + Thread hectorThread = buildProducer(hectorConnection, hectorToHalo); + Receiver hHectorReceiver = new Receiver() { + public void receive(String s) throws Exception { + haloToHectorCtr++; + if (haloToHectorCtr >= counter) { + synchronized (lock) { + lock.notifyAll(); + } + } + } + }; + buildReceiver(hectorConnection, haloToHector, false, hHectorReceiver); - xenaConnection = createConnection(); - Thread xenaThread = buildProducer(xenaConnection, xenaToHalo); - Receiver hXenaReceiver = new Receiver() { - public void receive(String s) throws Exception { - haloToXenaCtr++; - if (haloToXenaCtr >= counter) { - synchronized (lock) { - lock.notifyAll(); - } - } - } - }; - buildReceiver(xenaConnection, haloToXena, false, hXenaReceiver); + troyConnection = createConnection(); + Thread troyThread = buildProducer(troyConnection, troyToHalo); + Receiver hTroyReceiver = new Receiver() { + public void receive(String s) throws Exception { + haloToTroyCtr++; + if (haloToTroyCtr >= counter) { + synchronized (lock) { + lock.notifyAll(); + } + } + } + }; + buildReceiver(hectorConnection, haloToTroy, false, hTroyReceiver); - haloConnection = createConnection(); - final MessageSender hectorSender = buildTransactionalProducer( - haloToHector, haloConnection); - final MessageSender troySender = buildTransactionalProducer(haloToTroy, - haloConnection); - final MessageSender xenaSender = buildTransactionalProducer(haloToXena, - haloConnection); - Receiver hectorReceiver = new Receiver() { - public void receive(String s) throws Exception { - hectorToHaloCtr++; - troySender.send("halo to troy because of hector"); - if (hectorToHaloCtr >= counter) { - synchronized (lock) { - lock.notifyAll(); - } - } - } - }; - Receiver xenaReceiver = new Receiver() { - public void receive(String s) throws Exception { - xenaToHaloCtr++; - hectorSender.send("halo to hector because of xena"); - if (xenaToHaloCtr >= counter) { - synchronized (lock) { - lock.notifyAll(); - } - } - } - }; - Receiver troyReceiver = new Receiver() { - public void receive(String s) throws Exception { - troyToHaloCtr++; - xenaSender.send("halo to xena because of troy"); - if (troyToHaloCtr >= counter) { - synchronized (lock) { - lock.notifyAll(); - } - } - } - }; - buildReceiver(haloConnection, hectorToHalo, true, hectorReceiver); - buildReceiver(haloConnection, xenaToHalo, true, xenaReceiver); - buildReceiver(haloConnection, troyToHalo, true, troyReceiver); + xenaConnection = createConnection(); + Thread xenaThread = buildProducer(xenaConnection, xenaToHalo); + Receiver hXenaReceiver = new Receiver() { + public void receive(String s) throws Exception { + haloToXenaCtr++; + if (haloToXenaCtr >= counter) { + synchronized (lock) { + lock.notifyAll(); + } + } + } + }; + buildReceiver(xenaConnection, haloToXena, false, hXenaReceiver); - haloConnection.start(); + haloConnection = createConnection(); + final MessageSender hectorSender = buildTransactionalProducer(haloToHector, haloConnection); + final MessageSender troySender = buildTransactionalProducer(haloToTroy, haloConnection); + final MessageSender xenaSender = buildTransactionalProducer(haloToXena, haloConnection); + Receiver hectorReceiver = new Receiver() { + public void receive(String s) throws Exception { + hectorToHaloCtr++; + troySender.send("halo to troy because of hector"); + if (hectorToHaloCtr >= counter) { + synchronized (lock) { + lock.notifyAll(); + } + } + } + }; + Receiver xenaReceiver = new Receiver() { + public void receive(String s) throws Exception { + xenaToHaloCtr++; + hectorSender.send("halo to hector because of xena"); + if (xenaToHaloCtr >= counter) { + synchronized (lock) { + lock.notifyAll(); + } + } + } + }; + Receiver troyReceiver = new Receiver() { + public void receive(String s) throws Exception { + troyToHaloCtr++; + xenaSender.send("halo to xena because of troy"); + if (troyToHaloCtr >= counter) { + synchronized (lock) { + lock.notifyAll(); + } + } + } + }; + buildReceiver(haloConnection, hectorToHalo, true, hectorReceiver); + buildReceiver(haloConnection, xenaToHalo, true, xenaReceiver); + buildReceiver(haloConnection, troyToHalo, true, troyReceiver); - troyConnection.start(); - troyThread.start(); + haloConnection.start(); - xenaConnection.start(); - xenaThread.start(); + troyConnection.start(); + troyThread.start(); - hectorConnection.start(); - hectorThread.start(); - waitForMessagesToBeDelivered(); - //number of messages received should match messages sent - assertEquals(hectorToHaloCtr, counter); - log.info("hectorToHalo received " + hectorToHaloCtr + " messages"); - assertEquals(xenaToHaloCtr, counter); - log.info("xenaToHalo received " + xenaToHaloCtr + " messages"); - assertEquals(troyToHaloCtr, counter); - log.info("troyToHalo received " + troyToHaloCtr + " messages"); - assertEquals(haloToHectorCtr, counter); - log.info("haloToHector received " + haloToHectorCtr + " messages"); - assertEquals(haloToXenaCtr, counter); - log.info("haloToXena received " + haloToXenaCtr + " messages"); - assertEquals(haloToTroyCtr, counter); - log.info("haloToTroy received " + haloToTroyCtr + " messages"); + xenaConnection.start(); + xenaThread.start(); - } + hectorConnection.start(); + hectorThread.start(); + waitForMessagesToBeDelivered(); + // number of messages received should match messages sent + assertEquals(hectorToHaloCtr, counter); + LOG.info("hectorToHalo received " + hectorToHaloCtr + " messages"); + assertEquals(xenaToHaloCtr, counter); + LOG.info("xenaToHalo received " + xenaToHaloCtr + " messages"); + assertEquals(troyToHaloCtr, counter); + LOG.info("troyToHalo received " + troyToHaloCtr + " messages"); + assertEquals(haloToHectorCtr, counter); + LOG.info("haloToHector received " + haloToHectorCtr + " messages"); + assertEquals(haloToXenaCtr, counter); + LOG.info("haloToXena received " + haloToXenaCtr + " messages"); + assertEquals(haloToTroyCtr, counter); + LOG.info("haloToTroy received " + haloToTroyCtr + " messages"); - protected void waitForMessagesToBeDelivered() { - // let's give the listeners enough time to read all messages - long maxWaitTime = counter * 3000; - long waitTime = maxWaitTime; - long start = (maxWaitTime <= 0) ? 0 : System.currentTimeMillis(); + } - synchronized (lock) { - boolean hasMessages = true; - while (hasMessages && waitTime >= 0) { - try { - lock.wait(200); - } catch (InterruptedException e) { - log.error(e); - } - //check if all messages have been received - hasMessages = hectorToHaloCtr < counter - || xenaToHaloCtr < counter || troyToHaloCtr < counter || haloToHectorCtr < counter - || haloToXenaCtr < counter || haloToTroyCtr < counter; - waitTime = maxWaitTime - (System.currentTimeMillis() - start); - } - } - } + protected void waitForMessagesToBeDelivered() { + // let's give the listeners enough time to read all messages + long maxWaitTime = counter * 3000; + long waitTime = maxWaitTime; + long start = (maxWaitTime <= 0) ? 0 : System.currentTimeMillis(); - public MessageSender buildTransactionalProducer(String queueName, - Connection connection) throws Exception { + synchronized (lock) { + boolean hasMessages = true; + while (hasMessages && waitTime >= 0) { + try { + lock.wait(200); + } catch (InterruptedException e) { + LOG.error(e); + } + // check if all messages have been received + hasMessages = hectorToHaloCtr < counter || xenaToHaloCtr < counter || troyToHaloCtr < counter || haloToHectorCtr < counter || haloToXenaCtr < counter + || haloToTroyCtr < counter; + waitTime = maxWaitTime - (System.currentTimeMillis() - start); + } + } + } - return new MessageSender(queueName, connection, true); - } + public MessageSender buildTransactionalProducer(String queueName, Connection connection) throws Exception { - public Thread buildProducer(Connection connection, final String queueName) - throws Exception { + return new MessageSender(queueName, connection, true); + } - final Session session = connection.createSession(false, - Session.AUTO_ACKNOWLEDGE); - final MessageSender producer = new MessageSender(queueName, connection, - false); - Thread thread = new Thread() { + public Thread buildProducer(Connection connection, final String queueName) throws Exception { - public synchronized void run() { - for (int i = 0; i < counter; i++) { - try { - producer.send(queueName); - if (session.getTransacted()) { - session.commit(); - } + final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + final MessageSender producer = new MessageSender(queueName, connection, false); + Thread thread = new Thread() { - } catch (Exception e) { - throw new RuntimeException("on " + queueName + " send", - e); - } - } - } - }; - return thread; - } + public synchronized void run() { + for (int i = 0; i < counter; i++) { + try { + producer.send(queueName); + if (session.getTransacted()) { + session.commit(); + } - public void buildReceiver(Connection connection, final String queueName, - boolean transacted, final Receiver receiver) throws Exception { - final Session session = transacted ? connection.createSession(true, - Session.SESSION_TRANSACTED) : connection.createSession(false, - Session.AUTO_ACKNOWLEDGE); - MessageConsumer inputMessageConsumer = session.createConsumer(session - .createQueue(queueName)); - MessageListener messageListener = new MessageListener() { + } catch (Exception e) { + throw new RuntimeException("on " + queueName + " send", e); + } + } + } + }; + return thread; + } - public void onMessage(Message message) { - try { - ObjectMessage objectMessage = (ObjectMessage) message; - String s = (String) objectMessage.getObject(); - receiver.receive(s); - if (session.getTransacted()) { - session.commit(); - } + public void buildReceiver(Connection connection, final String queueName, boolean transacted, final Receiver receiver) throws Exception { + final Session session = transacted ? connection.createSession(true, Session.SESSION_TRANSACTED) : connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + MessageConsumer inputMessageConsumer = session.createConsumer(session.createQueue(queueName)); + MessageListener messageListener = new MessageListener() { - } catch (Exception e) { - e.printStackTrace(); - } - } - }; - inputMessageConsumer.setMessageListener(messageListener); - } + public void onMessage(Message message) { + try { + ObjectMessage objectMessage = (ObjectMessage)message; + String s = (String)objectMessage.getObject(); + receiver.receive(s); + if (session.getTransacted()) { + session.commit(); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + }; + inputMessageConsumer.setMessageListener(messageListener); + } } diff --git a/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQBytesMessageTest.java b/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQBytesMessageTest.java index 16979cf9ab..a972d5c392 100755 --- a/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQBytesMessageTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQBytesMessageTest.java @@ -27,6 +27,11 @@ import junit.framework.TestCase; * @version $Revision$ */ public class ActiveMQBytesMessageTest extends TestCase { + + public ActiveMQBytesMessageTest(String name) { + super(name); + } + public static void main(String[] args) { junit.textui.TestRunner.run(ActiveMQBytesMessageTest.class); } @@ -45,15 +50,6 @@ public class ActiveMQBytesMessageTest extends TestCase { super.tearDown(); } - /** - * Constructor for ActiveMQBytesMessageTest. - * - * @param arg0 - */ - public ActiveMQBytesMessageTest(String arg0) { - super(arg0); - } - public void testGetDataStructureType() { ActiveMQBytesMessage msg = new ActiveMQBytesMessage(); assertEquals(msg.getDataStructureType(), CommandTypes.ACTIVEMQ_BYTES_MESSAGE); diff --git a/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQDestinationTest.java b/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQDestinationTest.java index 6100ba5edd..60f88defc2 100755 --- a/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQDestinationTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQDestinationTest.java @@ -51,7 +51,7 @@ public class ActiveMQDestinationTest extends DataStructureTestSupport { addCombinationValues("destination", new Object[] {new ActiveMQQueue("TEST?k1=v1&k2=v2"), new ActiveMQTopic("TEST?k1=v1&k2=v2"), new ActiveMQTempQueue("TEST:1?k1=v1&k2=v2"), - new ActiveMQTempTopic("TEST:1?k1=v1&k2=v2"),}); + new ActiveMQTempTopic("TEST:1?k1=v1&k2=v2")}); } public void testDesintaionOptions() throws IOException { @@ -62,12 +62,12 @@ public class ActiveMQDestinationTest extends DataStructureTestSupport { } public void testSorting() throws Exception { - SortedSet set = new TreeSet(); + SortedSet set = new TreeSet(); ActiveMQDestination[] destinations = {new ActiveMQQueue("A"), new ActiveMQQueue("B"), new ActiveMQTopic("A"), new ActiveMQTopic("B")}; - List expected = Arrays.asList(destinations); + List expected = Arrays.asList(destinations); set.addAll(expected); - List actual = new ArrayList(set); + List actual = new ArrayList(set); assertEquals("Sorted order", expected, actual); } diff --git a/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQMapMessageTest.java b/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQMapMessageTest.java index 2f9f03fe47..9772160776 100755 --- a/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQMapMessageTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQMapMessageTest.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; +import java.util.List; import javax.jms.JMSException; import javax.jms.MessageFormatException; @@ -39,6 +40,15 @@ public class ActiveMQMapMessageTest extends TestCase { private String name = "testName"; + /** + * Constructor for ActiveMQMapMessageTest. + * + * @param name + */ + public ActiveMQMapMessageTest(String name) { + super(name); + } + public static void main(String[] args) { junit.textui.TestRunner.run(ActiveMQMapMessageTest.class); } @@ -57,15 +67,6 @@ public class ActiveMQMapMessageTest extends TestCase { super.tearDown(); } - /** - * Constructor for ActiveMQMapMessageTest. - * - * @param arg0 - */ - public ActiveMQMapMessageTest(String arg0) { - super(arg0); - } - public void testBytesConversion() throws JMSException, IOException { ActiveMQMapMessage msg = new ActiveMQMapMessage(); msg.setBoolean("boolean", true); @@ -316,8 +317,8 @@ public class ActiveMQMapMessageTest extends TestCase { msg = (ActiveMQMapMessage)msg.copy(); - Enumeration mapNamesEnum = msg.getMapNames(); - ArrayList mapNamesList = Collections.list(mapNamesEnum); + Enumeration mapNamesEnum = msg.getMapNames(); + List mapNamesList = Collections.list(mapNamesEnum); assertEquals(mapNamesList.size(), 12); assertTrue(mapNamesList.contains("boolean")); diff --git a/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQMessageTest.java b/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQMessageTest.java index 0d6041ec11..33ef3a75de 100755 --- a/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQMessageTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQMessageTest.java @@ -54,6 +54,15 @@ public class ActiveMQMessageTest extends TestCase { private int jmsPriority; private long jmsTimestamp; private long[] consumerIDs; + + /** + * Constructor for ActiveMQMessageTest. + * + * @param name + */ + public ActiveMQMessageTest(String name) { + super(name); + } public static void main(String[] args) { } @@ -88,15 +97,6 @@ public class ActiveMQMessageTest extends TestCase { super.tearDown(); } - /** - * Constructor for ActiveMQMessageTest. - * - * @param arg0 - */ - public ActiveMQMessageTest(String arg0) { - super(arg0); - } - public void testGetDataStructureType() { ActiveMQMessage msg = new ActiveMQMessage(); assertEquals(msg.getDataStructureType(), CommandTypes.ACTIVEMQ_MESSAGE); diff --git a/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQObjectMessageTest.java b/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQObjectMessageTest.java index 3987bc777d..16f8182e04 100755 --- a/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQObjectMessageTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQObjectMessageTest.java @@ -29,6 +29,15 @@ import junit.framework.TestCase; */ public class ActiveMQObjectMessageTest extends TestCase { + /** + * Constructor for ActiveMQObjectMessageTest. + * + * @param name + */ + public ActiveMQObjectMessageTest(String name) { + super(name); + } + public static void main(String[] args) { junit.textui.TestRunner.run(ActiveMQObjectMessageTest.class); } @@ -47,15 +56,6 @@ public class ActiveMQObjectMessageTest extends TestCase { super.tearDown(); } - /** - * Constructor for ActiveMQObjectMessageTest. - * - * @param arg0 - */ - public ActiveMQObjectMessageTest(String arg0) { - super(arg0); - } - public void testBytes() throws JMSException, IOException { ActiveMQObjectMessage msg = new ActiveMQObjectMessage(); String str = "testText"; diff --git a/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQStreamMessageTest.java b/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQStreamMessageTest.java index 2547bd11ea..49088a39fd 100755 --- a/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQStreamMessageTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQStreamMessageTest.java @@ -30,6 +30,15 @@ import junit.framework.TestCase; */ public class ActiveMQStreamMessageTest extends TestCase { + /** + * Constructor for ActiveMQStreamMessageTest. + * + * @param name + */ + public ActiveMQStreamMessageTest(String name) { + super(name); + } + public static void main(String[] args) { junit.textui.TestRunner.run(ActiveMQStreamMessageTest.class); } @@ -48,15 +57,6 @@ public class ActiveMQStreamMessageTest extends TestCase { super.tearDown(); } - /** - * Constructor for ActiveMQStreamMessageTest. - * - * @param arg0 - */ - public ActiveMQStreamMessageTest(String arg0) { - super(arg0); - } - public void testGetDataStructureType() { ActiveMQStreamMessage msg = new ActiveMQStreamMessage(); assertEquals(msg.getDataStructureType(), CommandTypes.ACTIVEMQ_STREAM_MESSAGE); diff --git a/activemq-core/src/test/java/org/apache/activemq/demo/DefaultQueueSender.java b/activemq-core/src/test/java/org/apache/activemq/demo/DefaultQueueSender.java index 12af12fa7d..09c1ed37a5 100644 --- a/activemq-core/src/test/java/org/apache/activemq/demo/DefaultQueueSender.java +++ b/activemq-core/src/test/java/org/apache/activemq/demo/DefaultQueueSender.java @@ -34,19 +34,23 @@ import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageProducer; -import javax.jms.QueueSession; import javax.jms.Session; import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * A simple queue sender which does not use JNDI * * @version $Revision: 1.1 $ */ -public class DefaultQueueSender { +public final class DefaultQueueSender { - private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(DefaultQueueSender.class); + private static final Log LOG = LogFactory.getLog(DefaultQueueSender.class); + + private DefaultQueueSender() { + } public static void main(String[] args) { @@ -54,7 +58,6 @@ public class DefaultQueueSender { String text = "Hello World!"; Connection connection = null; - QueueSession queueSession = null; if (args.length < 1) { printUsage(); diff --git a/activemq-core/src/test/java/org/apache/activemq/demo/SimpleConsumer.java b/activemq-core/src/test/java/org/apache/activemq/demo/SimpleConsumer.java index 223eb29ed6..811b1fa74f 100755 --- a/activemq-core/src/test/java/org/apache/activemq/demo/SimpleConsumer.java +++ b/activemq-core/src/test/java/org/apache/activemq/demo/SimpleConsumer.java @@ -42,9 +42,13 @@ import javax.naming.NamingException; * * @version $Revision: 1.2 $ */ -public class SimpleConsumer { +public final class SimpleConsumer { - private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(SimpleConsumer.class); + private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory + .getLog(SimpleConsumer.class); + + private SimpleConsumer() { + } /** * @param args the queue used by the example diff --git a/activemq-core/src/test/java/org/apache/activemq/demo/SimpleProducer.java b/activemq-core/src/test/java/org/apache/activemq/demo/SimpleProducer.java index e9346f988d..fb1425574e 100755 --- a/activemq-core/src/test/java/org/apache/activemq/demo/SimpleProducer.java +++ b/activemq-core/src/test/java/org/apache/activemq/demo/SimpleProducer.java @@ -39,15 +39,21 @@ import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + /** * A simple polymorphic JMS producer which can work with Queues or Topics which * uses JNDI to lookup the JMS connection factory and destination * * @version $Revision: 1.2 $ */ -public class SimpleProducer { +public final class SimpleProducer { - private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(SimpleProducer.class); + private static final Log LOG = LogFactory.getLog(SimpleProducer.class); + + private SimpleProducer() { + } /** * @param args the destination name to send to and optionally, the number of diff --git a/activemq-core/src/test/java/org/apache/activemq/demo/SimpleQueueReceiver.java b/activemq-core/src/test/java/org/apache/activemq/demo/SimpleQueueReceiver.java index b22a3132a1..94b6198ef1 100755 --- a/activemq-core/src/test/java/org/apache/activemq/demo/SimpleQueueReceiver.java +++ b/activemq-core/src/test/java/org/apache/activemq/demo/SimpleQueueReceiver.java @@ -37,9 +37,15 @@ import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; -public class SimpleQueueReceiver { +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; - private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(SimpleQueueReceiver.class); +public final class SimpleQueueReceiver { + + private static final Log LOG = LogFactory.getLog(SimpleQueueReceiver.class); + + private SimpleQueueReceiver() { + } /** * Main method. diff --git a/activemq-core/src/test/java/org/apache/activemq/demo/SimpleQueueSender.java b/activemq-core/src/test/java/org/apache/activemq/demo/SimpleQueueSender.java index 3fd411166e..e7b1725ff5 100755 --- a/activemq-core/src/test/java/org/apache/activemq/demo/SimpleQueueSender.java +++ b/activemq-core/src/test/java/org/apache/activemq/demo/SimpleQueueSender.java @@ -40,9 +40,15 @@ import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; -public class SimpleQueueSender { +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; - private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(SimpleQueueSender.class); +public final class SimpleQueueSender { + + private static final Log LOG = LogFactory.getLog(SimpleQueueSender.class); + + private SimpleQueueSender() { + } /** * Main method. diff --git a/activemq-core/src/test/java/org/apache/activemq/filter/DestinationMapTest.java b/activemq-core/src/test/java/org/apache/activemq/filter/DestinationMapTest.java index 8487173f50..0acf11f674 100755 --- a/activemq-core/src/test/java/org/apache/activemq/filter/DestinationMapTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/filter/DestinationMapTest.java @@ -371,6 +371,7 @@ public class DestinationMapTest extends TestCase { assertMapValue(destinationName, Arrays.asList(new Object[] {expected1, expected2, expected3, expected4, expected5, expected6})); } + @SuppressWarnings("unchecked") protected void assertMapValue(ActiveMQDestination destination, Object expected) { List expectedList = null; if (expected == null) { diff --git a/activemq-core/src/test/java/org/apache/activemq/jndi/InitialContextTest.java b/activemq-core/src/test/java/org/apache/activemq/jndi/InitialContextTest.java index 209a0e05a0..a7eeaa9e43 100755 --- a/activemq-core/src/test/java/org/apache/activemq/jndi/InitialContextTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/jndi/InitialContextTest.java @@ -23,13 +23,15 @@ import javax.naming.InitialContext; import junit.framework.TestCase; import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * @version $Revision: 1.3 $ */ public class InitialContextTest extends TestCase { - private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(InitialContextTest.class); + private static final Log LOG = LogFactory.getLog(InitialContextTest.class); public void testInitialContext() throws Exception { InitialContext context = new InitialContext(); diff --git a/activemq-core/src/test/java/org/apache/activemq/kaha/ListContainerTest.java b/activemq-core/src/test/java/org/apache/activemq/kaha/ListContainerTest.java index 136220151d..b1fb38e8e8 100644 --- a/activemq-core/src/test/java/org/apache/activemq/kaha/ListContainerTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/kaha/ListContainerTest.java @@ -95,7 +95,8 @@ public class ListContainerTest extends TestCase { */ public void testIterator() throws Exception { container.addAll(testList); - for (Iterator i = testList.iterator(), j = container.iterator(); i.hasNext();) { + Iterator j = container.iterator(); + for (Iterator i = testList.iterator(); i.hasNext();) { assertEquals(i.next(), j.next()); } for (Iterator i = container.iterator(); i.hasNext();) { @@ -117,7 +118,7 @@ public class ListContainerTest extends TestCase { */ public void testContains() throws Exception { container.addAll(testList); - for (Iterator i = testList.iterator(), j = container.iterator(); i.hasNext();) { + for (Iterator i = testList.iterator(); i.hasNext();) { assertTrue(container.contains(i.next())); } } diff --git a/activemq-core/src/test/java/org/apache/activemq/kaha/StoreTest.java b/activemq-core/src/test/java/org/apache/activemq/kaha/StoreTest.java index 84e32f5cfe..e6bf803906 100644 --- a/activemq-core/src/test/java/org/apache/activemq/kaha/StoreTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/kaha/StoreTest.java @@ -70,7 +70,7 @@ public class StoreTest extends TestCase { */ public void testGetMapContainer() throws Exception { String containerId = "test"; - MapContainer container = store.getMapContainer(containerId); + MapContainer container = store.getMapContainer(containerId); container.load(); assertNotNull(container); store.close(); @@ -86,7 +86,7 @@ public class StoreTest extends TestCase { */ public void testDeleteMapContainer() throws Exception { String containerId = "test"; - MapContainer container = store.getMapContainer(containerId); + MapContainer container = store.getMapContainer(containerId); assertNotNull(container); store.deleteMapContainer(containerId); assertFalse(store.doesMapContainerExist(containerId)); @@ -124,7 +124,7 @@ public class StoreTest extends TestCase { } public void testBasicAllocations() throws Exception { - Map testMap = new HashMap(); + Map testMap = new HashMap(); int count = 1000; for (int i = 0; i < count; i++) { String key = "key:" + i; @@ -138,11 +138,11 @@ public class StoreTest extends TestCase { String listId = "testList"; String mapId1 = "testMap"; String mapId2 = "testMap2"; - MapContainer mapContainer1 = store.getMapContainer(mapId1); + MapContainer mapContainer1 = store.getMapContainer(mapId1); mapContainer1.load(); mapContainer1.putAll(testMap); - MapContainer mapContainer2 = store.getMapContainer(mapId2, mapId2); + MapContainer mapContainer2 = store.getMapContainer(mapId2, mapId2); mapContainer2.load(); mapContainer2.putAll(testMap); @@ -158,20 +158,21 @@ public class StoreTest extends TestCase { mapContainer2.load(); listContainer = store.getListContainer(listId); listContainer.load(); - for (Iterator i = testMap.keySet().iterator(); i.hasNext();) { + for (Iterator i = testMap.keySet().iterator(); i.hasNext();) { Object key = i.next(); Object value = testMap.get(key); assertTrue(mapContainer1.containsKey(key)); assertEquals(value, mapContainer1.get(key)); } - for (Iterator i = testMap.keySet().iterator(); i.hasNext();) { + for (Iterator i = testMap.keySet().iterator(); i.hasNext();) { Object key = i.next(); Object value = testMap.get(key); assertTrue(mapContainer2.containsKey(key)); assertEquals(value, mapContainer2.get(key)); } assertEquals(testList.size(), listContainer.size()); - for (Iterator i = testList.iterator(), j = listContainer.iterator(); i.hasNext();) { + Iterator j = listContainer.iterator(); + for (Iterator i = testList.iterator(); i.hasNext();) { assertEquals(i.next(), j.next()); } } diff --git a/activemq-core/src/test/java/org/apache/activemq/memory/buffer/MemoryBufferTestSupport.java b/activemq-core/src/test/java/org/apache/activemq/memory/buffer/MemoryBufferTestSupport.java index f2c39ad385..181042f407 100644 --- a/activemq-core/src/test/java/org/apache/activemq/memory/buffer/MemoryBufferTestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/memory/buffer/MemoryBufferTestSupport.java @@ -29,14 +29,14 @@ import org.apache.commons.logging.LogFactory; public abstract class MemoryBufferTestSupport extends TestCase { private static final Log LOG = LogFactory.getLog(MemoryBufferTestSupport.class); - protected abstract MessageBuffer createMessageBuffer(); - protected MessageBuffer buffer = createMessageBuffer(); protected MessageQueue qA = buffer.createMessageQueue(); protected MessageQueue qB = buffer.createMessageQueue(); protected MessageQueue qC = buffer.createMessageQueue(); protected int messageCount; + protected abstract MessageBuffer createMessageBuffer(); + protected void setUp() throws Exception { buffer = createMessageBuffer(); qA = buffer.createMessageQueue(); diff --git a/activemq-core/src/test/java/org/apache/activemq/network/DuplexNetworkTest.java b/activemq-core/src/test/java/org/apache/activemq/network/DuplexNetworkTest.java index 7f40f001c8..23cbc2ca9c 100755 --- a/activemq-core/src/test/java/org/apache/activemq/network/DuplexNetworkTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/network/DuplexNetworkTest.java @@ -22,8 +22,6 @@ import org.apache.commons.logging.LogFactory; public class DuplexNetworkTest extends SimpleNetworkTest { - private static final Log LOG = LogFactory.getLog(DuplexNetworkTest.class); - protected String getLocalBrokerURI() { return "org/apache/activemq/network/duplexLocalBroker.xml"; } diff --git a/activemq-core/src/test/java/org/apache/activemq/network/ForwardingBridgeTest.java b/activemq-core/src/test/java/org/apache/activemq/network/ForwardingBridgeTest.java index 694ddfce76..f2659f8d69 100755 --- a/activemq-core/src/test/java/org/apache/activemq/network/ForwardingBridgeTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/network/ForwardingBridgeTest.java @@ -38,7 +38,7 @@ public class ForwardingBridgeTest extends NetworkTestSupport { addCombinationValues("deliveryMode", new Object[] {new Integer(DeliveryMode.NON_PERSISTENT), new Integer(DeliveryMode.PERSISTENT)}); addCombinationValues("destinationType", new Object[] {new Byte(ActiveMQDestination.QUEUE_TYPE), - new Byte(ActiveMQDestination.TOPIC_TYPE),}); + new Byte(ActiveMQDestination.TOPIC_TYPE)}); } public void testAddConsumerThenSend() throws Exception { diff --git a/activemq-core/src/test/java/org/apache/activemq/network/NetworkReconnectTest.java b/activemq-core/src/test/java/org/apache/activemq/network/NetworkReconnectTest.java index cea4f7c63c..92ff265029 100644 --- a/activemq-core/src/test/java/org/apache/activemq/network/NetworkReconnectTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/network/NetworkReconnectTest.java @@ -55,7 +55,7 @@ public class NetworkReconnectTest extends TestCase { private ActiveMQConnectionFactory producerConnectionFactory; private ActiveMQConnectionFactory consumerConnectionFactory; private Destination destination; - private ArrayList connections = new ArrayList(); + private ArrayList connections = new ArrayList(); public void testMultipleProducerBrokerRestarts() throws Exception { for (int i = 0; i < 10; i++) { @@ -207,8 +207,8 @@ public class NetworkReconnectTest extends TestCase { } protected void disposeConsumerConnections() { - for (Iterator iter = connections.iterator(); iter.hasNext();) { - Connection connection = (Connection)iter.next(); + for (Iterator iter = connections.iterator(); iter.hasNext();) { + Connection connection = iter.next(); try { connection.close(); } catch (Throwable ignore) { diff --git a/activemq-core/src/test/java/org/apache/activemq/network/SimpleNetworkTest.java b/activemq-core/src/test/java/org/apache/activemq/network/SimpleNetworkTest.java index 5456f7f3db..740b93c1c8 100755 --- a/activemq-core/src/test/java/org/apache/activemq/network/SimpleNetworkTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/network/SimpleNetworkTest.java @@ -45,9 +45,9 @@ import org.springframework.core.io.Resource; public class SimpleNetworkTest extends TestCase { + protected static final int MESSAGE_COUNT = 10; private static final Log LOG = LogFactory.getLog(SimpleNetworkTest.class); - protected static final int MESSAGE_COUNT = 10; protected AbstractApplicationContext context; protected Connection localConnection; protected Connection remoteConnection; @@ -139,7 +139,6 @@ public class SimpleNetworkTest extends TestCase { doSetUp(); remoteConsumer = remoteSession.createDurableSubscriber(included, consumerName); for (int i = 0; i < MESSAGE_COUNT; i++) { - Message test = localSession.createTextMessage("test-" + i); assertNotNull(remoteConsumer.receive(500)); } } diff --git a/activemq-core/src/test/java/org/apache/activemq/network/jms/QueueBridgeTest.java b/activemq-core/src/test/java/org/apache/activemq/network/jms/QueueBridgeTest.java index 4db12c6c87..34c32e926b 100755 --- a/activemq-core/src/test/java/org/apache/activemq/network/jms/QueueBridgeTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/network/jms/QueueBridgeTest.java @@ -39,9 +39,9 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; public class QueueBridgeTest extends TestCase implements MessageListener { + protected static final int MESSAGE_COUNT = 10; private static final Log LOG = LogFactory.getLog(QueueBridgeTest.class); - protected static final int MESSAGE_COUNT = 10; protected AbstractApplicationContext context; protected QueueConnection localConnection; protected QueueConnection remoteConnection; diff --git a/activemq-core/src/test/java/org/apache/activemq/network/jms/TopicBridgeSpringTest.java b/activemq-core/src/test/java/org/apache/activemq/network/jms/TopicBridgeSpringTest.java index fada65e28b..ab2ee1d070 100755 --- a/activemq-core/src/test/java/org/apache/activemq/network/jms/TopicBridgeSpringTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/network/jms/TopicBridgeSpringTest.java @@ -38,9 +38,9 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; public class TopicBridgeSpringTest extends TestCase implements MessageListener { + protected static final int MESSAGE_COUNT = 10; private static final Log LOG = LogFactory.getLog(TopicBridgeSpringTest.class); - protected static final int MESSAGE_COUNT = 10; protected AbstractApplicationContext context; protected TopicConnection localConnection; protected TopicConnection remoteConnection; diff --git a/activemq-core/src/test/java/org/apache/activemq/openwire/DataFileGeneratorTestSupport.java b/activemq-core/src/test/java/org/apache/activemq/openwire/DataFileGeneratorTestSupport.java index 9a6ccd218f..05670c0648 100644 --- a/activemq-core/src/test/java/org/apache/activemq/openwire/DataFileGeneratorTestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/openwire/DataFileGeneratorTestSupport.java @@ -67,7 +67,6 @@ public abstract class DataFileGeneratorTestSupport extends TestSupport { private static final Throwable SINGLETON_EXCEPTION = new Exception("shared exception"); private static final File MODULE_BASE_DIR; private static final File CONTROL_DIR; - private static final File CLASS_FILE_DIR; static { @@ -81,7 +80,6 @@ public abstract class DataFileGeneratorTestSupport extends TestSupport { } MODULE_BASE_DIR = basedir; CONTROL_DIR = new File(MODULE_BASE_DIR, "src/test/resources/openwire-control"); - CLASS_FILE_DIR = new File(MODULE_BASE_DIR, "src/test/java/org/activemq/openwire"); } private int counter; @@ -107,16 +105,16 @@ public abstract class DataFileGeneratorTestSupport extends TestSupport { LOG.info("Parsed: " + actual); - assertBeansEqual("", new HashSet(), expected, actual); + assertBeansEqual("", new HashSet(), expected, actual); } - protected void assertBeansEqual(String message, Set comparedObjects, Object expected, Object actual) throws Exception { + protected void assertBeansEqual(String message, Set comparedObjects, Object expected, Object actual) throws Exception { assertNotNull("Actual object should be equal to: " + expected + " but was null", actual); if (comparedObjects.contains(expected)) { return; } comparedObjects.add(expected); - Class type = expected.getClass(); + Class type = expected.getClass(); assertEquals("Should be of same type", type, actual.getClass()); BeanInfo beanInfo = Introspector.getBeanInfo(type); PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors(); @@ -138,7 +136,7 @@ public abstract class DataFileGeneratorTestSupport extends TestSupport { } } - protected void assertPropertyValuesEqual(String name, Set comparedObjects, Object expectedValue, Object actualValue) throws Exception { + protected void assertPropertyValuesEqual(String name, Set comparedObjects, Object expectedValue, Object actualValue) throws Exception { String message = "Property " + name + " not equal"; if (expectedValue == null) { assertNull("Property " + name + " should be null", actualValue); @@ -160,14 +158,14 @@ public abstract class DataFileGeneratorTestSupport extends TestSupport { } } - protected void assertArrayEqual(String message, Set comparedObjects, Object[] expected, Object[] actual) throws Exception { + protected void assertArrayEqual(String message, Set comparedObjects, Object[] expected, Object[] actual) throws Exception { assertEquals(message + ". Array length", expected.length, actual.length); for (int i = 0; i < expected.length; i++) { assertPropertyValuesEqual(message + ". element: " + i, comparedObjects, expected[i], actual[i]); } } - protected void assertPrimitiveArrayEqual(String message, Set comparedObjects, Object expected, Object actual) throws ArrayIndexOutOfBoundsException, IllegalArgumentException, + protected void assertPrimitiveArrayEqual(String message, Set comparedObjects, Object expected, Object actual) throws ArrayIndexOutOfBoundsException, IllegalArgumentException, Exception { int length = Array.getLength(expected); assertEquals(message + ". Array length", length, Array.getLength(actual)); diff --git a/activemq-core/src/test/java/org/apache/activemq/perf/InactiveDurableTopicTest.java b/activemq-core/src/test/java/org/apache/activemq/perf/InactiveDurableTopicTest.java index 8ef64c41db..185d1a7a8b 100644 --- a/activemq-core/src/test/java/org/apache/activemq/perf/InactiveDurableTopicTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/perf/InactiveDurableTopicTest.java @@ -25,6 +25,7 @@ import javax.jms.Session; import javax.jms.Topic; import javax.jms.TopicSubscriber; +import junit.framework.Assert; import junit.framework.AssertionFailedError; import junit.framework.TestCase; import org.apache.activemq.ActiveMQConnectionFactory; @@ -136,7 +137,7 @@ public class InactiveDurableTopicTest extends TestCase { LOG.debug("Sent " + loop + " messages"); } } - this.assertEquals(loop, MESSAGE_COUNT); + Assert.assertEquals(loop, MESSAGE_COUNT); publisher.close(); session.close(); connection.stop(); diff --git a/activemq-core/src/test/java/org/apache/activemq/perf/MemoryAllocationTest.java b/activemq-core/src/test/java/org/apache/activemq/perf/MemoryAllocationTest.java index 050bce7631..210ed0210d 100644 --- a/activemq-core/src/test/java/org/apache/activemq/perf/MemoryAllocationTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/perf/MemoryAllocationTest.java @@ -39,9 +39,9 @@ import org.apache.commons.logging.LogFactory; */ public class MemoryAllocationTest extends TestCase { + protected static final int MESSAGE_COUNT = 2000; private static final Log LOG = LogFactory.getLog(MemoryAllocationTest.class); - protected static final int MESSAGE_COUNT = 2000; protected BrokerService broker; protected String bindAddress = "vm://localhost"; protected int topicCount; @@ -53,7 +53,7 @@ public class MemoryAllocationTest extends TestCase { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination dest = session.createTemporaryTopic(); - MessageConsumer mc = session.createConsumer(dest); + session.createConsumer(dest); MessageProducer mp = session.createProducer(dest); Message msg = session.createTextMessage("test" + i); mp.send(msg); diff --git a/activemq-core/src/test/java/org/apache/activemq/perf/SimpleTopicTest.java b/activemq-core/src/test/java/org/apache/activemq/perf/SimpleTopicTest.java index 6bb0f79550..b0df95feab 100644 --- a/activemq-core/src/test/java/org/apache/activemq/perf/SimpleTopicTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/perf/SimpleTopicTest.java @@ -32,7 +32,8 @@ import org.apache.commons.logging.LogFactory; */ public class SimpleTopicTest extends TestCase { - private final Log log = LogFactory.getLog(getClass()); + private static final Log LOG = LogFactory.getLog(SimpleTopicTest.class); + protected BrokerService broker; // protected String // bindAddress="tcp://localhost:61616?wireFormat.cacheEnabled=true&wireFormat.tightEncodingEnabled=true&jms.useAsyncSend=false"; @@ -66,8 +67,8 @@ public class SimpleTopicTest extends TestCase { Connection con = factory.createConnection(); Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); destination = createDestination(session, destinationName); - log.info("Testing against destination: " + destination); - log.info("Running " + numberofProducers + " producer(s) and " + numberOfConsumers + " consumer(s)"); + LOG.info("Testing against destination: " + destination); + LOG.info("Running " + numberofProducers + " producer(s) and " + numberOfConsumers + " consumer(s)"); con.close(); producers = new PerfProducer[numberofProducers]; consumers = new PerfConsumer[numberOfConsumers]; @@ -139,7 +140,7 @@ public class SimpleTopicTest extends TestCase { for (int i = 0; i < numberofProducers; i++) { producers[i].start(); } - log.info("Sampling performance " + samepleCount + " times at a " + sampleInternal + " ms interval."); + LOG.info("Sampling performance " + samepleCount + " times at a " + sampleInternal + " ms interval."); for (int i = 0; i < samepleCount; i++) { Thread.sleep(sampleInternal); dumpProducerRate(); @@ -162,7 +163,7 @@ public class SimpleTopicTest extends TestCase { totalCount += rate.getTotalCount(); } int avgRate = totalRate / producers.length; - log.info("Avg producer rate = " + avgRate + " msg/sec | Total rate = " + totalRate + ", sent = " + totalCount); + LOG.info("Avg producer rate = " + avgRate + " msg/sec | Total rate = " + totalRate + ", sent = " + totalCount); } protected void dumpConsumerRate() { @@ -175,7 +176,7 @@ public class SimpleTopicTest extends TestCase { } if (consumers != null && consumers.length > 0) { int avgRate = totalRate / consumers.length; - log.info("Avg consumer rate = " + avgRate + " msg/sec | Total rate = " + totalRate + ", received = " + totalCount); + LOG.info("Avg consumer rate = " + avgRate + " msg/sec | Total rate = " + totalRate + ", received = " + totalCount); } } } diff --git a/activemq-core/src/test/java/org/apache/activemq/proxy/ProxyConnectorTest.java b/activemq-core/src/test/java/org/apache/activemq/proxy/ProxyConnectorTest.java index 131f671579..8aced23525 100755 --- a/activemq-core/src/test/java/org/apache/activemq/proxy/ProxyConnectorTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/proxy/ProxyConnectorTest.java @@ -29,6 +29,10 @@ import org.apache.activemq.command.SessionInfo; public class ProxyConnectorTest extends ProxyTestSupport { + public ActiveMQDestination destination; + public byte destinationType; + public int deliveryMode; + public static Test suite() { return suite(ProxyConnectorTest.class); } @@ -37,10 +41,6 @@ public class ProxyConnectorTest extends ProxyTestSupport { junit.textui.TestRunner.run(suite()); } - public ActiveMQDestination destination; - public byte destinationType; - public int deliveryMode; - public void setUp() throws Exception { super.setAutoFail(true); super.setUp(); @@ -48,7 +48,7 @@ public class ProxyConnectorTest extends ProxyTestSupport { public void initCombosForTestSendAndConsume() { addCombinationValues("deliveryMode", new Object[] {Integer.valueOf(DeliveryMode.NON_PERSISTENT), Integer.valueOf(DeliveryMode.PERSISTENT)}); - addCombinationValues("destinationType", new Object[] {Byte.valueOf(ActiveMQDestination.TOPIC_TYPE),}); + addCombinationValues("destinationType", new Object[] {Byte.valueOf(ActiveMQDestination.TOPIC_TYPE)}); } public void testSendAndConsume() throws Exception { diff --git a/activemq-core/src/test/java/org/apache/activemq/proxy/ProxyTestSupport.java b/activemq-core/src/test/java/org/apache/activemq/proxy/ProxyTestSupport.java index 7328964d8f..f860b8fcb6 100755 --- a/activemq-core/src/test/java/org/apache/activemq/proxy/ProxyTestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/proxy/ProxyTestSupport.java @@ -31,7 +31,7 @@ import org.apache.activemq.transport.TransportFactory; public class ProxyTestSupport extends BrokerTestSupport { - protected ArrayList connections = new ArrayList(); + protected ArrayList connections = new ArrayList(); protected TransportConnector connector; @@ -79,8 +79,8 @@ public class ProxyTestSupport extends BrokerTestSupport { } protected void tearDown() throws Exception { - for (Iterator iter = connections.iterator(); iter.hasNext();) { - StubConnection connection = (StubConnection)iter.next(); + for (Iterator iter = connections.iterator(); iter.hasNext();) { + StubConnection connection = iter.next(); connection.stop(); iter.remove(); } diff --git a/activemq-core/src/test/java/org/apache/activemq/security/AuthorizationMapTest.java b/activemq-core/src/test/java/org/apache/activemq/security/AuthorizationMapTest.java index 9760d3dbc7..3114aa5982 100644 --- a/activemq-core/src/test/java/org/apache/activemq/security/AuthorizationMapTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/security/AuthorizationMapTest.java @@ -61,7 +61,7 @@ public class AuthorizationMapTest extends TestCase { protected AuthorizationMap createAuthorizationMap() { DefaultAuthorizationMap answer = new DefaultAuthorizationMap(); - List entries = new ArrayList(); + List entries = new ArrayList(); AuthorizationEntry entry = new AuthorizationEntry(); entry.setGroupClass("org.apache.activemq.jaas.GroupPrincipal"); @@ -91,7 +91,7 @@ public class AuthorizationMapTest extends TestCase { protected AuthorizationMap createAuthorizationMapWithTempDest() { DefaultAuthorizationMap answer = new DefaultAuthorizationMap(); - List entries = new ArrayList(); + List entries = new ArrayList(); AuthorizationEntry entry = new AuthorizationEntry(); entry.setQueue(">"); diff --git a/activemq-core/src/test/java/org/apache/activemq/security/JaasCertificateAuthenticationBrokerTest.java b/activemq-core/src/test/java/org/apache/activemq/security/JaasCertificateAuthenticationBrokerTest.java index ca4c2625b3..2673f69f16 100644 --- a/activemq-core/src/test/java/org/apache/activemq/security/JaasCertificateAuthenticationBrokerTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/security/JaasCertificateAuthenticationBrokerTest.java @@ -57,24 +57,24 @@ public class JaasCertificateAuthenticationBrokerTest extends TestCase { super.tearDown(); } - private void setConfiguration(Set userNames, Set groupNames, boolean loginShouldSucceed) { - HashMap configOptions = new HashMap(); + private void setConfiguration(Set userNames, Set groupNames, boolean loginShouldSucceed) { + HashMap configOptions = new HashMap(); String userNamesString; { - Iterator iter = userNames.iterator(); - userNamesString = "" + (iter.hasNext() ? (String)iter.next() : ""); + Iterator iter = userNames.iterator(); + userNamesString = "" + (iter.hasNext() ? iter.next() : ""); while (iter.hasNext()) { - userNamesString += "," + (String)iter.next(); + userNamesString += "," + iter.next(); } } String groupNamesString = ""; { - Iterator iter = groupNames.iterator(); - groupNamesString = "" + (iter.hasNext() ? (String)iter.next() : ""); + Iterator iter = groupNames.iterator(); + groupNamesString = "" + (iter.hasNext() ? iter.next() : ""); while (iter.hasNext()) { - groupNamesString += "," + (String)iter.next(); + groupNamesString += "," + iter.next(); } } @@ -92,10 +92,10 @@ public class JaasCertificateAuthenticationBrokerTest extends TestCase { public void testAddConnectionSuccess() { String dnUserName = "dnUserName"; - HashSet userNames = new HashSet(); + HashSet userNames = new HashSet(); userNames.add(dnUserName); - HashSet groupNames = new HashSet(); + HashSet groupNames = new HashSet(); groupNames.add("testGroup1"); groupNames.add("testGroup2"); groupNames.add("tesetGroup3"); @@ -147,9 +147,9 @@ public class JaasCertificateAuthenticationBrokerTest extends TestCase { } public void testAddConnectionFailure() { - HashSet userNames = new HashSet(); + HashSet userNames = new HashSet(); - HashSet groupNames = new HashSet(); + HashSet groupNames = new HashSet(); groupNames.add("testGroup1"); groupNames.add("testGroup2"); groupNames.add("tesetGroup3"); diff --git a/activemq-core/src/test/java/org/apache/activemq/security/LDAPAuthorizationMapTest.java b/activemq-core/src/test/java/org/apache/activemq/security/LDAPAuthorizationMapTest.java index 582444c7b8..3310451943 100755 --- a/activemq-core/src/test/java/org/apache/activemq/security/LDAPAuthorizationMapTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/security/LDAPAuthorizationMapTest.java @@ -72,7 +72,7 @@ public class LDAPAuthorizationMapTest extends TestCase { public void testOpen() throws Exception { DirContext ctx = authMap.open(); - HashSet set = new HashSet(); + HashSet set = new HashSet(); NamingEnumeration list = ctx.list("ou=destinations,o=ActiveMQ,dc=example,dc=com"); while (list.hasMore()) { NameClassPair ncp = (NameClassPair) list.next(); diff --git a/activemq-core/src/test/java/org/apache/activemq/security/SecurityTestSupport.java b/activemq-core/src/test/java/org/apache/activemq/security/SecurityTestSupport.java index 475ccea40d..db285c0f17 100644 --- a/activemq-core/src/test/java/org/apache/activemq/security/SecurityTestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/security/SecurityTestSupport.java @@ -186,7 +186,7 @@ public class SecurityTestSupport extends JmsTestSupport { public void initCombosForTestUserReceiveFails() { addCombinationValues("userName", new Object[] {"user"}); addCombinationValues("password", new Object[] {"password"}); - addCombinationValues("destination", new Object[] {new ActiveMQQueue("TEST"), new ActiveMQTopic("TEST"), new ActiveMQQueue("GUEST.BAR"), new ActiveMQTopic("GUEST.BAR"),}); + addCombinationValues("destination", new Object[] {new ActiveMQQueue("TEST"), new ActiveMQTopic("TEST"), new ActiveMQQueue("GUEST.BAR"), new ActiveMQTopic("GUEST.BAR")}); } /** @@ -203,7 +203,7 @@ public class SecurityTestSupport extends JmsTestSupport { public void initCombosForTestUserReceiveSucceeds() { addCombinationValues("userName", new Object[] {"user"}); addCombinationValues("password", new Object[] {"password"}); - addCombinationValues("destination", new Object[] {new ActiveMQQueue("USERS.FOO"), new ActiveMQTopic("USERS.FOO"),}); + addCombinationValues("destination", new Object[] {new ActiveMQQueue("USERS.FOO"), new ActiveMQTopic("USERS.FOO")}); } /** @@ -212,7 +212,7 @@ public class SecurityTestSupport extends JmsTestSupport { public void initCombosForTestGuestReceiveSucceeds() { addCombinationValues("userName", new Object[] {"guest"}); addCombinationValues("password", new Object[] {"password"}); - addCombinationValues("destination", new Object[] {new ActiveMQQueue("GUEST.BAR"), new ActiveMQTopic("GUEST.BAR"),}); + addCombinationValues("destination", new Object[] {new ActiveMQQueue("GUEST.BAR"), new ActiveMQTopic("GUEST.BAR")}); } /** @@ -221,7 +221,7 @@ public class SecurityTestSupport extends JmsTestSupport { public void initCombosForTestGuestReceiveFails() { addCombinationValues("userName", new Object[] {"guest"}); addCombinationValues("password", new Object[] {"password"}); - addCombinationValues("destination", new Object[] {new ActiveMQQueue("TEST"), new ActiveMQTopic("TEST"), new ActiveMQQueue("USERS.FOO"), new ActiveMQTopic("USERS.FOO"),}); + addCombinationValues("destination", new Object[] {new ActiveMQQueue("TEST"), new ActiveMQTopic("TEST"), new ActiveMQQueue("USERS.FOO"), new ActiveMQTopic("USERS.FOO") }); } /** @@ -231,7 +231,7 @@ public class SecurityTestSupport extends JmsTestSupport { addCombinationValues("userName", new Object[] {"user"}); addCombinationValues("password", new Object[] {"password"}); addCombinationValues("destination", new Object[] {new ActiveMQQueue("USERS.FOO"), new ActiveMQQueue("GUEST.BAR"), new ActiveMQTopic("USERS.FOO"), - new ActiveMQTopic("GUEST.BAR"),}); + new ActiveMQTopic("GUEST.BAR")}); } /** @@ -240,7 +240,7 @@ public class SecurityTestSupport extends JmsTestSupport { public void initCombosForTestUserSendFails() { addCombinationValues("userName", new Object[] {"user"}); addCombinationValues("password", new Object[] {"password"}); - addCombinationValues("destination", new Object[] {new ActiveMQQueue("TEST"), new ActiveMQTopic("TEST"),}); + addCombinationValues("destination", new Object[] {new ActiveMQQueue("TEST"), new ActiveMQTopic("TEST")}); } /** @@ -258,6 +258,6 @@ public class SecurityTestSupport extends JmsTestSupport { public void initCombosForTestGuestSendSucceeds() { addCombinationValues("userName", new Object[] {"guest"}); addCombinationValues("password", new Object[] {"password"}); - addCombinationValues("destination", new Object[] {new ActiveMQQueue("GUEST.BAR"), new ActiveMQTopic("GUEST.BAR"),}); + addCombinationValues("destination", new Object[] {new ActiveMQQueue("GUEST.BAR"), new ActiveMQTopic("GUEST.BAR")}); } } diff --git a/activemq-core/src/test/java/org/apache/activemq/security/SimpleSecurityBrokerSystemTest.java b/activemq-core/src/test/java/org/apache/activemq/security/SimpleSecurityBrokerSystemTest.java index 26d911eb56..1c0c1c0211 100644 --- a/activemq-core/src/test/java/org/apache/activemq/security/SimpleSecurityBrokerSystemTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/security/SimpleSecurityBrokerSystemTest.java @@ -41,11 +41,11 @@ import org.apache.commons.logging.LogFactory; * @version $Revision$ */ public class SimpleSecurityBrokerSystemTest extends SecurityTestSupport { - private static final Log LOG = LogFactory.getLog(SimpleSecurityBrokerSystemTest.class); static final GroupPrincipal GUESTS = new GroupPrincipal("guests"); static final GroupPrincipal USERS = new GroupPrincipal("users"); static final GroupPrincipal ADMINS = new GroupPrincipal("admins"); + private static final Log LOG = LogFactory.getLog(SimpleSecurityBrokerSystemTest.class); public BrokerPlugin authorizationPlugin; public BrokerPlugin authenticationPlugin; @@ -108,15 +108,15 @@ public class SimpleSecurityBrokerSystemTest extends SecurityTestSupport { static class SimpleAuthenticationFactory implements BrokerPlugin { public Broker installPlugin(Broker broker) { - HashMap u = new HashMap(); + HashMap u = new HashMap(); u.put("system", "manager"); u.put("user", "password"); u.put("guest", "password"); - HashMap groups = new HashMap(); - groups.put("system", new HashSet(Arrays.asList(new Object[] {ADMINS, USERS}))); - groups.put("user", new HashSet(Arrays.asList(new Object[] {USERS}))); - groups.put("guest", new HashSet(Arrays.asList(new Object[] {GUESTS}))); + HashMap> groups = new HashMap>(); + groups.put("system", new HashSet(Arrays.asList(new Object[] {ADMINS, USERS}))); + groups.put("user", new HashSet(Arrays.asList(new Object[] {USERS}))); + groups.put("guest", new HashSet(Arrays.asList(new Object[] {GUESTS}))); return new SimpleAuthenticationBroker(broker, u, groups); } @@ -130,8 +130,10 @@ public class SimpleSecurityBrokerSystemTest extends SecurityTestSupport { * @see {@link CombinationTestSupport} */ public void initCombos() { - addCombinationValues("authorizationPlugin", new Object[] {new AuthorizationPlugin(createAuthorizationMap()),}); - addCombinationValues("authenticationPlugin", new Object[] {new SimpleAuthenticationFactory(), new JaasAuthenticationPlugin(),}); + addCombinationValues("authorizationPlugin", + new Object[] {new AuthorizationPlugin(createAuthorizationMap())}); + addCombinationValues("authenticationPlugin", new Object[] {new SimpleAuthenticationFactory(), + new JaasAuthenticationPlugin()}); } protected BrokerService createBroker() throws Exception { diff --git a/activemq-core/src/test/java/org/apache/activemq/security/StubSecurityContext.java b/activemq-core/src/test/java/org/apache/activemq/security/StubSecurityContext.java index b404ea34b1..3b35578c53 100644 --- a/activemq-core/src/test/java/org/apache/activemq/security/StubSecurityContext.java +++ b/activemq-core/src/test/java/org/apache/activemq/security/StubSecurityContext.java @@ -24,7 +24,7 @@ public class StubSecurityContext extends SecurityContext { super(""); } - public Set getPrincipals() { + public Set getPrincipals() { return null; } } diff --git a/activemq-core/src/test/java/org/apache/activemq/spring/ConsumerBean.java b/activemq-core/src/test/java/org/apache/activemq/spring/ConsumerBean.java index 812fb70693..91963790ed 100755 --- a/activemq-core/src/test/java/org/apache/activemq/spring/ConsumerBean.java +++ b/activemq-core/src/test/java/org/apache/activemq/spring/ConsumerBean.java @@ -28,7 +28,7 @@ import org.apache.commons.logging.LogFactory; public class ConsumerBean extends Assert implements MessageListener { private static final Log LOG = LogFactory.getLog(ConsumerBean.class); - private List messages = new ArrayList(); + private List messages = new ArrayList(); private Object semaphore; private boolean verbose; @@ -51,8 +51,8 @@ public class ConsumerBean extends Assert implements MessageListener { /** * @return all the messages on the list so far, clearing the buffer */ - public synchronized List flushMessages() { - List answer = new ArrayList(messages); + public synchronized List flushMessages() { + List answer = new ArrayList(messages); messages.clear(); return answer; } diff --git a/activemq-core/src/test/java/org/apache/activemq/test/JmsSendReceiveTestSupport.java b/activemq-core/src/test/java/org/apache/activemq/test/JmsSendReceiveTestSupport.java index 05ec903c2a..c9dd5de598 100755 --- a/activemq-core/src/test/java/org/apache/activemq/test/JmsSendReceiveTestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/test/JmsSendReceiveTestSupport.java @@ -50,7 +50,7 @@ public abstract class JmsSendReceiveTestSupport extends TestSupport implements M protected MessageProducer producer; protected Destination consumerDestination; protected Destination producerDestination; - protected List messages = createConcurrentList(); + protected List messages = createConcurrentList(); protected boolean topic = true; protected boolean durable; protected int deliveryMode = DeliveryMode.PERSISTENT; @@ -152,12 +152,12 @@ public abstract class JmsSendReceiveTestSupport extends TestSupport implements M * @param receivedMessages * @throws JMSException */ - protected void assertMessagesReceivedAreValid(List receivedMessages) throws JMSException { - List copyOfMessages = Arrays.asList(receivedMessages.toArray()); + protected void assertMessagesReceivedAreValid(List receivedMessages) throws JMSException { + List copyOfMessages = Arrays.asList(receivedMessages.toArray()); int counter = 0; if (data.length != copyOfMessages.size()) { - for (Iterator iter = copyOfMessages.iterator(); iter.hasNext();) { + for (Iterator iter = copyOfMessages.iterator(); iter.hasNext();) { Object message = iter.next(); LOG.info("<== " + counter++ + " = " + message); } @@ -166,7 +166,7 @@ public abstract class JmsSendReceiveTestSupport extends TestSupport implements M assertEquals("Not enough messages received", data.length, receivedMessages.size()); for (int i = 0; i < data.length; i++) { - Message received = (Message)receivedMessages.get(i); + Message received = receivedMessages.get(i); assertMessageValid(i, received); } } @@ -217,7 +217,7 @@ public abstract class JmsSendReceiveTestSupport extends TestSupport implements M * @param message - a newly received message. * @param messageList - list containing the received messages. */ - protected void consumeMessage(Message message, List messageList) { + protected void consumeMessage(Message message, List messageList) { if (verbose) { LOG.info("Received message: " + message); } @@ -236,7 +236,7 @@ public abstract class JmsSendReceiveTestSupport extends TestSupport implements M * * @return a synchronized view of the specified list. */ - protected List createConcurrentList() { - return Collections.synchronizedList(new ArrayList()); + protected List createConcurrentList() { + return Collections.synchronizedList(new ArrayList()); } } diff --git a/activemq-core/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest.java b/activemq-core/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest.java index c459090fd5..02e1a5863a 100644 --- a/activemq-core/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest.java @@ -32,7 +32,7 @@ import org.apache.commons.logging.LogFactory; * @version $Revision: 1.1 $ */ public class JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest extends JmsTopicSendReceiveWithTwoConnectionsAndEmbeddedBrokerTest { - private static final Log log = LogFactory.getLog(JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest.class); + private static final Log LOG = LogFactory.getLog(JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest.class); protected String userName = "James"; @@ -55,7 +55,7 @@ public class JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest extends JmsTopic Message message = (Message)iter.next(); String userID = message.getStringProperty("JMSXUserID"); - log.info("Received message with userID: " + userID); + LOG.info("Received message with userID: " + userID); assertEquals("JMSXUserID header", userName, userID); } diff --git a/activemq-core/src/test/java/org/apache/activemq/test/message/NestedMapMessageTest.java b/activemq-core/src/test/java/org/apache/activemq/test/message/NestedMapMessageTest.java index d4c5650aa7..fa5be7252c 100644 --- a/activemq-core/src/test/java/org/apache/activemq/test/message/NestedMapMessageTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/test/message/NestedMapMessageTest.java @@ -76,11 +76,11 @@ public class NestedMapMessageTest extends JmsTopicSendReceiveWithTwoConnectionsA answer.setString("textField", data[index]); - Map grandChildMap = new HashMap(); + Map grandChildMap = new HashMap(); grandChildMap.put("x", "abc"); grandChildMap.put("y", Arrays.asList(new Object[] {"a", "b", "c"})); - Map nestedMap = new HashMap(); + Map nestedMap = new HashMap(); nestedMap.put("a", "foo"); nestedMap.put("b", Integer.valueOf(23)); nestedMap.put("c", Long.valueOf(45)); diff --git a/activemq-core/src/test/java/org/apache/activemq/transport/StubTransport.java b/activemq-core/src/test/java/org/apache/activemq/transport/StubTransport.java index b1f07dd5c7..24abc0ef43 100644 --- a/activemq-core/src/test/java/org/apache/activemq/transport/StubTransport.java +++ b/activemq-core/src/test/java/org/apache/activemq/transport/StubTransport.java @@ -28,7 +28,7 @@ import org.apache.activemq.util.ServiceStopper; */ public class StubTransport extends TransportSupport { - private Queue queue = new ConcurrentLinkedQueue(); + private Queue queue = new ConcurrentLinkedQueue(); protected void doStop(ServiceStopper stopper) throws Exception { } @@ -40,7 +40,7 @@ public class StubTransport extends TransportSupport { queue.add(command); } - public Queue getQueue() { + public Queue getQueue() { return queue; } diff --git a/activemq-core/src/test/java/org/apache/activemq/transport/TopicClusterTest.java b/activemq-core/src/test/java/org/apache/activemq/transport/TopicClusterTest.java index a39e9c7286..3c3c74e12a 100755 --- a/activemq-core/src/test/java/org/apache/activemq/transport/TopicClusterTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/transport/TopicClusterTest.java @@ -49,9 +49,9 @@ import org.apache.commons.logging.LogFactory; */ public class TopicClusterTest extends TestCase implements MessageListener { - private static final Log LOG = LogFactory.getLog(TopicClusterTest.class); protected static final int MESSAGE_COUNT = 50; protected static final int NUMBER_IN_CLUSTER = 3; + private static final Log LOG = LogFactory.getLog(TopicClusterTest.class); protected Destination destination; protected boolean topic = true; @@ -59,13 +59,12 @@ public class TopicClusterTest extends TestCase implements MessageListener { protected int deliveryMode = DeliveryMode.NON_PERSISTENT; protected MessageProducer[] producers; protected Connection[] connections; - protected List services = new ArrayList(); + protected List services = new ArrayList(); protected void setUp() throws Exception { connections = new Connection[NUMBER_IN_CLUSTER]; producers = new MessageProducer[NUMBER_IN_CLUSTER]; Destination destination = createDestination(); - int portStart = 50000; String root = System.getProperty("activemq.store.dir"); if (root == null) { root = "target/store"; diff --git a/activemq-core/src/test/java/org/apache/activemq/transport/TransportBrokerTestSupport.java b/activemq-core/src/test/java/org/apache/activemq/transport/TransportBrokerTestSupport.java index d2c4b6845f..baf3de7e2d 100755 --- a/activemq-core/src/test/java/org/apache/activemq/transport/TransportBrokerTestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/transport/TransportBrokerTestSupport.java @@ -29,7 +29,7 @@ import org.apache.activemq.broker.TransportConnector; public abstract class TransportBrokerTestSupport extends BrokerTest { private TransportConnector connector; - ArrayList connections = new ArrayList(); + private ArrayList connections = new ArrayList(); protected void setUp() throws Exception { super.setUp(); @@ -44,8 +44,8 @@ public abstract class TransportBrokerTestSupport extends BrokerTest { protected abstract String getBindLocation(); protected void tearDown() throws Exception { - for (Iterator iter = connections.iterator(); iter.hasNext();) { - StubConnection connection = (StubConnection) iter.next(); + for (Iterator iter = connections.iterator(); iter.hasNext();) { + StubConnection connection = iter.next(); connection.stop(); iter.remove(); } diff --git a/activemq-core/src/test/java/org/apache/activemq/transport/failover/FailoverTransportBrokerTest.java b/activemq-core/src/test/java/org/apache/activemq/transport/failover/FailoverTransportBrokerTest.java index 9cf77cc23d..0281d22d4f 100755 --- a/activemq-core/src/test/java/org/apache/activemq/transport/failover/FailoverTransportBrokerTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/transport/failover/FailoverTransportBrokerTest.java @@ -83,7 +83,7 @@ public class FailoverTransportBrokerTest extends NetworkTestSupport { connection3.request(createMessage(producerInfo3, destination, deliveryMode)); // The message will be sent to one of the brokers. - FailoverTransport ft = (FailoverTransport)connection3.getTransport().narrow(FailoverTransport.class); + FailoverTransport ft = connection3.getTransport().narrow(FailoverTransport.class); // See which broker we were connected to. StubConnection connectionA; diff --git a/activemq-core/src/test/java/org/apache/activemq/transport/failover/ReconnectTest.java b/activemq-core/src/test/java/org/apache/activemq/transport/failover/ReconnectTest.java index 662a0182a4..5d84f3d0c5 100644 --- a/activemq-core/src/test/java/org/apache/activemq/transport/failover/ReconnectTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/transport/failover/ReconnectTest.java @@ -60,10 +60,11 @@ public class ReconnectTest extends TestCase { class Worker implements Runnable, ExceptionListener { - private ActiveMQConnection connection; - private AtomicBoolean stop = new AtomicBoolean(false); public AtomicInteger iterations = new AtomicInteger(); public CountDownLatch stopped = new CountDownLatch(1); + + private ActiveMQConnection connection; + private AtomicBoolean stop = new AtomicBoolean(false); private Throwable error; public Worker() throws URISyntaxException, JMSException { diff --git a/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java b/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java index 2ef7b4cca7..a33e2c08c0 100644 --- a/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java @@ -44,13 +44,14 @@ import org.apache.commons.logging.LogFactory; public class StompTest extends CombinationTestSupport { private static final Log LOG = LogFactory.getLog(StompTest.class); + protected String bindAddress = "stomp://localhost:0"; + private BrokerService broker; private TransportConnector connector; private StompConnection stompConnection = new StompConnection(); private Connection connection; private Session session; private ActiveMQQueue queue; - protected String bindAddress = "stomp://localhost:0"; protected void setUp() throws Exception { broker = new BrokerService(); diff --git a/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslSocketHelper.java b/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslSocketHelper.java index 96236cbb9b..9d393fff01 100644 --- a/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslSocketHelper.java +++ b/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslSocketHelper.java @@ -25,8 +25,13 @@ import javax.net.ssl.SSLSocket; /** * @version $Revision$ */ -public class SslSocketHelper { - public static SSLSocket createSSLSocket(String certDistinguishedName, boolean wantAuth, boolean needAuth) throws IOException { +public final class SslSocketHelper { + + private SslSocketHelper() { + } + + public static SSLSocket createSSLSocket(String certDistinguishedName, boolean wantAuth, boolean needAuth) + throws IOException { JMXPrincipal principal = new JMXPrincipal(certDistinguishedName); X509Certificate cert = new StubX509Certificate(principal); StubSSLSession sslSession = new StubSSLSession(cert); diff --git a/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslTransportFactoryTest.java b/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslTransportFactoryTest.java index 5c5ba51103..2d47b64224 100644 --- a/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslTransportFactoryTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslTransportFactoryTest.java @@ -90,7 +90,7 @@ public class SslTransportFactoryTest extends TestCase { // 2 transport options, 3 socket options, 3 settings for each option => // 3^5 = 243 combos. for (int i = 0; i < 243; ++i) { - Map options = new HashMap(); + Map options = new HashMap(); for (int j = 0; j < 5; ++j) { // -1 since the option range is [-1,1], not [0,2]. diff --git a/activemq-core/src/test/java/org/apache/activemq/transport/tcp/StubSSLSocket.java b/activemq-core/src/test/java/org/apache/activemq/transport/tcp/StubSSLSocket.java index 750e802018..d1de9aaef5 100644 --- a/activemq-core/src/test/java/org/apache/activemq/transport/tcp/StubSSLSocket.java +++ b/activemq-core/src/test/java/org/apache/activemq/transport/tcp/StubSSLSocket.java @@ -32,8 +32,7 @@ public class StubSSLSocket extends SSLSocket { private int wantClientAuthStatus = UNTOUCHED; private int needClientAuthStatus = UNTOUCHED; private int useClientModeStatus = UNTOUCHED; - - final StubSSLSession session; + private final StubSSLSession session; public StubSSLSocket(StubSSLSession ses) { this.session = ses; diff --git a/activemq-core/src/test/java/org/apache/activemq/transport/tcp/StubX509Certificate.java b/activemq-core/src/test/java/org/apache/activemq/transport/tcp/StubX509Certificate.java index a41fad4dd4..d46d0b8038 100644 --- a/activemq-core/src/test/java/org/apache/activemq/transport/tcp/StubX509Certificate.java +++ b/activemq-core/src/test/java/org/apache/activemq/transport/tcp/StubX509Certificate.java @@ -25,6 +25,9 @@ import java.util.Date; import java.util.Set; public class StubX509Certificate extends X509Certificate { + + private final Principal id; + public StubX509Certificate(Principal id) { this.id = id; } @@ -33,8 +36,6 @@ public class StubX509Certificate extends X509Certificate { return this.id; } - private final Principal id; - // --- Stubbed Methods --- public void checkValidity() { // TODO Auto-generated method stub @@ -146,11 +147,13 @@ public class StubX509Certificate extends X509Certificate { return false; } + @SuppressWarnings("unchecked") public Set getCriticalExtensionOIDs() { // TODO Auto-generated method stub return null; } + @SuppressWarnings("unchecked") public Set getNonCriticalExtensionOIDs() { // TODO Auto-generated method stub return null; diff --git a/activemq-core/src/test/java/org/apache/activemq/usecases/AMQFailoverIssue.java b/activemq-core/src/test/java/org/apache/activemq/usecases/AMQFailoverIssue.java index 0900e78bee..865d8a5723 100644 --- a/activemq-core/src/test/java/org/apache/activemq/usecases/AMQFailoverIssue.java +++ b/activemq-core/src/test/java/org/apache/activemq/usecases/AMQFailoverIssue.java @@ -18,6 +18,7 @@ package org.apache.activemq.usecases; import java.net.URI; import java.util.ArrayList; +import java.util.List; import java.util.Random; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; @@ -108,7 +109,7 @@ public class AMQFailoverIssue extends TestCase { final UsageManager memoryManager = new UsageManager(); memoryManager.setLimit(5000000); brokerService.setMemoryManager(memoryManager); - final ArrayList policyEntries = new ArrayList(); + final List policyEntries = new ArrayList(); final PolicyEntry entry = new PolicyEntry(); entry.setQueue(">"); // entry.setQueue(QUEUE1_NAME); diff --git a/activemq-core/src/test/java/org/apache/activemq/usecases/AMQStackOverFlowTest.java b/activemq-core/src/test/java/org/apache/activemq/usecases/AMQStackOverFlowTest.java index f60e5410b7..6c8a7fe365 100644 --- a/activemq-core/src/test/java/org/apache/activemq/usecases/AMQStackOverFlowTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/usecases/AMQStackOverFlowTest.java @@ -19,6 +19,7 @@ package org.apache.activemq.usecases; import java.net.URI; import java.util.ArrayList; +import java.util.List; import javax.jms.JMSException; import javax.jms.Message; @@ -120,7 +121,7 @@ public class AMQStackOverFlowTest extends TestCase { memoryManager.setLimit(10); brokerService.setMemoryManager(memoryManager); - final ArrayList policyEntries = new ArrayList(); + final List policyEntries = new ArrayList(); final PolicyEntry entry = new PolicyEntry(); entry.setQueue(">"); diff --git a/activemq-core/src/test/java/org/apache/activemq/usecases/ChangeSentMessageTest.java b/activemq-core/src/test/java/org/apache/activemq/usecases/ChangeSentMessageTest.java index 2167775c11..f144dfa771 100755 --- a/activemq-core/src/test/java/org/apache/activemq/usecases/ChangeSentMessageTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/usecases/ChangeSentMessageTest.java @@ -47,7 +47,7 @@ public class ChangeSentMessageTest extends TestSupport { MessageConsumer consumer = consumerSession.createConsumer(destination); Session publisherSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = publisherSession.createProducer(destination); - HashMap map = new HashMap(); + HashMap map = new HashMap(); ObjectMessage message = publisherSession.createObjectMessage(); for (int i = 0; i < COUNT; i++) { map.put(VALUE_NAME, Integer.valueOf(i)); diff --git a/activemq-core/src/test/java/org/apache/activemq/usecases/CompositePublishTest.java b/activemq-core/src/test/java/org/apache/activemq/usecases/CompositePublishTest.java index e77040c517..d7b4b77395 100755 --- a/activemq-core/src/test/java/org/apache/activemq/usecases/CompositePublishTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/usecases/CompositePublishTest.java @@ -93,7 +93,7 @@ public class CompositePublishTest extends JmsSendReceiveTestSupport { LOG.info("Started connections"); } - protected MessageListener createMessageListener(int i, final List messageList) { + protected MessageListener createMessageListener(int i, final List messageList) { return new MessageListener() { public void onMessage(Message message) { consumeMessage(message, messageList); @@ -121,12 +121,12 @@ public class CompositePublishTest extends JmsSendReceiveTestSupport { protected void assertMessagesAreReceived() throws JMSException { waitForMessagesToBeDelivered(); - - for (int i = 0, size = messageLists.length; i < size; i++) { + int size = messageLists.length; + for (int i = 0; i < size; i++) { LOG.info("Message list: " + i + " contains: " + messageLists[i].size() + " message(s)"); } - - for (int i = 0, size = messageLists.length; i < size; i++) { + size = messageLists.length; + for (int i = 0; i < size; i++) { assertMessagesReceivedAreValid(messageLists[i]); } } diff --git a/activemq-core/src/test/java/org/apache/activemq/usecases/ConsumeTopicPrefetchTest.java b/activemq-core/src/test/java/org/apache/activemq/usecases/ConsumeTopicPrefetchTest.java index 9845e1e7c2..ee76db52b2 100755 --- a/activemq-core/src/test/java/org/apache/activemq/usecases/ConsumeTopicPrefetchTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/usecases/ConsumeTopicPrefetchTest.java @@ -22,11 +22,15 @@ import javax.jms.Message; import javax.jms.TextMessage; import org.apache.activemq.ActiveMQConnection; +import org.apache.activemq.broker.policy.IndividualDeadLetterViaXmlTest; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * @version $Revision: 1.1.1.1 $ */ public class ConsumeTopicPrefetchTest extends ProducerConsumerTestSupport { + private static final Log LOG = LogFactory.getLog(ConsumeTopicPrefetchTest.class); protected int prefetchSize = 100; protected String[] messageTexts; @@ -47,7 +51,7 @@ public class ConsumeTopicPrefetchTest extends ProducerConsumerTestSupport { protected void testWithMessageCount(int messageCount) throws JMSException { makeMessages(messageCount); - log.info("About to send and receive: " + messageCount + " on destination: " + destination + LOG.info("About to send and receive: " + messageCount + " on destination: " + destination + " of type: " + destination.getClass().getName()); for (int i = 0; i < messageCount; i++) { diff --git a/activemq-core/src/test/java/org/apache/activemq/usecases/CreateTemporaryQueueBeforeStartTest.java b/activemq-core/src/test/java/org/apache/activemq/usecases/CreateTemporaryQueueBeforeStartTest.java index da638661ce..4efe47dbeb 100755 --- a/activemq-core/src/test/java/org/apache/activemq/usecases/CreateTemporaryQueueBeforeStartTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/usecases/CreateTemporaryQueueBeforeStartTest.java @@ -56,9 +56,9 @@ public class CreateTemporaryQueueBeforeStartTest extends TestCase { QueueConnection queueConnection = factory.createQueueConnection(); this.connection = queueConnection; QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); - QueueSender sender = session.createSender(null); // Unidentified + session.createSender(null); // Unidentified Queue receiverQueue = session.createTemporaryQueue(); - QueueReceiver receiver = session.createReceiver(receiverQueue); + session.createReceiver(receiverQueue); queueConnection.start(); } @@ -72,7 +72,7 @@ public class CreateTemporaryQueueBeforeStartTest extends TestCase { QueueConnection connection = createConnection(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createTemporaryQueue(); - QueueReceiver consumer = session.createReceiver(queue); + session.createReceiver(queue); connection.start(); if (count.incrementAndGet() >= number) { diff --git a/activemq-core/src/test/java/org/apache/activemq/usecases/MultiBrokersMultiClientsUsingTcpTest.java b/activemq-core/src/test/java/org/apache/activemq/usecases/MultiBrokersMultiClientsUsingTcpTest.java index 90ac2357a2..9f0ed5b60a 100644 --- a/activemq-core/src/test/java/org/apache/activemq/usecases/MultiBrokersMultiClientsUsingTcpTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/usecases/MultiBrokersMultiClientsUsingTcpTest.java @@ -31,7 +31,7 @@ import org.apache.activemq.transport.TransportFactory; * @version $Revision: 1.1.1.1 $ */ public class MultiBrokersMultiClientsUsingTcpTest extends MultiBrokersMultiClientsTest { - protected List bridges; + protected List bridges; protected void bridgeAllBrokers(String groupName) throws Exception { for (int i = 1; i <= BROKER_COUNT; i++) { @@ -49,7 +49,8 @@ public class MultiBrokersMultiClientsUsingTcpTest extends MultiBrokersMultiClien List remoteTransports = remoteBroker.getTransportConnectors(); List localTransports = localBroker.getTransportConnectors(); - URI remoteURI, localURI; + URI remoteURI; + URI localURI; if (!remoteTransports.isEmpty() && !localTransports.isEmpty()) { remoteURI = ((TransportConnector)remoteTransports.get(0)).getConnectUri(); localURI = ((TransportConnector)localTransports.get(0)).getConnectUri(); @@ -79,6 +80,6 @@ public class MultiBrokersMultiClientsUsingTcpTest extends MultiBrokersMultiClien ((BrokerItem)i.next()).broker.addConnector("tcp://localhost:" + (61616 + j++)); } - bridges = new ArrayList(); + bridges = new ArrayList(); } } diff --git a/activemq-core/src/test/java/org/apache/activemq/usecases/PublishOnQueueConsumedMessageInTransactionTest.java b/activemq-core/src/test/java/org/apache/activemq/usecases/PublishOnQueueConsumedMessageInTransactionTest.java index 3b95fce8e1..bc578d2ec7 100644 --- a/activemq-core/src/test/java/org/apache/activemq/usecases/PublishOnQueueConsumedMessageInTransactionTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/usecases/PublishOnQueueConsumedMessageInTransactionTest.java @@ -50,7 +50,7 @@ public final class PublishOnQueueConsumedMessageInTransactionTest extends TestCa private MessageConsumer consumer; private Connection connection; private ObjectMessage objectMessage; - private List messages = createConcurrentList(); + private List messages = createConcurrentList(); private final Object lock = new Object(); private String[] data; private String dataFileRoot = IOHelper.getDefaultDataDirectory(); @@ -134,7 +134,7 @@ public final class PublishOnQueueConsumedMessageInTransactionTest extends TestCa } } - protected void consumeMessage(Message message, List messageList) { + protected void consumeMessage(Message message, List messageList) { messageList.add(message); if (messageList.size() >= data.length) { synchronized (lock) { @@ -144,8 +144,8 @@ public final class PublishOnQueueConsumedMessageInTransactionTest extends TestCa } - protected List createConcurrentList() { - return Collections.synchronizedList(new ArrayList()); + protected List createConcurrentList() { + return Collections.synchronizedList(new ArrayList()); } protected void waitForMessagesToBeDelivered() { diff --git a/activemq-core/src/test/java/org/apache/activemq/usecases/QueueDuplicatesTest.java b/activemq-core/src/test/java/org/apache/activemq/usecases/QueueDuplicatesTest.java index eea96c2da7..43b89b889f 100755 --- a/activemq-core/src/test/java/org/apache/activemq/usecases/QueueDuplicatesTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/usecases/QueueDuplicatesTest.java @@ -114,11 +114,9 @@ public class QueueDuplicatesTest extends TestCase { } private class SendingThread extends Thread { - private String brokerUrl; private String subject; SendingThread(String brokerUrl, String subject) { - this.brokerUrl = brokerUrl; this.subject = subject; setDaemon(false); } @@ -144,7 +142,7 @@ public class QueueDuplicatesTest extends TestCase { } private static class SimpleConsumer implements MessageListener { - private Map msgs = new HashMap(); + private Map msgs = new HashMap(); public void onMessage(Message message) { LOG.info(formatter.format(new Date()) + " SimpleConsumer Message Received: " + message); diff --git a/activemq-core/src/test/java/org/apache/activemq/usecases/ReliableReconnectTest.java b/activemq-core/src/test/java/org/apache/activemq/usecases/ReliableReconnectTest.java index 331722cd2b..5aa16e56e5 100755 --- a/activemq-core/src/test/java/org/apache/activemq/usecases/ReliableReconnectTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/usecases/ReliableReconnectTest.java @@ -41,10 +41,11 @@ import org.apache.activemq.util.IdGenerator; * @version $Revision: 1.1.1.1 $ */ public class ReliableReconnectTest extends TestSupport { - private static final int RECEIVE_TIMEOUT = 10000; + protected static final int MESSAGE_COUNT = 100; protected static final String DEFAULT_BROKER_URL = "vm://localhost"; - private IdGenerator idGen = new IdGenerator(); + private static final int RECEIVE_TIMEOUT = 10000; + protected int deliveryMode = DeliveryMode.PERSISTENT; protected String consumerClientId; protected Destination destination; @@ -52,6 +53,7 @@ public class ReliableReconnectTest extends TestSupport { protected AtomicInteger messagesReceived = new AtomicInteger(0); protected BrokerService broker; protected int firstBatch = MESSAGE_COUNT / 10; + private IdGenerator idGen = new IdGenerator(); public ReliableReconnectTest() { } diff --git a/activemq-core/src/test/java/org/apache/activemq/usecases/TestSupport.java b/activemq-core/src/test/java/org/apache/activemq/usecases/TestSupport.java index 7c51e80980..3dcd5e548b 100755 --- a/activemq-core/src/test/java/org/apache/activemq/usecases/TestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/usecases/TestSupport.java @@ -36,7 +36,9 @@ import org.apache.commons.logging.LogFactory; * @version $Revision: 1.1.1.1 $ */ public class TestSupport extends TestCase { - protected Log log = LogFactory.getLog(getClass()); + + private static final Log LOG = LogFactory.getLog(TestSupport.class); + protected ActiveMQConnectionFactory connectionFactory; protected boolean topic = true; diff --git a/activemq-core/src/test/java/org/apache/activemq/usecases/ThreeBrokerQueueNetworkUsingTcpTest.java b/activemq-core/src/test/java/org/apache/activemq/usecases/ThreeBrokerQueueNetworkUsingTcpTest.java index 2f95a19287..d21bd8de58 100644 --- a/activemq-core/src/test/java/org/apache/activemq/usecases/ThreeBrokerQueueNetworkUsingTcpTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/usecases/ThreeBrokerQueueNetworkUsingTcpTest.java @@ -30,13 +30,14 @@ import org.apache.activemq.transport.TransportFactory; * @version $Revision: 1.1.1.1 $ */ public class ThreeBrokerQueueNetworkUsingTcpTest extends ThreeBrokerQueueNetworkTest { - protected List bridges; + protected List bridges; protected void bridgeBrokers(BrokerService localBroker, BrokerService remoteBroker) throws Exception { List remoteTransports = remoteBroker.getTransportConnectors(); List localTransports = localBroker.getTransportConnectors(); - URI remoteURI, localURI; + URI remoteURI; + URI localURI; if (!remoteTransports.isEmpty() && !localTransports.isEmpty()) { remoteURI = ((TransportConnector)remoteTransports.get(0)).getConnectUri(); localURI = ((TransportConnector)localTransports.get(0)).getConnectUri(); @@ -62,6 +63,6 @@ public class ThreeBrokerQueueNetworkUsingTcpTest extends ThreeBrokerQueueNetwork public void setUp() throws Exception { super.setUp(); - bridges = new ArrayList(); + bridges = new ArrayList(); } } diff --git a/activemq-core/src/test/java/org/apache/activemq/usecases/ThreeBrokerTopicNetworkUsingTcpTest.java b/activemq-core/src/test/java/org/apache/activemq/usecases/ThreeBrokerTopicNetworkUsingTcpTest.java index c4ff7a3505..da833b3f8b 100644 --- a/activemq-core/src/test/java/org/apache/activemq/usecases/ThreeBrokerTopicNetworkUsingTcpTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/usecases/ThreeBrokerTopicNetworkUsingTcpTest.java @@ -30,13 +30,14 @@ import org.apache.activemq.transport.TransportFactory; * @version $Revision: 1.1.1.1 $ */ public class ThreeBrokerTopicNetworkUsingTcpTest extends ThreeBrokerTopicNetworkTest { - protected List bridges; + protected List bridges; protected void bridgeBrokers(BrokerService localBroker, BrokerService remoteBroker) throws Exception { List remoteTransports = remoteBroker.getTransportConnectors(); List localTransports = localBroker.getTransportConnectors(); - URI remoteURI, localURI; + URI remoteURI; + URI localURI; if (!remoteTransports.isEmpty() && !localTransports.isEmpty()) { remoteURI = ((TransportConnector)remoteTransports.get(0)).getConnectUri(); localURI = ((TransportConnector)localTransports.get(0)).getConnectUri(); @@ -62,6 +63,6 @@ public class ThreeBrokerTopicNetworkUsingTcpTest extends ThreeBrokerTopicNetwork public void setUp() throws Exception { super.setUp(); - bridges = new ArrayList(); + bridges = new ArrayList(); } } diff --git a/activemq-core/src/test/java/org/apache/activemq/usecases/TopicRedeliverTest.java b/activemq-core/src/test/java/org/apache/activemq/usecases/TopicRedeliverTest.java index 04f02d5c61..637ce2c1e9 100755 --- a/activemq-core/src/test/java/org/apache/activemq/usecases/TopicRedeliverTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/usecases/TopicRedeliverTest.java @@ -35,8 +35,9 @@ import org.apache.activemq.util.IdGenerator; public class TopicRedeliverTest extends TestSupport { private static final int RECEIVE_TIMEOUT = 10000; - private IdGenerator idGen = new IdGenerator(); + protected int deliveryMode = DeliveryMode.PERSISTENT; + private IdGenerator idGen = new IdGenerator(); public TopicRedeliverTest() { } @@ -80,9 +81,9 @@ public class TopicRedeliverTest extends TestSupport { sent1.setText("msg3"); producer.send(sent3); - Message rec1 = consumer.receive(RECEIVE_TIMEOUT); + consumer.receive(RECEIVE_TIMEOUT); Message rec2 = consumer.receive(RECEIVE_TIMEOUT); - Message rec3 = consumer.receive(RECEIVE_TIMEOUT); + consumer.receive(RECEIVE_TIMEOUT); // ack rec2 rec2.acknowledge(); diff --git a/activemq-core/src/test/java/org/apache/activemq/usecases/TransactionRollbackOrderTest.java b/activemq-core/src/test/java/org/apache/activemq/usecases/TransactionRollbackOrderTest.java index b55dfbb2bd..9fffd1eb62 100644 --- a/activemq-core/src/test/java/org/apache/activemq/usecases/TransactionRollbackOrderTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/usecases/TransactionRollbackOrderTest.java @@ -56,10 +56,10 @@ public final class TransactionRollbackOrderTest extends TestCase { private Connection connection; private CountDownLatch latch = new CountDownLatch(1); private int numMessages = 5; - private List msgSent = new ArrayList(); - private List msgCommitted = new ArrayList(); - private List msgRolledBack = new ArrayList(); - private List msgRedelivered = new ArrayList(); + private List msgSent = new ArrayList(); + private List msgCommitted = new ArrayList(); + private List msgRolledBack = new ArrayList(); + private List msgRedelivered = new ArrayList(); public void testTransaction() throws Exception { diff --git a/activemq-core/src/test/java/org/apache/activemq/usecases/TwoBrokerMessageNotSentToRemoteWhenNoConsumerTest.java b/activemq-core/src/test/java/org/apache/activemq/usecases/TwoBrokerMessageNotSentToRemoteWhenNoConsumerTest.java index 2b5e977fa2..bbd75a966d 100644 --- a/activemq-core/src/test/java/org/apache/activemq/usecases/TwoBrokerMessageNotSentToRemoteWhenNoConsumerTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/usecases/TwoBrokerMessageNotSentToRemoteWhenNoConsumerTest.java @@ -39,7 +39,7 @@ import org.apache.activemq.util.MessageIdList; public class TwoBrokerMessageNotSentToRemoteWhenNoConsumerTest extends JmsMultipleBrokersTestSupport { protected static final int MESSAGE_COUNT = 10; - protected List bridges; + protected List bridges; protected AtomicInteger msgDispatchCount; /** @@ -108,7 +108,8 @@ public class TwoBrokerMessageNotSentToRemoteWhenNoConsumerTest extends JmsMultip List remoteTransports = remoteBroker.getTransportConnectors(); List localTransports = localBroker.getTransportConnectors(); - URI remoteURI, localURI; + URI remoteURI; + URI localURI; if (!remoteTransports.isEmpty() && !localTransports.isEmpty()) { remoteURI = ((TransportConnector)remoteTransports.get(0)).getConnectUri(); localURI = ((TransportConnector)localTransports.get(0)).getConnectUri(); @@ -147,7 +148,7 @@ public class TwoBrokerMessageNotSentToRemoteWhenNoConsumerTest extends JmsMultip createBroker(new URI("broker:(tcp://localhost:61616)/BrokerA?persistent=false&useJmx=false")); createBroker(new URI("broker:(tcp://localhost:61617)/BrokerB?persistent=false&useJmx=false")); - bridges = new ArrayList(); + bridges = new ArrayList(); msgDispatchCount = new AtomicInteger(0); } } diff --git a/activemq-core/src/test/java/org/apache/activemq/usecases/TwoBrokerMulticastQueueTest.java b/activemq-core/src/test/java/org/apache/activemq/usecases/TwoBrokerMulticastQueueTest.java index dc6ca81014..0a50e858e9 100644 --- a/activemq-core/src/test/java/org/apache/activemq/usecases/TwoBrokerMulticastQueueTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/usecases/TwoBrokerMulticastQueueTest.java @@ -42,7 +42,8 @@ public class TwoBrokerMulticastQueueTest extends CombinationTestSupport { public static final int BROKER_COUNT = 2; public static final int CONSUMER_COUNT = 20; - public String sendUri, recvUri; + public String sendUri; + public String recvUri; private BrokerService[] brokers; public static Test suite() { diff --git a/activemq-core/src/test/java/org/apache/activemq/usecases/TwoBrokerQueueClientsReconnectTest.java b/activemq-core/src/test/java/org/apache/activemq/usecases/TwoBrokerQueueClientsReconnectTest.java index 9d8b982fbd..9eb4bbf627 100644 --- a/activemq-core/src/test/java/org/apache/activemq/usecases/TwoBrokerQueueClientsReconnectTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/usecases/TwoBrokerQueueClientsReconnectTest.java @@ -39,8 +39,10 @@ public class TwoBrokerQueueClientsReconnectTest extends JmsMultipleBrokersTestSu private static final Log LOG = LogFactory.getLog(TwoBrokerQueueClientsReconnectTest.class); - protected int msgsClient1, msgsClient2; - protected String broker1, broker2; + protected int msgsClient1; + protected int msgsClient2; + protected String broker1; + protected String broker2; public void testClientAReceivesOnly() throws Exception { broker1 = "BrokerA"; @@ -353,7 +355,8 @@ public class TwoBrokerQueueClientsReconnectTest extends JmsMultipleBrokersTestSu createBroker(new URI("broker:(tcp://localhost:61617)/BrokerB?persistent=false&useJmx=false")); // Configure broker connection factory - ActiveMQConnectionFactory factoryA, factoryB; + ActiveMQConnectionFactory factoryA; + ActiveMQConnectionFactory factoryB; factoryA = (ActiveMQConnectionFactory)getConnectionFactory("BrokerA"); factoryB = (ActiveMQConnectionFactory)getConnectionFactory("BrokerB"); diff --git a/activemq-core/src/test/java/org/apache/activemq/util/MessageIdList.java b/activemq-core/src/test/java/org/apache/activemq/util/MessageIdList.java index 126eddd201..23c37f111b 100644 --- a/activemq-core/src/test/java/org/apache/activemq/util/MessageIdList.java +++ b/activemq-core/src/test/java/org/apache/activemq/util/MessageIdList.java @@ -44,7 +44,7 @@ public class MessageIdList extends Assert implements MessageListener { private static final Log LOG = LogFactory.getLog(MessageIdList.class); - private List messageIds = new ArrayList(); + private List messageIds = new ArrayList(); private Object semaphore; private boolean verbose; private MessageListener parent; @@ -84,17 +84,17 @@ public class MessageIdList extends Assert implements MessageListener { /** * @return all the messages on the list so far, clearing the buffer */ - public List flushMessages() { + public List flushMessages() { synchronized (semaphore) { - List answer = new ArrayList(messageIds); + List answer = new ArrayList(messageIds); messageIds.clear(); return answer; } } - public synchronized List getMessageIds() { + public synchronized List getMessageIds() { synchronized (semaphore) { - return new ArrayList(messageIds); + return new ArrayList(messageIds); } } diff --git a/activemq-core/src/test/java/org/apache/activemq/util/ReflectionSupportTest.java b/activemq-core/src/test/java/org/apache/activemq/util/ReflectionSupportTest.java index b50dc727b3..adafee4a5f 100755 --- a/activemq-core/src/test/java/org/apache/activemq/util/ReflectionSupportTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/util/ReflectionSupportTest.java @@ -26,7 +26,7 @@ public class ReflectionSupportTest extends TestCase { public void testSetProperties() throws URISyntaxException { SimplePojo pojo = new SimplePojo(); - HashMap map = new HashMap(); + HashMap map = new HashMap(); map.put("age", "27"); map.put("name", "Hiram"); map.put("enabled", "true"); diff --git a/activemq-core/src/test/java/org/apache/activemq/xbean/ManagementContextXBeanConfigTest.java b/activemq-core/src/test/java/org/apache/activemq/xbean/ManagementContextXBeanConfigTest.java index f69216fb4a..7eee520233 100644 --- a/activemq-core/src/test/java/org/apache/activemq/xbean/ManagementContextXBeanConfigTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/xbean/ManagementContextXBeanConfigTest.java @@ -43,7 +43,7 @@ public class ManagementContextXBeanConfigTest extends TestCase { MBeanServer beanServer = brokerService.getManagementContext().getMBeanServer(); // Make sure the broker is registered in the right jmx domain. - Hashtable map = new Hashtable(); + Hashtable map = new Hashtable(); map.put("Type", "Broker"); map.put("BrokerName", JMXSupport.encodeObjectNamePart("localhost")); ObjectName on = new ObjectName("test.domain", map); diff --git a/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CHeadersGenerator.java b/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CHeadersGenerator.java index de567c3c06..7996bc920d 100644 --- a/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CHeadersGenerator.java +++ b/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CHeadersGenerator.java @@ -98,8 +98,8 @@ out.println(" */"); /** * Sort the class list so that base classes come up first. */ - protected List sort(List source) { - LinkedHashMap rc = new LinkedHashMap(); + protected List sort(List source) { + LinkedHashMap rc = new LinkedHashMap(); ArrayList classes = new ArrayList(source); Collections.sort(classes, new Comparator(){ public int compare(Object o1, Object o2) { @@ -109,7 +109,7 @@ out.println(" */"); }}); // lets make a map of all the class names - HashMap classNames = new HashMap(); + HashMap classNames = new HashMap(); for (Iterator iter = classes.iterator(); iter.hasNext();) { JClass c = (JClass) iter.next(); classNames.put(c, c); @@ -129,7 +129,7 @@ out.println(" */"); rc.put(c,c); } - return new ArrayList(rc.keySet()); + return new ArrayList(rc.keySet()); } void generateFields(PrintWriter out, JClass jclass) { @@ -141,7 +141,7 @@ out.println(" */"); generateFields(out, jclass.getSuperclass()); } - ArrayList properties = new ArrayList(); + ArrayList properties = new ArrayList(); jclass.getDeclaredProperties(); for (int i = 0; i < jclass.getDeclaredProperties().length; i++) { JProperty p = jclass.getDeclaredProperties()[i]; @@ -149,8 +149,8 @@ out.println(" */"); properties.add(p); } } - for (Iterator iter = properties.iterator(); iter.hasNext();) { - JProperty property = (JProperty) iter.next(); + for (Iterator iter = properties.iterator(); iter.hasNext();) { + JProperty property = iter.next(); JAnnotation annotation = property.getGetter().getAnnotation("openwire:property"); JAnnotationValue size = annotation.getValue("size"); String name = toPropertyCase(property.getSimpleName()); diff --git a/activemq-optional/src/main/java/org/apache/activemq/tool/AcidTestTool.java b/activemq-optional/src/main/java/org/apache/activemq/tool/AcidTestTool.java index c85c038f56..56f5376315 100755 --- a/activemq-optional/src/main/java/org/apache/activemq/tool/AcidTestTool.java +++ b/activemq-optional/src/main/java/org/apache/activemq/tool/AcidTestTool.java @@ -53,7 +53,6 @@ public class AcidTestTool extends TestCase { private Random random = new Random(); private byte data[]; private int workerCount = 10; - private PrintWriter statWriter; // Worker configuration. protected int recordSize = 1024; @@ -68,7 +67,7 @@ public class AcidTestTool extends TestCase { AtomicInteger publishedBatches = new AtomicInteger(0); AtomicInteger consumedBatches = new AtomicInteger(0); - List errors = Collections.synchronizedList(new ArrayList()); + List errors = Collections.synchronizedList(new ArrayList()); private interface Worker extends Runnable { public boolean waitForExit(long i) throws InterruptedException; @@ -80,11 +79,9 @@ public class AcidTestTool extends TestCase { private MessageProducer producer; private BytesMessage message; CountDownLatch doneLatch = new CountDownLatch(1); - private final String workerId; ProducerWorker(Session session, String workerId) throws JMSException { this.session = session; - this.workerId = workerId; producer = session.createProducer(target); producer.setDeliveryMode(DeliveryMode.PERSISTENT); message = session.createBytesMessage(); @@ -141,11 +138,9 @@ public class AcidTestTool extends TestCase { private MessageConsumer consumer; private final long timeout; CountDownLatch doneLatch = new CountDownLatch(1); - private final String workerId; ConsumerWorker(Session session, String workerId, long timeout) throws JMSException { this.session = session; - this.workerId = workerId; this.timeout = timeout; consumer = session.createConsumer(target,"workerId='"+workerId+"'"); } @@ -233,7 +228,6 @@ public class AcidTestTool extends TestCase { } long reconnectDelay=1000; - JMSException lastError=null; while( connection == null) { if( reconnectDelay > 1000*10 ) { @@ -243,7 +237,6 @@ public class AcidTestTool extends TestCase { connection = factory.createConnection(); connection.start(); } catch (JMSException e) { - lastError = e; Thread.sleep(reconnectDelay); reconnectDelay*=2; } @@ -272,7 +265,7 @@ public class AcidTestTool extends TestCase { reconnect(); System.out.println("Starting " + workerCount + " Workers..."); - ArrayList workers = new ArrayList(); + ArrayList workers = new ArrayList(); for( int i=0; i< workerCount; i++ ){ String workerId = "worker-"+i; @@ -302,8 +295,8 @@ public class AcidTestTool extends TestCase { // Wait for all the workers to finish. System.out.println("Waiting for all workers to exit due to server shutdown."); - for (Iterator iter = workers.iterator(); iter.hasNext();) { - Worker worker = (Worker) iter.next(); + for (Iterator iter = workers.iterator(); iter.hasNext();) { + Worker worker = iter.next(); while( !worker.waitForExit(1000) ) { System.out.println("=============================================="); System.out.println("===> Server is under load now. Kill it!"); @@ -315,7 +308,7 @@ public class AcidTestTool extends TestCase { // No errors should have occured so far. if( errors.size()>0 ) - throw (Throwable) errors.get(0); + throw errors.get(0); System.out.println("=============================================="); System.out.println("===> Start the server now."); @@ -333,8 +326,8 @@ public class AcidTestTool extends TestCase { } System.out.println("Waiting for restarted consumers to finish consuming all messages.."); - for (Iterator iter = workers.iterator(); iter.hasNext();) { - Worker worker = (Worker) iter.next(); + for (Iterator iter = workers.iterator(); iter.hasNext();) { + Worker worker = iter.next(); while( !worker.waitForExit(1000*5) ) { System.out.println("Waiting for restarted consumers to finish consuming all messages.."); System.out.println("Stats: Produced Batches: "+this.publishedBatches.get()+", Consumed Batches: "+this.consumedBatches.get()); @@ -346,7 +339,7 @@ public class AcidTestTool extends TestCase { System.out.println("Stats: Produced Batches: "+this.publishedBatches.get()+", Consumed Batches: "+this.consumedBatches.get()); if( errors.size()>0 ) - throw (Throwable) errors.get(0); + throw errors.get(0); }