use of javax.xml.ws.AsyncHandler in project cxf by apache.
the class AsyncHTTPConduitTest method testCallsAsync.
@Test
@Ignore("peformance test")
public void testCallsAsync() throws Exception {
updateAddressPort(g, PORT);
final int warmupIter = 5000;
final int runIter = 5000;
final CountDownLatch wlatch = new CountDownLatch(warmupIter);
final boolean[] wdone = new boolean[warmupIter];
@SuppressWarnings("unchecked") AsyncHandler<GreetMeLaterResponse>[] whandler = new AsyncHandler[warmupIter];
for (int x = 0; x < warmupIter; x++) {
final int c = x;
whandler[x] = new AsyncHandler<GreetMeLaterResponse>() {
public void handleResponse(Response<GreetMeLaterResponse> res) {
try {
String s = res.get().getResponseType();
s = s.substring(s.lastIndexOf(' ') + 1);
if (c != Integer.parseInt(s)) {
System.out.println("Problem " + c + " != " + s);
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
wdone[c] = true;
wlatch.countDown();
}
};
}
// warmup
long start = System.currentTimeMillis();
for (int x = 0; x < warmupIter; x++) {
// builder.append("a");
// long s1 = System.nanoTime();
// System.out.println("aa1: " + s1);
g.greetMeLaterAsync(x, whandler[x]);
// long s2 = System.nanoTime();
// System.out.println("aa2: " + s2 + " " + (s2 - s1));
// System.out.println();
}
wlatch.await(30, TimeUnit.SECONDS);
long end = System.currentTimeMillis();
System.out.println("Warmup Total: " + (end - start) + " " + wlatch.getCount());
for (int x = 0; x < warmupIter; x++) {
if (!wdone[x]) {
System.out.println(" " + x);
}
}
if (wlatch.getCount() > 0) {
Thread.sleep(1000000);
}
final CountDownLatch rlatch = new CountDownLatch(runIter);
AsyncHandler<GreetMeLaterResponse> rhandler = new AsyncHandler<GreetMeLaterResponse>() {
public void handleResponse(Response<GreetMeLaterResponse> res) {
rlatch.countDown();
}
};
start = System.currentTimeMillis();
for (int x = 0; x < runIter; x++) {
// builder.append("a");
// long s1 = System.nanoTime();
// System.out.println("aa1: " + s1);
g.greetMeLaterAsync(x, rhandler);
// long s2 = System.nanoTime();
// System.out.println("aa2: " + s2 + " " + (s2 - s1));
// System.out.println();
}
rlatch.await(30, TimeUnit.SECONDS);
end = System.currentTimeMillis();
System.out.println("Total: " + (end - start) + " " + rlatch.getCount());
}
use of javax.xml.ws.AsyncHandler in project cxf by apache.
the class WSDiscoveryClient method probe.
public ProbeMatchesType probe(ProbeType params, int timeout) {
Dispatch<Object> disp = this.getDispatchInternal(false, version.getProbeAction());
if (adHoc) {
disp.getRequestContext().put("udp.multi.response.timeout", timeout);
final ProbeMatchesType response = new ProbeMatchesType();
AsyncHandler<Object> handler = new AsyncHandler<Object>() {
public void handleResponse(Response<Object> res) {
try {
Object o = res.get();
while (o instanceof JAXBElement) {
o = ((JAXBElement) o).getValue();
}
if (o instanceof ProbeMatchesType) {
response.getProbeMatch().addAll(((ProbeMatchesType) o).getProbeMatch());
} else if (o instanceof HelloType) {
HelloType h = (HelloType) o;
QName sn = version.getServiceName();
if (h.getTypes().contains(sn) || h.getTypes().contains(new QName("", sn.getLocalPart()))) {
// A DiscoveryProxy wants us to flip to managed mode
uncache();
resetDispatch(h.getXAddrs().get(0));
}
}
} catch (InterruptedException e) {
// ?
} catch (ExecutionException e) {
// ?
}
}
};
disp.invokeAsync(new ObjectFactory().createProbe(params), handler);
return response;
}
Object o = disp.invoke(new ObjectFactory().createProbe(params));
while (o instanceof JAXBElement) {
o = ((JAXBElement) o).getValue();
}
return (ProbeMatchesType) o;
}
use of javax.xml.ws.AsyncHandler in project cxf by apache.
the class JaxWsClientProxy method invokeAsync.
@SuppressWarnings("unchecked")
private Object invokeAsync(Method method, BindingOperationInfo oi, Object[] params) throws Exception {
client.setExecutor(getClient().getEndpoint().getExecutor());
AsyncHandler<Object> handler;
if (params.length > 0 && params[params.length - 1] instanceof AsyncHandler) {
handler = (AsyncHandler<Object>) params[params.length - 1];
Object[] newParams = new Object[params.length - 1];
for (int i = 0; i < newParams.length; i++) {
newParams[i] = params[i];
}
params = newParams;
} else {
handler = null;
}
ClientCallback callback = new JaxwsClientCallback<Object>(handler, this);
Response<Object> ret = new JaxwsResponseCallback<Object>(callback);
client.invoke(callback, oi, params);
return ret;
}
use of javax.xml.ws.AsyncHandler in project cxf by apache.
the class WSAPureWsdlTest method testBasicInvocationTimeouts.
@Test
public void testBasicInvocationTimeouts() throws Exception {
AddNumbersPortType port = getPort();
((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + PORT + "/jaxws/add");
HTTPConduit conduit = (HTTPConduit) ((Client) port).getConduit();
conduit.getClient().setConnectionTimeout(25);
conduit.getClient().setReceiveTimeout(10);
try {
// read timeout
port.addNumbersAsync(5092, 25).get();
fail("should have failed");
} catch (Exception t) {
// expected
assertTrue(t.getCause().toString(), t.getCause() instanceof java.net.SocketTimeoutException);
}
AsyncHandler<AddNumbersResponse> handler = new AsyncHandler<AddNumbersResponse>() {
public void handleResponse(Response<AddNumbersResponse> res) {
// System.out.println("in handle response");
synchronized (this) {
notifyAll();
}
}
};
synchronized (handler) {
port.addNumbersAsync(5092, 25, handler);
handler.wait(1000);
}
try {
// connection timeout
((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + PORT2 + "/jaxws/add");
port.addNumbersAsync(25, 25).get();
fail("should have failed");
} catch (Exception t) {
// expected
assertTrue(t.getCause().getCause().toString(), t.getCause().getCause() instanceof java.net.ConnectException || t.getCause().getCause() instanceof java.net.SocketTimeoutException);
}
synchronized (handler) {
port.addNumbersAsync(25, 25, handler);
handler.wait(1000);
}
MAPCodec mp = getMAPCodec((Client) port);
assertEquals(0, mp.getUncorrelatedExchanges().size());
}
use of javax.xml.ws.AsyncHandler in project cxf by apache.
the class WSDiscoveryClient method resolve.
public ResolveMatchType resolve(W3CEndpointReference ref, int timeout) {
Dispatch<Object> disp = this.getDispatchInternal(false, version.getResolveAction());
ResolveType rt = new ResolveType();
rt.setEndpointReference(ref);
if (adHoc) {
disp.getRequestContext().put("udp.multi.response.timeout", timeout);
final Holder<ResolveMatchesType> response = new Holder<ResolveMatchesType>();
AsyncHandler<Object> handler = new AsyncHandler<Object>() {
public void handleResponse(Response<Object> res) {
try {
Object o = res.get();
while (o instanceof JAXBElement) {
o = ((JAXBElement) o).getValue();
}
if (o instanceof ResolveMatchesType) {
response.value = (ResolveMatchesType) o;
} else if (o instanceof HelloType) {
HelloType h = (HelloType) o;
QName sn = version.getServiceName();
if (h.getTypes().contains(sn) || h.getTypes().contains(new QName("", sn.getLocalPart()))) {
// A DiscoveryProxy wants us to flip to managed mode
uncache();
resetDispatch(h.getXAddrs().get(0));
}
}
} catch (InterruptedException e) {
// ?
} catch (ExecutionException e) {
// ?
}
}
};
disp.invokeAsync(new ObjectFactory().createResolve(rt), handler);
return response.value == null ? null : response.value.getResolveMatch();
}
Object o = disp.invoke(new ObjectFactory().createResolve(rt));
while (o instanceof JAXBElement) {
o = ((JAXBElement) o).getValue();
}
return o == null ? null : ((ResolveMatchesType) o).getResolveMatch();
}
Aggregations