01 /*
02 *
03 * Licensed to the Apache Software Foundation (ASF) under one
04 * or more contributor license agreements. See the NOTICE file
05 * distributed with this work for additional information
06 * regarding copyright ownership. The ASF licenses this file
07 * to you under the Apache License, Version 2.0 (the
08 * "License"); you may not use this file except in compliance
09 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 */
21 package org.apache.qpid.protocol;
22
23 import org.apache.qpid.framing.AMQMethodBody;
24
25 /**
26 * AMQMethodEvent encapsulates an AMQP method call, and the channel on which that method call occurred.
27 *
28 * <p/>Supplies the:
29 * <ul>
30 * <li>channel id</li>
31 * <li>protocol method</li>
32 * </ul>
33 *
34 * <p/>As the event contains the context in which it occurred, event listeners do not need to be statefull.
35 * to listeners. Events are often handled by {@link AMQMethodListener}s.
36 *
37 * <p/><table id="crc"><caption>CRC Card</caption>
38 * <tr><th> Responsibilities <th> Collaborations
39 * <tr><td> Encapsulate an AMQP method call and the channel as the context for the method call.
40 * </table>
41 */
42 public class AMQMethodEvent<M extends AMQMethodBody>
43 {
44 /** Holds the method call. */
45 private final M _method;
46
47 /** Holds the channel handle for the method call. */
48 private final int _channelId;
49
50 /**
51 * Creates a method event to encasulate a method call and channel.
52 *
53 * @param channelId The channel on which the method call occurred.
54 * @param method The method call.
55 */
56 public AMQMethodEvent(int channelId, M method)
57 {
58 _channelId = channelId;
59 _method = method;
60 }
61
62 /**
63 * Gets the method call.
64 *
65 * @return The method call.
66 */
67 public M getMethod()
68 {
69 return _method;
70 }
71
72 /**
73 * Gets the channel handle for the method call.
74 *
75 * @return The channel handle for the method call.
76 */
77 public int getChannelId()
78 {
79 return _channelId;
80 }
81
82 /**
83 * Prints the method call as a string, mainly for debugging purposes.
84 *
85 * @return The method call as a string, mainly for debugging purposes.
86 */
87 public String toString()
88 {
89 StringBuilder buf = new StringBuilder("Method event: ");
90 buf.append("\nChannel id: ").append(_channelId);
91 buf.append("\nMethod: ").append(_method);
92
93 return buf.toString();
94 }
95 }
|