Package uk.gov.gchq.gaffer.cache
Class CacheServiceLoader
- java.lang.Object
-
- uk.gov.gchq.gaffer.cache.CacheServiceLoader
-
public final class CacheServiceLoader extends Object
Initialised when the store is initialised. Looks at a system property to determine the cache service to load. Then initialises it, after which any component may useCacheServiceLoader.getService()
to get the service that can retrieve the appropriate cache.
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_SERVICE_NAME
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static ICacheService
getDefaultService()
Get the default cache service object.static ICacheService
getService()
Deprecated.Cache services should instead be fetched by name usinggetService(String)
, or by usinggetDefaultService()
.static ICacheService
getService(String serviceName)
Get the cache service identified by the supplied name.static void
initialise(String cacheClass)
Creates a default cache service using the supplied class name to initialise the service.static void
initialise(String serviceName, String cacheClass, Properties properties)
Creates a cache service identified by the given service name, using the supplied class name and properties to initialise the service.static void
initialise(Properties properties)
Deprecated.Instead useinitialise(String, String, Properties)
, or optionallyinitialise(String)
when writing tests.static boolean
isDefaultEnabled()
static boolean
isEnabled()
Deprecated.UseisDefaultEnabled()
instead, orisEnabled(String)
with a service name.static boolean
isEnabled(String serviceName)
static void
shutdown()
Gracefully shutdown and reset the cache service.
-
-
-
Field Detail
-
DEFAULT_SERVICE_NAME
public static final String DEFAULT_SERVICE_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
initialise
public static void initialise(String serviceName, String cacheClass, Properties properties)
Creates a cache service identified by the given service name, using the supplied class name and properties to initialise the service.Adds a shutdown hook which gracefully closes the cache service if JVM is stopped. This shouldn't be relied upon in a servlet context, instead use ServletLifecycleListener.
- Parameters:
serviceName
- name to identify the cache service to initialisecacheClass
- class name of the cache service provider to useproperties
- properties to pass to the cache service provider- Throws:
IllegalArgumentException
- if an invalid cache class is specified
-
initialise
public static void initialise(String cacheClass)
Creates a default cache service using the supplied class name to initialise the service. No properties are passed to the cache service, this is primarily a convenience method. Seeinitialise(String, String, Properties)
for further details.- Parameters:
cacheClass
- class name of the cache service provider to use- Throws:
IllegalArgumentException
- if an invalid cache class is specified
-
getDefaultService
public static ICacheService getDefaultService()
Get the default cache service object.- Returns:
- the default cache service
-
getService
public static ICacheService getService(String serviceName)
Get the cache service identified by the supplied name.- Parameters:
serviceName
- name identifying the cache service- Returns:
- the cache service
-
isDefaultEnabled
public static boolean isDefaultEnabled()
- Returns:
- true if the default cache service is enabled
-
isEnabled
public static boolean isEnabled(String serviceName)
- Parameters:
serviceName
- name identifying a cache service- Returns:
- true if a cache service with that name exists (and is therefore enabled)
-
initialise
@Deprecated public static void initialise(Properties properties)
Deprecated.Instead useinitialise(String, String, Properties)
, or optionallyinitialise(String)
when writing tests.Looks at a system property and initialises an appropriate cache service. Adds a shutdown hook which gracefully closes the cache service if JVM is stopped. This should not be relied upon in a servlet context - use the ServletLifecycleListener located in the REST module instead.- Parameters:
properties
- the cache service properties- Throws:
IllegalArgumentException
- if an invalid cache class is specified in the system property
-
getService
@Deprecated public static ICacheService getService()
Deprecated.Cache services should instead be fetched by name usinggetService(String)
, or by usinggetDefaultService()
.Get the default cache service object.- Returns:
- the default cache service
-
isEnabled
@Deprecated public static boolean isEnabled()
Deprecated.UseisDefaultEnabled()
instead, orisEnabled(String)
with a service name.- Returns:
- true if the default cache is enabled
-
shutdown
public static void shutdown()
Gracefully shutdown and reset the cache service.
-
-