java - Parallel webservices access in a Weld CDI environment -
we're developing web frontend using jsf 2 , weld cdi on tomcat.
i've problem executing multiple webservices in parallel optimize request time.
user may select mutliple items form list.
each selected item, process gathers it's information 1 webservice using list key parameter.
current approach using producer, returns webservice port interface, injected bean. bean calls webservie in loop each selected key.
@inject private wsanzeigeassetsummen serviceaccess; : ( integer pfnr : sessionkeys.getpfnrlist() ) { summarytable = serviceaccess.execute(snr, pfnr, requesttype, "", desiredrows, username); processresult(summarytable): }
to faster, tried use executorservice , many workers needed, returning futures.
the problem of construct is, can't inject service port worker, cause worker not managed. creating service port hand, works not appreciated, cause ignores producer class.
also when testing, it's not possible inject dummy service port, delivers predefined result sets.
since did not find anything, parallel execution in tomcat-weld enviroment, there must wrong approach.
what correct approach solve such situation ?
edit: more clear tried...
public class datacollector implements isumrequest<integer, integer, string, futureresult> { executorservice pool = executors.newcachedthreadpool(); @inject sessionbean sessionbean; public future<futureresult> collectinformation(integer snr, integer pfnr, string requesttype) { collectworker worker = new collectworker (snr,pfnr,requesttype,sessionbean.getusername()); return pool.submit(worker); }
}
when doing this, worker not managed.
you can wrap created worker in cdi creational context, this:
@inject private beanmanager beanmanager; public <t extends object> t performinjection(final t obj) { if (this.beanmanager != null) { // injection if bean manager present. // create creational context beanmanager final creationalcontext creationalcontext = this.beanmanager.createcreationalcontext(null); // create injection target type of instance need inject final injectiontarget injectiontarget = this.beanmanager.createinjectiontarget(this.beanmanager.createannotatedtype(obj.getclass())); // perform injection instance injectiontarget.inject(obj, creationalcontext); // call postconstruct on instance injectiontarget.postconstruct(obj); } return obj; }
Comments
Post a Comment