1 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 ; 15 16 17 public class Client 18 { 19 public static void main(String [] args) throws Exception 20 { 21 InitialContext ctx = new InitialContext (); 22 Echo echo = (Echo)ctx.lookup(org.jboss.tutorial.asynch.bean.Echo.class.getName()); 23 System.out.println("-------- Synchronous call"); 24 String 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 )future.get(); 47 System.out.println(ret); 48 49 50 } 51 } 52 | Popular Tags |