KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cluster > ejb > CalledBean


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.cluster.ejb;
23
24 import java.rmi.RemoteException JavaDoc;
25 import java.rmi.dgc.VMID JavaDoc;
26 import java.util.Properties JavaDoc;
27 import javax.ejb.SessionBean JavaDoc;
28 import javax.ejb.SessionContext JavaDoc;
29 import javax.ejb.CreateException JavaDoc;
30 import javax.naming.InitialContext JavaDoc;
31 import javax.naming.Context JavaDoc;
32 import javax.rmi.PortableRemoteObject JavaDoc;
33
34 import org.jboss.logging.Logger;
35
36 /** This bean is called by the test client to validate ejb to ejb calls between
37  * server instances.
38  *
39  * @author Scott.Stark@jboss.org
40  * @version $Revision: 37406 $
41  */

42 public class CalledBean implements SessionBean JavaDoc
43 {
44    private static Logger log = Logger.getLogger(CalledBean.class);
45    private static VMID JavaDoc vmid = new VMID JavaDoc();
46
47    public void ejbCreate() throws CreateException JavaDoc
48    {
49       log.debug("ejbCreate() called");
50    }
51
52    public void ejbActivate()
53    {
54       log.debug("ejbActivate() called");
55    }
56
57    public void ejbPassivate()
58    {
59       log.debug("ejbPassivate() called");
60    }
61
62    public void ejbRemove()
63    {
64       log.debug("ejbRemove() called");
65    }
66
67    public void setSessionContext(SessionContext JavaDoc context)
68    {
69    }
70
71    /** This method calls echo on a CalleeBean
72     */

73    public VMID JavaDoc[] invokeCall(String JavaDoc jndiURL, String JavaDoc jndiName)
74       throws RemoteException JavaDoc
75    {
76       log.info("invokeCall, jndiURL="+jndiURL+", jndiName="+jndiName);
77       VMID JavaDoc[] ids = {vmid, null};
78       try
79       {
80          Properties JavaDoc props = new Properties JavaDoc();
81          props.setProperty(Context.PROVIDER_URL, jndiURL);
82          InitialContext JavaDoc ic = new InitialContext JavaDoc(props);
83          Object JavaDoc ref = ic.lookup(jndiName);
84          CalleeHome localHome = (CalleeHome) PortableRemoteObject.narrow(ref,
85                CalleeHome.class);
86          CalleeRemote remoteBean = localHome.create();
87          ids[1] = remoteBean.call("invokeCall");
88         log.info("echo, CalleeRemote.call="+ids[1]+", vmid="+ids[0]);
89       }
90       catch(Exception JavaDoc e)
91       {
92          log.error("Failed to invoke CalleeRemote.call", e);
93          throw new RemoteException JavaDoc("Failed to invoke CalleeRemote.call", e);
94       }
95       return ids;
96    }
97    
98 }
99
Popular Tags