Source code: org/activemq/advisories/TempDestinationAdvisoryEvent.java
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.activemq.advisories;
20 import java.io.Externalizable;
21 import java.io.IOException;
22 import java.io.ObjectInput;
23 import java.io.ObjectOutput;
24
25 import org.activemq.message.AbstractPacket;
26 import org.activemq.message.ActiveMQDestination;
27
28 /**
29 * This event is raised when a MessageTempDestination starts/stops *
30 *
31 * @version $Revision: 1.1.1.1 $
32 */
33 public class TempDestinationAdvisoryEvent extends AbstractPacket implements Externalizable {
34
35 private static final long serialVersionUID = -541770480868770950L;
36
37 private ActiveMQDestination destination;
38 private boolean started;
39
40 /**
41 * Empty constructor
42 */
43 public TempDestinationAdvisoryEvent() {
44 }
45
46 /**
47 * Default Constructor
48 *
49 * @param dest
50 * @param started
51 */
52 public TempDestinationAdvisoryEvent(ActiveMQDestination dest, boolean started) {
53 this.destination = dest;
54 this.started = started;
55 }
56
57 /**
58 * @return Returns the destination.
59 */
60 public ActiveMQDestination getDestination() {
61 return destination;
62 }
63
64 /**
65 * @param destination The destination to set.
66 */
67 public void setDestination(ActiveMQDestination destination) {
68 this.destination = destination;
69 }
70
71 /**
72 * @return Returns the started.
73 */
74 public boolean isStarted() {
75 return started;
76 }
77
78 /**
79 * @param started The started to set.
80 */
81 public void setStarted(boolean started) {
82 this.started = started;
83 }
84
85 /**
86 * write to a stream
87 *
88 * @param out
89 * @throws IOException
90 */
91 public void writeExternal(ObjectOutput out) throws IOException {
92 out.writeBoolean(this.started);
93 ActiveMQDestination.writeToStream(getDestination(), out);
94 }
95
96 /**
97 * read from a stream
98 *
99 * @param in
100 * @throws IOException
101 * @throws ClassNotFoundException
102 */
103 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
104 this.started = in.readBoolean();
105 this.destination = ActiveMQDestination.readFromStream(in);
106 }
107
108 /**
109 * @param obj
110 * @return true if obj is equal
111 */
112 public boolean equals(Object obj) {
113 boolean result = false;
114 if (obj != null && obj instanceof TempDestinationAdvisoryEvent) {
115 TempDestinationAdvisoryEvent event = (TempDestinationAdvisoryEvent) obj;
116 result = destination != null && event.destination != null && destination.equals(event.destination);
117 }
118 return result;
119 }
120
121 /**
122 * @return hash code
123 */
124 public int hashCode() {
125 return destination != null ? destination.hashCode() : super.hashCode();
126 }
127
128 /**
129 * @return Packet type - for this case -1
130 */
131 public int getPacketType() {
132 return -1;
133 }
134
135 /**
136 * @return pretty print of 'this'
137 */
138 public String toString() {
139 String str = "TempDestinationAdvisoryEvent: " + destination + " has " + (started ? "started" : "stopped");
140 return str;
141 }
142 }