Interface Service<A extends ServiceInstance,B,C extends TrafficPolicy<A,B>>

Type Parameters:
A - the type of service instance
B - the type of service request
C - the type of traffic policy
All Known Subinterfaces:
ManageableService<A,B,C>
All Known Implementing Classes:
AbstractConfigurationService, AbstractService

public interface Service<A extends ServiceInstance,B,C extends TrafficPolicy<A,B>>

A service is resolved by a DiscoveryService, it gives access to one or more ServiceInstance that are eventually used to process a service request.

It is uniquely identified by a ServiceID and a TrafficPolicy specified which are specified when resolving a service using a discovery service. The traffic policy can convey specific configuration for the creation of the service instances and/or specify how a service should assign service instances to process requests as for instance load balancing strategy, content based routing...

A service is obtained from a DiscoveryService, it is uniquely identified by the ServiceID and TrafficPolicy passed to the discovery service. A traffic policy can provide specific configuration for the creation of service instances and/or specify how service instances are selected to process requests. The getInstance(Object) method resolves the service instance to use to process a particular service request at a particular time based on the traffic policy. Depending on the implementation, service instances can be load balanced, matched against some request criteria (i.e. content based routing), request can be transformed (e.g. path translation, headers manipulation...)...

A service can be refreshed in order to update the list of service instances or change the traffic policy.

Since:
1.12
Author:
Jeremy Kuhn
See Also:
  • Method Details

    • getID

      ServiceID getID()

      Returns the service ID.

      Returns:
      the service ID
    • getTrafficPolicy

      C getTrafficPolicy()

      Returns the traffic policy.

      Returns:
      the traffic policy
    • getInstance

      Mono<? extends A> getInstance(B serviceRequest)

      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.

      Parameters:
      serviceRequest - a service request
      Returns:
      a Mono emitting the instance to use to process the service request or an empty Mono if no instance matching the request could be found
    • refresh

      default Mono<? extends Service<A,B,C>> refresh()

      Refreshes the service.

      This basically refreshes the list of service instances. When no service instance could be resolved, the service is assumed to be gone and an empty Mono shall be returned.

      Whether a new instance is returned or not is implementation specific.

      Returns:
      a Mono emitting a refreshed service or an empty Mono if no service instance could be resolved
    • refresh

      Mono<? extends Service<A,B,C>> refresh(C trafficPolicy)

      Refreshes the service using the specified traffic policy.

      This basically refreshes the list of service instances using the specified traffic policy. When no service instance could be resolved, the service is assumed to be gone and an empty Mono shall be returned.

      Whether a new instance is returned or not is implementation specific.

      Parameters:
      trafficPolicy - a traffic policy
      Returns:
      a Mono emitting a refreshed service or an empty Mono if no service instance could be resolved
    • getLastRefreshed

      long getLastRefreshed()

      Returns the refreshed time stamp.

      Returns:
      an epoch time in milliseconds
    • shutdown

      Mono<Void> shutdown()

      Shutdowns the service.

      This basically shutdowns all service instances and free resources.

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

      Mono<Void> shutdownGracefully()

      Gracefully shutdowns the service.

      This basically gracefully shutdowns all service instances and free resources.

      Returns:
      a Mono which completes once the service is shutdown