@Override protected Operation prepareOperation() { MapEntries mapEntries = new MapEntries(); for (Map.Entry<Data, Data> entry : parameters.entries) { mapEntries.add(entry.getKey(), entry.getValue()); } MapOperationProvider operationProvider = getMapOperationProvider(parameters.name); return operationProvider.createPutAllOperation(parameters.name, mapEntries, false); }
public void clearInternal() { try { Operation clearOperation = operationProvider.createClearOperation(name); clearOperation.setServiceName(SERVICE_NAME); BinaryOperationFactory factory = new BinaryOperationFactory(clearOperation, getNodeEngine()); Map<Integer, Object> resultMap = operationService.invokeOnAllPartitions(SERVICE_NAME, factory); int numberOfAffectedEntries = 0; for (Object object : resultMap.values()) { numberOfAffectedEntries += (Integer) object; } MemberSelector selector = MemberSelectors.and(LITE_MEMBER_SELECTOR, NON_LOCAL_MEMBER_SELECTOR); for (Member member : getNodeEngine().getClusterService().getMembers(selector)) { operationService.invokeOnTarget( SERVICE_NAME, new ClearOperation(name), member.getAddress()); } if (numberOfAffectedEntries > 0) { publishMapEvent(numberOfAffectedEntries, EntryEventType.CLEAR_ALL); } } catch (Throwable t) { throw rethrow(t); } }
// TODO: add a feature to mancenter to sync cache to db completely public void flush() { try { MapOperation mapFlushOperation = operationProvider.createMapFlushOperation(name); BinaryOperationFactory operationFactory = new BinaryOperationFactory(mapFlushOperation, getNodeEngine()); Map<Integer, Object> results = operationService.invokeOnAllPartitions(SERVICE_NAME, operationFactory); List<Future> futures = new ArrayList<Future>(); for (Entry<Integer, Object> entry : results.entrySet()) { Integer partitionId = entry.getKey(); Long count = ((Long) entry.getValue()); if (count != 0) { Operation operation = new AwaitMapFlushOperation(name, count); futures.add( operationService.invokeOnPartition(MapService.SERVICE_NAME, operation, partitionId)); } } for (Future future : futures) { future.get(); } } catch (Throwable t) { throw rethrow(t); } }
protected void invokePutAllOperationFactory( Address address, final long size, int[] partitions, MapEntries[] entries) throws Exception { OperationFactory factory = operationProvider.createPutAllOperationFactory(name, partitions, entries); final long time = System.currentTimeMillis(); operationService.invokeOnPartitions(SERVICE_NAME, factory, partitions); localMapStats.incrementPuts(size, System.currentTimeMillis() - time); }
protected EntryView getEntryViewInternal(Data key) { int partitionId = partitionService.getPartitionId(key); MapOperation operation = operationProvider.createGetEntryViewOperation(name, key); operation.setThreadId(ThreadUtil.getThreadId()); operation.setServiceName(SERVICE_NAME); try { Future future = operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId); return (EntryView) toObject(future.get()); } catch (Throwable t) { throw rethrow(t); } }
protected Object getInternal(Data key) { // todo action for read-backup true is not well tested. if (getMapConfig().isReadBackupData()) { Object fromBackup = readBackupDataOrNull(key); if (fromBackup != null) { return fromBackup; } } MapOperation operation = operationProvider.createGetOperation(name, key); operation.setThreadId(ThreadUtil.getThreadId()); return invokeOperation(key, operation); }
protected ICompletableFuture<Data> setAsyncInternal( Data key, Data value, long ttl, TimeUnit timeunit) { int partitionId = getNodeEngine().getPartitionService().getPartitionId(key); MapOperation operation = operationProvider.createSetOperation(name, key, value, getTimeInMillis(ttl, timeunit)); operation.setThreadId(ThreadUtil.getThreadId()); try { return operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId); } catch (Throwable t) { throw rethrow(t); } }
protected boolean containsKeyInternal(Data key) { int partitionId = partitionService.getPartitionId(key); MapOperation containsKeyOperation = operationProvider.createContainsKeyOperation(name, key); containsKeyOperation.setThreadId(ThreadUtil.getThreadId()); containsKeyOperation.setServiceName(SERVICE_NAME); try { Future future = operationService.invokeOnPartition(SERVICE_NAME, containsKeyOperation, partitionId); return (Boolean) toObject(future.get()); } catch (Throwable t) { throw rethrow(t); } }
protected void loadAllInternal(boolean replaceExistingValues) { int mapNamePartition = partitionService.getPartitionId(name); Operation operation = operationProvider.createLoadMapOperation(name, replaceExistingValues); Future loadMapFuture = operationService.invokeOnPartition(SERVICE_NAME, operation, mapNamePartition); try { loadMapFuture.get(); } catch (Throwable t) { throw rethrow(t); } waitUntilLoaded(); }
public Data executeOnKeyInternal(Data key, EntryProcessor entryProcessor) { int partitionId = partitionService.getPartitionId(key); MapOperation operation = operationProvider.createEntryOperation(name, key, entryProcessor); operation.setThreadId(ThreadUtil.getThreadId()); try { Future future = operationService .createInvocationBuilder(SERVICE_NAME, operation, partitionId) .setResultDeserialized(false) .invoke(); return (Data) future.get(); } catch (Throwable t) { throw rethrow(t); } }
public int size() { try { OperationFactory sizeOperationFactory = operationProvider.createMapSizeOperationFactory(name); Map<Integer, Object> results = operationService.invokeOnAllPartitions(SERVICE_NAME, sizeOperationFactory); int total = 0; for (Object result : results.values()) { Integer size = toObject(result); total += size; } return total; } catch (Throwable t) { throw rethrow(t); } }
public boolean containsValueInternal(Data dataValue) { try { OperationFactory operationFactory = operationProvider.createContainsValueOperationFactory(name, dataValue); Map<Integer, Object> results = operationService.invokeOnAllPartitions(SERVICE_NAME, operationFactory); for (Object result : results.values()) { Boolean contains = toObject(result); if (contains) { return true; } } return false; } catch (Throwable t) { throw rethrow(t); } }
protected ICompletableFuture<Data> removeAsyncInternal(Data key) { int partitionId = getNodeEngine().getPartitionService().getPartitionId(key); MapOperation operation = operationProvider.createRemoveOperation(name, key, false); operation.setThreadId(ThreadUtil.getThreadId()); try { long startTime = System.currentTimeMillis(); InternalCompletableFuture<Data> future = operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId); if (statisticsEnabled) { future.andThen(new IncrementStatsExecutionCallback<Data>(operation, startTime)); } return future; } catch (Throwable t) { throw rethrow(t); } }
public ICompletableFuture executeOnKeyInternal( Data key, EntryProcessor entryProcessor, ExecutionCallback<Object> callback) { int partitionId = partitionService.getPartitionId(key); MapOperation operation = operationProvider.createEntryOperation(name, key, entryProcessor); operation.setThreadId(ThreadUtil.getThreadId()); try { if (callback == null) { return operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId); } else { return operationService .createInvocationBuilder(SERVICE_NAME, operation, partitionId) .setExecutionCallback(new MapExecutionCallbackAdapter(callback)) .invoke(); } } catch (Throwable t) { throw rethrow(t); } }
protected ICompletableFuture<Data> getAsyncInternal(Data key) { int partitionId = partitionService.getPartitionId(key); MapOperation operation = operationProvider.createGetOperation(name, key); try { long startTime = System.currentTimeMillis(); InternalCompletableFuture<Data> future = operationService .createInvocationBuilder(SERVICE_NAME, operation, partitionId) .setResultDeserialized(false) .invoke(); if (statisticsEnabled) { future.andThen(new IncrementStatsExecutionCallback<Data>(operation, startTime)); } return future; } catch (Throwable t) { throw rethrow(t); } }
/** {@link IMap#executeOnEntries(EntryProcessor, Predicate)} */ public void executeOnEntriesInternal( EntryProcessor entryProcessor, Predicate predicate, List<Data> result) { try { OperationFactory operation = operationProvider.createPartitionWideEntryWithPredicateOperationFactory( name, entryProcessor, predicate); Map<Integer, Object> results = operationService.invokeOnAllPartitions(SERVICE_NAME, operation); for (Object object : results.values()) { if (object != null) { MapEntries mapEntries = (MapEntries) object; for (int i = 0; i < mapEntries.size(); i++) { result.add(mapEntries.getKey(i)); result.add(mapEntries.getValue(i)); } } } } catch (Throwable t) { throw rethrow(t); } }
public Map executeOnKeysInternal(Set<Data> keys, EntryProcessor entryProcessor) { // TODO: why are we not forwarding to executeOnKeysInternal(keys, entryProcessor, null) or some // other kind of fake // callback? now there is a lot of code duplication Map<Object, Object> result = new HashMap<Object, Object>(); Collection<Integer> partitionsForKeys = getPartitionsForKeys(keys); try { OperationFactory operationFactory = operationProvider.createMultipleEntryOperationFactory(name, keys, entryProcessor); Map<Integer, Object> results = operationService.invokeOnPartitions(SERVICE_NAME, operationFactory, partitionsForKeys); for (Object object : results.values()) { if (object != null) { MapEntries mapEntries = (MapEntries) object; mapEntries.putAllToMap(serializationService, result); } } } catch (Throwable t) { throw rethrow(t); } return result; }
protected void getAllObjectInternal(List<Data> keys, List<Object> resultingKeyValuePairs) { if (keys == null || keys.isEmpty()) { return; } if (keys.isEmpty()) { return; } Collection<Integer> partitions = getPartitionsForKeys(keys); Map<Integer, Object> responses; try { OperationFactory operationFactory = operationProvider.createGetAllOperationFactory(name, keys); responses = operationService.invokeOnPartitions(SERVICE_NAME, operationFactory, partitions); for (Object response : responses.values()) { MapEntries entries = toObject(response); for (int i = 0; i < entries.size(); i++) { resultingKeyValuePairs.add(toObject(entries.getKey(i))); resultingKeyValuePairs.add(toObject(entries.getValue(i))); } } } catch (Exception e) { throw rethrow(e); } }
protected boolean tryRemoveInternal(Data key, long timeout, TimeUnit timeunit) { MapOperation operation = operationProvider.createTryRemoveOperation(name, key, getTimeInMillis(timeout, timeunit)); return (Boolean) invokeOperation(key, operation); }
protected boolean replaceInternal(Data key, Data expect, Data update) { MapOperation operation = operationProvider.createReplaceIfSameOperation(name, key, expect, update); return (Boolean) invokeOperation(key, operation); }
protected Data removeInternal(Data key) { MapOperation operation = operationProvider.createRemoveOperation(name, key, false); return (Data) invokeOperation(key, operation); }
private Operation createLoadAllOperation(List<Data> keys, boolean replaceExistingValues) { return operationProvider.createLoadAllOperation(name, keys, replaceExistingValues); }
protected Data putIfAbsentInternal(Data key, Data value, long ttl, TimeUnit timeunit) { MapOperation operation = operationProvider.createPutIfAbsentOperation( name, key, value, getTimeInMillis(ttl, timeunit)); return (Data) invokeOperation(key, operation); }
// warning: When UpdateEvent is fired it does *NOT* contain oldValue. // see this: https://github.com/hazelcast/hazelcast/pull/6088#issuecomment-136025968 protected void setInternal(Data key, Data value, long ttl, TimeUnit timeunit) { MapOperation operation = operationProvider.createSetOperation(name, key, value, timeunit.toMillis(ttl)); invokeOperation(key, operation); }
protected Data replaceInternal(Data key, Data value) { MapOperation operation = operationProvider.createReplaceOperation(name, key, value); return (Data) invokeOperation(key, operation); }
protected void deleteInternal(Data key) { MapOperation operation = operationProvider.createDeleteOperation(name, key); invokeOperation(key, operation); }
protected boolean removeInternal(Data key, Data value) { MapOperation operation = operationProvider.createRemoveIfSameOperation(name, key, value); return (Boolean) invokeOperation(key, operation); }
/** * Evicts a key from a map. * * @param key the key to evict * @return {@code true} if eviction was successful, {@code false} otherwise */ protected boolean evictInternal(Data key) { MapOperation operation = operationProvider.createEvictOperation(name, key, false); return (Boolean) invokeOperation(key, operation); }
protected void putTransientInternal(Data key, Data value, long ttl, TimeUnit timeunit) { MapOperation operation = operationProvider.createPutTransientOperation( name, key, value, getTimeInMillis(ttl, timeunit)); invokeOperation(key, operation); }