7a23d2bda45e7353334de9bf940f6d236c03ff35
[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, 2008 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 by LShift Ltd., Cohesive Financial Technologies
42 //   LLC., and Rabbit Technologies Ltd. are Copyright (C) 2007, 2008
43 //   LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit
44 //   Technologies Ltd.;
45 //
46 //   All Rights Reserved.
47 //
48 //   Contributor(s): ______________________________________.
49 //
50 //---------------------------------------------------------------------------
51 using System;
52
53 namespace RabbitMQ.Client
54 {
55     ///<summary>Information about the reason why a particular model,
56     ///session, or connection was destroyed.</summary>
57     ///<remarks>
58     ///The ClassId and Initiator properties should be
59     ///used to determine the originator of the shutdown event.
60     ///</remarks>
61     public class ShutdownEventArgs : EventArgs
62     {
63         private readonly ShutdownInitiator m_initiator;
64         private readonly ushort m_replyCode;
65         private readonly string m_replyText;
66         private readonly ushort m_classId;
67         private readonly ushort m_methodId;
68         private readonly object m_cause;
69
70         ///<summary>Returns the source of the shutdown event: either
71         ///the application, the library, or the remote peer.</summary>
72         public ShutdownInitiator Initiator { get { return m_initiator; } }
73
74         ///<summary>One of the standardised AMQP reason codes. See
75         ///RabbitMQ.Client.Framing.*.Constants.</summary>
76         public ushort ReplyCode { get { return m_replyCode; } }
77
78         ///<summary>Informative human-readable reason text.</summary>
79         public string ReplyText { get { return m_replyText; } }
80
81         ///<summary>AMQP content-class ID, or 0 if none.</summary>
82         public ushort ClassId { get { return m_classId; } }
83
84         ///<summary>AMQP method ID within a content-class, or 0 if none.</summary>
85         public ushort MethodId { get { return m_methodId; } }
86
87         ///<summary>Object causing the shutdown, or null if none.</summary>
88         public object Cause { get { return m_cause; } }
89
90         ///<summary>Construct a ShutdownEventArgs with the given
91         ///parameters, 0 for ClassId and MethodId, and a null
92         ///Cause.</summary>
93         public ShutdownEventArgs(ShutdownInitiator initiator,
94                                  ushort replyCode,
95                                  string replyText)
96             : this(initiator,
97                 replyCode,
98                 replyText,
99                 null)
100         { }
101
102         ///<summary>Construct a ShutdownEventArgs with the given
103         ///parameters and 0 for ClassId and MethodId.</summary>
104         public ShutdownEventArgs(ShutdownInitiator initiator,
105                                  ushort replyCode,
106                                  string replyText,
107                  object cause)
108             : this(initiator,
109                 replyCode,
110                 replyText,
111                 0,
112                 0,
113                 cause)
114         { }
115
116         ///<summary>Construct a ShutdownEventArgs with the given
117         ///parameters and a null cause.</summary>
118         public ShutdownEventArgs(ShutdownInitiator initiator,
119                                  ushort replyCode,
120                                  string replyText,
121                                  ushort classId,
122                                  ushort methodId)
123             : this(initiator,
124                     replyCode,
125                     replyText,
126                     classId,
127                     methodId,
128                     null)
129         { }
130
131         ///<summary>Construct a ShutdownEventArgs with the given
132         ///parameters.</summary>
133         public ShutdownEventArgs(ShutdownInitiator initiator,
134                                  ushort replyCode,
135                                  string replyText,
136                                  ushort classId,
137                                  ushort methodId,
138                                  object cause)
139         {
140             m_initiator = initiator;
141             m_replyCode = replyCode;
142             m_replyText = replyText;
143             m_classId = classId;
144             m_methodId = methodId;
145             m_cause = cause;
146         }
147
148         ///<summary>Override ToString to be useful for debugging.</summary>
149         public override string ToString()
150         {
151             return "AMQP close-reason, initiated by " + m_initiator +
152                 ", code=" + m_replyCode +
153                 ", text=\"" + m_replyText + "\"" +
154                 ", classId=" + m_classId +
155                 ", methodId=" + m_methodId +
156                 ", cause=" + m_cause;
157         }
158     }
159 }