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 /**
022 * Denotes an object that can be serialized/deserailized using a Packet Reader/Writer
023 */
024
025 public class SessionInfo extends AbstractPacket {
026
027 private String clientId;
028 private short sessionId;
029 private long startTime;
030 private boolean started;
031 private int sessionMode;
032
033 /**
034 * @return Returns the sessionMode.
035 */
036 public int getSessionMode() {
037 return sessionMode;
038 }
039 /**
040 * @param sessionMode The sessionMode to set.
041 */
042 public void setSessionMode(int sessionMode) {
043 this.sessionMode = sessionMode;
044 }
045 /**
046 * Return the type of Packet
047 *
048 * @return integer representation of the type of Packet
049 */
050
051 public int getPacketType() {
052 return SESSION_INFO;
053 }
054
055
056 /**
057 * Test for equality
058 *
059 * @param obj object to test
060 * @return true if equivalent
061 */
062 public boolean equals(Object obj) {
063 boolean result = false;
064 if (obj != null && obj instanceof SessionInfo) {
065 SessionInfo info = (SessionInfo) obj;
066 result = this.clientId.equals(info.clientId) && this.sessionId == info.sessionId;
067 }
068 return result;
069 }
070
071 /**
072 * @return hash code for instance
073 */
074 public int hashCode() {
075 if (cachedHashCode == -1){
076 String hashCodeStr = clientId + sessionId;
077 cachedHashCode = hashCodeStr.hashCode();
078 }
079 return cachedHashCode;
080 }
081
082
083
084 /**
085 * @return Returns the sessionId.
086 */
087 public short getSessionId() {
088 return sessionId;
089 }
090
091 /**
092 * @param sessionId The sessionId to set.
093 */
094 public void setSessionId(short sessionId) {
095 this.sessionId = sessionId;
096 }
097
098
099 /**
100 * @return Returns the clientId.
101 */
102 public String getClientId() {
103 return this.clientId;
104 }
105
106 /**
107 * @param newClientId The clientId to set.
108 */
109 public void setClientId(String newClientId) {
110 this.clientId = newClientId;
111 }
112
113
114 /**
115 * @return Returns the started.
116 */
117 public boolean isStarted() {
118 return this.started;
119 }
120
121 /**
122 * @param flag to indicate if started
123 */
124 public void setStarted(boolean flag) {
125 this.started = flag;
126 }
127
128 /**
129 * @return Returns the startTime.
130 */
131 public long getStartTime() {
132 return this.startTime;
133 }
134
135 /**
136 * @param newStartTime The startTime to set.
137 */
138 public void setStartTime(long newStartTime) {
139 this.startTime = newStartTime;
140 }
141
142 public String toString() {
143 return super.toString() + " SessionInfo{ " +
144 "clientId = '" + clientId + "' " +
145 ", sessionId = '" + sessionId + "' " +
146 ", startTime = " + startTime +
147 ", started = " + started +
148 " }";
149 }
150 }