1 5 package ve.luz.ica.jackass.instantiator; 6 7 import java.util.Map ; 8 9 import org.apache.commons.logging.Log; 10 import org.apache.commons.logging.LogFactory; 11 import org.apache.commons.pool.ObjectPool; 12 13 import org.omg.CORBA.CompletionStatus ; 14 import org.omg.CORBA.INTERNAL ; 15 16 import org.omg.PortableServer.ForwardRequest ; 17 import org.omg.PortableServer.POA ; 18 import org.omg.PortableServer.Servant ; 19 import org.omg.PortableServer.ServantLocatorPackage.CookieHolder ; 20 21 26 public class StatelessServantLocator 28 extends org.omg.CORBA.LocalObject 29 implements org.omg.PortableServer.ServantLocator 30 { 31 private static final Log LOG = LogFactory.getLog(StatelessServantLocator.class); 32 33 private static final int ERR_MINOR_CODE = 0; 34 private static final Object ERROR_COOKIE = new int[0]; 35 36 private Map objectInfoTable = null; 37 38 42 public StatelessServantLocator(Map objectInfoTable) 43 { 44 this.objectInfoTable = objectInfoTable; 45 } 46 47 51 public Servant preinvoke(byte[] oid, POA adapter, String operation, CookieHolder theCookie) 52 throws ForwardRequest 53 { 54 try 55 { 56 if (LOG.isDebugEnabled()) LOG.debug("Preinvoke " + operation + " on " + new String (oid)); 57 StatelessObjectInfo info = (StatelessObjectInfo) objectInfoTable.get(new String (oid)); 58 ObjectPool pool = info.getServantPool(); 59 Servant servant = (Servant ) pool.borrowObject(); 60 if (LOG.isDebugEnabled()) LOG.debug("Servant obtained from the pool"); 61 return servant; 62 } 63 catch (Exception e) 64 { 65 if (LOG.isErrorEnabled()) 66 { 67 LOG.error(e.getMessage(), e); 68 } 69 theCookie.value = ERROR_COOKIE; 70 throw new INTERNAL (e.getMessage(), ERR_MINOR_CODE, CompletionStatus.COMPLETED_NO); 71 } 72 } 73 74 78 public void postinvoke(byte[] oid, POA adapter, String operation, Object theCookie, Servant theServant) 79 { 80 try 81 { 82 if (LOG.isDebugEnabled()) LOG.debug("Postinvoke " + operation + " on " + new String (oid)); 83 StatelessObjectInfo info = (StatelessObjectInfo) objectInfoTable.get(new String (oid)); 84 ObjectPool pool = info.getServantPool(); 85 pool.returnObject(theServant); 86 } 87 catch (Exception e) 88 { 89 if (LOG.isErrorEnabled()) 90 { 91 LOG.error(e.getMessage(), e); 92 } 93 CompletionStatus completionStatus = (theCookie == null ? CompletionStatus.COMPLETED_MAYBE : 94 CompletionStatus.COMPLETED_NO); 95 throw new INTERNAL (e.getMessage(), ERR_MINOR_CODE, completionStatus); 96 } 97 } 98 99 } 100 | Popular Tags |