2009-05-21 Michael Barker <mike@middlesoft.co.uk>
[mono.git] / mcs / class / RabbitMQ.Client / src / client / api / ShutdownEventArgs.cs
1 // This source code is dual-licensed under the Apache License, version
2 // 2.0, and the Mozilla Public License, version 1.1.
3 //
4 // The APL v2.0:
5 //
6 //---------------------------------------------------------------------------
7 //   Copyright (C) 2007-2009 LShift Ltd., Cohesive Financial
8 //   Technologies LLC., and Rabbit Technologies Ltd.
9 //
10 //   Licensed under the Apache License, Version 2.0 (the "License");
11 //   you may not use this file except in compliance with the License.
12 //   You may obtain a copy of the License at
13 //
14 //       http://www.apache.org/licenses/LICENSE-2.0
15 //
16 //   Unless required by applicable law or agreed to in writing, software
17 //   distributed under the License is distributed on an "AS IS" BASIS,
18 //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 //   See the License for the specific language governing permissions and
20 //   limitations under the License.
21 //---------------------------------------------------------------------------
22 //
23 // The MPL v1.1:
24 //
25 //---------------------------------------------------------------------------
26 //   The contents of this file are subject to the Mozilla Public License
27 //   Version 1.1 (the "License"); you may not use this file except in
28 //   compliance with the License. You may obtain a copy of the License at
29 //   http://www.rabbitmq.com/mpl.html
30 //
31 //   Software distributed under the License is distributed on an "AS IS"
32 //   basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
33 //   License for the specific language governing rights and limitations
34 //   under the License.
35 //
36 //   The Original Code is The RabbitMQ .NET Client.
37 //
38 //   The Initial Developers of the Original Code are LShift Ltd,
39 //   Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd.
40 //
41 //   Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd,
42 //   Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd
43 //   are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial
44 //   Technologies LLC, and Rabbit Technologies Ltd.
45 //
46 //   Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift
47 //   Ltd. Portions created by Cohesive Financial Technologies LLC are
48 //   Copyright (C) 2007-2009 Cohesive Financial Technologies
49 //   LLC. Portions created by Rabbit Technologies Ltd are Copyright
50 //   (C) 2007-2009 Rabbit Technologies Ltd.
51 //
52 //   All Rights Reserved.
53 //
54 //   Contributor(s): ______________________________________.
55 //
56 //---------------------------------------------------------------------------
57 using System;
58
59 namespace RabbitMQ.Client
60 {
61     ///<summary>Information about the reason why a particular model,
62     ///session, or connection was destroyed.</summary>
63     ///<remarks>
64     ///The ClassId and Initiator properties should be
65     ///used to determine the originator of the shutdown event.
66     ///</remarks>
67     public class ShutdownEventArgs : EventArgs
68     {
69         private readonly ShutdownInitiator m_initiator;
70         private readonly ushort m_replyCode;
71         private readonly string m_replyText;
72         private readonly ushort m_classId;
73         private readonly ushort m_methodId;
74         private readonly object m_cause;
75
76         ///<summary>Returns the source of the shutdown event: either
77         ///the application, the library, or the remote peer.</summary>
78         public ShutdownInitiator Initiator { get { return m_initiator; } }
79
80         ///<summary>One of the standardised AMQP reason codes. See
81         ///RabbitMQ.Client.Framing.*.Constants.</summary>
82         public ushort ReplyCode { get { return m_replyCode; } }
83
84         ///<summary>Informative human-readable reason text.</summary>
85         public string ReplyText { get { return m_replyText; } }
86
87         ///<summary>AMQP content-class ID, or 0 if none.</summary>
88         public ushort ClassId { get { return m_classId; } }
89
90         ///<summary>AMQP method ID within a content-class, or 0 if none.</summary>
91         public ushort MethodId { get { return m_methodId; } }
92
93         ///<summary>Object causing the shutdown, or null if none.</summary>
94         public object Cause { get { return m_cause; } }
95
96         ///<summary>Construct a ShutdownEventArgs with the given
97         ///parameters, 0 for ClassId and MethodId, and a null
98         ///Cause.</summary>
99         public ShutdownEventArgs(ShutdownInitiator initiator,
100                                  ushort replyCode,
101                                  string replyText)
102             : this(initiator,
103                 replyCode,
104                 replyText,
105                 null)
106         { }
107
108         ///<summary>Construct a ShutdownEventArgs with the given
109         ///parameters and 0 for ClassId and MethodId.</summary>
110         public ShutdownEventArgs(ShutdownInitiator initiator,
111                                  ushort replyCode,
112                                  string replyText,
113                  object cause)
114             : this(initiator,
115                 replyCode,
116                 replyText,
117                 0,
118                 0,
119                 cause)
120         { }
121
122         ///<summary>Construct a ShutdownEventArgs with the given
123         ///parameters and a null cause.</summary>
124         public ShutdownEventArgs(ShutdownInitiator initiator,
125                                  ushort replyCode,
126                                  string replyText,
127                                  ushort classId,
128                                  ushort methodId)
129             : this(initiator,
130                     replyCode,
131                     replyText,
132                     classId,
133                     methodId,
134                     null)
135         { }
136
137         ///<summary>Construct a ShutdownEventArgs with the given
138         ///parameters.</summary>
139         public ShutdownEventArgs(ShutdownInitiator initiator,
140                                  ushort replyCode,
141                                  string replyText,
142                                  ushort classId,
143                                  ushort methodId,
144                                  object cause)
145         {
146             m_initiator = initiator;
147             m_replyCode = replyCode;
148             m_replyText = replyText;
149             m_classId = classId;
150             m_methodId = methodId;
151             m_cause = cause;
152         }
153
154         ///<summary>Override ToString to be useful for debugging.</summary>
155         public override string ToString()
156         {
157             return "AMQP close-reason, initiated by " + m_initiator +
158                 ", code=" + m_replyCode +
159                 ", text=\"" + m_replyText + "\"" +
160                 ", classId=" + m_classId +
161                 ", methodId=" + m_methodId +
162                 ", cause=" + m_cause;
163         }
164     }
165 }