KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > testbeancluster > 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.testbeancluster.bean;
23
24 import java.rmi.RemoteException JavaDoc;
25 import javax.ejb.SessionBean JavaDoc;
26 import javax.ejb.EJBException JavaDoc;
27 import javax.ejb.SessionContext JavaDoc;
28 import javax.naming.InitialContext JavaDoc;
29
30 import org.jboss.test.testbeancluster.interfaces.StatelessSessionHome;
31 import org.jboss.test.testbeancluster.interfaces.StatelessSession;
32
33 public class StatelessSessionBean implements SessionBean JavaDoc
34 {
35    public static long numberOfCalls = 0;
36
37    public void ejbCreate()
38    {
39    }
40    public void ejbActivate() throws EJBException JavaDoc, RemoteException JavaDoc
41    {
42    }
43
44    public void ejbPassivate() throws EJBException JavaDoc, RemoteException JavaDoc
45    {
46    }
47
48    public void ejbRemove() throws EJBException JavaDoc, RemoteException JavaDoc
49    {
50    }
51
52    public void setSessionContext(SessionContext JavaDoc ctx) throws EJBException JavaDoc, RemoteException JavaDoc
53    {
54    }
55
56    public void callBusinessMethodA()
57    {
58       numberOfCalls++;
59    }
60    
61    public String JavaDoc callBusinessMethodB(String JavaDoc jndiURL)
62    {
63       numberOfCalls++;
64       String JavaDoc rtn = "callBusinessMethodB-" + numberOfCalls;
65       testColocation(jndiURL);
66       return rtn;
67    }
68
69    public void testColocation(String JavaDoc jndiURL)
70    {
71       try
72       {
73          System.out.println("begin testColocation");
74          InitialContext JavaDoc ctx = new InitialContext JavaDoc();
75          if( jndiURL == null )
76             jndiURL = "jnp://" + System.getProperty("jboss.bind.address", "localhost") + ":1100/nextgen_StatelessSession";
77          StatelessSessionHome home = (StatelessSessionHome) ctx.lookup(jndiURL);
78          StatelessSession session = home.create();
79          session.callBusinessMethodA();
80          System.out.println("end testColocation");
81       }
82       catch (Exception JavaDoc ex)
83       {
84          ex.printStackTrace();
85       }
86
87    }
88    
89    public void resetNumberOfCalls ()
90    {
91       System.out.println("Number of calls has been reseted");
92       numberOfCalls = 0;
93    }
94    
95    public void makeCountedCall ()
96    {
97       System.out.println("makeCountedCall called");
98       numberOfCalls++;
99    }
100    
101    public long getCallCount ()
102    {
103       System.out.println("getCallCount called");
104       return numberOfCalls;
105    }
106    
107    public String JavaDoc getBindAddress()
108    {
109       return System.getProperty("jboss.bind.address");
110    }
111
112 }
113
Popular Tags