Search in sources :

Example 26 with ReplicatedMapService

use of com.hazelcast.replicatedmap.impl.ReplicatedMapService in project hazelcast by hazelcast.

the class ContainsKeyOperation method run.

@Override
public void run() throws Exception {
    ReplicatedMapService service = getService();
    ReplicatedRecordStore store = service.getReplicatedRecordStore(name, false, getPartitionId());
    response = store.containsKey(key);
}
Also used : ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService)

Example 27 with ReplicatedMapService

use of com.hazelcast.replicatedmap.impl.ReplicatedMapService in project hazelcast by hazelcast.

the class EntrySetOperation method run.

@Override
public void run() throws Exception {
    ReplicatedMapService service = getService();
    Collection<ReplicatedRecordStore> stores = service.getAllReplicatedRecordStores(name);
    List<Map.Entry<Object, ReplicatedRecord>> entries = new ArrayList<Map.Entry<Object, ReplicatedRecord>>();
    for (ReplicatedRecordStore store : stores) {
        entries.addAll(store.entrySet(false));
    }
    ArrayList<Map.Entry<Data, Data>> dataEntries = new ArrayList<Map.Entry<Data, Data>>(entries.size());
    SerializationService serializationService = getNodeEngine().getSerializationService();
    for (Map.Entry<Object, ReplicatedRecord> entry : entries) {
        Data key = serializationService.toData(entry.getKey());
        Data value = serializationService.toData(entry.getValue().getValue());
        dataEntries.add(new AbstractMap.SimpleImmutableEntry<Data, Data>(key, value));
    }
    response = new ReplicatedMapEntries(dataEntries);
}
Also used : ReplicatedRecord(com.hazelcast.replicatedmap.impl.record.ReplicatedRecord) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) ArrayList(java.util.ArrayList) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) AbstractMap(java.util.AbstractMap) ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) AbstractMap(java.util.AbstractMap) Map(java.util.Map) ReplicatedMapEntries(com.hazelcast.replicatedmap.impl.client.ReplicatedMapEntries)

Example 28 with ReplicatedMapService

use of com.hazelcast.replicatedmap.impl.ReplicatedMapService in project hazelcast by hazelcast.

the class GetOperation method run.

@Override
public void run() throws Exception {
    ReplicatedMapService service = getService();
    ReplicatedRecordStore store = service.getReplicatedRecordStore(name, false, getPartitionId());
    ReplicatedRecord record = store.getReplicatedRecord(key);
    if (record != null) {
        response = record.getValue();
    }
}
Also used : ReplicatedRecord(com.hazelcast.replicatedmap.impl.record.ReplicatedRecord) ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService)

Example 29 with ReplicatedMapService

use of com.hazelcast.replicatedmap.impl.ReplicatedMapService in project hazelcast by hazelcast.

the class IsEmptyOperation method run.

@Override
public void run() throws Exception {
    ReplicatedMapService service = getService();
    Collection<ReplicatedRecordStore> stores = service.getAllReplicatedRecordStores(name);
    for (ReplicatedRecordStore store : stores) {
        if (!store.isEmpty()) {
            response = false;
            return;
        }
    }
    response = true;
}
Also used : ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService)

Example 30 with ReplicatedMapService

use of com.hazelcast.replicatedmap.impl.ReplicatedMapService in project hazelcast by hazelcast.

the class ReplicatedMapReorderedReplicationTest method testNonConvergingReplicatedMaps.

@Test
public void testNonConvergingReplicatedMaps() throws Exception {
    final int nodeCount = 4;
    final int keyCount = 10000;
    final int threadCount = 2;
    updateFactory();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    final Config config = new Config();
    final HazelcastInstance[] instances = factory.newInstances(config, nodeCount);
    warmUpPartitions(instances);
    final int partitionId = randomPartitionOwnedBy(instances[0]).getPartitionId();
    final String mapName = randomMapName();
    final NodeEngineImpl nodeEngine = getNodeEngineImpl(instances[0]);
    final Thread[] threads = new Thread[threadCount];
    for (int i = 0; i < threadCount; i++) {
        final int startIndex = i;
        threads[i] = new Thread(new Runnable() {

            @Override
            public void run() {
                for (int j = startIndex; j < keyCount; j += threadCount) {
                    put(nodeEngine, mapName, partitionId, j, j);
                }
            }
        });
    }
    for (Thread thread : threads) {
        thread.start();
    }
    for (Thread thread : threads) {
        thread.join();
    }
    final ReplicatedRecordStore[] stores = new ReplicatedRecordStore[nodeCount];
    for (int i = 0; i < nodeCount; i++) {
        ReplicatedMapService service = getNodeEngineImpl(instances[i]).getService(ReplicatedMapService.SERVICE_NAME);
        service.triggerAntiEntropy();
        stores[i] = service.getReplicatedRecordStore(mapName, false, partitionId);
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            long version = stores[0].getVersion();
            for (ReplicatedRecordStore store : stores) {
                assertEquals(version, store.getVersion());
                assertFalse(store.isStale(version));
            }
        }
    });
    for (int i = 0; i < keyCount; i++) {
        for (ReplicatedRecordStore store : stores) {
            assertTrue(store.containsKey(i));
        }
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Config(com.hazelcast.config.Config) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

ReplicatedMapService (com.hazelcast.replicatedmap.impl.ReplicatedMapService)32 ReplicatedRecordStore (com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore)17 ILogger (com.hazelcast.logging.ILogger)6 Data (com.hazelcast.nio.serialization.Data)6 ReplicatedMapEventPublishingService (com.hazelcast.replicatedmap.impl.ReplicatedMapEventPublishingService)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 Test (org.junit.Test)5 ReplicatedRecord (com.hazelcast.replicatedmap.impl.record.ReplicatedRecord)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Config (com.hazelcast.config.Config)3 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)3 SerializationService (com.hazelcast.spi.serialization.SerializationService)3 ArrayList (java.util.ArrayList)3 QueueService (com.hazelcast.collection.impl.queue.QueueService)2 DistributedExecutorService (com.hazelcast.executor.impl.DistributedExecutorService)2 MapService (com.hazelcast.map.impl.MapService)2 MultiMapService (com.hazelcast.multimap.impl.MultiMapService)2 Address (com.hazelcast.nio.Address)2 PartitionContainer (com.hazelcast.replicatedmap.impl.PartitionContainer)2