001 /** 002 * 003 * Copyright 2004 Protique Ltd 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 * 017 **/ 018 019 package org.activemq.advisories; 020 import java.io.Externalizable; 021 import java.io.IOException; 022 import java.io.ObjectInput; 023 import java.io.ObjectOutput; 024 025 import org.activemq.message.AbstractPacket; 026 import org.activemq.message.ActiveMQDestination; 027 028 /** 029 * This event is raised when a MessageTempDestination starts/stops * 030 * 031 * @version $Revision: 1.1.1.1 $ 032 */ 033 public class TempDestinationAdvisoryEvent extends AbstractPacket implements Externalizable { 034 035 private static final long serialVersionUID = -541770480868770950L; 036 037 private ActiveMQDestination destination; 038 private boolean started; 039 040 /** 041 * Empty constructor 042 */ 043 public TempDestinationAdvisoryEvent() { 044 } 045 046 /** 047 * Default Constructor 048 * 049 * @param dest 050 * @param started 051 */ 052 public TempDestinationAdvisoryEvent(ActiveMQDestination dest, boolean started) { 053 this.destination = dest; 054 this.started = started; 055 } 056 057 /** 058 * @return Returns the destination. 059 */ 060 public ActiveMQDestination getDestination() { 061 return destination; 062 } 063 064 /** 065 * @param destination The destination to set. 066 */ 067 public void setDestination(ActiveMQDestination destination) { 068 this.destination = destination; 069 } 070 071 /** 072 * @return Returns the started. 073 */ 074 public boolean isStarted() { 075 return started; 076 } 077 078 /** 079 * @param started The started to set. 080 */ 081 public void setStarted(boolean started) { 082 this.started = started; 083 } 084 085 /** 086 * write to a stream 087 * 088 * @param out 089 * @throws IOException 090 */ 091 public void writeExternal(ObjectOutput out) throws IOException { 092 out.writeBoolean(this.started); 093 ActiveMQDestination.writeToStream(getDestination(), out); 094 } 095 096 /** 097 * read from a stream 098 * 099 * @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 }