Class CachingDiscoveryService<A extends ServiceInstance,B,C extends TrafficPolicy<A,B>>
- Type Parameters:
A
- the type of service instanceB
- the type of service requestC
- the type of traffic policy
- All Implemented Interfaces:
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 Summary
Modifier and TypeFieldDescriptionstatic final long
The default time to live in milliseconds. -
Constructor Summary
ConstructorDescriptionCachingDiscoveryService
(Reactor reactor, DiscoveryService<A, B, C> discoveryService) Creates a caching discovery service wrapping the specified discovery service.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. -
Method Summary
Modifier and TypeMethodDescriptionReturns the list of schemes supported by the discovery service.Resolves a service.shutdown()
Shutdowns the discovery service.Gracefully shutdowns the discovery service.boolean
Determines whether the discovery service supports the specified scheme.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.inverno.mod.discovery.DiscoveryService
supports, supports
-
Field Details
-
DEFAULT_TIME_TO_lIVE
public static final long DEFAULT_TIME_TO_lIVEThe default time to live in milliseconds.- See Also:
-
-
Constructor Details
-
CachingDiscoveryService
Creates a caching discovery service wrapping the specified discovery service.
- Parameters:
reactor
- the reactordiscoveryService
- 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 reactordiscoveryService
- the discovery service resolving servicestimeToLive
- the service time to live in milliseconds
-
-
Method Details
-
supports
Description copied from interface:DiscoveryService
Determines whether the discovery service supports the specified scheme.
- Specified by:
supports
in interfaceDiscoveryService<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
Description copied from interface:DiscoveryService
Returns the list of schemes supported by the discovery service.
- Specified by:
getSupportedSchemes
in interfaceDiscoveryService<A extends ServiceInstance,
B, C extends TrafficPolicy<A, B>> - Returns:
- a set of lower cased schemes
-
resolve
Description copied from interface:DiscoveryService
Resolves a service.
- Specified by:
resolve
in interfaceDiscoveryService<A extends ServiceInstance,
B, C extends TrafficPolicy<A, B>> - Parameters:
serviceId
- a service IDtrafficPolicy
- a traffic policy- Returns:
- a
Mono
emitting the resolved service or an emptyMono
if no service could be resolved
-
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
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
-