use of com.hazelcast.internal.partition.IPartitionService in project hazelcast by hazelcast.
the class CacheClearOperation method afterRun.
@Override
public void afterRun() throws Exception {
super.afterRun();
CacheService cacheService = getService();
int partitionId = getPartitionId();
IPartitionService partitionService = getNodeEngine().getPartitionService();
if (partitionService.getPartitionId(name) == partitionId) {
cacheService.sendInvalidationEvent(name, null, SOURCE_NOT_AVAILABLE);
} else {
cacheService.getCacheEventHandler().forceIncrementSequence(name, partitionId);
}
}
use of com.hazelcast.internal.partition.IPartitionService in project hazelcast by hazelcast.
the class CacheProxyLoadAllTask method run.
@Override
public void run() {
try {
completionListener = injectDependencies(completionListener);
OperationService operationService = nodeEngine.getOperationService();
OperationFactory operationFactory;
IPartitionService partitionService = nodeEngine.getPartitionService();
Map<Address, List<Integer>> memberPartitionsMap = partitionService.getMemberPartitionsMap();
int partitionCount = partitionService.getPartitionCount();
Map<Integer, Object> results = createHashMap(partitionCount);
for (Map.Entry<Address, List<Integer>> memberPartitions : memberPartitionsMap.entrySet()) {
Set<Integer> partitions = new PartitionIdSet(partitionCount, memberPartitions.getValue());
Set<Data> ownerKeys = filterOwnerKeys(partitionService, partitions);
operationFactory = operationProvider.createLoadAllOperationFactory(ownerKeys, replaceExistingValues);
Map<Integer, Object> memberResults;
memberResults = operationService.invokeOnPartitions(serviceName, operationFactory, partitions);
results.putAll(memberResults);
}
validateResults(results);
if (completionListener != null) {
completionListener.onCompletion();
}
} catch (Exception e) {
if (completionListener != null) {
completionListener.onException(e);
}
} catch (Throwable t) {
if (t instanceof OutOfMemoryError) {
throw rethrow(t);
} else {
if (completionListener != null) {
completionListener.onException(new CacheException(t));
}
}
}
}
use of com.hazelcast.internal.partition.IPartitionService in project hazelcast by hazelcast.
the class ScheduledExecutorGetAllScheduledMessageTask method accumulateTaskHandlersAsUrnValues.
@SuppressWarnings("unchecked")
private void accumulateTaskHandlersAsUrnValues(List<ScheduledTaskHandler> accumulator, Map<?, ?> taskHandlersMap) {
ClusterService clusterService = nodeEngine.getClusterService();
IPartitionService partitionService = nodeEngine.getPartitionService();
for (Map.Entry<?, ?> entry : taskHandlersMap.entrySet()) {
MemberImpl owner;
Object key = entry.getKey();
if (key instanceof Number) {
owner = clusterService.getMember(partitionService.getPartitionOwner((Integer) key));
} else {
owner = (MemberImpl) key;
}
List<ScheduledTaskHandler> handlers = (List<ScheduledTaskHandler>) entry.getValue();
for (ScheduledTaskHandler handler : handlers) {
ScheduledTaskHandlerAccessor.setUuid(handler, owner.getUuid());
}
accumulator.addAll(handlers);
}
}
use of com.hazelcast.internal.partition.IPartitionService in project hazelcast by hazelcast.
the class EvictionMaxSizePolicyTest method setMockRuntimeMemoryInfoAccessor.
public static void setMockRuntimeMemoryInfoAccessor(IMap map, final long totalMemoryMB, final long freeMemoryMB, final long maxMemoryMB) {
final MapProxyImpl mapProxy = (MapProxyImpl) map;
final MapService mapService = (MapService) mapProxy.getService();
final MapServiceContext mapServiceContext = mapService.getMapServiceContext();
MemoryInfoAccessor memoryInfoAccessor = new MemoryInfoAccessor() {
@Override
public long getTotalMemory() {
return MEGABYTES.toBytes(totalMemoryMB);
}
@Override
public long getFreeMemory() {
return MEGABYTES.toBytes(freeMemoryMB);
}
@Override
public long getMaxMemory() {
return MEGABYTES.toBytes(maxMemoryMB);
}
};
MapContainer mapContainer = mapServiceContext.getMapContainer(map.getName());
EvictionChecker evictionChecker = new EvictionChecker(memoryInfoAccessor, mapServiceContext);
IPartitionService partitionService = mapServiceContext.getNodeEngine().getPartitionService();
Evictor evictor = new TestEvictor(LRUEvictionPolicyComparator.INSTANCE, evictionChecker, partitionService);
mapContainer.setEvictor(evictor);
}
use of com.hazelcast.internal.partition.IPartitionService in project hazelcast by hazelcast.
the class EvictionMaxSizePolicyTest method setTestSizeEstimator.
public static void setTestSizeEstimator(IMap map, final long oneEntryHeapCostInBytes) {
final MapProxyImpl mapProxy = (MapProxyImpl) map;
final MapService mapService = (MapService) mapProxy.getService();
final MapServiceContext mapServiceContext = mapService.getMapServiceContext();
final NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
final IPartitionService partitionService = nodeEngine.getPartitionService();
for (int i = 0; i < partitionService.getPartitionCount(); i++) {
final Address owner = partitionService.getPartitionOwner(i);
if (nodeEngine.getThisAddress().equals(owner)) {
final PartitionContainer container = mapServiceContext.getPartitionContainer(i);
if (container == null) {
continue;
}
final RecordStore recordStore = container.getRecordStore(map.getName());
final DefaultRecordStore defaultRecordStore = (DefaultRecordStore) recordStore;
defaultRecordStore.setSizeEstimator(new EntryCostEstimator() {
long size;
@Override
public long getEstimate() {
return size;
}
@Override
public void adjustEstimateBy(long size) {
this.size += size;
}
@Override
public long calculateValueCost(Object record) {
if (record == null) {
return 0L;
}
return oneEntryHeapCostInBytes;
}
@Override
public long calculateEntryCost(Object key, Object record) {
if (record == null) {
return 0L;
}
return 2 * oneEntryHeapCostInBytes;
}
@Override
public void reset() {
size = 0;
}
});
}
}
}
Aggregations