On Fri, Jan 25, 2019 at 10:15 AM Benjamin Edwards <edwards.b...@gmail.com> wrote:
> I'd also suggest that blocking the thread either by polling in a loop or > using a dedicated timeout method is somewhat antithetical to the point of > an asynchronous call. Better usually to do something like resolve a promise > either with the service result or an exception after a threshold. This > allows you to chain promises together nicely without blocking but also > keeps things ticking along. It seems a shame that OSGi promises don't > support a notion of cancellation (which is helpful when racing a long > running call with a timeout). If you have access to the deferred that the promise came from you can "cancel" by self-resolving using: org.osgi.util.promise.Deferred.resolveWith(Promise<? extends T>) See org.osgi.util.promise.Promises for handy factory methods you can pair that with to get the effect you want, a failure or success with a value. - Ray > > Can't have everything I guess. > > Ben > > On Fri, 25 Jan 2019, 2:58 pm Raymond Auge, <raymond.a...@liferay.com> > wrote: > >> I'm not sure if Aries Async uses the Promise API in a substitutable way, >> but the latest version of the Promise API has timeout methods [1]. >> >> Perhaps Tim Ward could shed some light on this? >> One option is simply to try to use the lastest Promise API along with >> Aries Async. >> >> Sincerely, >> - Ray >> >> [1] >> https://osgi.org/specification/osgi.cmpn/7.0.0/util.promise.html#util.promise-timing.methods >> >> On Fri, Jan 25, 2019 at 7:07 AM Lorr, Sebastian < >> sebastian.l...@its-digital.de> wrote: >> >>> Hi there, >>> >>> >>> >>> I want to call a Service and wait for a given time for a response. >>> >>> So I did a async servicecall like this: >>> >>> >>> >>> // Create mediator, to call service asynchronously >>> >>> IMyService mediated = asyncService.mediate(myService, IMyService.class); >>> >>> >>> >>> // Call service and await promise to be fulfilled >>> >>> Promise<Result> promise = asyncService.call(mediated.process()); >>> >>> boolean timeoutExceeded = false; >>> >>> long startTime = Calendar.getInstance().getTimeInMillis(); >>> >>> >>> >>> serviceTimeoutMillis = 100; >>> >>> // Wait until timeout for promise to be done >>> >>> while (!promise.isDone()) { >>> >>> Thread.sleep(10); >>> >>> if (Calendar.getInstance().getTimeInMillis() > >>> startTime + serviceTimeoutMillis) { >>> >>> timeoutExceeded = true; >>> >>> break; >>> >>> } >>> >>> } >>> >>> if (timeoutExceeded) { >>> throw new TimeoutException("Timeout exceeded"); >>> } >>> >>> >>> Now the question: is there a better way for waiting for promise-resolve >>> until a given timeout? >>> >>> Maybe some feature of Async that i missed? >>> >>> >>> >>> >>> >>> Thanks in advance, >>> >>> >>> >>> Sebastian >>> >>> >>> ---------------------------------------------------------------- >>> Sebastian Lorr >>> ITS Digital Solutions GmbH >>> Dillenburger Str. 77 >>> <https://maps.google.com/?q=Dillenburger+Str.+77+%0D%0A+D-51105+K%C3%B6ln&entry=gmail&source=g> >>> >>> <https://maps.google.com/?q=Dillenburger+Str.+77+%0D%0A+D-51105+K%C3%B6ln&entry=gmail&source=g> >>> D-51105 Köln >>> <https://maps.google.com/?q=Dillenburger+Str.+77+%0D%0A+D-51105+K%C3%B6ln&entry=gmail&source=g> >>> Tel.: +49 (0)221 820 07 0 >>> Fax : +49 (0)221 820 07 22 <%2B49%20%280%29221%20820%2007%2022> >>> Mail: i...@its-telco.de >>> Web : http://www.its-telco.de >>> ---------------------------------------------------------------- >>> Sitz der Gesellschaft: Dortmund >>> Amtsgericht Dortmund, HRB 28563 >>> Geschäftsführer: Gunnar Haack, Ludger Schulte, Heinrich Toben, Raimund >>> Schipp, Ralf Petersilka >>> ---------------------------------------------------------------- >>> >>> Diese E-Mail enthält vertrauliche Informationen. Wenn Sie nicht der >>> richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, >>> informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. >>> Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser E-Mail ist >>> nicht gestattet. >>> >>> This e-mail may contain confidential information. If you are not the >>> intended recipient (or have received this e-mail in error) please notify >>> the sender immediately and destroy this e-mail. Any unauthorised copying, >>> disclosure or distribution of the material in this e-mail is strictly >>> forbidden. >>> >>> >> >> -- >> *Raymond Augé* <http://www.liferay.com/web/raymond.auge/profile> >> (@rotty3000) >> Senior Software Architect *Liferay, Inc.* <http://www.liferay.com> >> (@Liferay) >> Board Member & EEG Co-Chair, OSGi Alliance <http://osgi.org> >> (@OSGiAlliance) >> > -- *Raymond Augé* <http://www.liferay.com/web/raymond.auge/profile> (@rotty3000) Senior Software Architect *Liferay, Inc.* <http://www.liferay.com> (@Liferay) Board Member & EEG Co-Chair, OSGi Alliance <http://osgi.org> (@OSGiAlliance)