public abstract class AbstractCacheService extends Object implements ICacheService, PreJoinAwareService, PartitionAwareService, QuorumAwareService, SplitBrainHandlerService, ClusterStateListener
CACHE_SUPPORT_NOT_AVAILABLE_ERROR_MESSAGE, MAX_ADD_CACHE_CONFIG_RETRIES, SERVICE_NAME
Constructor and Description |
---|
AbstractCacheService() |
Modifier and Type | Method and Description |
---|---|
void |
addCacheResource(String cacheNameWithPrefix,
Closeable resource) |
String |
addInvalidationListener(String cacheNameWithPrefix,
CacheEventListener listener,
boolean localOnly)
Registers and
CacheEventListener for specified cacheNameWithPrefix |
void |
beforeMigration(PartitionMigrationEvent event)
Called before migration process starts, on both source and destination members.
|
void |
cacheEntryListenerDeregistered(String name,
javax.cache.configuration.CacheEntryListenerConfiguration cacheEntryListenerConfiguration) |
void |
cacheEntryListenerRegistered(String name,
javax.cache.configuration.CacheEntryListenerConfiguration cacheEntryListenerConfiguration) |
protected void |
closeSegments(String name) |
void |
commitMigration(PartitionMigrationEvent event)
Commits the migration process for this service, on both source and destination members.
|
<K,V> void |
createCacheConfigOnAllMembers(PreJoinCacheConfig<K,V> cacheConfig)
Creates the given CacheConfig on all members of the cluster synchronously.
|
<K,V> ICompletableFuture |
createCacheConfigOnAllMembersAsync(PreJoinCacheConfig<K,V> cacheConfig) |
CacheStatisticsImpl |
createCacheStatIfAbsent(String cacheNameWithPrefix) |
DistributedObject |
createDistributedObject(String cacheNameWithPrefix)
Creates a distributed object.
|
protected abstract ICacheRecordStore |
createNewRecordStore(String cacheNameWithPrefix,
int partitionId) |
protected abstract CacheOperationProvider |
createOperationProvider(String nameWithPrefix,
InMemoryFormat inMemoryFormat) |
void |
deleteCache(String cacheNameWithPrefix,
String callerUuid,
boolean destroy) |
CacheConfig |
deleteCacheConfig(String cacheNameWithPrefix) |
protected void |
deleteCacheResources(String name) |
void |
deleteCacheStat(String cacheNameWithPrefix) |
void |
deregisterAllListener(String cacheNameWithPrefix) |
boolean |
deregisterListener(String cacheNameWithPrefix,
String registrationId) |
void |
destroyDistributedObject(String objectName)
Destroys a distributed object.
|
protected void |
destroySegments(CacheConfig cacheConfig) |
void |
dispatchEvent(Object event,
CacheEventListener listener)
Notifies the service of a published event.
|
CacheConfig |
findCacheConfig(String simpleName) |
CacheConfig |
getCacheConfig(String cacheNameWithPrefix) |
Collection<CacheConfig> |
getCacheConfigs() |
CacheContext |
getCacheContext(String name) |
CacheEventHandler |
getCacheEventHandler() |
CacheOperationProvider |
getCacheOperationProvider(String cacheNameWithPrefix,
InMemoryFormat inMemoryFormat)
Creates cache operations according to the storage-type of the cache
|
ConcurrentMap<String,CacheConfig> |
getConfigs() |
CacheEventJournal |
getEventJournal()
Returns an interface for interacting with the cache event journals.
|
ExpirationManager |
getExpirationManager() |
Object |
getMergePolicy(String name) |
CacheMergePolicyProvider |
getMergePolicyProvider() |
NodeEngine |
getNodeEngine() |
CacheContext |
getOrCreateCacheContext(String cacheNameWithPrefix) |
ICacheRecordStore |
getOrCreateRecordStore(String cacheNameWithPrefix,
int partitionId)
Gets or creates a cache record store with the prefixed
cacheNameWithPrefix
and partition ID. |
CachePartitionSegment[] |
getPartitionSegments() |
Operation |
getPreJoinOperation()
An operation to be executed on the joining member before it is set as joined.
|
String |
getQuorumName(String cacheName)
Gets the name of the quorum associated with specified cache
|
ICacheRecordStore |
getRecordStore(String cacheNameWithPrefix,
int partitionId)
Returns a cache record store with the prefixed
cacheNameWithPrefix and partition ID
or null if one doesn't exist. |
CachePartitionSegment |
getSegment(int partitionId) |
CacheStatisticsImpl |
getStatistics(String cacheNameWithPrefix) |
void |
init(NodeEngine nodeEngine,
Properties properties)
Initializes this service.
|
protected abstract CachePartitionSegment |
newPartitionSegment(int partitionId) |
void |
onClusterStateChange(ClusterState newState)
Called when cluster state is changed
|
void |
onPartitionLost(IPartitionLostEvent partitionLostEvent)
Invoked when a partition lost is detected
|
protected void |
postInit(NodeEngine nodeEngine,
Properties properties) |
Runnable |
prepareMergeRunnable()
When the two separate clusters merge (resolve a split-brain), this method is called to return
a
Runnable , that will merge the clusters. |
protected void |
publishCachePartitionLostEvent(String cacheName,
int partitionId) |
void |
publishEvent(CacheEventContext cacheEventContext) |
void |
publishEvent(String cacheNameWithPrefix,
CacheEventSet eventSet,
int orderKey) |
CacheConfig |
putCacheConfigIfAbsent(CacheConfig config) |
String |
registerListener(String cacheNameWithPrefix,
CacheEventListener listener,
boolean isLocal) |
String |
registerListener(String cacheNameWithPrefix,
CacheEventListener listener,
EventFilter eventFilter,
boolean isLocal) |
protected String |
registerListenerInternal(String cacheNameWithPrefix,
CacheEventListener listener,
EventFilter eventFilter,
boolean isLocal) |
void |
reset()
Resets this service back to its initial state.
|
void |
rollbackMigration(PartitionMigrationEvent event)
Rollback the migration process for this service, on both source and destination members.
|
void |
sendInvalidationEvent(String cacheNameWithPrefix,
Data key,
String sourceUuid)
Sends an invalidation event for given
cacheName with specified key
from mentioned source with sourceUuid . |
void |
setManagementEnabled(CacheConfig cacheConfig,
String cacheNameWithPrefix,
boolean enabled) |
void |
setStatisticsEnabled(CacheConfig cacheConfig,
String cacheNameWithPrefix,
boolean enabled) |
void |
setTenantControl(CacheConfig cacheConfig) |
void |
shutdown(boolean terminate)
Shuts down this service.
|
Data |
toData(Object object) |
Object |
toObject(Object data) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getCacheWanEventPublisher, isWanReplicationEnabled
getAllServiceNamespaces, isKnownServiceNamespace, prepareReplicationOperation
prepareReplicationOperation
public static final String TENANT_CONTROL_FACTORY
protected final ConcurrentMap<String,CacheConfig> configs
CacheConfig
protected final ConcurrentMap<String,CacheContext> cacheContexts
CacheContext
protected final ConcurrentMap<String,CacheStatisticsImpl> statistics
CacheStatisticsImpl
protected final ConcurrentMap<String,Set<Closeable>> resources
Closeable
resourcesprotected final ConcurrentMap<String,Closeable> closeableListeners
protected final ConcurrentMap<String,CacheOperationProvider> operationProviderCache
protected final ConstructorFunction<String,CacheContext> cacheContextsConstructorFunction
protected final ConstructorFunction<String,CacheStatisticsImpl> cacheStatisticsConstructorFunction
protected final ContextMutexFactory cacheResourcesMutexFactory
protected final ConstructorFunction<String,Set<Closeable>> cacheResourcesConstructorFunction
protected ILogger logger
protected NodeEngine nodeEngine
protected CachePartitionSegment[] segments
protected CacheEventHandler cacheEventHandler
protected RingbufferCacheEventJournalImpl eventJournal
protected CacheMergePolicyProvider mergePolicyProvider
protected com.hazelcast.cache.impl.CacheSplitBrainHandlerService splitBrainHandlerService
protected CacheClearExpiredRecordsTask clearExpiredRecordsTask
protected ExpirationManager expirationManager
public final void init(NodeEngine nodeEngine, Properties properties)
ManagedService
init
in interface ManagedService
nodeEngine
- the NodeEngine that this service belongs toproperties
- the Properties (can be used to pass settings to the service)public CacheMergePolicyProvider getMergePolicyProvider()
public ConcurrentMap<String,CacheConfig> getConfigs()
protected void postInit(NodeEngine nodeEngine, Properties properties)
protected abstract CachePartitionSegment newPartitionSegment(int partitionId)
protected abstract ICacheRecordStore createNewRecordStore(String cacheNameWithPrefix, int partitionId)
public void reset()
ManagedService
TODO: what is the purpose of reset
reset
in interface ManagedService
public void shutdown(boolean terminate)
ManagedService
TODO: what is the purpose of the terminate variable
shutdown
in interface ManagedService
terminate
- true
to shut down this servicepublic CachePartitionSegment[] getPartitionSegments()
getPartitionSegments
in interface ICacheService
public DistributedObject createDistributedObject(String cacheNameWithPrefix)
RemoteService
createDistributedObject
in interface RemoteService
cacheNameWithPrefix
- the name for the created distributed objectpublic void destroyDistributedObject(String objectName)
RemoteService
destroyDistributedObject
in interface RemoteService
objectName
- the name of the distributed object to destroypublic void beforeMigration(PartitionMigrationEvent event)
MigrationAwareService
Service can take actions required before migration. Migration process will block until this method returns. If this method fails by throwing an exception, migration process for specific partition will fail and will be rolled back.
beforeMigration
in interface MigrationAwareService
event
- migration eventpublic void commitMigration(PartitionMigrationEvent event)
MigrationAwareService
Commit is not expected to fail at this point, all exceptions will be suppressed and logged. Implementations of this method must be thread safe as this method may be called concurrently for different migrations on different partitions.
commitMigration
in interface MigrationAwareService
event
- migration eventpublic void rollbackMigration(PartitionMigrationEvent event)
MigrationAwareService
Rollback is not expected to fail at this point, all exceptions will be suppressed and logged. Implementations of this method must be thread safe as this method may be called concurrently for different migrations on different partitions.
rollbackMigration
in interface MigrationAwareService
event
- migration eventpublic ICacheRecordStore getOrCreateRecordStore(String cacheNameWithPrefix, int partitionId)
ICacheService
cacheNameWithPrefix
and partition ID.getOrCreateRecordStore
in interface ICacheService
cacheNameWithPrefix
- the full name of the ICache
, including the manager scope prefixpartitionId
- the record store partition IDpublic ICacheRecordStore getRecordStore(String cacheNameWithPrefix, int partitionId)
ICacheService
cacheNameWithPrefix
and partition ID
or null
if one doesn't exist.getRecordStore
in interface ICacheService
cacheNameWithPrefix
- the full name of the ICache
, including the manager scope prefixpartitionId
- the record store partition IDnull
if it doesn't existpublic CachePartitionSegment getSegment(int partitionId)
getSegment
in interface ICacheService
protected void destroySegments(CacheConfig cacheConfig)
protected void closeSegments(String name)
public void deleteCache(String cacheNameWithPrefix, String callerUuid, boolean destroy)
deleteCache
in interface ICacheService
public CacheConfig putCacheConfigIfAbsent(CacheConfig config)
putCacheConfigIfAbsent
in interface ICacheService
public CacheConfig deleteCacheConfig(String cacheNameWithPrefix)
deleteCacheConfig
in interface ICacheService
public ExpirationManager getExpirationManager()
getExpirationManager
in interface ICacheService
public CacheStatisticsImpl createCacheStatIfAbsent(String cacheNameWithPrefix)
createCacheStatIfAbsent
in interface ICacheService
public CacheContext getCacheContext(String name)
public CacheContext getOrCreateCacheContext(String cacheNameWithPrefix)
getOrCreateCacheContext
in interface ICacheService
public void deleteCacheStat(String cacheNameWithPrefix)
deleteCacheStat
in interface ICacheService
public void setStatisticsEnabled(CacheConfig cacheConfig, String cacheNameWithPrefix, boolean enabled)
setStatisticsEnabled
in interface ICacheService
public void setManagementEnabled(CacheConfig cacheConfig, String cacheNameWithPrefix, boolean enabled)
setManagementEnabled
in interface ICacheService
public CacheConfig getCacheConfig(String cacheNameWithPrefix)
getCacheConfig
in interface ICacheService
public CacheConfig findCacheConfig(String simpleName)
findCacheConfig
in interface ICacheService
public void setTenantControl(CacheConfig cacheConfig)
setTenantControl
in interface ICacheService
public Collection<CacheConfig> getCacheConfigs()
getCacheConfigs
in interface ICacheService
public void publishEvent(CacheEventContext cacheEventContext)
publishEvent
in interface ICacheService
public void publishEvent(String cacheNameWithPrefix, CacheEventSet eventSet, int orderKey)
publishEvent
in interface ICacheService
public NodeEngine getNodeEngine()
getNodeEngine
in interface ICacheService
public void dispatchEvent(Object event, CacheEventListener listener)
EventPublishingService
dispatchEvent
in interface EventPublishingService<Object,CacheEventListener>
event
- the published eventlistener
- the listener registered for this eventpublic String registerListener(String cacheNameWithPrefix, CacheEventListener listener, boolean isLocal)
registerListener
in interface ICacheService
public String registerListener(String cacheNameWithPrefix, CacheEventListener listener, EventFilter eventFilter, boolean isLocal)
registerListener
in interface ICacheService
protected String registerListenerInternal(String cacheNameWithPrefix, CacheEventListener listener, EventFilter eventFilter, boolean isLocal)
public boolean deregisterListener(String cacheNameWithPrefix, String registrationId)
deregisterListener
in interface ICacheService
public void deregisterAllListener(String cacheNameWithPrefix)
deregisterAllListener
in interface ICacheService
public CacheStatisticsImpl getStatistics(String cacheNameWithPrefix)
getStatistics
in interface ICacheService
public CacheOperationProvider getCacheOperationProvider(String cacheNameWithPrefix, InMemoryFormat inMemoryFormat)
ICacheService
getCacheOperationProvider
in interface ICacheService
protected abstract CacheOperationProvider createOperationProvider(String nameWithPrefix, InMemoryFormat inMemoryFormat)
protected void deleteCacheResources(String name)
public Operation getPreJoinOperation()
PreJoinAwareService
PostJoinAwareService.getPostJoinOperation()
s, no partition locks, no key-based locks, no service level
locks, no database interaction are allowed. Additionally, a pre-join operation is executed while the cluster
lock is being held on the joining member, so it is important that the operation finishes quickly and does not
interact with other locks.
The Operation.getPartitionId()
method should return a negative value.
This means that the operations should not implement PartitionAwareOperation
.
Pre join operations should return response, which may also be a null
response.
getPreJoinOperation
in interface PreJoinAwareService
null
.protected void publishCachePartitionLostEvent(String cacheName, int partitionId)
public void onPartitionLost(IPartitionLostEvent partitionLostEvent)
PartitionAwareService
onPartitionLost
in interface PartitionAwareService
partitionLostEvent
- The event object that contains the partition ID and the number of replicas that is lostpublic void cacheEntryListenerRegistered(String name, javax.cache.configuration.CacheEntryListenerConfiguration cacheEntryListenerConfiguration)
public void cacheEntryListenerDeregistered(String name, javax.cache.configuration.CacheEntryListenerConfiguration cacheEntryListenerConfiguration)
public String getQuorumName(String cacheName)
getQuorumName
in interface QuorumAwareService
cacheName
- name of the cachepublic String addInvalidationListener(String cacheNameWithPrefix, CacheEventListener listener, boolean localOnly)
CacheEventListener
for specified cacheNameWithPrefix
addInvalidationListener
in interface ICacheService
cacheNameWithPrefix
- the full name of the cache (including manager scope prefix)
that CacheEventListener
will be registered forlistener
- the CacheEventListener
to be registered
for specified cacheNameWithPrefix
localOnly
- true if only events originated from this member wants be listened, false if all
invalidation events in the cluster wants to be listenedpublic void sendInvalidationEvent(String cacheNameWithPrefix, Data key, String sourceUuid)
cacheName
with specified key
from mentioned source with sourceUuid
.sendInvalidationEvent
in interface ICacheService
cacheNameWithPrefix
- the name of the cache that invalidation event is sent forkey
- the Data
represents the invalidation eventsourceUuid
- an ID that represents the source for invalidation eventpublic Runnable prepareMergeRunnable()
SplitBrainHandlerService
Runnable
, that will merge the clusters.prepareMergeRunnable
in interface SplitBrainHandlerService
Runnable
that will merge the clusterspublic CacheEventHandler getCacheEventHandler()
public CacheEventJournal getEventJournal()
ICacheService
getEventJournal
in interface ICacheService
public <K,V> void createCacheConfigOnAllMembers(PreJoinCacheConfig<K,V> cacheConfig)
ICacheService
createCacheConfigOnAllMembers
in interface ICacheService
K
- key type parameterV
- value type parametercacheConfig
- the cache config to create on all members of the clusterpublic <K,V> ICompletableFuture createCacheConfigOnAllMembersAsync(PreJoinCacheConfig<K,V> cacheConfig)
public void onClusterStateChange(ClusterState newState)
ClusterStateListener
onClusterStateChange
in interface ClusterStateListener
newState
- new cluster stateClusterState
Copyright © 2021 Hazelcast, Inc.. All Rights Reserved.