services().
The global singleton instance is accessed via picoServices(). Note that optionally one can provide a
primordial bootstrap configuration to the Pico services provider. One must establish any bootstrap instance
prior to the first call to picoServices() as it will use a default configuration if not explicitly set. Once
the bootstrap has been set it cannot be changed for the lifespan of the JVM.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ServiceInfoCriteriaEmpty criteria will match anything and everything.static final ContextualServiceQueryDenotes a match to any (default) service, but required to be matched to at least one. -
Method Summary
Modifier and TypeMethodDescriptionOptionally, the service provider activation log.Returns theBootstrapconfiguration instance that was used to initialize this instance.config()The governing configuration.static ActivationRequestWill create an activation request either toPhase.ACTIVEor limited to anyBootstrap.limitRuntimePhase()specified.Retrieves any primordial bootstrap configuration that previously set.static voidglobalBootstrap(Bootstrap bootstrap) Sets the primordial bootstrap configuration that will supplypicoServices()during global singleton initialization.injector()Optionally, the injector.static booleanReturns true if debugging is enabled.lookups()Optionally, the set ofServiceslookup criteria that were recorded.metrics()Optionally, the metrics that are exposed by the provider implementation.static Optional<PicoServices>GetPicoServicesinstance if available.static BootstrapFirst attempts to locate and return theglobalBootstrap()and if not found will create a new bootstrap instance.static ServicesShort-cut for the following code block.default Servicesservices()The service registry.services(boolean initialize) The service registry.shutdown()Attempts to perform a gracefulInjector.deactivate(Object, InjectorOptions)on all managed service instances in theServicesregistry.static PhaseThe terminal phase for activation that we should not cross.Similar toservices(), but here if Pico is not available or the services registry has not yet been initialized then this method will returnOptional.empty().
-
Field Details
-
EMPTY_CRITERIA
Empty criteria will match anything and everything. -
SERVICE_QUERY_REQUIRED
Denotes a match to any (default) service, but required to be matched to at least one.
-
-
Method Details
-
bootstrap
Bootstrap bootstrap()Returns theBootstrapconfiguration instance that was used to initialize this instance.- Returns:
- the bootstrap configuration instance
-
isDebugEnabled
static boolean isDebugEnabled()Returns true if debugging is enabled.- Returns:
- true if debugging is enabled
- See Also:
-
globalBootstrap
Retrieves any primordial bootstrap configuration that previously set.- Returns:
- the bootstrap primordial configuration already assigned
- See Also:
-
realizedGlobalBootStrap
First attempts to locate and return theglobalBootstrap()and if not found will create a new bootstrap instance.- Returns:
- a bootstrap
-
globalBootstrap
Sets the primordial bootstrap configuration that will supplypicoServices()during global singleton initialization.- Parameters:
bootstrap- the primordial global bootstrap configuration- See Also:
-
picoServices
GetPicoServicesinstance if available. The highestWeightedservice will be loaded and returned. Remember to optionally configure any primordialBootstrapconfiguration prior to the first call to getPicoServices.- Returns:
- the Pico services instance
-
realizedServices
Short-cut for the following code block. During the first invocation theServicesregistry will be initialized.return picoServices().orElseThrow().services();- Returns:
- the services instance
-
unrealizedServices
Similar toservices(), but here if Pico is not available or the services registry has not yet been initialized then this method will returnOptional.empty(). This is convenience for users who conditionally want to use Pico's service registry if it is currently available and in active use, but if not do alternative processing or allocations directly, etc.- Returns:
- the services instance if it has already been activated and initialized, empty otherwise
-
services
The service registry. The first call typically loads and initializes the service registry. To avoid automatic loading and initialization on any first request then consider usingunrealizedServices()orservices(boolean).- Returns:
- the services registry
-
services
The service registry. The first call typically loads and initializes the service registry.- Parameters:
initialize- true to allow initialization applicable for the 1st request, false to prevent 1st call initialization- Returns:
- the services registry if it is available and already has been initialized, empty if not yet initialized
-
config
PicoServicesConfig config()The governing configuration.- Returns:
- the config
-
injector
Optionally, the injector.- Returns:
- the injector, or empty if not available
-
shutdown
Optional<Map<String,ActivationResult>> shutdown()Attempts to perform a gracefulInjector.deactivate(Object, InjectorOptions)on all managed service instances in theServicesregistry. Deactivation is handled within the current thread.If the service provider does not support shutdown an empty is returned.
The default reference implementation for Pico will return a map of all service types that were deactivated to any throwable that was observed during that services shutdown sequence.
The order in which services are deactivated is dependent upon whether the
activationLog()is available. If the activation log is available, then services will be shutdown in reverse chronological order as how they were started. If the activation log is not enabled or found to be empty then the deactivation will be in reverse order ofRunLevelfrom the highest value down to the lowest value. If two services share the sameRunLevelvalue then the ordering will be based upon the implementation's comparator.When shutdown returns, it is guaranteed that all services were shutdown, or failed to achieve shutdown.
- Returns:
- a map of all managed service types deactivated to results of deactivation, or empty if shutdown is not supported
-
activationLog
Optional<ActivationLog> activationLog()Optionally, the service provider activation log.- Returns:
- the injector, or empty if not available
-
metrics
Optionally, the metrics that are exposed by the provider implementation.- Returns:
- the metrics, or empty if not available
-
lookups
Optional<Set<ServiceInfoCriteria>> lookups()Optionally, the set ofServiceslookup criteria that were recorded. This is only available ifPicoServicesConfig.serviceLookupCaching()is enabled.- Returns:
- the lookup criteria recorded, or empty if not available
-
createDefaultActivationRequest
Will create an activation request either toPhase.ACTIVEor limited to anyBootstrap.limitRuntimePhase()specified.- Returns:
- the activation request
-
terminalActivationPhase
The terminal phase for activation that we should not cross.- Returns:
- the terminal phase for activation
-