1

Topic: Forced for the task

There is a dial-up of services on Spring. Services actively interact with external components, frequently through indirect SDK. Some of these SDK can produce very durable time delays. For example, call Azure SDK can easy fall asleep for 20 minutes under some circumstances. I need to process this business somehow. To wait for 20 minutes is not present either desires, nor possibilities - users will consider that service hung. It is necessary to interrupt forcedly the task and to return any TimeoutException that application could show to the user the message and ask it what to do. Azure SDK such functional directly does not expose. There is  which probably can be used for these purposes but while it would be desirable more simple decision - to envelop calls in any wrapper which will cause exterior service with forcedly exposed as much as possible admissible time of the response and to return performance in case of absence of the response. It is thought to me that there should be any ready libraries-wrappers for this purpose. The task like quite typical. Can advise something easy-to-use?

2

Re: Forced for the task

Hello, Artem Korneev, you wrote: AK> Can advise something easy-to-use? Try to look java.util.concurrent. CompletableFuture in a combination with the ExecutorService. At CompletableFuture there is a method get with a time-out, and if it works the ExecutorService allows to make shutdown and to stop performance since by experience:: cancel it is not enough method CompetableFuture.

3

Re: Forced for the task

Hello, Artem Korneev, you wrote: AK> It is thought to me that there should be any ready libraries-wrappers for this purpose. The task like quite typical. Can advise something easy-to-use? Generally - only through separate processes.

4

Re: Forced for the task

Hello, Artem Korneev, you wrote: Hystrix?

5

Re: Forced for the task

Hello, Artem Korneev, you wrote: AK> It is thought to me that there should be any ready libraries-wrappers for this purpose. The task like quite typical. Can advise something easy-to-use? It is possible to try to alter on workflow model - at yanking API the request is put in queue and result at once goes to the user with , which needs to be pulled periodically to check up result. Worker takes request from a pool, processes and writes result which API processing that as a result reads to a link and produces to the user. Can be as a first approximation made on queues. For difficult asynchronous processes it is possible to use engines of type Amazon Simple Workflow Service or Uber Cadence.

6

Re: Forced for the task

Hello, Artem Korneev, you wrote: AK> It is thought to me that there should be any ready libraries-wrappers for this purpose. The task like quite typical. Can advise something easy-to-use? Stupidly you turn a lambda of a call of service in other function which inside fulfills a lambda asynchronously if similar requests are not fulfilled, and traces runtime. For the least hemorrhoids with asynchrony under a cowl I RxJava , with its help similar high-level  with the convenient signature am written very quickly. In practice even itself RxJava solves 90 problems for you, you need to make only a convenient wrapper with convenient API for you are interested in the synchronous call. At me it that that like: ConcurrentHashMap <String, AbortableTask> currentExecutedTasks = ConcurrentHashMap <String, AbortableTask> (); shared Callable <Return, Args> asyncMemoizeWithDefaultWithRepeat <Return, Args> (Callable <Return, Args> func, Return defaultValueIfNotMemoized, Integer maxRepeatTimeOutMillis, MutableMap <String, Return> cache = defaultCache <String, Return> (), Anything (Return) onReturn = (Return res) {}) given Args satisfies Anything [] given Return satisfies Object {Return callFun (Args args) {value fnKey = ConversionUtils.getMetaInfo (func) + "Async"; value key = fnKey + args.string; return ConcurrentUtils.javaSynchronizeOnIntern<Return> (key, () {value subject = BehaviorSubject.create <Return> (); subject.subscribe (onReturn); Null|Return cached = cache.get (key); if (exists cached) {subject.onNext (cached); subject.onComplete (); return cached;} currentExecutedTasks.computeIfAbsent (key, (key) => async ((stopFlag) {try {value data = func (*args); cache.put (key, data); subject.onNext (data);} catch (Throwable ex) {log.error (ex.message, ex); subject.onError (ex);} subject.onComplete (); currentExecutedTasks.remove (key);})); subject.buffer (maxRepeatTimeOutMillis, TimeUnit.milliseconds, 1).blockingFirst (); Null|Return cachedAfterBlocking = cache.get (key); if (exists cachedAfterBlocking) {return cachedAfterBlocking;} return defaultValueIfNotMemoized;});} return flatten (callFun);} Truth not absolutely it Java, and is not absolutely exact that is necessary for you, wrote ASAP, but these are trifles. For my tasks works normally, probably what to a bug and passed.

7

Re: Forced for the task

Hello, elmal, you wrote: E> Stupidly you turn a lambda of a call of service in other function which inside fulfills a lambda asynchronously if similar requests are not fulfilled, and traces runtime. For the least hemorrhoids with asynchrony under a cowl I RxJava , with its help similar high-level  with the convenient signature am written very quickly. In practice even itself RxJava solves 90 problems for you, you need to make only a convenient wrapper with convenient API for you are interested in the synchronous call. I of such councils never understood. Is certain generally it is not known that a doing call which returns result. Or does not return. That it there does  itself(himself) - not clearly. It is possible to envelop certainly it in start of the separate... That? As though you it named, in a basis will be normal thread, expecting result, or at once heaps of results from different launched . If activity was not completed in time - as you tear off it, thread.interrupt to it send? And if it still  produced, resources ? In  there were trees , a certain hierarchy? No, did not appear, interrupting parent thread, you make nothing with descendants. That is, the wrapper can not wait completions of activity and return an error on , but thus activity remains! Also will do do not understand that, indefinite time.

8

Re: Forced for the task

Hello, Glory, you wrote: I of such councils never understood. Is certain generally it is not known that a doing call which returns result. Or does not return. That it there does  itself(himself) - not clearly. It is possible to envelop certainly it in start of the separate... That? As though you it named, in a basis will be normal thread, expecting result, or at once heaps of results from different launched . If activity was not completed in time - as you tear off it, thread.interrupt to it send? And if it still  produced, resources ? In  there were trees , a certain hierarchy? No, did not appear, interrupting parent thread, you make nothing with descendants. That is, the wrapper can not wait completions of activity and return an error on , but thus activity remains! Also will do do not understand that, indefinite time. It is clear. Was specific for my case I do not need to interrupt request. I need to return value by default in case the request is fulfilled too long. And not to admit  start of heavy function with the same parameters if now there is a performance. And on end to place value in . If it is necessary to interrupt, at me any asynchronous method is a lambda from AtomicBoolean stopFlag which inside heavy calculation undertakes to check periodically and undertakes to be completed anyhow in case it will from the outside be exposed in true. While for similar tasks at me such decision if who can offer the decision better - I listen.