KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > deadlock > bean > StatelessSessionBean


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.deadlock.bean;
23
24 import java.rmi.*;
25 import javax.ejb.*;
26 import javax.naming.InitialContext JavaDoc;
27 import javax.naming.Context JavaDoc;
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       //Exception e = new Exception("in set Session context");
53
//log.debug("failed", e);
54
}
55    
56    
57    public void callAB() throws RemoteException
58    {
59       try
60       {
61      log.info("****callAB start****");
62      EnterpriseEntityHome home = (EnterpriseEntityHome)new InitialContext JavaDoc().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 JavaDoc 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 JavaDoc().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 JavaDoc 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 JavaDoc ctx = new InitialContext JavaDoc();
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 JavaDoc ex)
139       {
140          throw new RemoteException("failed");
141       }
142    }
143
144    public void createCMRTestData(String JavaDoc jndiName)
145    {
146       try
147       {
148          InitialContext JavaDoc ctx = new InitialContext JavaDoc();
149          Context JavaDoc enc = (Context JavaDoc) 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 JavaDoc e)
171       {
172          throw new EJBException("Unable to create data", e);
173       }
174    }
175
176    public void cmrTest(String JavaDoc jndiName, String JavaDoc start)
177    {
178       try
179       {
180          InitialContext JavaDoc ctx = new InitialContext JavaDoc();
181          Context JavaDoc enc = (Context JavaDoc) 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 JavaDoc e)
187       {
188          throw new EJBException("Unable to create data", e);
189       }
190    }
191 }
192
Popular Tags