1 22 package org.jboss.ejb.plugins; 23 24 import java.rmi.RemoteException ; 25 import javax.ejb.EJBException ; 26 27 import org.jboss.deployment.DeploymentException; 28 import org.jboss.ejb.EnterpriseContext; 29 import org.jboss.ejb.StatelessSessionEnterpriseContext; 30 import org.jboss.metadata.MetaData; 31 import org.w3c.dom.Element ; 32 33 40 public class SingletonStatelessSessionInstancePool extends AbstractInstancePool 41 { 42 44 EnterpriseContext ctx; 46 boolean inUse = false; 47 boolean isSynchronized = true; 48 49 51 53 55 public void create() 56 throws Exception 57 { 58 } 59 60 public void start() 61 throws Exception 62 { 63 } 64 65 public void stop() 66 { 67 } 68 69 public void destroy() 70 { 71 } 72 73 79 public synchronized EnterpriseContext get() 80 throws Exception 81 { 82 while(inUse && isSynchronized) 84 { 85 try { this.wait(); } catch (InterruptedException e) {} 86 } 87 88 if (ctx == null) 90 { 91 try 92 { 93 ctx = create(getContainer().createBeanClassInstance()); 94 } catch (InstantiationException e) 95 { 96 throw new EJBException ("Could not instantiate bean", e); 97 } catch (IllegalAccessException e) 98 { 99 throw new EJBException ("Could not instantiate bean", e); 100 } 101 } 102 else 103 { 104 } 105 106 inUse = true; 108 return ctx; 109 } 110 111 120 public synchronized void free(EnterpriseContext ctx) 121 { 122 inUse = false; 124 this.notifyAll(); 125 } 126 127 public synchronized void discard(EnterpriseContext ctx) 128 { 129 try 131 { 132 ctx.discard(); 133 } catch (RemoteException e) 134 { 135 } 137 138 inUse = false; 140 this.notifyAll(); 141 } 142 143 146 public void add() 147 throws Exception 148 { 149 } 151 152 public int getCurrentSize() 153 { 154 return 1; 155 } 156 157 public int getMaxSize() 158 { 159 return 1; 160 } 161 162 164 public void importXml(Element element) throws DeploymentException 166 { 167 Element synch = MetaData.getUniqueChild(element, "Synchronized"); 168 isSynchronized = Boolean.valueOf(MetaData.getElementContent(synch)).booleanValue(); 169 } 170 171 173 protected EnterpriseContext create(Object instance) 175 throws Exception 176 { 177 return new StatelessSessionEnterpriseContext(instance, getContainer()); 179 } 180 182 184 } 185 | Popular Tags |