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();
}
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;
}
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;
}
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)));
});
}
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;
}
Aggregations