...
Example #5: Client and Server with parallel trace (involving thread pools)
In this example server-side implementation of the JAX-RS service is going to offload some work into thread pool and then return the response to the client, simulating parallel execution. The client-side code stays unchanged.
Code Block | ||||
---|---|---|---|---|
| ||||
@Produces( { MediaType.APPLICATION_JSON } )
@GET
public Collection<Book> getBooks(@Context final TracerContext tracer) throws Exception {
final Future<Book> book1 = executor.submit(
tracer.wrap("Getting Book 1", new Traceable<Book>() {
public Book call(final TracerContext context) throws Exception {
// Simulating a delay of 100ms required to call external system
Thread.sleep(100);
return new Book("Apache CXF Web Service Development",
"Naveen Balani, Rajeev Hathi");
}
})
);
final Future<Book> book2 = executor.submit(
tracer.wrap("Getting Book 2", new Traceable<Book>() {
public Book call(final TracerContext context) throws Exception {
// Simulating a delay of 100ms required to call external system
Thread.sleep(200);
return new Book("Developing Web Services with Apache CXF and Axis2",
"Kent Ka Iok Tong");
}
})
);
return Arrays.asList(book1.get(), book2.get());
} |
The actual invocation of the request by the client (with process name jaxrsclient/192.168.0.100) and consequent invocation of the service on the server side (process name jaxrsserver/192.168.0.100) is going to generate the following sample traces:
TODO
Example #6: Client and Server with asynchronous JAX-RS service (server-side)
...