Non-Bloking API - 调用端运行完调用函数以后就直接往下走了,调用端和被调用端是异步执行的。返回值是用回调函数来实现的。
这种异步叫做API层异步(API Level Asynchrony)。他们只用到一个连接来发送和接收消息,而且,假如是那种需要运行很长时间的函数,还会碰到Time Out 错误,假如用两个连接分别处理发送和接收消息,调用的时间就可以缩短,也可以解决Time Out 问题。用两个连接来分别处理发送和接收消息,叫做传输层异步(Transport Level Asynchrony)。
EchoBlockingClient.java public class EchoBlockingClient { private static EndpointReference targetEPR = new EndpointReference("http://localhost:8080/axis2/services/MyService");
EchoBlockingDualClient.java public class EchoBlockingDualClient { private static EndpointReference targetEPR = new EndpointReference("http://127.0.0.1:8080/axis2/services/MyService");
public class EchoNonBlockingClient { private static EndpointReference targetEPR = new EndpointReference("http://127.0.0.1:8080/axis2/services/MyService");
public class EchoNonBlockingDualClient { private static EndpointReference targetEPR = new EndpointReference("http://127.0.0.1:8080/axis2/services/MyService");
//The boolean flag informs the axis2 engine to use two separate transport connection //to retrieve the response. call.engageModule(new QName(Constants.MODULE_ADDRESSING)); call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, true);
//Callback to handle the response Callback callback = new Callback() { public void onComplete(AsyncResult result) { try { StringWriter writer = new StringWriter(); result.getResponseEnvelope().serializeWithCache(XMLOutputFactory.newInstance() .createXMLStreamWriter(writer)); writer.flush(); System.out.println(writer.toString());
//Wait till the callback receives the response. while (!callback.isComplete()) { Thread.sleep(1000); } //Need to close the Client Side Listener. call.close();