Search in sources :

Example 21 with IMap

use of com.hazelcast.map.IMap in project hazelcast by hazelcast.

the class TestCacheManager method testCacheNames.

@Test
public void testCacheNames() {
    // create a test instance, to reproduce the behavior described in the GitHub issue
    // https://github.com/hazelcast/hazelcast/issues/492
    final String testMap = "test-map";
    final CountDownLatch distributionSignal = new CountDownLatch(1);
    instance.addDistributedObjectListener(new DistributedObjectListener() {

        @Override
        public void distributedObjectCreated(DistributedObjectEvent event) {
            DistributedObject distributedObject = event.getDistributedObject();
            if (distributedObject instanceof IMap) {
                IMap<?, ?> map = (IMap) distributedObject;
                if (testMap.equals(map.getName())) {
                    distributionSignal.countDown();
                }
            }
        }

        @Override
        public void distributedObjectDestroyed(DistributedObjectEvent event) {
        }
    });
    HazelcastInstance testInstance = Hazelcast.newHazelcastInstance(extractConfig());
    testInstance.getMap(testMap);
    // be sure that test-map is distributed
    HazelcastTestSupport.assertOpenEventually(distributionSignal);
    Collection<String> test = cacheManager.getCacheNames();
    assertContains(test, testMap);
    testInstance.shutdown();
}
Also used : DistributedObject(com.hazelcast.core.DistributedObject) IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) DistributedObjectEvent(com.hazelcast.core.DistributedObjectEvent) CountDownLatch(java.util.concurrent.CountDownLatch) DistributedObjectListener(com.hazelcast.core.DistributedObjectListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 22 with IMap

use of com.hazelcast.map.IMap in project hazelcast by hazelcast.

the class HazelcastCacheManager method getCacheNames.

@Override
public Collection<String> getCacheNames() {
    Set<String> cacheNames = new HashSet<String>();
    Collection<DistributedObject> distributedObjects = hazelcastInstance.getDistributedObjects();
    for (DistributedObject distributedObject : distributedObjects) {
        if (distributedObject instanceof IMap) {
            IMap<?, ?> map = (IMap) distributedObject;
            cacheNames.add(map.getName());
        }
    }
    return cacheNames;
}
Also used : DistributedObject(com.hazelcast.core.DistributedObject) IMap(com.hazelcast.map.IMap) HashSet(java.util.HashSet)

Example 23 with IMap

use of com.hazelcast.map.IMap in project hazelcast by hazelcast.

the class UpdateProcessorSupplier method get.

@Nonnull
@Override
public Collection<? extends Processor> get(int count) {
    List<Processor> processors = new ArrayList<>(count);
    for (int i = 0; i < count; i++) {
        String mapName = this.mapName;
        Processor processor = new AsyncTransformUsingServiceBatchedP<>(ServiceFactories.nonSharedService(SecuredFunctions.iMapFn(mapName)), null, MAX_CONCURRENT_OPS, MAX_BATCH_SIZE, (IMap<Object, Object> map, List<JetSqlRow> rows) -> update(rows, map));
        processors.add(processor);
    }
    return processors;
}
Also used : IMap(com.hazelcast.map.IMap) Processor(com.hazelcast.jet.core.Processor) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) AsyncTransformUsingServiceBatchedP(com.hazelcast.jet.impl.processor.AsyncTransformUsingServiceBatchedP) Nonnull(javax.annotation.Nonnull)

Example 24 with IMap

use of com.hazelcast.map.IMap in project hazelcast by hazelcast.

the class MasterSnapshotContext method onSnapshotPhase1Complete.

/**
 * @param responses collected responses from the members
 * @param snapshotMapName the IMap name to which the snapshot is written
 * @param snapshotFlags flags of the snapshot
 * @param future a future to be completed when the phase-2 is fully completed
 */
private void onSnapshotPhase1Complete(Collection<Map.Entry<MemberInfo, Object>> responses, long executionId, long snapshotId, String snapshotMapName, int snapshotFlags, @Nullable CompletableFuture<Void> future) {
    mc.coordinationService().submitToCoordinatorThread(() -> {
        SnapshotPhase1Result mergedResult = new SnapshotPhase1Result();
        List<CompletableFuture<Void>> missingResponses = new ArrayList<>();
        for (Map.Entry<MemberInfo, Object> entry : responses) {
            // the response is either SnapshotOperationResult or an exception, see #invokeOnParticipants() method
            Object response = entry.getValue();
            if (response instanceof Throwable) {
                // all the responses to an array, and we'll wait for them later.
                if (response instanceof ExecutionNotFoundException) {
                    missingResponses.add(mc.startOperationResponses().get(entry.getKey().getAddress()));
                    continue;
                }
                response = new SnapshotPhase1Result(0, 0, 0, (Throwable) response);
            }
            mergedResult.merge((SnapshotPhase1Result) response);
        }
        if (!missingResponses.isEmpty()) {
            LoggingUtil.logFine(logger, "%s will wait for %d responses to StartExecutionOperation in " + "onSnapshotPhase1Complete()", mc.jobIdString(), missingResponses.size());
        }
        // In a typical case `missingResponses` will be empty. It will be non-empty if some member completed
        // its execution and some other did not, or near the completion of a job, e.g. after a failure.
        // `allOf` for an empty array returns a completed future immediately.
        // Another edge case is that we'll be waiting for a response to start operation from a next execution,
        // which can happen much later - we could handle it, but we ignore it: when it arrives, we'll find a
        // changed executionId and ignore the response. It also doesn't occupy a thread - we're using a future.
        CompletableFuture.allOf(missingResponses.toArray(new CompletableFuture[0])).whenComplete(withTryCatch(logger, (r, t) -> onSnapshotPhase1CompleteWithStartResponses(responses, executionId, snapshotId, snapshotMapName, snapshotFlags, future, mergedResult, missingResponses)));
    });
}
Also used : SnapshotPhase2Operation(com.hazelcast.jet.impl.operation.SnapshotPhase2Operation) LoggingUtil(com.hazelcast.jet.impl.util.LoggingUtil) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) ExecutionNotFoundException(com.hazelcast.jet.impl.exception.ExecutionNotFoundException) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) JetException(com.hazelcast.jet.JetException) Util.jobNameAndExecutionId(com.hazelcast.jet.impl.util.Util.jobNameAndExecutionId) ILogger(com.hazelcast.logging.ILogger) Operation(com.hazelcast.spi.impl.operationservice.Operation) ExceptionUtil.withTryCatch(com.hazelcast.jet.impl.util.ExceptionUtil.withTryCatch) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) Map(java.util.Map) SnapshotPhase1Operation(com.hazelcast.jet.impl.operation.SnapshotPhase1Operation) LinkedList(java.util.LinkedList) EXPORTED_SNAPSHOTS_PREFIX(com.hazelcast.jet.impl.JobRepository.EXPORTED_SNAPSHOTS_PREFIX) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Tuple3(com.hazelcast.jet.datamodel.Tuple3) SnapshotFlags(com.hazelcast.jet.impl.execution.SnapshotFlags) Collection(java.util.Collection) JobRepository.snapshotDataMapName(com.hazelcast.jet.impl.JobRepository.snapshotDataMapName) ExecutionException(java.util.concurrent.ExecutionException) JobRepository.exportedSnapshotMapName(com.hazelcast.jet.impl.JobRepository.exportedSnapshotMapName) SnapshotPhase1Result(com.hazelcast.jet.impl.operation.SnapshotPhase1Operation.SnapshotPhase1Result) Tuple3.tuple3(com.hazelcast.jet.datamodel.Tuple3.tuple3) List(java.util.List) Util.idToString(com.hazelcast.jet.Util.idToString) LoggingUtil.logFine(com.hazelcast.jet.impl.util.LoggingUtil.logFine) ExecutionPlan(com.hazelcast.jet.impl.execution.init.ExecutionPlan) Entry(java.util.Map.Entry) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) Queue(java.util.Queue) SnapshotStats(com.hazelcast.jet.impl.JobExecutionRecord.SnapshotStats) IMap(com.hazelcast.map.IMap) CompletableFuture(java.util.concurrent.CompletableFuture) ExecutionNotFoundException(com.hazelcast.jet.impl.exception.ExecutionNotFoundException) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) SnapshotPhase1Result(com.hazelcast.jet.impl.operation.SnapshotPhase1Operation.SnapshotPhase1Result) ArrayList(java.util.ArrayList) Map(java.util.Map) IMap(com.hazelcast.map.IMap)

Example 25 with IMap

use of com.hazelcast.map.IMap in project hazelcast by hazelcast.

the class AbstractUpdateMapP method submitPending.

// returns true if we were able to submit all pending items
@SuppressWarnings({ "rawtypes", "unchecked" })
private boolean submitPending() {
    if (pendingItemCount == 0) {
        return true;
    }
    for (int i = 0; i < partitionBuffers.length; i++, currentPartitionId = incrCircular(currentPartitionId, partitionBuffers.length)) {
        if (partitionBuffers[currentPartitionId].isEmpty()) {
            continue;
        }
        if (!tryAcquirePermit()) {
            return false;
        }
        Map<Data, Object> buffer = partitionBuffers[currentPartitionId];
        EntryProcessor<K, V, Void> entryProcessor = entryProcessor(buffer);
        // submit Set<Data> here
        IMap map = this.map;
        setCallback(map.submitToKeys(buffer.keySet(), entryProcessor));
        pendingItemCount -= pendingInPartition[currentPartitionId];
        pendingInPartition[currentPartitionId] = 0;
        partitionBuffers[currentPartitionId] = new HashMap<>();
    }
    if (currentPartitionId == partitionBuffers.length) {
        currentPartitionId = 0;
    }
    assert pendingItemCount == 0 : "pending item count should be 0, but was " + pendingItemCount;
    return true;
}
Also used : IMap(com.hazelcast.map.IMap) Data(com.hazelcast.internal.serialization.Data)

Aggregations

IMap (com.hazelcast.map.IMap)294 Test (org.junit.Test)259 QuickTest (com.hazelcast.test.annotation.QuickTest)237 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)228 HazelcastInstance (com.hazelcast.core.HazelcastInstance)139 Config (com.hazelcast.config.Config)103 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)82 Map (java.util.Map)75 CountDownLatch (java.util.concurrent.CountDownLatch)65 MapStoreConfig (com.hazelcast.config.MapStoreConfig)54 Category (org.junit.experimental.categories.Category)51 Assert.assertEquals (org.junit.Assert.assertEquals)50 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)48 HashMap (java.util.HashMap)48 Collection (java.util.Collection)41 RunWith (org.junit.runner.RunWith)41 MapConfig (com.hazelcast.config.MapConfig)36 Set (java.util.Set)34 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)33 AssertTask (com.hazelcast.test.AssertTask)32