diff --git a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedMessageProducer.cs b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedMessageProducer.cs index c4fbafa8..61f09549 100644 --- a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedMessageProducer.cs +++ b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedMessageProducer.cs @@ -43,6 +43,8 @@ namespace Spring.Messaging.Nms.Connections private TimeSpan timeToLive; + private TimeSpan requestTimeout; + /// /// Initializes a new instance of the class. @@ -198,6 +200,17 @@ namespace Spring.Messaging.Nms.Connections set { timeToLive = value; } } + + /// + /// Gets or sets the request timeout for the message producer. + /// + /// The request timeout. + public TimeSpan RequestTimeout + { + get { return requestTimeout; } + set { requestTimeout = value; } + } + /// /// Gets or sets the priority of messages sent with this producer. /// @@ -253,7 +266,7 @@ namespace Spring.Messaging.Nms.Connections /// /// Reset properties. /// - public void Dispose() + public void Close() { // It's a cached MessageProducer... reset properties only. if (originalDisableMessageID != null) @@ -268,6 +281,14 @@ namespace Spring.Messaging.Nms.Connections } } + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public void Dispose() + { + target.Dispose(); + } + /// /// Returns string indicated this is a wrapped MessageProducer diff --git a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedSession.cs b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedSession.cs index 579577eb..ea7db0c0 100644 --- a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedSession.cs +++ b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedSession.cs @@ -18,6 +18,7 @@ #endregion +using System; using System.Collections; using Apache.NMS; using Common.Logging; @@ -125,7 +126,7 @@ namespace Spring.Messaging.Nms.Connections /// Creates the producer, potentially returning a cached instance. /// /// The destination. - /// + /// A message producer. public IMessageProducer CreateProducer(IDestination destination) { if (shouldCacheProducers) @@ -165,6 +166,19 @@ namespace Spring.Messaging.Nms.Connections } } + + /// + /// Creates the producer given the destinaton and requst timeout, potentially returning a cached instance. + /// + /// The destination. + /// The request timeout. + /// The message producer + public IMessageProducer CreateProducer(IDestination destination, TimeSpan requestTimeout) + { + LOG.Warn("RequestTimeout for Producers created from CachedSession not yet supported"); + return CreateProducer(destination, requestTimeout); + } + /// /// If have not yet reached session cache size, cache the session, otherwise /// dispose of all cached message producers and close the session. @@ -256,46 +270,88 @@ namespace Spring.Messaging.Nms.Connections } /// - /// Creates the consumer. + /// Creates the consumer, potentially returning a cached instance. /// /// The destination. - /// + /// A message consumer public IMessageConsumer CreateConsumer(IDestination destination) { return CreateConsumer(destination, null, false, null); } + /// - /// Creates the consumer. + /// Creates the consumer for the given destinaton and request timeout, potentially returning a cached instance. + /// + /// The destination. + /// The request timeout. + /// A message consumer + public IMessageConsumer CreateConsumer(IDestination destination, TimeSpan requestTimeout) + { + LOG.Warn("RequestTimeout not yet supported in CachedSesion."); + return CreateConsumer(destination, null, false, null); + } + + /// + /// Creates the consumer, potentially returning a cached instance. /// /// The destination. /// The selector. - /// + /// A message consumer public IMessageConsumer CreateConsumer(IDestination destination, string selector) { return CreateConsumer(destination, selector, false, null); } /// - /// Creates the consumer. + /// Creates the consumer, potentially returning a cached instance. + /// + /// The destination. + /// The selector. + /// The request timeout. + /// A message consumer. + public IMessageConsumer CreateConsumer(IDestination destination, string selector, TimeSpan requestTimeout) + { + LOG.Warn("RequestTimeout not yet supported in CachedSesion."); + return CreateConsumer(destination, selector, false, null); + } + + /// + /// Creates the consumer, potentially returning a cached instance. /// /// The destination. /// The selector. /// if set to true [no local]. - /// + /// A message consumer. public IMessageConsumer CreateConsumer(IDestination destination, string selector, bool noLocal) { return CreateConsumer(destination, selector, noLocal, null); } + /// - /// Creates the durable consumer. + /// Creates the consumer, potentially returning a cached instance. + /// + /// The destination. + /// The selector. + /// if set to true [no local]. + /// The request timeout. + /// A message consumer + public IMessageConsumer CreateConsumer(IDestination destination, string selector, bool noLocal, + TimeSpan requestTimeout) + { + LOG.Warn("RequestTimeout not yet supported in CachedSesion."); + return CreateConsumer(destination, selector, noLocal, null); + } + + /// + /// Creates the durable consumer, potentially returning a cached instance. /// /// The destination. /// The name of the durable subscription. /// The selector. /// if set to true [no local]. - /// + /// A message consumer public IMessageConsumer CreateDurableConsumer(ITopic destination, string subscription, string selector, bool noLocal) { this.transactionOpen = true; @@ -309,6 +365,43 @@ namespace Spring.Messaging.Nms.Connections } } + + /// + /// Creates the durable consumer, potentially returning a cached instance. + /// + /// The destination. + /// The name. + /// The selector. + /// if set to true [no local]. + /// The request timeout. + /// A message consumer + public IMessageConsumer CreateDurableConsumer(ITopic destination, string name, string selector, bool noLocal, + TimeSpan requestTimeout) + { + LOG.Warn("RequestTimeout not yet supported in CachedSesion."); + return CreateDurableConsumer(destination, name, selector, noLocal); + } + + + /// + /// Deletes the durable consumer. + /// + /// The name. + public void DeleteDurableConsumer(string name) + { + throw new NotImplementedException(); + } + + /// + /// Deletes the durable consumer. + /// + /// The name. + /// The request timeout. + public void DeleteDurableConsumer(string name, TimeSpan requestTimeout) + { + throw new NotImplementedException(); + } + /// /// Creates the consumer. /// diff --git a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachingConnectionFactory.cs b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachingConnectionFactory.cs index de297899..6bed6cfd 100644 --- a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachingConnectionFactory.cs +++ b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachingConnectionFactory.cs @@ -252,6 +252,24 @@ namespace Spring.Messaging.Nms.Connections return session; } + /// + /// Template method for obtaining a (potentially cached) Session. + /// + /// The connection to operate on. + /// The session ack mode. + /// The request timeout. + /// + /// the Session to use, or null to indicate + /// creation of a raw standard Session + /// + public override ISession GetSession(IConnection con, AcknowledgementMode mode, TimeSpan requestTimeout) + { + ISession session = GetSession(con, mode); + LOG.Warn("RequestTimeout parameter not yet supported in CachingConnectionFactory"); + return session; + } + + /// /// Wraps the given Session so that it delegates every method call to the target session but /// adapts close calls. This is useful for allowing application code to diff --git a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/SingleConnectionFactory.cs b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/SingleConnectionFactory.cs index 255b23b6..4b374b71 100644 --- a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/SingleConnectionFactory.cs +++ b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/SingleConnectionFactory.cs @@ -325,6 +325,21 @@ namespace Spring.Messaging.Nms.Connections return null; } + /// + /// Template method for obtaining a (potentially cached) Session. + /// + /// The connection to operate on. + /// The session ack mode. + /// The request timeout. + /// + /// the Session to use, or null to indicate + /// creation of a raw standard Session + /// + public virtual ISession GetSession(IConnection con, AcknowledgementMode mode, TimeSpan requestTimeout) + { + return null; + } + /// /// reate a JMS Connection via this template's ConnectionFactory. /// @@ -489,6 +504,17 @@ namespace Spring.Messaging.Nms.Connections return target.CreateSession(acknowledgementMode); } + + public ISession CreateSession(AcknowledgementMode acknowledgementMode, TimeSpan requestTimeout) + { + ISession session = singleConnectionFactory.GetSession(target, acknowledgementMode, requestTimeout); + if (session != null) + { + return session; + } + return target.CreateSession(acknowledgementMode, requestTimeout); + } + #region Pass through implementations to the target connection diff --git a/src/Spring/Spring.Messaging.Nms/Spring.Messaging.Nms.2008.csproj b/src/Spring/Spring.Messaging.Nms/Spring.Messaging.Nms.2008.csproj index ec5d8328..4bc1e7f7 100644 --- a/src/Spring/Spring.Messaging.Nms/Spring.Messaging.Nms.2008.csproj +++ b/src/Spring/Spring.Messaging.Nms/Spring.Messaging.Nms.2008.csproj @@ -48,9 +48,9 @@ - + @@ -58,35 +58,39 @@ - - + + - - - - - - - + + + + + + + + + + + + + - + + - - - - - + + diff --git a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestConnection.cs b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestConnection.cs index f58653d8..e34200d0 100644 --- a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestConnection.cs +++ b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestConnection.cs @@ -33,6 +33,11 @@ namespace Spring.Messaging.Nms.Connections return new TestSession(); } + public ISession CreateSession(AcknowledgementMode acknowledgementMode, TimeSpan requestTimeout) + { + throw new NotImplementedException(); + } + public void Close() { closeCount++; diff --git a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestMessageProducer.cs b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestMessageProducer.cs index b26cac7e..92b73667 100644 --- a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestMessageProducer.cs +++ b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestMessageProducer.cs @@ -27,7 +27,8 @@ namespace Spring.Messaging.Nms.Connections public class TestMessageProducer : IMessageProducer { private bool persistent; - private TimeSpan timeToLive = new TimeSpan(0,0,0,60,0); + private TimeSpan timeToLive = new TimeSpan(0,0,0,60,0); + private TimeSpan requestTimeout; public void Send(IMessage message) { @@ -49,6 +50,11 @@ namespace Spring.Messaging.Nms.Connections throw new NotImplementedException(); } + public void Close() + { + throw new NotImplementedException(); + } + public IMessage CreateMessage() { throw new NotImplementedException(); @@ -96,6 +102,12 @@ namespace Spring.Messaging.Nms.Connections set { timeToLive = value; } } + public TimeSpan RequestTimeout + { + get { return requestTimeout; } + set { requestTimeout = value; } + } + public byte Priority { get { return 1; } diff --git a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestSession.cs b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestSession.cs index 0322d8f9..06775263 100644 --- a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestSession.cs +++ b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestSession.cs @@ -59,11 +59,21 @@ namespace Spring.Messaging.Nms.Connections return new TestMessageProducer(); } + public IMessageProducer CreateProducer(IDestination destination, TimeSpan requestTimeout) + { + throw new NotImplementedException(); + } + public IMessageConsumer CreateConsumer(IDestination destination) { throw new NotImplementedException(); } + public IMessageConsumer CreateConsumer(IDestination destination, TimeSpan requestTimeout) + { + throw new NotImplementedException(); + } + public IMessageConsumer CreateConsumer(IDestination destination, string selector) { //IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory)); @@ -71,16 +81,43 @@ namespace Spring.Messaging.Nms.Connections return msgConsumer; } + public IMessageConsumer CreateConsumer(IDestination destination, string selector, TimeSpan requestTimeout) + { + throw new NotImplementedException(); + } + public IMessageConsumer CreateConsumer(IDestination destination, string selector, bool noLocal) { throw new NotImplementedException(); } + public IMessageConsumer CreateConsumer(IDestination destination, string selector, bool noLocal, + TimeSpan requestTimeout) + { + throw new NotImplementedException(); + } + public IMessageConsumer CreateDurableConsumer(ITopic destination, string name, string selector, bool noLocal) { throw new NotImplementedException(); } + public IMessageConsumer CreateDurableConsumer(ITopic destination, string name, string selector, bool noLocal, + TimeSpan requestTimeout) + { + throw new NotImplementedException(); + } + + public void DeleteDurableConsumer(string name) + { + throw new NotImplementedException(); + } + + public void DeleteDurableConsumer(string name, TimeSpan requestTimeout) + { + throw new NotImplementedException(); + } + public IQueue GetQueue(string name) { return new ActiveMQQueue(name);