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
Fields -
Constructor Summary
Constructors -
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.longReturns 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:ServiceReturns the service ID.
- Specified by:
getIDin interfaceService<A extends ServiceInstance,B, C extends TrafficPolicy<A, B>> - Returns:
- the service ID
-
getTrafficPolicy
Description copied from interface:ServiceReturns the traffic policy.
- Specified by:
getTrafficPolicyin interfaceService<A extends ServiceInstance,B, C extends TrafficPolicy<A, B>> - Returns:
- the traffic policy
-
getInstance
Description copied from interface:ServiceReturns 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
Monoshall then be returned.- Specified by:
getInstancein interfaceService<A extends ServiceInstance,B, C extends TrafficPolicy<A, B>> - Parameters:
serviceRequest- a service request- Returns:
- a
Monoemitting the instance to use to process the service request or an emptyMonoif no instance matching the request could be found
-
getInstances
Description copied from interface:ManageableServiceReturns the service instances.
- Specified by:
getInstancesin 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:
refreshin interfaceService<A extends ServiceInstance,B, C extends TrafficPolicy<A, B>> - Parameters:
trafficPolicy- a traffic policy- Returns:
- a
Monoemitting a refreshed service or an emptyMonoif 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:ServiceReturns the refreshed time stamp.
- Specified by:
getLastRefreshedin interfaceService<A extends ServiceInstance,B, C extends TrafficPolicy<A, B>> - Returns:
- an epoch time in milliseconds
-
shutdown
Description copied from interface:ServiceShutdowns the service.
This basically shutdowns all service instances and free resources.
- Specified by:
shutdownin interfaceService<A extends ServiceInstance,B, C extends TrafficPolicy<A, B>> - Returns:
- a
Monowhich completes once the service is shutdown
-
shutdownGracefully
Description copied from interface:ServiceGracefully shutdowns the service.
This basically gracefully shutdowns all service instances and free resources.
- Specified by:
shutdownGracefullyin interfaceService<A extends ServiceInstance,B, C extends TrafficPolicy<A, B>> - Returns:
- a
Monowhich completes once the service is shutdown
-