From 6e72dc997ba4b02abfd440284e28d29db79eecb2 Mon Sep 17 00:00:00 2001 From: markpollack Date: Thu, 14 Aug 2008 00:41:21 +0000 Subject: [PATCH] Add queue browsing functionality to TIBCO EmsTemplate --- .../Messaging/Ems/Core/BrowserDelegate.cs | 31 ++ .../Messaging/Ems/Core/EmsTemplate.cs | 335 +++++++++++++++--- .../Messaging/Ems/Core/IBrowserCallback.cs | 47 +++ .../Messaging/Ems/Core/IEmsOperations.cs | 187 ++++++++-- .../Messaging/Ems/Support/EmsUtils.cs | 23 +- 5 files changed, 550 insertions(+), 73 deletions(-) create mode 100644 src/Spring/Spring.Messaging.Ems/Messaging/Ems/Core/BrowserDelegate.cs create mode 100644 src/Spring/Spring.Messaging.Ems/Messaging/Ems/Core/IBrowserCallback.cs diff --git a/src/Spring/Spring.Messaging.Ems/Messaging/Ems/Core/BrowserDelegate.cs b/src/Spring/Spring.Messaging.Ems/Messaging/Ems/Core/BrowserDelegate.cs new file mode 100644 index 00000000..2219e6ab --- /dev/null +++ b/src/Spring/Spring.Messaging.Ems/Messaging/Ems/Core/BrowserDelegate.cs @@ -0,0 +1,31 @@ + + +#region License + +/* + * Copyright 2002-2008 the original author or authors. + * + * Licensed 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. + */ + +#endregion + +using TIBCO.EMS; + +namespace Spring.Messaging.Ems.Core +{ + /// + /// Delegate callback for browsing the messages in an EMS queue. + /// + public delegate object BrowserDelegate(Session session, QueueBrowser browser); +} \ No newline at end of file diff --git a/src/Spring/Spring.Messaging.Ems/Messaging/Ems/Core/EmsTemplate.cs b/src/Spring/Spring.Messaging.Ems/Messaging/Ems/Core/EmsTemplate.cs index c2182ad8..1b4062bd 100644 --- a/src/Spring/Spring.Messaging.Ems/Messaging/Ems/Core/EmsTemplate.cs +++ b/src/Spring/Spring.Messaging.Ems/Messaging/Ems/Core/EmsTemplate.cs @@ -28,6 +28,7 @@ using Spring.Messaging.Ems.Support.Destinations; using Spring.Transaction.Support; using Spring.Util; using TIBCO.EMS; +using Queue=TIBCO.EMS.Queue; namespace Spring.Messaging.Ems.Core { @@ -164,8 +165,30 @@ namespace Spring.Messaging.Ems.Core /// /// the result object from working with the session /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public virtual object Execute(ISessionCallback action, bool startConnection) + { + return Execute(action.DoInEms, startConnection); + } + + + /// Execute the action specified by the given action object within a + /// EMS Session. + /// + /// Generalized version of execute(SessionCallback), + /// allowing the EMS Connection to be started on the fly. + ///

Use execute(SessionCallback) for the general case. + /// Starting the EMS Connection is just necessary for receiving messages, + /// which is preferably achieved through the receive methods.

+ ///
+ /// callback object that exposes the session + /// + /// Start the connection before performing callback action. + /// + /// the result object from working with the session + /// + /// If there is any problem accessing the EMS API + public virtual object Execute(SessionDelegate action, bool startConnection) { AssertUtils.ArgumentNotNull(action, "Callback object must not be null"); @@ -195,7 +218,7 @@ namespace Spring.Messaging.Ems.Core { logger.Debug("Executing callback on EMS Session [" + sessionToUse + "]"); } - return action.DoInEms(sessionToUse); + return action(sessionToUse); } finally { @@ -433,7 +456,7 @@ namespace Spring.Messaging.Ems.Core /// /// the new EMS MessageProducer /// - /// EMSException if thrown by EMS API methods + /// If there is any problem accessing the EMS API /// /// /// @@ -487,7 +510,7 @@ namespace Spring.Messaging.Ems.Core /// /// the new EMS MessageProducer /// - /// EMSException if thrown by EMS API methods + /// If there is any problem accessing the EMS API protected virtual MessageProducer DoCreateProducer(Session session, Destination destination) { if (CacheEmsResources) @@ -543,7 +566,7 @@ namespace Spring.Messaging.Ems.Core /// /// the new EMS MessageConsumer /// - /// EMSException if thrown by EMS API methods + /// If there is any problem accessing the EMS API protected virtual MessageConsumer CreateConsumer(Session session, Destination destination, string messageSelector) { @@ -568,7 +591,7 @@ namespace Spring.Messaging.Ems.Core /// /// A EMS Connection /// - /// EMSException if thrown by EMS API methods + /// If there is any problem accessing the EMS API protected override Connection CreateConnection() { if (CacheEmsResources) @@ -596,7 +619,7 @@ namespace Spring.Messaging.Ems.Core /// /// the new EMS Session /// - /// EMSException if thrown by EMS API methods + /// If there is any problem accessing the EMS API protected override Session CreateSession(Connection con) { if (CacheEmsResources) @@ -646,7 +669,7 @@ namespace Spring.Messaging.Ems.Core /// /// delegate callback to create a EMS Message /// - /// EMSException if thrown by EMS API methods + /// If there is any problem accessing the EMS API protected internal virtual void DoSend(Session session, Destination destination, IMessageCreator messageCreator, MessageCreatorDelegate messageCreatorDelegate) { @@ -656,7 +679,7 @@ namespace Spring.Messaging.Ems.Core try { - Message message = null; + Message message; if (messageCreator != null) { message = messageCreator.CreateMessage(session) ; @@ -689,7 +712,7 @@ namespace Spring.Messaging.Ems.Core /// /// the EMS Message to send /// - /// EMSException if thrown by EMS API methods + /// If there is any problem accessing the EMS API protected virtual void DoSend(MessageProducer producer, Message message) { if (ExplicitQosEnabled) @@ -720,7 +743,7 @@ namespace Spring.Messaging.Ems.Core /// If PubSubDomain equals true, then a Session is passed to the callback. /// If false, then a Session is passed to the callback.b /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public object Execute(SessionDelegate del) { return Execute(new ExecuteSessionCallbackUsingDelegate(del)); @@ -736,7 +759,7 @@ namespace Spring.Messaging.Ems.Core /// /// the result object from working with the session /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public object Execute(ISessionCallback action) { return Execute(action, false); @@ -750,7 +773,7 @@ namespace Spring.Messaging.Ems.Core /// /// the result object from working with the session /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public object Execute(IProducerCallback action) { return Execute(new ProducerCreatorCallback(this, action)); @@ -764,7 +787,7 @@ namespace Spring.Messaging.Ems.Core /// /// the result object from working with the session /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public object Execute(ProducerDelegate del) { return Execute(new ProducerCreatorCallback(this, del)); @@ -775,7 +798,7 @@ namespace Spring.Messaging.Ems.Core /// /// delegate callback to create a message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public void SendWithDelegate(MessageCreatorDelegate messageCreatorDelegate) { CheckDefaultDestination(); @@ -796,7 +819,7 @@ namespace Spring.Messaging.Ems.Core /// /// delegate callback to create a message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public void SendWithDelegate(Destination destination, MessageCreatorDelegate messageCreatorDelegate) { Execute(new SendDestinationCallback(this, destination, messageCreatorDelegate), false); @@ -810,7 +833,7 @@ namespace Spring.Messaging.Ems.Core /// /// delegate callback to create a message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public void SendWithDelegate(string destinationName, MessageCreatorDelegate messageCreatorDelegate) { Execute(new SendDestinationCallback(this, destinationName, messageCreatorDelegate), false); @@ -821,7 +844,7 @@ namespace Spring.Messaging.Ems.Core /// /// callback to create a message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public void Send(IMessageCreator messageCreator) { CheckDefaultDestination(); @@ -842,7 +865,7 @@ namespace Spring.Messaging.Ems.Core /// /// callback to create a message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public void Send(Destination destination, IMessageCreator messageCreator) { @@ -856,7 +879,7 @@ namespace Spring.Messaging.Ems.Core /// /// callback to create a message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public void Send(string destinationName, IMessageCreator messageCreator) { Execute(new SendDestinationCallback(this, destinationName, messageCreator), false); @@ -867,7 +890,7 @@ namespace Spring.Messaging.Ems.Core /// /// the object to convert to a message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public void ConvertAndSend(object message) { CheckDefaultDestination(); @@ -888,7 +911,7 @@ namespace Spring.Messaging.Ems.Core /// /// the object to convert to a message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public void ConvertAndSend(Destination destination, object message) { CheckMessageConverter(); @@ -903,7 +926,7 @@ namespace Spring.Messaging.Ems.Core /// /// the object to convert to a message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public void ConvertAndSend(string destinationName, object message) { Send(destinationName, new SimpleMessageCreator(this, message)); @@ -918,7 +941,7 @@ namespace Spring.Messaging.Ems.Core /// /// the callback to modify the message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public void ConvertAndSend(object message, IMessagePostProcessor postProcessor) { CheckDefaultDestination(); @@ -942,7 +965,7 @@ namespace Spring.Messaging.Ems.Core /// /// the callback to modify the message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public void ConvertAndSend(Destination destination, object message, IMessagePostProcessor postProcessor) { CheckMessageConverter(); @@ -961,7 +984,7 @@ namespace Spring.Messaging.Ems.Core /// /// the callback to modify the message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public void ConvertAndSend(string destinationName, object message, IMessagePostProcessor postProcessor) { CheckMessageConverter(); @@ -975,7 +998,7 @@ namespace Spring.Messaging.Ems.Core /// /// the object to convert to a message /// the callback to modify the message - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public void ConvertAndSendWithDelegate(object message, MessagePostProcessorDelegate postProcessor) { //Execute(new SendDestinationCallback(this, destination, messageCreatorDelegate), false); @@ -998,7 +1021,7 @@ namespace Spring.Messaging.Ems.Core /// the destination to send this message to /// the object to convert to a message /// the callback to modify the message - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public void ConvertAndSendWithDelegate(Destination destination, object message, MessagePostProcessorDelegate postProcessor) { @@ -1015,7 +1038,7 @@ namespace Spring.Messaging.Ems.Core /// (to be resolved to an actual destination by a DestinationResolver) /// the object to convert to a message. /// the callback to modify the message - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public void ConvertAndSendWithDelegate(string destinationName, object message, MessagePostProcessorDelegate postProcessor) { @@ -1032,7 +1055,7 @@ namespace Spring.Messaging.Ems.Core /// /// the message received by the consumer, or null if the timeout expires /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public Message Receive() { CheckDefaultDestination(); @@ -1055,7 +1078,7 @@ namespace Spring.Messaging.Ems.Core /// /// the message received by the consumer, or null if the timeout expires /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public Message Receive(Destination destination) { return Execute(new ReceiveCallback(this, destination)) as Message; @@ -1072,7 +1095,7 @@ namespace Spring.Messaging.Ems.Core /// /// the message received by the consumer, or null if the timeout expires /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public Message Receive(string destinationName) { return Execute(new ReceiveCallback(this, destinationName)) as Message; @@ -1089,7 +1112,7 @@ namespace Spring.Messaging.Ems.Core /// /// the message received by the consumer, or null if the timeout expires /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public Message ReceiveSelected(string messageSelector) { CheckDefaultDestination(); @@ -1115,7 +1138,7 @@ namespace Spring.Messaging.Ems.Core /// /// the message received by the consumer, or null if the timeout expires /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public Message ReceiveSelected(Destination destination, string messageSelector) { return Execute(new ReceiveSelectedCallback(this, destination, messageSelector), true) as Message; @@ -1134,7 +1157,7 @@ namespace Spring.Messaging.Ems.Core /// /// the message received by the consumer, or null if the timeout expires /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public Message ReceiveSelected(string destinationName, string messageSelector) { return Execute(new ReceiveSelectedCallback(this, destinationName, messageSelector), true) as Message; @@ -1208,7 +1231,7 @@ namespace Spring.Messaging.Ems.Core /// /// the message produced for the consumer or null if the timeout expires. /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public object ReceiveAndConvert() { CheckMessageConverter(); @@ -1225,7 +1248,7 @@ namespace Spring.Messaging.Ems.Core /// /// the message produced for the consumer or null if the timeout expires. /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public object ReceiveAndConvert(Destination destination) { CheckMessageConverter(); @@ -1244,7 +1267,7 @@ namespace Spring.Messaging.Ems.Core /// /// the message produced for the consumer or null if the timeout expires. /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public object ReceiveAndConvert(string destinationName) { CheckMessageConverter(); @@ -1263,11 +1286,11 @@ namespace Spring.Messaging.Ems.Core /// /// the message produced for the consumer or null if the timeout expires. /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public object ReceiveSelectedAndConvert(string messageSelector) { CheckMessageConverter(); - return DoConvertFromMessage(ReceiveSelected(messageSelector)); ; + return DoConvertFromMessage(ReceiveSelected(messageSelector)); } /// Receive a message synchronously from the specified destination, but only @@ -1283,7 +1306,7 @@ namespace Spring.Messaging.Ems.Core /// /// the message produced for the consumer or null if the timeout expires. /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public object ReceiveSelectedAndConvert(Destination destination, string messageSelector) { CheckMessageConverter(); @@ -1304,15 +1327,243 @@ namespace Spring.Messaging.Ems.Core /// /// the message produced for the consumer or null if the timeout expires. /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API public object ReceiveSelectedAndConvert(string destinationName, string messageSelector) { CheckMessageConverter(); return DoConvertFromMessage(ReceiveSelected(destinationName, messageSelector)); } + + /// + /// Browses messages in the default EMS queue. The callback gives access to the EMS + /// Session and QueueBrowser in order to browse the queue and react to the contents. + /// + /// The action callback object that exposes the session/browser pair. + /// the result object from working with the session + /// If there is any problem accessing the EMS API + public object Browse(IBrowserCallback action) + { + AssertUtils.ArgumentNotNull(action, "action"); + return BrowseWithDelegate(action.DoInEms); + } + + /// + /// Browses messages in a EMS queue. The callback gives access to the EMS Session + /// and QueueBrowser in order to browse the queue and react to the contents. + /// + /// The queue to browse. + /// The action callback object that exposes the session/browser pair. + /// the result object from working with the session + /// If there is any problem accessing the EMS API + public object Browse(Queue queue, IBrowserCallback action) + { + AssertUtils.ArgumentNotNull(action, "action"); + return BrowseSelectedWithDelegate(queue, null, action.DoInEms); + } + + /// + /// Browses messages in a EMS queue. The callback gives access to the EMS Session + /// and QueueBrowser in order to browse the queue and react to the contents. + /// + /// Name of the queue to browse, + /// (to be resolved to an actual destination by a DestinationResolver) + /// The action callback object that exposes the session/browser pair. + /// If there is any problem accessing the EMS API + public object Browse(string queueName, IBrowserCallback action) + { + AssertUtils.ArgumentNotNull(action, "action"); + return BrowseSelectedWithDelegate(queueName, null, action.DoInEms); + } + + /// + /// Browses messages in a EMS queue. The callback gives access to the EMS Session + /// and QueueBrowser in order to browse the queue and react to the contents. + /// + /// The EMS message selector expression (or null if none). + /// The action callback object that exposes the session/browser pair. + /// If there is any problem accessing the EMS API + public object BrowseSelected(string messageSelector, IBrowserCallback action) + { + AssertUtils.ArgumentNotNull(action, "action"); + return BrowseSelectedWithDelegate(messageSelector, action.DoInEms); + } + + /// + /// Browses messages in a EMS queue. The callback gives access to the EMS Session + /// and QueueBrowser in order to browse the queue and react to the contents. + /// + /// The queue to browse. + /// The EMS message selector expression (or null if none). + /// The action callback object that exposes the session/browser pair. + /// + /// If there is any problem accessing the EMS API + public object BrowseSelected(Queue queue, string messageSelector, IBrowserCallback action) + { + AssertUtils.ArgumentNotNull(action, "action"); + return BrowseSelectedWithDelegate(queue, messageSelector, action.DoInEms); + } + + + /// + /// Browses messages in a EMS queue. The callback gives access to the EMS Session + /// and QueueBrowser in order to browse the queue and react to the contents. + /// + /// Name of the queue to browse, + /// (to be resolved to an actual destination by a DestinationResolver) + /// The EMS message selector expression (or null if none). + /// The action callback object that exposes the session/browser pair. + /// + /// If there is any problem accessing the EMS API + public object BrowseSelected(string queueName, string messageSelector, IBrowserCallback action) + { + AssertUtils.ArgumentNotNull(action, "action"); + return BrowseSelectedWithDelegate(queueName, messageSelector, action.DoInEms); + } + + + + /// + /// Browses messages in the default EMS queue. The callback gives access to the EMS + /// Session and QueueBrowser in order to browse the queue and react to the contents. + /// + /// The action callback delegate that exposes the session/browser pair. + /// the result object from working with the session + public object BrowseWithDelegate(BrowserDelegate action) + { + if (DefaultDestinationName != null) + { + return BrowseSelectedWithDelegate(DefaultDestinationName, action); + } + else + { + Destination destination = DefaultDestination; + if (!(destination is Queue)) + { + throw new InvalidOperationException("defaultDestination does not correspond to a Queue. Check configuration of NmsTemplate."); + } + return BrowseWithDelegate((Queue)destination, action); + } + } + + /// + /// Browses messages in a EMS queue. The callback gives access to the EMS Session + /// and QueueBrowser in order to browse the queue and react to the contents. + /// + /// The queue to browse. + /// The action callback delegate that exposes the session/browser pair. + /// the result object from working with the session + public object BrowseWithDelegate(Queue queue, BrowserDelegate action) + { + return BrowseSelectedWithDelegate(queue, null, action); + } + + /// + /// Browses messages in a EMS queue. The callback gives access to the EMS Session + /// and QueueBrowser in order to browse the queue and react to the contents. + /// + /// Name of the queue to browse, + /// (to be resolved to an actual destination by a DestinationResolver) + /// The action callback delegate that exposes the session/browser pair. + /// If there is any problem accessing the EMS API + public object BrowseWithDelegate(string queueName, BrowserDelegate action) + { + return BrowseSelectedWithDelegate(queueName, null, action); + } + + /// + /// Browses messages in a EMS queue. The callback gives access to the EMS Session + /// and QueueBrowser in order to browse the queue and react to the contents. + /// + /// The EMS message selector expression (or null if none). + /// The action callback delegate that exposes the session/browser pair. + /// If there is any problem accessing the EMS API + public object BrowseSelectedWithDelegate(string messageSelector, BrowserDelegate action) + { + if (DefaultDestinationName != null) + { + return BrowseSelectedWithDelegate(DefaultDestinationName, messageSelector, action); + } + else + { + Destination destination = DefaultDestination; + if (!(destination is Queue)) + { + throw new InvalidOperationException("defaultDestination does not correspond to a Queue. Check configuration of NmsTemplate."); + } + return BrowseSelectedWithDelegate((Queue)destination, messageSelector, action); + } + } + + /// + /// Browses messages in a EMS queue. The callback gives access to the EMS Session + /// and QueueBrowser in order to browse the queue and react to the contents. + /// + /// The queue to browse. + /// The EMS message selector expression (or null if none). + /// The action callback delegate that exposes the session/browser pair. + /// + /// If there is any problem accessing the EMS API + public object BrowseSelectedWithDelegate(Queue queue, string messageSelector, BrowserDelegate action) + { + AssertUtils.ArgumentNotNull(action, "action"); + return Execute(delegate(Session session) + { + QueueBrowser browser = CreateBrowser(session, queue, messageSelector); + try + { + return action(session, browser); + } + finally + { + EmsUtils.CloseQueueBrowser(browser); + } + }, true); + } + + /// + /// Browses messages in a EMS queue. The callback gives access to the EMS Session + /// and QueueBrowser in order to browse the queue and react to the contents. + /// + /// Name of the queue to browse, + /// (to be resolved to an actual destination by a DestinationResolver) + /// The EMS message selector expression (or null if none). + /// The action callback delegate that exposes the session/browser pair. + /// + /// If there is any problem accessing the EMS API + public object BrowseSelectedWithDelegate(string queueName, string messageSelector, BrowserDelegate action) + { + AssertUtils.ArgumentNotNull(action, "action"); + return Execute(delegate(Session session) + { + Queue queue = (Queue)DestinationResolver.ResolveDestinationName(session, queueName, false); + QueueBrowser browser = CreateBrowser(session, queue, messageSelector); + try + { + return action(session, browser); + } + finally + { + EmsUtils.CloseQueueBrowser(browser); + } + }, true); + } + #endregion + /// + /// Creates the queue browser. + /// + /// The session. + /// The queue. + /// The selector. + /// A new queue browser + protected virtual QueueBrowser CreateBrowser(Session session, Queue queue, string selector) + { + return session.CreateBrowser(queue, selector); + } + + #region Supporting Internal Classes /// diff --git a/src/Spring/Spring.Messaging.Ems/Messaging/Ems/Core/IBrowserCallback.cs b/src/Spring/Spring.Messaging.Ems/Messaging/Ems/Core/IBrowserCallback.cs new file mode 100644 index 00000000..7f7b44b2 --- /dev/null +++ b/src/Spring/Spring.Messaging.Ems/Messaging/Ems/Core/IBrowserCallback.cs @@ -0,0 +1,47 @@ + + +#region License + +/* + * Copyright 2002-2008 the original author or authors. + * + * Licensed 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. + */ + +#endregion + +using TIBCO.EMS; + +namespace Spring.Messaging.Ems.Core +{ + /// + /// Callback for browsing the messages in an EMS queue. + /// + /// + /// To be used with EmsTemplate's callback methods that take a IBrowserCallback argument + /// + /// Juergen Hoeller + /// Mark Pollack (.NET) + public interface IBrowserCallback + { + + /// + /// Perform operations on the given Session and QueueBrowser + /// + /// The session. + /// The browser. + /// The object from working with the Session and QueueBrowser, may be null + /// If there is any problem when accessing EMS API + object DoInEms(Session session, QueueBrowser browser); + } +} \ No newline at end of file diff --git a/src/Spring/Spring.Messaging.Ems/Messaging/Ems/Core/IEmsOperations.cs b/src/Spring/Spring.Messaging.Ems/Messaging/Ems/Core/IEmsOperations.cs index 18d57c94..d4a23a45 100644 --- a/src/Spring/Spring.Messaging.Ems/Messaging/Ems/Core/IEmsOperations.cs +++ b/src/Spring/Spring.Messaging.Ems/Messaging/Ems/Core/IEmsOperations.cs @@ -45,7 +45,7 @@ namespace Spring.Messaging.Ems.Core /// delegate that exposes the session /// the result object from working with the session /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API object Execute(SessionDelegate del); /// Execute the action specified by the given action object within @@ -55,7 +55,7 @@ namespace Spring.Messaging.Ems.Core /// /// the result object from working with the session /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API object Execute(ISessionCallback action); /// Send a message to a EMS destination. The callback gives access to @@ -77,7 +77,7 @@ namespace Spring.Messaging.Ems.Core /// /// the result object from working with the session /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API object Execute(ProducerDelegate del); @@ -90,7 +90,7 @@ namespace Spring.Messaging.Ems.Core /// /// callback to create a message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API void Send(IMessageCreator messageCreator); /// Send a message to the specified destination. @@ -100,7 +100,7 @@ namespace Spring.Messaging.Ems.Core /// /// callback to create a message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API void Send(Destination destination, IMessageCreator messageCreator); /// Send a message to the specified destination. @@ -111,7 +111,7 @@ namespace Spring.Messaging.Ems.Core /// /// callback to create a message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API void Send(string destinationName, IMessageCreator messageCreator); //------------------------------------------------------------------------- @@ -123,7 +123,7 @@ namespace Spring.Messaging.Ems.Core /// /// delegate callback to create a message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API void SendWithDelegate(MessageCreatorDelegate messageCreatorDelegate); /// Send a message to the specified destination. @@ -133,7 +133,7 @@ namespace Spring.Messaging.Ems.Core /// /// delegate callback to create a message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API void SendWithDelegate(Destination destination, MessageCreatorDelegate messageCreatorDelegate); /// Send a message to the specified destination. @@ -144,7 +144,7 @@ namespace Spring.Messaging.Ems.Core /// /// delegate callback to create a message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API void SendWithDelegate(string destinationName, MessageCreatorDelegate messageCreatorDelegate); //------------------------------------------------------------------------- @@ -157,7 +157,7 @@ namespace Spring.Messaging.Ems.Core /// /// the object to convert to a message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API void ConvertAndSend(object message); /// Send the given object to the specified destination, converting the object @@ -167,7 +167,7 @@ namespace Spring.Messaging.Ems.Core /// /// the object to convert to a message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API void ConvertAndSend(Destination destination, object message); /// Send the given object to the specified destination, converting the object @@ -178,7 +178,7 @@ namespace Spring.Messaging.Ems.Core /// /// the object to convert to a message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API void ConvertAndSend(string destinationName, object message); /// Send the given object to the default destination, converting the object @@ -190,7 +190,7 @@ namespace Spring.Messaging.Ems.Core /// /// the callback to modify the message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API void ConvertAndSend(object message, IMessagePostProcessor postProcessor); /// Send the given object to the specified destination, converting the object @@ -203,7 +203,7 @@ namespace Spring.Messaging.Ems.Core /// /// the callback to modify the message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API void ConvertAndSend(Destination destination, object message, IMessagePostProcessor postProcessor); /// Send the given object to the specified destination, converting the object @@ -217,7 +217,7 @@ namespace Spring.Messaging.Ems.Core /// /// the callback to modify the message /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API void ConvertAndSend(string destinationName, object message, IMessagePostProcessor postProcessor); @@ -229,7 +229,7 @@ namespace Spring.Messaging.Ems.Core /// /// the object to convert to a message /// the callback to modify the message - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API void ConvertAndSendWithDelegate(object message, MessagePostProcessorDelegate postProcessor); /// @@ -240,7 +240,7 @@ namespace Spring.Messaging.Ems.Core /// the destination to send this message to /// the object to convert to a message /// the callback to modify the message - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API void ConvertAndSendWithDelegate(Destination destination, object message, MessagePostProcessorDelegate postProcessor); /// @@ -252,7 +252,7 @@ namespace Spring.Messaging.Ems.Core /// (to be resolved to an actual destination by a DestinationResolver) /// the object to convert to a message. /// the callback to modify the message - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API void ConvertAndSendWithDelegate(string destinationName, object message, MessagePostProcessorDelegate postProcessor); @@ -268,7 +268,7 @@ namespace Spring.Messaging.Ems.Core /// /// the message received by the consumer, or null if the timeout expires /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API Message Receive(); /// Receive a message synchronously from the specified destination, but only @@ -280,7 +280,7 @@ namespace Spring.Messaging.Ems.Core /// /// the message received by the consumer, or null if the timeout expires /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API Message Receive(Destination destination); /// Receive a message synchronously from the specified destination, but only @@ -293,7 +293,7 @@ namespace Spring.Messaging.Ems.Core /// /// the message received by the consumer, or null if the timeout expires /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API Message Receive(string destinationName); /// Receive a message synchronously from the default destination, but only @@ -307,7 +307,7 @@ namespace Spring.Messaging.Ems.Core /// /// the message received by the consumer, or null if the timeout expires /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API Message ReceiveSelected(string messageSelector); /// Receive a message synchronously from the specified destination, but only @@ -322,7 +322,7 @@ namespace Spring.Messaging.Ems.Core /// /// the message received by the consumer, or null if the timeout expires /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API Message ReceiveSelected(Destination destination, string messageSelector); /// Receive a message synchronously from the specified destination, but only @@ -338,7 +338,7 @@ namespace Spring.Messaging.Ems.Core /// /// the message received by the consumer, or null if the timeout expires /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API Message ReceiveSelected(string destinationName, string messageSelector); @@ -355,7 +355,7 @@ namespace Spring.Messaging.Ems.Core /// /// the message produced for the consumer or null if the timeout expires. /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API object ReceiveAndConvert(); /// Receive a message synchronously from the specified destination, but only @@ -368,7 +368,7 @@ namespace Spring.Messaging.Ems.Core /// /// the message produced for the consumer or null if the timeout expires. /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API object ReceiveAndConvert(Destination destination); /// Receive a message synchronously from the specified destination, but only @@ -382,7 +382,7 @@ namespace Spring.Messaging.Ems.Core /// /// the message produced for the consumer or null if the timeout expires. /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API object ReceiveAndConvert(string destinationName); /// Receive a message synchronously from the default destination, but only @@ -397,7 +397,7 @@ namespace Spring.Messaging.Ems.Core /// /// the message produced for the consumer or null if the timeout expires. /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API object ReceiveSelectedAndConvert(string messageSelector); /// Receive a message synchronously from the specified destination, but only @@ -413,7 +413,7 @@ namespace Spring.Messaging.Ems.Core /// /// the message produced for the consumer or null if the timeout expires. /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API object ReceiveSelectedAndConvert(Destination destination, string messageSelector); /// Receive a message synchronously from the specified destination, but only @@ -430,7 +430,134 @@ namespace Spring.Messaging.Ems.Core /// /// the message produced for the consumer or null if the timeout expires. /// - /// EMSException if there is any problem + /// If there is any problem accessing the EMS API object ReceiveSelectedAndConvert(string destinationName, string messageSelector); + + + /// + /// Browses messages in the default EMS queue. The callback gives access to the EMS + /// Session and QueueBrowser in order to browse the queue and react to the contents. + /// + /// The action callback object that exposes the session/browser pair. + /// the result object from working with the session + /// If there is any problem accessing the EMS API + object Browse(IBrowserCallback action); + + + /// + /// Browses messages in a EMS queue. The callback gives access to the EMS Session + /// and QueueBrowser in order to browse the queue and react to the contents. + /// + /// The queue to browse. + /// The action callback object that exposes the session/browser pair. + /// the result object from working with the session + /// If there is any problem accessing the EMS API + object Browse(Queue queue, IBrowserCallback action); + + /// + /// Browses messages in a EMS queue. The callback gives access to the EMS Session + /// and QueueBrowser in order to browse the queue and react to the contents. + /// + /// Name of the queue to browse, + /// (to be resolved to an actual destination by a DestinationResolver) + /// The action callback object that exposes the session/browser pair. + /// If there is any problem accessing the EMS API + object Browse(string queueName, IBrowserCallback action); + + + /// + /// Browses messages in a EMS queue. The callback gives access to the EMS Session + /// and QueueBrowser in order to browse the queue and react to the contents. + /// + /// The EMS message selector expression (or null if none). + /// The action callback object that exposes the session/browser pair. + /// If there is any problem accessing the EMS API + object BrowseSelected(string messageSelector, IBrowserCallback action); + + + /// + /// Browses messages in a EMS queue. The callback gives access to the EMS Session + /// and QueueBrowser in order to browse the queue and react to the contents. + /// + /// The queue to browse. + /// The EMS message selector expression (or null if none). + /// The action callback object that exposes the session/browser pair. + /// + /// If there is any problem accessing the EMS API + object BrowseSelected(Queue queue, string messageSelector, IBrowserCallback action); + + /// + /// Browses messages in a EMS queue. The callback gives access to the EMS Session + /// and QueueBrowser in order to browse the queue and react to the contents. + /// + /// Name of the queue to browse, + /// (to be resolved to an actual destination by a DestinationResolver) + /// The EMS message selector expression (or null if none). + /// The action callback object that exposes the session/browser pair. + /// + /// If there is any problem accessing the EMS API + object BrowseSelected(string queueName, string messageSelector, IBrowserCallback action); + + /// + /// Browses messages in the default EMS queue. The callback gives access to the EMS + /// Session and QueueBrowser in order to browse the queue and react to the contents. + /// + /// The action callback delegate that exposes the session/browser pair. + /// the result object from working with the session + object BrowseWithDelegate(BrowserDelegate action); + + /// + /// Browses messages in a EMS queue. The callback gives access to the EMS Session + /// and QueueBrowser in order to browse the queue and react to the contents. + /// + /// The queue to browse. + /// The action callback delegate that exposes the session/browser pair. + /// the result object from working with the session + object BrowseWithDelegate(Queue queue, BrowserDelegate action); + + /// + /// Browses messages in a EMS queue. The callback gives access to the EMS Session + /// and QueueBrowser in order to browse the queue and react to the contents. + /// + /// Name of the queue to browse, + /// (to be resolved to an actual destination by a DestinationResolver) + /// The action callback delegate that exposes the session/browser pair. + /// If there is any problem accessing the EMS API + object BrowseWithDelegate(string queueName, BrowserDelegate action); + + + /// + /// Browses messages in a EMS queue. The callback gives access to the EMS Session + /// and QueueBrowser in order to browse the queue and react to the contents. + /// + /// The EMS message selector expression (or null if none). + /// The action callback delegate that exposes the session/browser pair. + /// If there is any problem accessing the EMS API + object BrowseSelectedWithDelegate(string messageSelector, BrowserDelegate action); + + /// + /// Browses messages in a EMS queue. The callback gives access to the EMS Session + /// and QueueBrowser in order to browse the queue and react to the contents. + /// + /// The queue to browse. + /// The EMS message selector expression (or null if none). + /// The action callback delegate that exposes the session/browser pair. + /// + /// If there is any problem accessing the EMS API + object BrowseSelectedWithDelegate(Queue queue, string messageSelector, BrowserDelegate action); + + + /// + /// Browses messages in a EMS queue. The callback gives access to the EMS Session + /// and QueueBrowser in order to browse the queue and react to the contents. + /// + /// Name of the queue to browse, + /// (to be resolved to an actual destination by a DestinationResolver) + /// The EMS message selector expression (or null if none). + /// The action callback delegate that exposes the session/browser pair. + /// + /// If there is any problem accessing the EMS API + object BrowseSelectedWithDelegate(string queueName, string messageSelector, BrowserDelegate action); + } } diff --git a/src/Spring/Spring.Messaging.Ems/Messaging/Ems/Support/EmsUtils.cs b/src/Spring/Spring.Messaging.Ems/Messaging/Ems/Support/EmsUtils.cs index 7ea6e203..a123096c 100644 --- a/src/Spring/Spring.Messaging.Ems/Messaging/Ems/Support/EmsUtils.cs +++ b/src/Spring/Spring.Messaging.Ems/Messaging/Ems/Support/EmsUtils.cs @@ -238,6 +238,27 @@ namespace Spring.Messaging.Ems.Support // // Ignore -> can only happen in case of a JTA transaction. // } } - + + /// + /// Closes the given queue browser and ignore any thrown exception. + /// This is useful for typical finally blocks in manual EMS code. + /// + /// The queue browser to close (may be null. + public static void CloseQueueBrowser(QueueBrowser browser) + { + if (browser != null) + { + try + { + browser.Close(); + } catch (EMSException ex) + { + logger.Debug("Could not close EMS QueueBrowser", ex); + } catch (Exception ex) + { + logger.Debug("Unexpected exception on closing EMS QueueBrowser", ex); + } + } + } } }