AbstractSendToQueueExceptionHandler.cs :  » Inversion-of-Control-Dependency-Injection » Spring.net » Spring » Messaging » Listener » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Inversion of Control Dependency Injection » Spring.net 
Spring.net » Spring » Messaging » Listener » AbstractSendToQueueExceptionHandler.cs
using System;
using System.Collections;
using System.Messaging;
using Spring.Context;
using Spring.Messaging.Core;
using Spring.Objects.Factory;

namespace Spring.Messaging.Listener{
    /// <summary>
    /// Provides common functionality to exception handlers that will send the exceptional message to 
    /// another queue.
    /// </summary>
    /// <remarks>Allows for setting of MaxRetry limit and contains an internal dictionary to keep track
    /// of the Message Ids of messages.
    /// </remarks>
    /// <author>Mark Pollack</author>
    public abstract class AbstractSendToQueueExceptionHandler : IInitializingObject, IApplicationContextAware
    {
        private int maxRetry = 5;

        private IMessageQueueFactory messageQueueFactory;
        private string messageQueueObjectName;
        private IApplicationContext applicationContext;

        /// <summary>
        /// Synchronization object for access to messageMap protected variable
        /// </summary>
        protected object messageMapMonitor = new object();


        /// <summary>
        /// In-memory storage to keep track of Message Ids that have been already processed.
        /// </summary>
        protected IDictionary messageMap = new Hashtable();

        /// <summary>
        /// Gets or sets the maximum retry count to reattempt processing of a message that has thrown
        /// an exception
        /// </summary>
        /// <value>The max retry count.</value>
        public int MaxRetry
        {
            get { return maxRetry; }
            set { maxRetry = value; }
        }

        /// <summary>
        /// Gets or sets the message queue factory.
        /// </summary>
        /// <value>The message queue factory.</value>
        public IMessageQueueFactory MessageQueueFactory
        {
            get { return messageQueueFactory; }
            set { messageQueueFactory = value; }
        }

        /// <summary>
        /// Gets or sets the name of the message queue object to send the message that cannot be
        /// processed successfully after MaxRetry delivery attempts.
        /// </summary>
        /// <value>The name of the message queue object.</value>
        public string MessageQueueObjectName
        {
            get { return messageQueueObjectName; }
            set { messageQueueObjectName = value; }
        }

        #region IApplicationContextAware Members

        /// <summary>
        /// Gets or sets the <see cref="Spring.Context.IApplicationContext"/> that this
        /// object runs in.
        /// </summary>
        /// <remarks>
        /// <p>
        /// Normally this call will be used to initialize the object.
        /// </p>
        /// <p>
        /// Invoked after population of normal object properties but before an
        /// init callback such as
        /// <see cref="Spring.Objects.Factory.IInitializingObject"/>'s
        /// <see cref="Spring.Objects.Factory.IInitializingObject.AfterPropertiesSet"/>
        /// or a custom init-method. Invoked after the setting of any
        /// <see cref="Spring.Context.IResourceLoaderAware"/>'s
        /// <see cref="Spring.Context.IResourceLoaderAware.ResourceLoader"/>
        /// property.
        /// </p>
        /// </remarks>
        /// <exception cref="Spring.Context.ApplicationContextException">
        /// In the case of application context initialization errors.
        /// </exception>
        /// <exception cref="Spring.Objects.ObjectsException">
        /// If thrown by any application context methods.
        /// </exception>
        /// <exception cref="Spring.Objects.Factory.ObjectInitializationException"/>
        public IApplicationContext ApplicationContext
        {
            get { return applicationContext; }
            set { applicationContext = value; }
        }

        #endregion

        #region IInitializingObject Members

        /// <summary>
        /// Ensure that the MessageQueueObject name is set and creates a 
        /// <see cref="DefaultMessageQueueFactory"/> if no <see cref="IMessageQueueFactory"/>
        /// is specified.
        /// </summary>
        /// <remarks>Will attempt to create an instance of the DefaultMessageQueue to detect early
        /// any configuraiton errors.</remarks>
        /// <exception cref="System.Exception">
        /// In the event of misconfiguration (such as the failure to set a
        /// required property) or if initialization fails.
        /// </exception>
        public virtual void AfterPropertiesSet()
        {
            if (MessageQueueObjectName == null)
            {
                throw new ArgumentException("The DefaultMessageQueueObjectName property has not been set.");
            }
            if (messageQueueFactory == null)
            {
                DefaultMessageQueueFactory mqf = new DefaultMessageQueueFactory();
                mqf.ApplicationContext = applicationContext;
                messageQueueFactory = mqf;
            }
            //Create an instance so we can 'fail-fast' if there isn't an DefaultMessageQueue unde 
            MessageQueue mq = MessageQueueFactory.CreateMessageQueue(messageQueueObjectName);
        }

        #endregion
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.