public class RingbufferService extends Object implements ManagedService, RemoteService, FragmentedMigrationAwareService, QuorumAwareService, SplitBrainHandlerService
Ringbuffer
.Modifier and Type | Field and Description |
---|---|
static String |
SERVICE_NAME
The ringbuffer service name which defines it in the node engine.
|
static String |
TOPIC_RB_PREFIX
Prefix of ringbuffers that are created for topics.
|
Constructor and Description |
---|
RingbufferService(NodeEngineImpl nodeEngine) |
Modifier and Type | Method and Description |
---|---|
void |
addRingbuffer(int partitionId,
RingbufferContainer ringbuffer,
RingbufferConfig config) |
void |
beforeMigration(PartitionMigrationEvent partitionMigrationEvent)
Called before migration process starts, on both source and destination members.
|
void |
commitMigration(PartitionMigrationEvent event)
Commits the migration process for this service, on both source and destination members.
|
DistributedObject |
createDistributedObject(String objectName)
Creates a distributed object.
|
void |
destroyContainer(int partitionId,
ObjectNamespace namespace) |
void |
destroyDistributedObject(String name)
Destroys a distributed object.
|
void |
ensureQuorumPresent(String distributedObjectName,
QuorumType requiredQuorumPermissionType) |
Collection<ServiceNamespace> |
getAllServiceNamespaces(PartitionReplicationEvent event)
Returns all known namespaces for given replication event.
|
<T,E> RingbufferContainer<T,E> |
getContainerOrNull(int partitionId,
ObjectNamespace namespace)
Returns the ringbuffer container if it already exists for the
given
partitionId and namespace . |
ConcurrentMap<Integer,Map<ObjectNamespace,RingbufferContainer>> |
getContainers() |
<T,E> RingbufferContainer<T,E> |
getOrCreateContainer(int partitionId,
ObjectNamespace namespace,
RingbufferConfig config)
Return the ringbuffer containter for the specified
namespace . |
String |
getQuorumName(String name)
Gets the name of the quorum associated with specified operation name.
|
RingbufferConfig |
getRingbufferConfig(String name) |
static ObjectNamespace |
getRingbufferNamespace(String name) |
int |
getRingbufferPartitionId(String ringbufferName) |
void |
init(NodeEngine nodeEngine,
Properties properties)
Initializes this service.
|
boolean |
isKnownServiceNamespace(ServiceNamespace namespace)
Returns true if namespace is known by this service, false otherwise
|
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. |
Operation |
prepareReplicationOperation(PartitionReplicationEvent event)
Returns an operation to replicate service data and/or state for a specific partition replica
on another cluster member.
|
Operation |
prepareReplicationOperation(PartitionReplicationEvent event,
Collection<ServiceNamespace> namespaces)
Returns an operation to replicate service data and/or state for a specific partition replica and namespaces
on another cluster member.
|
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 |
shutdown(boolean terminate)
Shuts down this service.
|
public static final String TOPIC_RB_PREFIX
public static final String SERVICE_NAME
public RingbufferService(NodeEngineImpl nodeEngine)
public 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 ConcurrentMap<Integer,Map<ObjectNamespace,RingbufferContainer>> getContainers()
public DistributedObject createDistributedObject(String objectName)
RemoteService
createDistributedObject
in interface RemoteService
objectName
- the name for the created distributed objectpublic void destroyDistributedObject(String name)
RemoteService
destroyDistributedObject
in interface RemoteService
name
- the name of the distributed object to destroypublic void destroyContainer(int partitionId, ObjectNamespace namespace)
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 <T,E> RingbufferContainer<T,E> getOrCreateContainer(int partitionId, ObjectNamespace namespace, RingbufferConfig config)
namespace
.
If there is no ringbuffer container, create it using the config
.namespace
- the ringbuffer container namespaceconfig
- the ringbuffer config. Used to create the container when the container doesn't existNullPointerException
- if the config
is null
public <T,E> RingbufferContainer<T,E> getContainerOrNull(int partitionId, ObjectNamespace namespace)
partitionId
and namespace
. Returns null
if it doesn't exist.T
- the type of items in the ringbuffer containerE
- the type of items in the ringbufferpartitionId
- the partition ID of the ringbuffer containernamespace
- the namespace of the ringbuffer containernull
if it has not been createdpublic RingbufferConfig getRingbufferConfig(String name)
public static ObjectNamespace getRingbufferNamespace(String name)
public int getRingbufferPartitionId(String ringbufferName)
public void addRingbuffer(int partitionId, RingbufferContainer ringbuffer, RingbufferConfig config)
public void beforeMigration(PartitionMigrationEvent partitionMigrationEvent)
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
partitionMigrationEvent
- migration eventpublic Operation prepareReplicationOperation(PartitionReplicationEvent event)
MigrationAwareService
This method will be called on source member whenever partitioning system requires to copy/replicate a partition replica. Returned operation will be executed on destination member. If operation fails by throwing exception, migration process will fail and will be rolled back.
Returning null is allowed and means service does not have anything to replicate.
prepareReplicationOperation
in interface MigrationAwareService
event
- replicationpublic Operation prepareReplicationOperation(PartitionReplicationEvent event, Collection<ServiceNamespace> namespaces)
FragmentedMigrationAwareService
MigrationAwareService.prepareReplicationOperation(PartitionReplicationEvent)
,
instead of copying whole partition replica, allows copying only some portion of replica,
specified by given namespaces.
This method will be called on source member whenever partitioning system requires to copy/replicate a partition replica. Returned operation will be executed on destination member. If operation fails by throwing exception, migration process will fail and will be rolled back.
Returning null is allowed and means service does not have anything to replicate.
prepareReplicationOperation
in interface FragmentedMigrationAwareService
event
- replication eventnamespaces
- replica fragment namespaces to replicateMigrationAwareService.prepareReplicationOperation(PartitionReplicationEvent)
public 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 Collection<ServiceNamespace> getAllServiceNamespaces(PartitionReplicationEvent event)
FragmentedMigrationAwareService
getAllServiceNamespaces
in interface FragmentedMigrationAwareService
event
- replication eventpublic boolean isKnownServiceNamespace(ServiceNamespace namespace)
FragmentedMigrationAwareService
isKnownServiceNamespace
in interface FragmentedMigrationAwareService
namespace
- namespacepublic String getQuorumName(String name)
QuorumAwareService
getQuorumName
in interface QuorumAwareService
name
- the operation name for which the quorum name is returedpublic void ensureQuorumPresent(String distributedObjectName, QuorumType requiredQuorumPermissionType)
public Runnable prepareMergeRunnable()
SplitBrainHandlerService
Runnable
, that will merge the clusters.prepareMergeRunnable
in interface SplitBrainHandlerService
Runnable
that will merge the clustersCopyright © 2020 Hazelcast, Inc.. All Rights Reserved.