1 14 15 package chatserver; 16 17 import org.quickserver.net.server.*; 18 19 import org.quickserver.util.pool.PoolableObject; 20 import org.apache.commons.pool.BasePoolableObjectFactory; 21 import org.apache.commons.pool.PoolableObjectFactory; 22 23 import java.util.*; 24 import java.io.*; 25 import java.nio.*; 26 import java.util.logging.*; 27 28 32 public class ChatData implements ClientData, ClientIdentifiable, PoolableObject { 33 private static final Logger logger = 34 Logger.getLogger(ChatData.class.getName()); 35 36 private static Set usernameList = new HashSet(); 37 38 private String username = null; 39 private String room = null; 40 private String info = null; 41 42 private String lastAsked = null; 44 private byte password[] = null; 45 46 public void setLastAsked(String lastAsked) { 47 this.lastAsked = lastAsked; 48 } 49 public String getLastAsked() { 50 return lastAsked; 51 } 52 53 public void setPassword(byte[] password) { 54 this.password = password; 55 } 56 public byte[] getPassword() { 57 return password; 58 } 59 60 public boolean registerUsername(String username) { 61 return usernameList.add(username); 62 } 63 public void deregisterUsername(String username) { 64 usernameList.remove(username); 65 } 66 public void setUsername(String username) { 67 this.username = username; 68 } 69 public String getUsername() { 70 return username; 71 } 72 73 public void setRoom(String room) { 74 this.room = room; 75 } 76 public String getRoom() { 77 return room; 78 } 79 80 public String getClientId() { 81 return username; 82 } 83 84 public String getClientKey() { 85 if(room==null) 86 return username; 87 else 88 return username+"@"+room; 89 } 90 91 public void setClientInfo(String info) { 92 this.info = info; 93 } 94 public String getClientInfo() { 95 return getClientKey()+" - "+info; 96 } 97 98 public String toString() { 99 return getClientInfo(); 100 } 101 102 public void clean() { 104 usernameList.remove(username); 105 username = null; 106 room = null; 107 info = null; 108 lastAsked = null; 109 } 110 111 public boolean isPoolable() { 112 return true; 113 } 114 115 public PoolableObjectFactory getPoolableObjectFactory() { 116 return new BasePoolableObjectFactory() { 117 public Object makeObject() { 118 return new ChatData(); 119 } 120 public void passivateObject(Object obj) { 121 ChatData ed = (ChatData)obj; 122 ed.clean(); 123 } 124 public void destroyObject(Object obj) { 125 if(obj==null) return; 126 passivateObject(obj); 127 obj = null; 128 } 129 public boolean validateObject(Object obj) { 130 if(obj==null) 131 return false; 132 else 133 return true; 134 } 135 }; 136 } 137 } 138 139 140 | Popular Tags |