1 25 26 package org.objectweb.easybeans.container.session; 27 28 import org.objectweb.easybeans.api.EZBContainer; 29 import org.objectweb.easybeans.api.FactoryException; 30 import org.objectweb.easybeans.api.bean.EasyBeansSB; 31 import org.objectweb.easybeans.api.bean.info.IBeanInfo; 32 import org.objectweb.easybeans.api.container.EZBSessionContext; 33 import org.objectweb.easybeans.api.pool.PoolException; 34 import org.objectweb.easybeans.container.AbsFactory; 35 import org.objectweb.easybeans.container.info.SessionBeanInfo; 36 import org.objectweb.easybeans.log.JLog; 37 import org.objectweb.easybeans.log.JLogFactory; 38 import org.objectweb.easybeans.rpc.api.EJBRequest; 39 import org.objectweb.easybeans.rpc.api.EJBResponse; 40 41 46 public abstract class SessionFactory<PoolType extends EasyBeansSB<PoolType>> extends AbsFactory<PoolType> { 47 48 51 private static JLog logger = JLogFactory.getLog(SessionFactory.class); 52 53 56 private SessionBeanInfo sessionBeanInfo = null; 57 58 64 public SessionFactory(final String className, final EZBContainer container) throws FactoryException { 65 super(className, container); 66 } 67 68 71 public void stop() { 72 try { 74 getPool().stop(); 75 } catch (PoolException e) { 76 logger.error("Problem when stopping the factory", e); 77 } 78 79 } 80 81 84 public IBeanInfo getBeanInfo() { 85 return sessionBeanInfo; 86 } 87 88 91 public SessionBeanInfo getSessionBeanInfo() { 92 return sessionBeanInfo; 93 } 94 95 99 public void setSessionBeanInfo(final SessionBeanInfo sessionBeanInfo) { 100 this.sessionBeanInfo = sessionBeanInfo; 101 } 102 103 108 protected abstract Long getId(final Long beanId); 109 110 116 public PoolType create(final Long clue) throws PoolException { 117 PoolType instance = null; 118 ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); 119 Thread.currentThread().setContextClassLoader(getContainer().getClassLoader()); 120 try { 121 try { 122 instance = getBeanClass().newInstance(); 123 } catch (InstantiationException e) { 124 throw new PoolException("Cannot create a new instance", e); 125 } catch (IllegalAccessException e) { 126 throw new PoolException("Cannot create a new instance", e); 127 } catch (Exception e) { 128 throw new PoolException("Cannot create a new instance", e); 129 } 130 } finally { 131 Thread.currentThread().setContextClassLoader(oldClassLoader); 132 } 133 134 instance.setEasyBeansFactory(this); 136 137 EZBSessionContext<PoolType> sessionContext = new EasyBeansSessionContext<PoolType>(instance); 139 instance.setEasyBeansContext(sessionContext); 140 141 oldClassLoader = Thread.currentThread().getContextClassLoader(); 142 Thread.currentThread().setContextClassLoader(getContainer().getClassLoader()); 143 try { 144 injectResources(instance); 146 147 instance.postConstructEasyBeansLifeCycle(); 149 } finally { 150 Thread.currentThread().setContextClassLoader(oldClassLoader); 151 } 152 153 return instance; 154 } 155 156 162 @Override 163 public EJBResponse rpcInvoke(final EJBRequest request) { 164 long hash = request.getMethodHash(); 166 167 Object [] args = null; 169 ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); 170 Thread.currentThread().setContextClassLoader(getContainer().getClassLoader()); 171 try { 172 args = request.getMethodArgs(); 173 } finally { 174 Thread.currentThread().setContextClassLoader(oldClassLoader); 175 } 176 177 return localCall(hash, args, request.getBeanId()); 179 180 } 181 182 188 protected abstract PoolType getBean(final Long beanId) throws IllegalArgumentException ; 189 190 191 198 public abstract EJBResponse localCall(final long hash, final Object [] methodArgs, final Long beanId); 199 200 } 201 | Popular Tags |