use of com.hazelcast.spi.partition.IPartitionService in project hazelcast by hazelcast.
the class QueueService method createLocalQueueStats.
/**
* Returns the local queue statistics for the queue with the given {@code name}. If this node is the owner of the queue,
* returned stats contain {@link LocalQueueStats#getOwnedItemCount()}, otherwise it contains
* {@link LocalQueueStats#getBackupItemCount()}.
*
* @param name the name of the queue for which the statistics are returned
* @return the statistics
*/
public LocalQueueStats createLocalQueueStats(String name) {
SerializationService serializationService = nodeEngine.getSerializationService();
IPartitionService partitionService = nodeEngine.getPartitionService();
Data keyData = serializationService.toData(name, StringPartitioningStrategy.INSTANCE);
int partitionId = partitionService.getPartitionId(keyData);
return createLocalQueueStats(name, partitionId);
}
use of com.hazelcast.spi.partition.IPartitionService in project hazelcast by hazelcast.
the class CacheSplitBrainHandler method prepareMergeRunnable.
Runnable prepareMergeRunnable() {
final Map<String, Map<Data, CacheRecord>> recordMap = new HashMap<String, Map<Data, CacheRecord>>(configs.size());
final IPartitionService partitionService = nodeEngine.getPartitionService();
final int partitionCount = partitionService.getPartitionCount();
final Address thisAddress = nodeEngine.getClusterService().getThisAddress();
for (int i = 0; i < partitionCount; i++) {
// Add your owned entries so they will be merged
if (thisAddress.equals(partitionService.getPartitionOwner(i))) {
CachePartitionSegment segment = segments[i];
Iterator<ICacheRecordStore> iter = segment.recordStoreIterator();
while (iter.hasNext()) {
ICacheRecordStore cacheRecordStore = iter.next();
if (!(cacheRecordStore instanceof SplitBrainAwareCacheRecordStore)) {
continue;
}
String cacheName = cacheRecordStore.getName();
Map<Data, CacheRecord> records = recordMap.get(cacheName);
if (records == null) {
records = new HashMap<Data, CacheRecord>(cacheRecordStore.size());
recordMap.put(cacheName, records);
}
for (Map.Entry<Data, CacheRecord> cacheRecordEntry : cacheRecordStore.getReadOnlyRecords().entrySet()) {
Data key = cacheRecordEntry.getKey();
CacheRecord cacheRecord = cacheRecordEntry.getValue();
records.put(key, cacheRecord);
}
// Clear all records either owned or backup
cacheRecordStore.clear();
// send the cache invalidation event regardless if any actually cleared or not (no need to know how many
// actually cleared)
final CacheService cacheService = nodeEngine.getService(CacheService.SERVICE_NAME);
cacheService.sendInvalidationEvent(cacheName, null, AbstractCacheRecordStore.SOURCE_NOT_AVAILABLE);
}
}
}
return new CacheMerger(nodeEngine, configs, recordMap, mergePolicyProvider);
}
use of com.hazelcast.spi.partition.IPartitionService in project hazelcast by hazelcast.
the class CardinalityEstimatorService method getPartitionId.
private int getPartitionId(String name) {
IPartitionService partitionService = nodeEngine.getPartitionService();
String partitionKey = getPartitionKey(name);
return partitionService.getPartitionId(partitionKey);
}
use of com.hazelcast.spi.partition.IPartitionService in project hazelcast by hazelcast.
the class CacheClearOperation method afterRun.
@Override
public void afterRun() throws Exception {
super.afterRun();
IPartitionService partitionService = getNodeEngine().getPartitionService();
if (partitionService.getPartitionId(name) == getPartitionId()) {
CacheService cacheService = getService();
cacheService.sendInvalidationEvent(name, null, SOURCE_NOT_AVAILABLE);
}
}
use of com.hazelcast.spi.partition.IPartitionService in project hazelcast by hazelcast.
the class AddPartitionLostListenerMessageTask method call.
@Override
protected Object call() throws Exception {
final IPartitionService partitionService = getService(getServiceName());
final PartitionLostListener listener = new PartitionLostListener() {
@Override
public void partitionLost(PartitionLostEvent event) {
if (endpoint.isAlive()) {
ClientMessage eventMessage = ClientAddPartitionLostListenerCodec.encodePartitionLostEvent(event.getPartitionId(), event.getLostBackupCount(), event.getEventSource());
sendClientMessage(null, eventMessage);
}
}
};
String registrationId;
if (parameters.localOnly) {
registrationId = partitionService.addLocalPartitionLostListener(listener);
} else {
registrationId = partitionService.addPartitionLostListener(listener);
}
endpoint.addListenerDestroyAction(getServiceName(), PARTITION_LOST_EVENT_TOPIC, registrationId);
return registrationId;
}
Aggregations