Top Description Inners Fields Constructors Methods
org.springframework.scheduling.annotation

pack-priv abstract Class ScheduledAnnotationReactiveSupport

extends Object
Class Inheritance
Imports
java.lang.reflect.InvocationTargetException, .Method, java.util.List, java.util.concurrent.CountDownLatch, java.util.function.Supplier, io.micrometer.observation.Observation, .ObservationRegistry, io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor, org.apache.commons.logging.Log, .LogFactory, org.reactivestreams.Publisher, .Subscriber, .Subscription, reactor.core.publisher.Flux, org.springframework.aop.support.AopUtils, org.springframework.core.CoroutinesUtils, .KotlinDetector, .ReactiveAdapter, .ReactiveAdapterRegistry, org.springframework.lang.Nullable, org.springframework.scheduling.SchedulingAwareRunnable, org.springframework.scheduling.support.DefaultScheduledTaskObservationConvention, .ScheduledTaskObservationContext, .ScheduledTaskObservationConvention, org.springframework.util.Assert, .ClassUtils, .ReflectionUtils, .StringUtils

Helper class for @ScheduledAnnotationBeanPostProcessor to support reactive cases without a dependency on optional classes.
Authors
Simon Baslé, Brian Clozel
Since
6.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
ScheduledAnnotationReactiveSupport.SubscribingRunnable

Utility implementation of Runnable that subscribes to a Publisher or subscribes-then-blocks if shouldBlock is set to true.

private static class
ScheduledAnnotationReactiveSupport.TrackingSubscriber

A Subscriber which keeps track of its Subscription and exposes the capacity to cancel the subscription as a Runnable.

Field Summary

Modifier and TypeField and Description
pack-priv static final boolean
private static final Log
pack-priv static final boolean

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public static Runnable
createSubscriptionRunnable(Method method, Object targetBean, Scheduled scheduled, Supplier<ObservationRegistry> observationRegistrySupplier, List<Runnable> subscriptionTrackerRegistry)

Create a Runnable for the Scheduled infrastructure, allowing for scheduled subscription to the publisher produced by a reactive method.

pack-priv static Publisher<?>
getPublisherFor(Method method, Object bean)

Turn the invocation of the provided Method into a Publisher, either by reflectively invoking it and converting the result to a Publisher via ReactiveAdapterRegistry or by converting a Kotlin suspending function into a Publisher via CoroutinesUtils.

public static boolean
isReactive(Method method)

Checks that if the method is reactive, it can be scheduled.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

coroutinesReactorPresentback to summary
pack-priv static final boolean coroutinesReactorPresent
loggerback to summary
private static final Log logger
reactorPresentback to summary
pack-priv static final boolean reactorPresent

Constructor Detail

ScheduledAnnotationReactiveSupportback to summary
pack-priv ScheduledAnnotationReactiveSupport()

Method Detail

createSubscriptionRunnableback to summary
public static Runnable createSubscriptionRunnable(Method method, Object targetBean, Scheduled scheduled, Supplier<ObservationRegistry> observationRegistrySupplier, List<Runnable> subscriptionTrackerRegistry)

Create a Runnable for the Scheduled infrastructure, allowing for scheduled subscription to the publisher produced by a reactive method.

Note that the reactive method is invoked once, but the resulting Publisher is subscribed to repeatedly, once per each invocation of the Runnable.

In the case of a fixed-delay configuration, the subscription inside the Runnable is turned into a blocking call in order to maintain fixed-delay semantics (i.e. the task blocks until completion of the Publisher, and the delay is applied until the next iteration).

getPublisherForback to summary
pack-priv static Publisher<?> getPublisherFor(Method method, Object bean)

Turn the invocation of the provided Method into a Publisher, either by reflectively invoking it and converting the result to a Publisher via ReactiveAdapterRegistry or by converting a Kotlin suspending function into a Publisher via CoroutinesUtils.

The isReactive(Method) check is a precondition to calling this method. If Reactor is present at runtime, the Publisher is additionally converted to a Flux with a checkpoint String, allowing for better debugging.

isReactiveback to summary
public static boolean isReactive(Method method)

Checks that if the method is reactive, it can be scheduled. Methods are considered eligible for reactive scheduling if they either return an instance of a type that can be converted to Publisher or are a Kotlin suspending function. If the method doesn't match these criteria, this check returns false.

For scheduling of Kotlin suspending functions, the Coroutine-Reactor bridge kotlinx.coroutines.reactor must be present at runtime (in order to invoke suspending functions as a Publisher). Provided that is the case, this method returns true. Otherwise, it throws an IllegalStateException.

Exceptions
IllegalStateException:
if the method is reactive but Reactor and/or the Kotlin coroutines bridge are not present at runtime
org.springframework.scheduling.annotation back to summary

pack-priv final Class ScheduledAnnotationReactiveSupport.SubscribingRunnable

extends Object
implements SchedulingAwareRunnable
Class Inheritance
  • java.lang.Object
  • org.springframework.scheduling.annotation.ScheduledAnnotationReactiveSupport.SubscribingRunnable
All Implemented Interfaces
org.springframework.scheduling.SchedulingAwareRunnable, java.lang.Runnable

Utility implementation of Runnable that subscribes to a Publisher or subscribes-then-blocks if shouldBlock is set to true.

Field Summary

Modifier and TypeField and Description
pack-priv final Supplier<ScheduledTaskObservationContext>
private static final ScheduledTaskObservationConvention
pack-priv final Supplier<ObservationRegistry>
private final Publisher<?>
private final String
pack-priv final boolean
private final List<Runnable>

Constructor Summary

AccessConstructor and Description
pack-priv
SubscribingRunnable(Publisher<?> publisher, boolean shouldBlock, String qualifier, List<Runnable> subscriptionTrackerRegistry, Supplier<ObservationRegistry> observationRegistrySupplier, Supplier<ScheduledTaskObservationContext> contextSupplier)

Method Summary

Modifier and TypeMethod and Description
public String
getQualifier()

Overrides default org.springframework.scheduling.SchedulingAwareRunnable.getQualifier.

Return a qualifier associated with this Runnable.

public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contextSupplierback to summary
pack-priv final Supplier<ScheduledTaskObservationContext> contextSupplier
DEFAULT_CONVENTIONback to summary
private static final ScheduledTaskObservationConvention DEFAULT_CONVENTION
observationRegistrySupplierback to summary
pack-priv final Supplier<ObservationRegistry> observationRegistrySupplier
publisherback to summary
private final Publisher<?> publisher
qualifierback to summary
private final String qualifier
Annotations
@Nullable
shouldBlockback to summary
pack-priv final boolean shouldBlock
subscriptionTrackerRegistryback to summary
private final List<Runnable> subscriptionTrackerRegistry

Constructor Detail

SubscribingRunnableback to summary
pack-priv SubscribingRunnable(Publisher<?> publisher, boolean shouldBlock, String qualifier, List<Runnable> subscriptionTrackerRegistry, Supplier<ObservationRegistry> observationRegistrySupplier, Supplier<ScheduledTaskObservationContext> contextSupplier)

Method Detail

getQualifierback to summary
public String getQualifier()

Overrides default org.springframework.scheduling.SchedulingAwareRunnable.getQualifier.

Doc from org.springframework.scheduling.SchedulingAwareRunnable.getQualifier.

Return a qualifier associated with this Runnable.

The default implementation returns null.

May be used for custom purposes depending on the scheduler implementation. org.springframework.scheduling.config.TaskSchedulerRouter introspects this qualifier in order to determine the target scheduler to be used for a given Runnable, matching the qualifier value (or the bean name) of a specific org.springframework.scheduling.TaskScheduler or java.util.concurrent.ScheduledExecutorService bean definition.

Annotations
@Override
@Nullable
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
subscribeback to summary
private void subscribe(ScheduledAnnotationReactiveSupport.TrackingSubscriber subscriber, Observation observation)
org.springframework.scheduling.annotation back to summary

private final Class ScheduledAnnotationReactiveSupport.TrackingSubscriber

extends Object
implements Subscriber<Object>, Runnable
Class Inheritance
  • java.lang.Object
  • org.springframework.scheduling.annotation.ScheduledAnnotationReactiveSupport.TrackingSubscriber
All Implemented Interfaces
java.lang.Runnable, org.reactivestreams.Subscriber

A Subscriber which keeps track of its Subscription and exposes the capacity to cancel the subscription as a Runnable. Can optionally support blocking if a CountDownLatch is supplied during construction.

Field Summary

Modifier and TypeField and Description
private final CountDownLatch
private final Observation
private Subscription
private final List<Runnable>

Constructor Summary

AccessConstructor and Description
pack-priv
TrackingSubscriber(List<Runnable> subscriptionTrackerRegistry, Observation observation)

pack-priv
TrackingSubscriber(List<Runnable> subscriptionTrackerRegistry, Observation observation, CountDownLatch latch)

Method Summary

Modifier and TypeMethod and Description
public void
onComplete()

Implements org.reactivestreams.Subscriber.onComplete.

Successful terminal state.

public void
onError(Throwable
the throwable signaled
ex
)

Implements org.reactivestreams.Subscriber.onError.

Failed terminal state.

public void
onNext(Object
the element signaled
obj
)

Implements org.reactivestreams.Subscriber.onNext.

Data notification sent by the Publisher in response to requests to Subscription#request(long).

public void
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blockingLatchback to summary
private final CountDownLatch blockingLatch
Annotations
@Nullable
observationback to summary
private final Observation observation
subscriptionback to summary
private Subscription subscription
Annotations
@Nullable
subscriptionTrackerRegistryback to summary
private final List<Runnable> subscriptionTrackerRegistry

Constructor Detail

TrackingSubscriberback to summary
pack-priv TrackingSubscriber(List<Runnable> subscriptionTrackerRegistry, Observation observation)
TrackingSubscriberback to summary
pack-priv TrackingSubscriber(List<Runnable> subscriptionTrackerRegistry, Observation observation, CountDownLatch latch)

Method Detail

onCompleteback to summary
public void onComplete()

Implements org.reactivestreams.Subscriber.onComplete.

Doc from org.reactivestreams.Subscriber.onComplete.

Successful terminal state.

No further events will be sent even if Subscription#request(long) is invoked again.

Annotations
@Override
onErrorback to summary
public void onError(Throwable ex)

Implements org.reactivestreams.Subscriber.onError.

Doc from org.reactivestreams.Subscriber.onError.

Failed terminal state.

No further events will be sent even if Subscription#request(long) is invoked again.

Parameters
ex:Throwable

the throwable signaled

Annotations
@Override
onNextback to summary
public void onNext(Object obj)

Implements org.reactivestreams.Subscriber.onNext.

Doc from org.reactivestreams.Subscriber.onNext.

Data notification sent by the Publisher in response to requests to Subscription#request(long).

Parameters
obj:Object

the element signaled

Annotations
@Override
onSubscribeback to summary
public void onSubscribe(Subscription subscription)

Implements org.reactivestreams.Subscriber.onSubscribe.

Doc from org.reactivestreams.Subscriber.onSubscribe.

Invoked after calling Publisher#subscribe(Subscriber).

No data will start flowing until Subscription#request(long) is invoked.

It is the responsibility of this Subscriber instance to call Subscription#request(long) whenever more data is wanted.

The Publisher will send notifications only in response to Subscription#request(long).

Parameters
subscription:Subscription

the Subscription that allows requesting data via Subscription#request(long)

Annotations
@Override
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override