1 /***
2 *
3 * Copyright 2004 Protique Ltd
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 **/
18
19 package org.codehaus.activemq.transport;
20 import java.net.URI;
21
22 /***
23 * A TransportStatusEvent is raised when the state of the underlying transport channel changes
24 *
25 * @version $Revision: 1.2 $
26 */
27 public class TransportStatusEvent {
28 /***
29 * The channel has been intially and successfully connected
30 */
31 public static final int CONNECTED = 1;
32 /***
33 * The channel has been disconnected, but maybe reconnected
34 */
35 public static final int DISCONNECTED = 2;
36 /***
37 * The channel has successfully reconnected after a disconnect
38 */
39 public static final int RECONNECTED = 3;
40 /***
41 * The channel has failed
42 */
43 public static final int FAILED = 4;
44
45 /***
46 * The channel has been STOPPED
47 */
48 public static final int STOPPED = 5;
49
50 private URI remoteURI;
51 private int channelStatus;
52
53 /***
54 * Default Constructor
55 */
56 public TransportStatusEvent() {
57 }
58
59 /***
60 * @return a pretty print of this
61 */
62 public String toString() {
63 return "channel: " + remoteURI + " has " + getStatusAsString(channelStatus);
64 }
65
66 private String getStatusAsString(int status) {
67 String result = null;
68 switch (status) {
69 case CONNECTED :
70 result = "connected";
71 break;
72 case DISCONNECTED :
73 result = "disconnected";
74 break;
75 case RECONNECTED :
76 result = "reconnected";
77 break;
78 case FAILED :
79 result = "failed";
80 break;
81 case STOPPED:
82 result = "stopped";
83 break;
84 default :
85 result = "unknown";
86 }
87 return result;
88 }
89
90 /***
91 * @return Returns the channelStatus.
92 */
93 public int getChannelStatus() {
94 return channelStatus;
95 }
96
97 /***
98 * @param channelStatus The channelStatus to set.
99 */
100 public void setChannelStatus(int channelStatus) {
101 this.channelStatus = channelStatus;
102 }
103
104 /***
105 * @return Returns the remoteURI.
106 */
107 public URI getRemoteURI() {
108 return remoteURI;
109 }
110
111 /***
112 * @param remoteURI The remoteURI to set.
113 */
114 public void setRemoteURI(URI remoteURI) {
115 this.remoteURI = remoteURI;
116 }
117 }