Class AbstractService<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:
ManageableService<A,
,B, C> Service<A,
B, C>
Base Service
implementation.
- Since:
- 1.12
- Author:
- Jeremy Kuhn
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetID()
Returns the service ID.getInstance
(B serviceRequest) Returns a service instance for processing the specified service request.Returns the service instances.long
Returns the refreshed time stamp.Returns the traffic policy.Refreshes the service instances keeping the pre-existing instances, creating added instances and closing removed instances.resolveInstances
(C trafficPolicy) Resolves and returns the service instances using the specified traffic policy.shutdown()
Shutdowns the service.Gracefully shutdowns the service.
-
Field Details
-
serviceId
The service ID.
-
-
Constructor Details
-
AbstractService
Creates a service.
- Parameters:
serviceId
- the service ID
-
-
Method Details
-
getID
Description copied from interface:Service
Returns the service ID.
- Specified by:
getID
in interfaceService<A extends ServiceInstance,
B, C extends TrafficPolicy<A, B>> - Returns:
- the service ID
-
getTrafficPolicy
Description copied from interface:Service
Returns the traffic policy.
- Specified by:
getTrafficPolicy
in interfaceService<A extends ServiceInstance,
B, C extends TrafficPolicy<A, B>> - Returns:
- the traffic policy
-
getInstance
Description copied from interface:Service
Returns a service instance for processing the specified service request.
Implementations should typically rely on the service traffic policy to determine which instance should be assigned to process a particular request. A typical use case is service load balancing where a service is deployed on multiple servers and requests must be distributed among these servers in a random or round robin fashion, by taking the server load into account...
Implementations can also assign instances based on the content of the request in which case it is possible that no service instance could match the request and an empty
Mono
shall then be returned.- Specified by:
getInstance
in interfaceService<A extends ServiceInstance,
B, C extends TrafficPolicy<A, B>> - Parameters:
serviceRequest
- a service request- Returns:
- a
Mono
emitting the instance to use to process the service request or an emptyMono
if no instance matching the request could be found
-
getInstances
Description copied from interface:ManageableService
Returns the service instances.
- Specified by:
getInstances
in interfaceManageableService<A extends ServiceInstance,
B, C extends TrafficPolicy<A, B>> - Returns:
- a list of service instances
-
refresh
Refreshes the service instances keeping the pre-existing instances, creating added instances and closing removed instances.
The load balancer is eventually recreated with the refreshed list of instances.
- Specified by:
refresh
in interfaceService<A extends ServiceInstance,
B, C extends TrafficPolicy<A, B>> - Parameters:
trafficPolicy
- a traffic policy- Returns:
- a
Mono
emitting a refreshed service or an emptyMono
if no service instance could be resolved - See Also:
-
resolveInstances
Resolves and returns the service instances using the specified traffic policy.
The traffic policy must be considered to uniquely identify a service instance as it might impact how a service instance is eventually created. For instance, considering a server instance, it is uniquely identified by an Inet Socket Address and the traffic policy which specifies how to connect to the server. Such identifier is typically obtained with
Objects.hash(address, trafficPolicy)
.- Parameters:
trafficPolicy
- a traffic policy- Returns:
- a map with unique service instance identifiers as key and service instance provider as value
-
getLastRefreshed
public long getLastRefreshed()Description copied from interface:Service
Returns the refreshed time stamp.
- Specified by:
getLastRefreshed
in interfaceService<A extends ServiceInstance,
B, C extends TrafficPolicy<A, B>> - Returns:
- an epoch time in milliseconds
-
shutdown
Description copied from interface:Service
Shutdowns the service.
This basically shutdowns all service instances and free resources.
- Specified by:
shutdown
in interfaceService<A extends ServiceInstance,
B, C extends TrafficPolicy<A, B>> - Returns:
- a
Mono
which completes once the service is shutdown
-
shutdownGracefully
Description copied from interface:Service
Gracefully shutdowns the service.
This basically gracefully shutdowns all service instances and free resources.
- Specified by:
shutdownGracefully
in interfaceService<A extends ServiceInstance,
B, C extends TrafficPolicy<A, B>> - Returns:
- a
Mono
which completes once the service is shutdown
-