jezell / iserviceoriented

This URL has Read+Write access

iserviceoriented / IServiceOriented.ServiceBus / Dispatcher.cs
100644 120 lines (101 sloc) 2.722 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
using System.Runtime.Serialization;
 
 
namespace IServiceOriented.ServiceBus
{
    /// <summary>
    /// Base class for all service bus dispatchers.
    /// </summary>
    /// <remarks>
    /// Dispatchers are responsible for delivering messages to subscription endpoints.
    /// </remarks>
[Serializable]
[DataContract]
    public abstract class Dispatcher : IDisposable
    {
        protected Dispatcher()
        {
        }
        protected Dispatcher(SubscriptionEndpoint endpoint)
        {
            _endpoint = endpoint;
        }
[NonSerialized]
        ServiceBusRuntime _runtime;
        /// <summary>
        /// Gets the service bus instance associated with this dispatcher.
        /// </summary>
        public ServiceBusRuntime Runtime
        {
            get
            {
                return _runtime;
            }
            internal set
            {
                _runtime = value;
            }
        }
 
[NonSerialized]
        SubscriptionEndpoint _endpoint;
        /// <summary>
        /// Gets the subscription endpoint associated with this dispatcher.
        /// </summary>
        public SubscriptionEndpoint Endpoint
        {
            get
            {
                return _endpoint;
            }
            internal set
            {
                _endpoint = value;
            }
        }
 
        internal void StartInternal()
        {
            OnStart();
 
            Started = true;
        }
 
        internal void StopInternal()
        {
            OnStop();
            Started = false;
        }
 
        protected virtual void OnStart()
        {
        }
 
        protected virtual void OnStop()
        {
        }
 
        public bool Started
        {
            get;
            private set;
        }
 
        /// <summary>
        /// Handles sending a message to a subscriber endpoint.
        /// </summary>
        public abstract void Dispatch(MessageDelivery messageDelivery);
 
        /// <summary>
        /// Dispose any resources held by this dispatcher.
        /// </summary>
        /// <param name="disposing">Indicates whether this method is being called as a result of a direct call to Dispose (true) or by the object's finalizer (false).</param>
        protected virtual void Dispose(bool disposing)
        {
            
        }
        #region IDisposable Members
 
        public void Dispose()
        {
            Dispose(true);
 
            GC.SuppressFinalize(this);
        }
 
        #endregion
 
        ~Dispatcher()
        {
            Dispose(false);
        }
    }
 
}