001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.deadlock.bean;
023:
024: import java.rmi.*;
025: import javax.ejb.*;
026: import javax.naming.InitialContext;
027: import javax.naming.Context;
028: import org.jboss.test.deadlock.interfaces.*;
029: import org.jboss.util.deadlock.ApplicationDeadlockException;
030:
031: public class StatelessSessionBean implements SessionBean {
032: org.apache.log4j.Category log = org.apache.log4j.Category
033: .getInstance(getClass());
034:
035: private SessionContext sessionContext;
036:
037: public void ejbCreate() throws RemoteException, CreateException {
038: }
039:
040: public void ejbActivate() throws RemoteException {
041: }
042:
043: public void ejbPassivate() throws RemoteException {
044: }
045:
046: public void ejbRemove() throws RemoteException {
047: }
048:
049: public void setSessionContext(SessionContext context)
050: throws RemoteException {
051: sessionContext = context;
052: //Exception e = new Exception("in set Session context");
053: //log.debug("failed", e);
054: }
055:
056: public void callAB() throws RemoteException {
057: try {
058: log.info("****callAB start****");
059: EnterpriseEntityHome home = (EnterpriseEntityHome) new InitialContext()
060: .lookup("nextgenEnterpriseEntity");
061: EnterpriseEntity A = home.findByPrimaryKey("A");
062: EnterpriseEntity B = home.findByPrimaryKey("B");
063: A.getOtherField();
064: log.debug("callAB is sleeping");
065: Thread.sleep(1000);
066: log.debug("callAB woke up");
067: B.getOtherField();
068: log.debug("callAB end");
069: } catch (ApplicationDeadlockException ade) {
070: System.out.println("APPLICATION DEADLOCK EXCEPTION");
071: throw ade;
072: } catch (RemoteException rex) {
073: throw rex;
074: } catch (Exception ex) {
075: throw new RemoteException("failed");
076: }
077: }
078:
079: public void callBA() throws RemoteException {
080: try {
081: log.info("****callBA start****");
082: EnterpriseEntityHome home = (EnterpriseEntityHome) new InitialContext()
083: .lookup("nextgenEnterpriseEntity");
084: EnterpriseEntity B = home.findByPrimaryKey("B");
085: EnterpriseEntity A = home.findByPrimaryKey("A");
086: B.getOtherField();
087: log.debug("callBA is sleeping");
088: Thread.sleep(1000);
089: log.debug("callBA woke up");
090: A.getOtherField();
091: log.debug("callBA end");
092: } catch (ApplicationDeadlockException ade) {
093: System.out.println("APPLICATION DEADLOCK EXCEPTION");
094: throw ade;
095: } catch (RemoteException rex) {
096: throw rex;
097: } catch (Exception ex) {
098: throw new RemoteException("failed");
099: }
100: }
101:
102: public void requiresNewTest(boolean first) throws RemoteException {
103: try {
104: log.info("***requiresNewTest start***");
105: InitialContext ctx = new InitialContext();
106: EnterpriseEntityHome home = (EnterpriseEntityHome) ctx
107: .lookup("nextgenEnterpriseEntity");
108: EnterpriseEntity C = home.findByPrimaryKey("C");
109:
110: C.getOtherField();
111: if (first) {
112: StatelessSessionHome shome = (StatelessSessionHome) ctx
113: .lookup("nextgen.StatelessSession");
114: StatelessSession session = shome.create();
115: session.requiresNewTest(false);
116: }
117: } catch (RemoteException rex) {
118: throw rex;
119: } catch (Exception ex) {
120: throw new RemoteException("failed");
121: }
122: }
123:
124: public void createCMRTestData(String jndiName) {
125: try {
126: InitialContext ctx = new InitialContext();
127: Context enc = (Context) ctx.lookup("java:comp/env");
128: EnterpriseEntityLocalHome home = (EnterpriseEntityLocalHome) enc
129: .lookup(jndiName);
130: try {
131: home.create("First");
132: } catch (DuplicateKeyException dontCare) {
133: }
134: try {
135: home.create("Second");
136: } catch (DuplicateKeyException dontCare) {
137: }
138: EnterpriseEntityLocal first = home
139: .findByPrimaryKey("First");
140: EnterpriseEntityLocal second = home
141: .findByPrimaryKey("Second");
142: first.setNext(second);
143: second.setNext(first);
144: } catch (Exception e) {
145: throw new EJBException("Unable to create data", e);
146: }
147: }
148:
149: public void cmrTest(String jndiName, String start) {
150: try {
151: InitialContext ctx = new InitialContext();
152: Context enc = (Context) ctx.lookup("java:comp/env");
153: EnterpriseEntityLocalHome home = (EnterpriseEntityLocalHome) enc
154: .lookup(jndiName);
155: EnterpriseEntityLocal initial = home
156: .findByPrimaryKey(start);
157: initial.getNext().getName();
158: } catch (Exception e) {
159: throw new EJBException("Unable to create data", e);
160: }
161: }
162: }
|