Package net.solarnetwork.service
Interface OptionalService<T>
- Type Parameters:
T- the tracked service type
- All Known Subinterfaces:
OptionalService.OptionalFilterableService<T>
- All Known Implementing Classes:
FallbackOptionalService,StaticOptionalService
public interface OptionalService<T>
API for an "optional" service.
This API is like a simplified OSGi ServiceTracker. Calling the
service() method will return the first available matching service,
or null if none available.
- Version:
- 2.0
- Author:
- matt
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA convenient configurable optional service. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TrequiredService(OptionalService<T> optional) Resolve a required optional service, throwing an exception if not available.static <T> TrequiredService(OptionalService<T> optional, String description) Resolve a required optional service, throwing an exception if not available.service()Get the configured service, or null if none available.static <T> Tservice(OptionalService<T> optional) Resolve an optional service.static <T> Tservice(OptionalService<T> optional, T fallback) Resolve an optional service with a fallback.
-
Method Details
-
service
T service()Get the configured service, or null if none available.- Returns:
- the service, or null
-
service
Resolve an optional service.This method is a convenient way to deal with a possibly null
OptionalService.- Type Parameters:
T- the service type- Parameters:
optional- the optional service, or null- Returns:
- the resolved service, or null
- Since:
- 1.1
-
service
Resolve an optional service with a fallback.This method is a convenient way to deal with a possibly null
OptionalService.- Type Parameters:
T- the service type- Parameters:
optional- the optional service, or nullfallback- the result to return ifoptionalis null or its resolved service is null- Returns:
- the resolved service, or
fallback - Since:
- 1.1
-
requiredService
Resolve a required optional service, throwing an exception if not available.- Type Parameters:
T- the service type- Parameters:
optional- the optional service, or null- Returns:
- the resolved service, never null
- Throws:
OptionalServiceNotAvailableException- if the service can not be resolved- Since:
- 2.0
-
requiredService
Resolve a required optional service, throwing an exception if not available.- Type Parameters:
T- the service type- Parameters:
optional- the optional service, or nulldescription- a description to use if the service can not be resolved, or null- Returns:
- the resolved service, never null
- Throws:
OptionalServiceNotAvailableException- if the service can not be resolved- Since:
- 2.0
-