1 22 package org.jboss.test.deadlock.bean; 23 24 import java.rmi.*; 25 import javax.ejb.*; 26 import javax.naming.InitialContext ; 27 import javax.naming.Context ; 28 import org.jboss.test.deadlock.interfaces.*; 29 import org.jboss.util.deadlock.ApplicationDeadlockException; 30 31 public class StatelessSessionBean implements SessionBean 32 { 33 org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass()); 34 35 private SessionContext sessionContext; 36 37 public void ejbCreate() throws RemoteException, CreateException 38 { 39 } 40 41 public void ejbActivate() throws RemoteException { 42 } 43 44 public void ejbPassivate() throws RemoteException { 45 } 46 47 public void ejbRemove() throws RemoteException { 48 } 49 50 public void setSessionContext(SessionContext context) throws RemoteException { 51 sessionContext = context; 52 } 55 56 57 public void callAB() throws RemoteException 58 { 59 try 60 { 61 log.info("****callAB start****"); 62 EnterpriseEntityHome home = (EnterpriseEntityHome)new InitialContext ().lookup("nextgenEnterpriseEntity"); 63 EnterpriseEntity A = home.findByPrimaryKey("A"); 64 EnterpriseEntity B = home.findByPrimaryKey("B"); 65 A.getOtherField(); 66 log.debug("callAB is sleeping"); 67 Thread.sleep(1000); 68 log.debug("callAB woke up"); 69 B.getOtherField(); 70 log.debug("callAB end"); 71 } 72 catch (ApplicationDeadlockException ade) 73 { 74 System.out.println("APPLICATION DEADLOCK EXCEPTION"); 75 throw ade; 76 } 77 catch (RemoteException rex) 78 { 79 throw rex; 80 } 81 catch (Exception ex) 82 { 83 throw new RemoteException("failed"); 84 } 85 } 86 87 public void callBA() throws RemoteException 88 { 89 try 90 { 91 log.info("****callBA start****"); 92 EnterpriseEntityHome home = (EnterpriseEntityHome)new InitialContext ().lookup("nextgenEnterpriseEntity"); 93 EnterpriseEntity B = home.findByPrimaryKey("B"); 94 EnterpriseEntity A = home.findByPrimaryKey("A"); 95 B.getOtherField(); 96 log.debug("callBA is sleeping"); 97 Thread.sleep(1000); 98 log.debug("callBA woke up"); 99 A.getOtherField(); 100 log.debug("callBA end"); 101 } 102 catch (ApplicationDeadlockException ade) 103 { 104 System.out.println("APPLICATION DEADLOCK EXCEPTION"); 105 throw ade; 106 } 107 catch (RemoteException rex) 108 { 109 throw rex; 110 } 111 catch (Exception ex) 112 { 113 throw new RemoteException("failed"); 114 } 115 } 116 117 public void requiresNewTest(boolean first) throws RemoteException 118 { 119 try 120 { 121 log.info("***requiresNewTest start***"); 122 InitialContext ctx = new InitialContext (); 123 EnterpriseEntityHome home = (EnterpriseEntityHome)ctx.lookup("nextgenEnterpriseEntity"); 124 EnterpriseEntity C = home.findByPrimaryKey("C"); 125 126 C.getOtherField(); 127 if (first) 128 { 129 StatelessSessionHome shome = (StatelessSessionHome)ctx.lookup("nextgen.StatelessSession"); 130 StatelessSession session = shome.create(); 131 session.requiresNewTest(false); 132 } 133 } 134 catch (RemoteException rex) 135 { 136 throw rex; 137 } 138 catch (Exception ex) 139 { 140 throw new RemoteException("failed"); 141 } 142 } 143 144 public void createCMRTestData(String jndiName) 145 { 146 try 147 { 148 InitialContext ctx = new InitialContext (); 149 Context enc = (Context ) ctx.lookup("java:comp/env"); 150 EnterpriseEntityLocalHome home = (EnterpriseEntityLocalHome)enc.lookup(jndiName); 151 try 152 { 153 home.create("First"); 154 } 155 catch (DuplicateKeyException dontCare) 156 { 157 } 158 try 159 { 160 home.create("Second"); 161 } 162 catch (DuplicateKeyException dontCare) 163 { 164 } 165 EnterpriseEntityLocal first = home.findByPrimaryKey("First"); 166 EnterpriseEntityLocal second = home.findByPrimaryKey("Second"); 167 first.setNext(second); 168 second.setNext(first); 169 } 170 catch (Exception e) 171 { 172 throw new EJBException("Unable to create data", e); 173 } 174 } 175 176 public void cmrTest(String jndiName, String start) 177 { 178 try 179 { 180 InitialContext ctx = new InitialContext (); 181 Context enc = (Context ) ctx.lookup("java:comp/env"); 182 EnterpriseEntityLocalHome home = (EnterpriseEntityLocalHome)enc.lookup(jndiName); 183 EnterpriseEntityLocal initial = home.findByPrimaryKey(start); 184 initial.getNext().getName(); 185 } 186 catch (Exception e) 187 { 188 throw new EJBException("Unable to create data", e); 189 } 190 } 191 } 192 | Popular Tags |