KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > consumer > client > Client


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.tutorial.consumer.client;
8
9 import org.jboss.tutorial.consumer.bean.ExampleProducerRemote;
10 import org.jboss.tutorial.consumer.bean.Tester;
11 import org.jboss.ejb3.mdb.ProducerManager;
12 import org.jboss.ejb3.mdb.ProducerObject;
13
14 import javax.naming.InitialContext JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.Map JavaDoc;
17
18 public class Client
19 {
20    public static void main(String JavaDoc[] args) throws Exception JavaDoc
21    {
22       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
23       ExampleProducerRemote remote = (ExampleProducerRemote) ctx.lookup(ExampleProducerRemote.class.getName());
24       ProducerManager manager = ((ProducerObject) remote).getProducerManager();
25
26
27       // connect
28
manager.connect();
29
30       try
31       {
32          // Call method1
33
remote.method1("Remote method1 called", 1);
34
35          // Call method2
36
Map JavaDoc<String JavaDoc, String JavaDoc> map = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
37          map.put("hello", "world");
38          map.put("great", "ejb3");
39
40          remote.method2("Remote method2 called", map);
41       }
42       finally
43       {
44          manager.close();
45       }
46
47
48       // Try out local producers by interfacing with Session bean
49
Tester tester = (Tester) ctx.lookup(Tester.class.getName());
50       tester.testLocal();
51       tester.testXA();
52    }
53 }
54
Popular Tags