1 14 15 package org.quickserver.net.server.impl; 16 17 import java.io.*; 18 import java.net.*; 19 import java.util.*; 20 import java.util.logging.*; 21 import java.util.regex.*; 22 import org.quickserver.net.server.*; 23 import org.quickserver.util.pool.*; 24 25 30 public abstract class BasicClientIdentifier implements ClientIdentifier{ 31 private static final Logger logger = Logger.getLogger(BasicClientIdentifier.class.getName()); 32 33 protected QSObjectPool clientHandlerPool; 34 protected QuickServer quickserver; 35 36 public void setQuickServer(QuickServer quickserver) { 37 this.quickserver = quickserver; 38 } 39 40 public void setClientHandlerPool(QSObjectPool clientHandlerPool) { 41 this.clientHandlerPool = clientHandlerPool; 42 } 43 44 public Object getObjectToSynchronize() { 45 return clientHandlerPool.getObjectToSynchronize(); 46 } 47 48 public Iterator findAllClient() { 49 return clientHandlerPool.getAllActiveObjects(); 50 } 51 52 protected ClientIdentifiable getClientIdentifiable( 53 ClientHandler foundClientHandler) { 54 if(foundClientHandler==null) return null; 55 if(foundClientHandler.isOpen()==false) return null; 56 ClientData foundClientData = null; 57 58 foundClientData = foundClientHandler.getClientData(); 59 if(foundClientData==null) 60 throw new IllegalStateException ("No ClientData was set! Can't find a client with out it."); 61 if(ClientIdentifiable.class.isInstance(foundClientData)==false) 62 throw new IllegalStateException ("ClientData does not implement ClientIdentifiable! Can't find a client with out it."); 63 return (ClientIdentifiable) foundClientData; 64 } 65 66 protected ClientHandler checkClientId(ClientHandler foundClientHandler, 67 String id) { 68 ClientIdentifiable data = getClientIdentifiable(foundClientHandler); 69 if(data==null) return null; 70 71 String foundId = data.getClientId(); 72 if(foundId==null) { 74 logger.finest("Id returned by ClientData was null! Client may not yet ready.. skipping"); 76 return null; 77 } 78 if(foundId.equals(id)==false) 79 foundClientHandler = null; 80 return foundClientHandler; 81 } 82 83 protected ClientHandler checkClientId(ClientHandler foundClientHandler, 84 Pattern pattern) { 85 ClientIdentifiable data = getClientIdentifiable(foundClientHandler); 86 if(data==null) return null; 87 88 String foundId = data.getClientId(); 89 if(foundId==null) { 91 logger.finest("Id returned by ClientData was null! Client may not yet ready.. skipping"); 93 return null; 94 } 95 Matcher m = pattern.matcher(foundId); 96 if(m.matches()==false) 97 foundClientHandler = null; 98 return foundClientHandler; 99 } 100 101 protected ClientHandler checkClientKey(ClientHandler foundClientHandler, 102 String key) { 103 ClientIdentifiable data = getClientIdentifiable(foundClientHandler); 104 if(data==null) return null; 105 106 String foundKey = data.getClientKey(); 107 if(foundKey==null) { 109 logger.finest("Key returned by ClientData was null! Client may not yet ready.. skipping"); 111 return null; 112 } 113 if(foundKey.equals(key)==false) 114 foundClientHandler = null; 115 return foundClientHandler; 116 } 117 118 protected ClientHandler checkClientKey(ClientHandler foundClientHandler, 119 Pattern pattern) { 120 ClientIdentifiable data = getClientIdentifiable(foundClientHandler); 121 if(data==null) return null; 122 123 String foundKey = data.getClientKey(); 124 if(foundKey==null) { 126 logger.finest("Key returned by ClientData was null! Client may not yet ready.. skipping"); 128 return null; 129 } 130 Matcher m = pattern.matcher(foundKey); 131 if(m.matches()==false) 132 foundClientHandler = null; 133 return foundClientHandler; 134 } 135 136 } 137 | Popular Tags |