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.message;
020
021 import java.io.Serializable;
022
023 /**
024 * Denotes life cycle infomation for a Producer of messages
025 */
026
027 public class ProducerInfo extends AbstractPacket implements Serializable{
028 static final long serialVersionUID = 3489666788L;
029 private ActiveMQDestination destination;
030 private short producerId;
031 private String clientId;
032 private short sessionId;
033 private long startTime;
034 private boolean started;
035
036
037 /**
038 * Test for equality
039 *
040 * @param obj object to test
041 * @return true if equivalent
042 */
043 public boolean equals(Object obj) {
044 boolean result = false;
045 if (obj != null && obj instanceof ProducerInfo) {
046 ProducerInfo info = (ProducerInfo) obj;
047 result = this.producerId == info.producerId &&
048 this.sessionId == info.sessionId &&
049 this.clientId.equals(info.clientId);
050 }
051 return result;
052 }
053
054 /**
055 * @return hash code for instance
056 */
057
058 public int hashCode() {
059 if (cachedHashCode == -1){
060 String hashCodeStr = clientId + sessionId + producerId;
061 cachedHashCode = hashCodeStr.hashCode();
062 }
063 return cachedHashCode;
064 }
065
066
067 /**
068 * @return Returns the producerId.
069 */
070 public short getProducerId() {
071 return producerId;
072 }
073
074 /**
075 * @param producerId The producerId to set.
076 */
077 public void setProducerId(short producerId) {
078 this.producerId = producerId;
079 }
080
081 /**
082 * @return Returns the sessionId.
083 */
084 public short getSessionId() {
085 return sessionId;
086 }
087
088 /**
089 * @param sessionId The sessionId to set.
090 */
091 public void setSessionId(short sessionId) {
092 this.sessionId = sessionId;
093 }
094
095 /**
096 * Return the type of Packet
097 *
098 * @return integer representation of the type of Packet
099 */
100
101 public int getPacketType() {
102 return PRODUCER_INFO;
103 }
104
105
106 /**
107 * @return Returns the clientId.
108 */
109 public String getClientId() {
110 return this.clientId;
111 }
112
113 /**
114 * @param newClientId The clientId to set.
115 */
116 public void setClientId(String newClientId) {
117 this.clientId = newClientId;
118 }
119
120
121 /**
122 * @return Returns the destination.
123 */
124 public ActiveMQDestination getDestination() {
125 return this.destination;
126 }
127
128 /**
129 * @param newDestination The destination to set.
130 */
131 public void setDestination(ActiveMQDestination newDestination) {
132 this.destination = newDestination;
133 }
134
135
136 /**
137 * @return Returns the started.
138 */
139 public boolean isStarted() {
140 return this.started;
141 }
142
143 /**
144 * @param flag to indicate if started
145 */
146 public void setStarted(boolean flag) {
147 this.started = flag;
148 }
149
150 /**
151 * @return Returns the startTime.
152 */
153 public long getStartTime() {
154 return this.startTime;
155 }
156
157 /**
158 * @param newStartTime The startTime to set.
159 */
160 public void setStartTime(long newStartTime) {
161 this.startTime = newStartTime;
162 }
163
164 public String toString() {
165 return super.toString() + " ProducerInfo{ " +
166 "clientId = '" + clientId + "' " +
167 ", destination = " + destination +
168 ", producerId = '" + producerId + "' " +
169 ", sessionId = '" + sessionId + "' " +
170 ", startTime = " + startTime +
171 ", started = " + started +
172 " }";
173 }
174 }