Ejemplo n.º 1
0
  @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);
  }
Ejemplo n.º 2
0
  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);
    }
  }
Ejemplo n.º 3
0
  // 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);
    }
  }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
 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);
   }
 }
Ejemplo n.º 6
0
 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);
 }
Ejemplo n.º 7
0
 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);
   }
 }
Ejemplo n.º 8
0
 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);
   }
 }
Ejemplo n.º 9
0
  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();
  }
Ejemplo n.º 10
0
 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);
   }
 }
Ejemplo n.º 11
0
 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);
   }
 }
Ejemplo n.º 12
0
 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);
   }
 }
Ejemplo n.º 13
0
  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);
    }
  }
Ejemplo n.º 14
0
 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);
   }
 }
Ejemplo n.º 15
0
  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);
    }
  }
Ejemplo n.º 16
0
 /** {@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);
   }
 }
Ejemplo n.º 17
0
 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;
 }
Ejemplo n.º 18
0
 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);
   }
 }
Ejemplo n.º 19
0
 protected boolean tryRemoveInternal(Data key, long timeout, TimeUnit timeunit) {
   MapOperation operation =
       operationProvider.createTryRemoveOperation(name, key, getTimeInMillis(timeout, timeunit));
   return (Boolean) invokeOperation(key, operation);
 }
Ejemplo n.º 20
0
 protected boolean replaceInternal(Data key, Data expect, Data update) {
   MapOperation operation =
       operationProvider.createReplaceIfSameOperation(name, key, expect, update);
   return (Boolean) invokeOperation(key, operation);
 }
Ejemplo n.º 21
0
 protected Data removeInternal(Data key) {
   MapOperation operation = operationProvider.createRemoveOperation(name, key, false);
   return (Data) invokeOperation(key, operation);
 }
Ejemplo n.º 22
0
 private Operation createLoadAllOperation(List<Data> keys, boolean replaceExistingValues) {
   return operationProvider.createLoadAllOperation(name, keys, replaceExistingValues);
 }
Ejemplo n.º 23
0
 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);
 }
Ejemplo n.º 24
0
 // 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);
 }
Ejemplo n.º 25
0
 protected Data replaceInternal(Data key, Data value) {
   MapOperation operation = operationProvider.createReplaceOperation(name, key, value);
   return (Data) invokeOperation(key, operation);
 }
Ejemplo n.º 26
0
 protected void deleteInternal(Data key) {
   MapOperation operation = operationProvider.createDeleteOperation(name, key);
   invokeOperation(key, operation);
 }
Ejemplo n.º 27
0
 protected boolean removeInternal(Data key, Data value) {
   MapOperation operation = operationProvider.createRemoveIfSameOperation(name, key, value);
   return (Boolean) invokeOperation(key, operation);
 }
Ejemplo n.º 28
0
 /**
  * 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);
 }
Ejemplo n.º 29
0
 protected void putTransientInternal(Data key, Data value, long ttl, TimeUnit timeunit) {
   MapOperation operation =
       operationProvider.createPutTransientOperation(
           name, key, value, getTimeInMillis(ttl, timeunit));
   invokeOperation(key, operation);
 }