1 14 15 package org.quickserver.util.pool; 16 17 import org.quickserver.net.server.ClientHandler; 18 import org.quickserver.net.server.impl.*; 19 import org.apache.commons.pool.BasePoolableObjectFactory; 20 21 27 public class ClientHandlerObjectFactory extends BasePoolableObjectFactory { 28 private static int instanceCount = 0; 29 private int id = -1; 30 private boolean blocking = true; 31 32 public ClientHandlerObjectFactory(boolean blocking) { 33 super(); 34 id = ++instanceCount; 35 this.blocking = blocking; 36 } 37 38 public Object makeObject() { 40 if(blocking) 41 return new BlockingClientHandler(id); 42 else 43 return new NonBlockingClientHandler(id); 44 } 45 46 public void passivateObject(Object obj) { 48 ClientHandler ch = (ClientHandler)obj; 49 ch.clean(); 50 } 51 52 public void activateObject(Object obj) { 54 } 55 56 public void destroyObject(Object obj) { 58 if(obj==null) return; 59 passivateObject(obj); 60 obj = null; 61 } 62 63 public boolean validateObject(Object obj) { 65 if(obj==null) 66 return false; 67 68 BasicClientHandler ch = (BasicClientHandler)obj; 69 if(ch.getInstanceCount()==id) 70 return true; 71 else { 72 return false; 73 } 74 } 75 } 76 | Popular Tags |