Search in sources :

Example 16 with MultiMapService

use of com.hazelcast.multimap.impl.MultiMapService in project hazelcast by hazelcast.

the class AbstractMultiMapAddEntryListenerMessageTask method processInternal.

@Override
protected CompletableFuture<UUID> processInternal() {
    final MultiMapService service = getService(MultiMapService.SERVICE_NAME);
    EntryAdapter listener = new MultiMapListener();
    final String name = getDistributedObjectName();
    Data key = getKey();
    boolean includeValue = shouldIncludeValue();
    if (isLocalOnly()) {
        return newCompletedFuture(service.addLocalListener(name, listener, key, includeValue));
    }
    return service.addListenerAsync(name, listener, key, includeValue);
}
Also used : MultiMapService(com.hazelcast.multimap.impl.MultiMapService) EntryAdapter(com.hazelcast.core.EntryAdapter) Data(com.hazelcast.internal.serialization.Data)

Example 17 with MultiMapService

use of com.hazelcast.multimap.impl.MultiMapService in project hazelcast by hazelcast.

the class MultiMapClearMessageTask method reduce.

@Override
protected Object reduce(Map<Integer, Object> map) {
    int totalAffectedEntries = 0;
    for (Object affectedEntries : map.values()) {
        totalAffectedEntries += (Integer) affectedEntries;
    }
    updateStats(LocalMapStatsImpl::incrementOtherOperations);
    final MultiMapService service = getService(MultiMapService.SERVICE_NAME);
    service.publishMultiMapEvent(parameters, EntryEventType.CLEAR_ALL, totalAffectedEntries);
    return null;
}
Also used : LocalMapStatsImpl(com.hazelcast.internal.monitor.impl.LocalMapStatsImpl) MultiMapService(com.hazelcast.multimap.impl.MultiMapService)

Example 18 with MultiMapService

use of com.hazelcast.multimap.impl.MultiMapService in project hazelcast by hazelcast.

the class MultiMapTestUtil method getBackupMultiMap.

/**
 * Returns all backup entries of an {@link MultiMap} by a given map name.
 * <p>
 * Note: This method returns all backups from all nodes and doesn't consider the replica indexes.
 *
 * @param instances    the {@link HazelcastInstance} array to gather the data from
 * @param multiMapName the MultiMap name
 * @param <K>          type of the key
 * @param <V>          type of the value
 * @return a {@link Map} with the backup entries
 */
public static <K, V> Map<K, Collection<V>> getBackupMultiMap(HazelcastInstance[] instances, String multiMapName) {
    Map<K, Collection<V>> map = new HashMap<K, Collection<V>>();
    for (HazelcastInstance instance : instances) {
        NodeEngineImpl nodeEngine = getNodeEngineImpl(instance);
        MultiMapService mapService = nodeEngine.getService(MultiMapService.SERVICE_NAME);
        InternalPartitionService partitionService = nodeEngine.getPartitionService();
        SerializationService serializationService = nodeEngine.getSerializationService();
        for (int partitionId = 0; partitionId < partitionService.getPartitionCount(); partitionId++) {
            if (partitionService.isPartitionOwner(partitionId)) {
                continue;
            }
            MultiMapPartitionContainer partitionContainer = mapService.getPartitionContainer(partitionId);
            MultiMapContainer multiMapContainer = partitionContainer.getMultiMapContainer(multiMapName, false);
            if (multiMapContainer == null) {
                continue;
            }
            for (Map.Entry<Data, MultiMapValue> entry : multiMapContainer.getMultiMapValues().entrySet()) {
                K key = serializationService.toObject(entry.getKey());
                Collection<MultiMapRecord> collection = entry.getValue().getCollection(false);
                Collection<V> values = new ArrayList<V>(collection.size());
                for (MultiMapRecord record : collection) {
                    V value = serializationService.toObject(record.getObject());
                    values.add(value);
                }
                map.put(key, values);
            }
        }
    }
    return map;
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) MultiMapValue(com.hazelcast.multimap.impl.MultiMapValue) HashMap(java.util.HashMap) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) MultiMapPartitionContainer(com.hazelcast.multimap.impl.MultiMapPartitionContainer) MultiMapContainer(com.hazelcast.multimap.impl.MultiMapContainer) MultiMapService(com.hazelcast.multimap.impl.MultiMapService) ArrayList(java.util.ArrayList) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map)

Example 19 with MultiMapService

use of com.hazelcast.multimap.impl.MultiMapService in project hazelcast by hazelcast.

the class MultiMapContainerStatisticsTest method getMultiMapContainer.

private static MultiMapContainer getMultiMapContainer(HazelcastInstance hz, String key) {
    NodeEngineImpl nodeEngine = getNodeEngineImpl(hz);
    MultiMapService mapService = nodeEngine.getService(MultiMapService.SERVICE_NAME);
    Data dataKey = nodeEngine.getSerializationService().toData(key);
    int partitionId = nodeEngine.getPartitionService().getPartitionId(dataKey);
    return mapService.getOrCreateCollectionContainerWithoutAccess(partitionId, MULTI_MAP_NAME);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) MultiMapService(com.hazelcast.multimap.impl.MultiMapService) Data(com.hazelcast.internal.serialization.Data)

Aggregations

MultiMapService (com.hazelcast.multimap.impl.MultiMapService)19 QueueService (com.hazelcast.collection.impl.queue.QueueService)3 DistributedExecutorService (com.hazelcast.executor.impl.DistributedExecutorService)3 Data (com.hazelcast.internal.serialization.Data)3 MapService (com.hazelcast.map.impl.MapService)3 ReplicatedMapService (com.hazelcast.replicatedmap.impl.ReplicatedMapService)3 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)3 TopicService (com.hazelcast.topic.impl.TopicService)3 CacheConfig (com.hazelcast.config.CacheConfig)2 Config (com.hazelcast.config.Config)2 EntryAdapter (com.hazelcast.core.EntryAdapter)2 DistributedDurableExecutorService (com.hazelcast.durableexecutor.impl.DistributedDurableExecutorService)2 FlakeIdGeneratorService (com.hazelcast.flakeidgen.impl.FlakeIdGeneratorService)2 PNCounterService (com.hazelcast.internal.crdt.pncounter.PNCounterService)2 MultiMapRecord (com.hazelcast.multimap.impl.MultiMapRecord)2 DistributedScheduledExecutorService (com.hazelcast.scheduledexecutor.impl.DistributedScheduledExecutorService)2 Accessors.getNodeEngineImpl (com.hazelcast.test.Accessors.getNodeEngineImpl)2 ReliableTopicService (com.hazelcast.topic.impl.reliable.ReliableTopicService)2 CacheStatistics (com.hazelcast.cache.CacheStatistics)1 CacheService (com.hazelcast.cache.impl.CacheService)1