Class CachingDiscoveryService<A extends ServiceInstance,B,C extends TrafficPolicy<A,B>>

java.lang.Object
io.inverno.mod.discovery.CachingDiscoveryService<A,B,C>
Type Parameters:
A - the type of service instance
B - the type of service request
C - the type of traffic policy
All Implemented Interfaces:
DiscoveryService<A,B,C>

public class CachingDiscoveryService<A extends ServiceInstance,B,C extends TrafficPolicy<A,B>> extends Object implements DiscoveryService<A,B,C>

A discovery service wrapper that caches services by service ID and traffic policy.

A service is uniquely identified by its service ID and the traffic policy that was used to resolve it. In order to prevent service instances from leaking, the caching discovery service caches resolved service instances by (serviceId, trafficPolicy) hash and periodically refreshes those instances to keep them up to date.

Since:
1.12
Author:
Jeremy Kuhn
  • Field Details

    • DEFAULT_TIME_TO_lIVE

      public static final long DEFAULT_TIME_TO_lIVE
      The default time to live in milliseconds.
      See Also:
  • Constructor Details

    • CachingDiscoveryService

      public CachingDiscoveryService(Reactor reactor, DiscoveryService<A,B,C> discoveryService)

      Creates a caching discovery service wrapping the specified discovery service.

      Parameters:
      reactor - the reactor
      discoveryService - the discovery service resolving services
    • CachingDiscoveryService

      public CachingDiscoveryService(Reactor reactor, DiscoveryService<A,B,C> discoveryService, long timeToLive)

      Creates a caching discovery service wrapping the specified discovery service refreshing services after the specified time to live.

      Parameters:
      reactor - the reactor
      discoveryService - the discovery service resolving services
      timeToLive - the service time to live in milliseconds
  • Method Details

    • supports

      public boolean supports(String scheme)
      Description copied from interface: DiscoveryService

      Determines whether the discovery service supports the specified scheme.

      Specified by:
      supports in interface DiscoveryService<A extends ServiceInstance,B,C extends TrafficPolicy<A,B>>
      Parameters:
      scheme - a URI scheme
      Returns:
      true if the discovery service can resolve service URI with the specified scheme, false otherwise
    • getSupportedSchemes

      public Set<String> getSupportedSchemes()
      Description copied from interface: DiscoveryService

      Returns the list of schemes supported by the discovery service.

      Specified by:
      getSupportedSchemes in interface DiscoveryService<A extends ServiceInstance,B,C extends TrafficPolicy<A,B>>
      Returns:
      a set of lower cased schemes
    • resolve

      public Mono<? extends Service<A,B,C>> resolve(ServiceID serviceId, C trafficPolicy)
      Description copied from interface: DiscoveryService

      Resolves a service.

      Specified by:
      resolve in interface DiscoveryService<A extends ServiceInstance,B,C extends TrafficPolicy<A,B>>
      Parameters:
      serviceId - a service ID
      trafficPolicy - a traffic policy
      Returns:
      a Mono emitting the resolved service or an empty Mono if no service could be resolved
    • shutdown

      public Mono<Void> shutdown()

      Shutdowns the discovery service.

      This basically shutdowns all cached services and free resources.

      Returns:
      a Mono which completes once the service is shutdown
    • shutdownGracefully

      public Mono<Void> shutdownGracefully()

      Gracefully shutdowns the discovery service.

      This basically gracefully shutdowns all cached services and free resources.

      Returns:
      a Mono which completes once the service is shutdown