KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > asynch > 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.asynch.client;
8
9 import org.jboss.tutorial.asynch.bean.Echo;
10 import org.jboss.ejb3.JBossProxy;
11 import org.jboss.aspects.asynch.AsynchProvider;
12 import org.jboss.aspects.asynch.Future;
13
14 import javax.naming.InitialContext JavaDoc;
15
16
17 public class Client
18 {
19    public static void main(String JavaDoc[] args) throws Exception JavaDoc
20    {
21       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
22       Echo echo = (Echo)ctx.lookup(org.jboss.tutorial.asynch.bean.Echo.class.getName());
23       System.out.println("-------- Synchronous call");
24       String JavaDoc ret = echo.echo("normal call");
25       System.out.println(ret);
26
27       JBossProxy proxy = (JBossProxy)echo;
28       Echo asynchEcho = (Echo)proxy.getAsynchronousProxy();
29       System.out.println("-------- Asynchronous call");
30       ret = asynchEcho.echo("asynchronous call");
31       System.out.println("Direct return of async invocation is: " + ret);
32
33       System.out.println("-------- Synchronous call");
34       ret = echo.echo("normal call 2");
35       System.out.println(ret);
36
37       System.out.println("-------- Result of Asynchronous call");
38       AsynchProvider provider = (AsynchProvider)asynchEcho;
39       Future future = provider.getFuture();
40
41       System.out.println("Waiting for asynbch invocation to complete");
42       while (!future.isDone())
43       {
44          Thread.sleep(100);
45       }
46       ret = (String JavaDoc)future.get();
47       System.out.println(ret);
48
49
50    }
51 }
52
Popular Tags