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.testbeancluster.bean;
023:
024: import java.rmi.RemoteException;
025: import javax.ejb.SessionBean;
026: import javax.ejb.EJBException;
027: import javax.ejb.SessionContext;
028: import javax.naming.InitialContext;
029:
030: import org.jboss.test.testbeancluster.interfaces.StatelessSessionHome;
031: import org.jboss.test.testbeancluster.interfaces.StatelessSession;
032:
033: public class StatelessSessionBean implements SessionBean {
034: public static long numberOfCalls = 0;
035:
036: public void ejbCreate() {
037: }
038:
039: public void ejbActivate() throws EJBException, RemoteException {
040: }
041:
042: public void ejbPassivate() throws EJBException, RemoteException {
043: }
044:
045: public void ejbRemove() throws EJBException, RemoteException {
046: }
047:
048: public void setSessionContext(SessionContext ctx)
049: throws EJBException, RemoteException {
050: }
051:
052: public void callBusinessMethodA() {
053: numberOfCalls++;
054: }
055:
056: public String callBusinessMethodB(String jndiURL) {
057: numberOfCalls++;
058: String rtn = "callBusinessMethodB-" + numberOfCalls;
059: testColocation(jndiURL);
060: return rtn;
061: }
062:
063: public void testColocation(String jndiURL) {
064: try {
065: System.out.println("begin testColocation");
066: InitialContext ctx = new InitialContext();
067: if (jndiURL == null)
068: jndiURL = "jnp://"
069: + System.getProperty("jboss.bind.address",
070: "localhost")
071: + ":1100/nextgen_StatelessSession";
072: StatelessSessionHome home = (StatelessSessionHome) ctx
073: .lookup(jndiURL);
074: StatelessSession session = home.create();
075: session.callBusinessMethodA();
076: System.out.println("end testColocation");
077: } catch (Exception ex) {
078: ex.printStackTrace();
079: }
080:
081: }
082:
083: public void resetNumberOfCalls() {
084: System.out.println("Number of calls has been reseted");
085: numberOfCalls = 0;
086: }
087:
088: public void makeCountedCall() {
089: System.out.println("makeCountedCall called");
090: numberOfCalls++;
091: }
092:
093: public long getCallCount() {
094: System.out.println("getCallCount called");
095: return numberOfCalls;
096: }
097:
098: public String getBindAddress() {
099: return System.getProperty("jboss.bind.address");
100: }
101:
102: }
|