1 11 12 package org.jivesoftware.messenger; 13 14 import org.jivesoftware.messenger.auth.AuthToken; 15 import org.xmpp.packet.JID; 16 17 import java.util.Date ; 18 19 29 public abstract class Session implements RoutableChannelHandler { 30 31 34 protected static String CHARSET = "UTF-8"; 35 36 public static final int STATUS_CLOSED = -1; 37 public static final int STATUS_CONNECTED = 1; 38 public static final int STATUS_STREAMING = 2; 39 public static final int STATUS_AUTHENTICATED = 3; 40 41 44 private JID address; 45 46 49 private StreamID streamID; 50 51 54 protected int status = STATUS_CONNECTED; 55 56 59 protected Connection conn; 60 61 64 protected AuthToken authToken; 65 66 protected SessionManager sessionManager; 67 68 private String serverName; 69 70 private Date startDate = new Date (); 71 72 private long lastActiveDate; 73 private long clientPacketCount = 0; 74 private long serverPacketCount = 0; 75 76 81 public Session(String serverName, Connection connection, StreamID streamID) { 82 conn = connection; 83 this.streamID = streamID; 84 this.serverName = serverName; 85 String id = streamID.getID(); 86 this.address = new JID(null, serverName, id); 87 this.sessionManager = SessionManager.getInstance(); 88 } 89 90 98 public JID getAddress() { 99 return address; 100 } 101 102 108 public void setAddress(JID address){ 109 this.address = address; 110 } 111 112 117 public Connection getConnection() { 118 return conn; 119 } 120 121 126 public int getStatus() { 127 return status; 128 } 129 130 137 public void setStatus(int status) { 138 this.status = status; 139 } 140 141 147 public StreamID getStreamID() { 148 return streamID; 149 } 150 151 156 public String getServerName() { 157 return serverName; 158 } 159 160 165 public Date getCreationDate() { 166 return startDate; 167 } 168 169 174 public Date getLastActiveDate() { 175 return new Date (lastActiveDate); 176 } 177 178 181 public void incrementClientPacketCount() { 182 clientPacketCount++; 183 lastActiveDate = System.currentTimeMillis(); 184 } 185 186 189 public void incrementServerPacketCount() { 190 serverPacketCount++; 191 lastActiveDate = System.currentTimeMillis(); 192 } 193 194 199 public long getNumClientPackets() { 200 return clientPacketCount; 201 } 202 203 208 public long getNumServerPackets() { 209 return serverPacketCount; 210 } 211 212 public String toString() { 213 return super.toString() + " status: " + status + " address: " + address + " id: " + streamID; 214 } 215 } | Popular Tags |