Search in sources :

Example 16 with IPartitionService

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);
    }
}
Also used : IPartitionService(com.hazelcast.spi.partition.IPartitionService) CacheService(com.hazelcast.cache.impl.CacheService) ICacheService(com.hazelcast.cache.impl.ICacheService)

Example 17 with IPartitionService

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;
}
Also used : PartitionLostListener(com.hazelcast.partition.PartitionLostListener) IPartitionService(com.hazelcast.spi.partition.IPartitionService) PartitionLostEvent(com.hazelcast.partition.PartitionLostEvent) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 18 with IPartitionService

use of com.hazelcast.spi.partition.IPartitionService in project hazelcast by hazelcast.

the class ScheduledExecutorGetAllScheduledMessageTask method accumulateTaskHandlersAsUrnValues.

@SuppressWarnings("unchecked")
private void accumulateTaskHandlersAsUrnValues(Map<Member, List<ScheduledTaskHandler>> accumulator, Map<?, ?> taskHandlersMap) {
    ClusterService clusterService = nodeEngine.getClusterService();
    IPartitionService partitionService = nodeEngine.getPartitionService();
    for (Map.Entry<?, ?> entry : taskHandlersMap.entrySet()) {
        Member owner;
        Object key = entry.getKey();
        if (key instanceof Number) {
            owner = clusterService.getMember(partitionService.getPartitionOwner((Integer) key));
        } else {
            owner = (Member) key;
        }
        List<ScheduledTaskHandler> handlers = (List<ScheduledTaskHandler>) entry.getValue();
        if (accumulator.containsKey(owner)) {
            List<ScheduledTaskHandler> memberUrns = accumulator.get(owner);
            memberUrns.addAll(handlers);
        } else {
            accumulator.put(owner, handlers);
        }
    }
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) IPartitionService(com.hazelcast.spi.partition.IPartitionService) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Member(com.hazelcast.core.Member)

Example 19 with IPartitionService

use of com.hazelcast.spi.partition.IPartitionService in project hazelcast by hazelcast.

the class CollectionService method rollbackTransaction.

@Override
public void rollbackTransaction(String transactionId) {
    final Set<String> collectionNames = getContainerMap().keySet();
    IPartitionService partitionService = nodeEngine.getPartitionService();
    OperationService operationService = nodeEngine.getOperationService();
    for (String name : collectionNames) {
        int partitionId = partitionService.getPartitionId(StringPartitioningStrategy.getPartitionKey(name));
        Operation operation = new CollectionTransactionRollbackOperation(name, transactionId).setPartitionId(partitionId).setService(this).setNodeEngine(nodeEngine);
        operationService.execute(operation);
    }
}
Also used : CollectionTransactionRollbackOperation(com.hazelcast.collection.impl.txncollection.operations.CollectionTransactionRollbackOperation) IPartitionService(com.hazelcast.spi.partition.IPartitionService) OperationService(com.hazelcast.spi.OperationService) CollectionTransactionRollbackOperation(com.hazelcast.collection.impl.txncollection.operations.CollectionTransactionRollbackOperation) Operation(com.hazelcast.spi.Operation) MigrationEndpoint(com.hazelcast.spi.partition.MigrationEndpoint)

Example 20 with IPartitionService

use of com.hazelcast.spi.partition.IPartitionService in project hazelcast by hazelcast.

the class CollectionService method getMigrationData.

protected Map<String, CollectionContainer> getMigrationData(PartitionReplicationEvent event) {
    Map<String, CollectionContainer> migrationData = new HashMap<String, CollectionContainer>();
    IPartitionService partitionService = nodeEngine.getPartitionService();
    for (Map.Entry<String, ? extends CollectionContainer> entry : getContainerMap().entrySet()) {
        String name = entry.getKey();
        int partitionId = partitionService.getPartitionId(StringPartitioningStrategy.getPartitionKey(name));
        CollectionContainer container = entry.getValue();
        if (partitionId == event.getPartitionId() && container.getConfig().getTotalBackupCount() >= event.getReplicaIndex()) {
            migrationData.put(name, container);
        }
    }
    return migrationData;
}
Also used : HashMap(java.util.HashMap) IPartitionService(com.hazelcast.spi.partition.IPartitionService) HashMap(java.util.HashMap) Map(java.util.Map) MigrationEndpoint(com.hazelcast.spi.partition.MigrationEndpoint)

Aggregations

IPartitionService (com.hazelcast.spi.partition.IPartitionService)48 Data (com.hazelcast.nio.serialization.Data)11 NodeEngine (com.hazelcast.spi.NodeEngine)11 Address (com.hazelcast.nio.Address)8 HashMap (java.util.HashMap)8 OperationService (com.hazelcast.spi.OperationService)7 MigrationEndpoint (com.hazelcast.spi.partition.MigrationEndpoint)7 Map (java.util.Map)7 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)5 IPartition (com.hazelcast.spi.partition.IPartition)5 MapService (com.hazelcast.map.impl.MapService)3 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 ICacheService (com.hazelcast.cache.impl.ICacheService)2 CacheRecord (com.hazelcast.cache.impl.record.CacheRecord)2 QueueReplicationOperation (com.hazelcast.collection.impl.queue.operations.QueueReplicationOperation)2 Member (com.hazelcast.core.Member)2 ClusterService (com.hazelcast.internal.cluster.ClusterService)2 MapEvictionPolicy (com.hazelcast.map.eviction.MapEvictionPolicy)2