Package org.hibernate.service
Interface ServiceRegistry
-
- All Superinterfaces:
AutoCloseable
- All Known Subinterfaces:
BootstrapServiceRegistry
,ServiceRegistryImplementor
,SessionFactoryServiceRegistry
,StandardServiceRegistry
- All Known Implementing Classes:
AbstractServiceRegistryImpl
,BootstrapServiceRegistryImpl
,ServiceRegistryTestingImpl
,SessionFactoryServiceRegistryImpl
,StandardServiceRegistryImpl
public interface ServiceRegistry extends AutoCloseable
A registry of services. This interface abstracts the operations of:- bootstrap service registries, which may be obtained from a
BootstrapServiceRegistryBuilder
, and - standard service registries, which may be obtained from a
StandardServiceRegistryBuilder
.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
close()
@Nullable ServiceRegistry
getParentServiceRegistry()
Retrieve this registry's parent registry.<R extends Service>
@Nullable RgetService(Class<R> serviceRole)
Retrieve a service by role, returning null if there is no such service.default <R extends Service>
RrequireService(Class<R> serviceRole)
Retrieve a service by role, throwing an exception if there is no such service.
-
-
-
Method Detail
-
getParentServiceRegistry
@Nullable ServiceRegistry getParentServiceRegistry()
Retrieve this registry's parent registry.- Returns:
- The parent registry. May be null.
-
getService
<R extends Service> @Nullable R getService(Class<R> serviceRole)
Retrieve a service by role, returning null if there is no such service. If service is not found, but aServiceInitiator
is registered for this service role, the service will be initialized and returned. Most of the time, use ofrequireService(Class)
is preferred, being much less likely to cause aNullPointerException
in the client.- Type Parameters:
R
- The service role type- Parameters:
serviceRole
- The service role- Returns:
- The requested service or null if the service was not found.
- Throws:
UnknownServiceException
- Indicates the service was not known.- API Note:
- We cannot return
<R extends Service<T>>
here because the service might come from the parent.
-
requireService
default <R extends Service> R requireService(Class<R> serviceRole)
Retrieve a service by role, throwing an exception if there is no such service. If service is not found, but aServiceInitiator
is registered for this service role, the service will be initialized and returned.- Type Parameters:
R
- The service role type- Parameters:
serviceRole
- The service role- Returns:
- The requested service .
- Throws:
UnknownServiceException
- Indicates the service was not known.NullServiceException
- Indicates the service was null.- API Note:
- We cannot return
<R extends Service<T>>
here because the service might come from the parent.
-
close
void close()
- Specified by:
close
in interfaceAutoCloseable
-
-