Exemplo n.º 1
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);
    }
  }
  @Override
  public Map<Integer, Object> invokeOnAllPartitions(Object request) throws Exception {
    checkInstanceOf(OperationFactory.class, request, "request");

    OperationFactory factory = (OperationFactory) request;
    return operationService.invokeOnAllPartitions(MapService.SERVICE_NAME, factory);
  }
  public int size() {
    checkTransactionState();
    try {
      final OperationService operationService = getNodeEngine().getOperationService();
      final Map<Integer, Object> results =
          operationService.invokeOnAllPartitions(
              MultiMapService.SERVICE_NAME,
              new MultiMapOperationFactory(
                  name, MultiMapOperationFactory.OperationFactoryType.SIZE));
      int size = 0;
      for (Object obj : results.values()) {
        if (obj == null) {
          continue;
        }
        Integer result = getNodeEngine().toObject(obj);
        size += result;
      }
      for (Data key : txMap.keySet()) {
        MultiMapTransactionLog log =
            (MultiMapTransactionLog) tx.getTransactionLog(getTxLogKey(key));
        if (log != null) {
          size += log.size();
        }
      }

      return size;
    } catch (Throwable t) {
      throw ExceptionUtil.rethrow(t);
    }
  }
Exemplo n.º 4
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);
    }
  }
Exemplo n.º 5
0
 public void addIndex(String attribute, boolean ordered) {
   validateIndexAttribute(attribute);
   try {
     AddIndexOperation addIndexOperation = new AddIndexOperation(name, attribute, ordered);
     operationService.invokeOnAllPartitions(
         SERVICE_NAME, new BinaryOperationFactory(addIndexOperation, getNodeEngine()));
   } catch (Throwable t) {
     throw rethrow(t);
   }
 }
Exemplo n.º 6
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);
   }
 }
 @Override
 public void run() {
   try {
     final OperationService operationService = nodeEngine.getOperationService();
     final Map<Integer, Object> results =
         operationService.invokeOnAllPartitions(getServiceName(), operationFactory);
     validateResults(results);
     if (completionListener != null) {
       completionListener.onCompletion();
     }
   } catch (Exception e) {
     if (completionListener != null) {
       completionListener.onException(e);
     }
   }
 }
Exemplo n.º 8
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);
   }
 }
Exemplo n.º 9
0
 public boolean isEmpty() {
   try {
     // TODO: we don't need to wait for all futures to complete, we can stop on the first returned
     // false
     // also there is no need to make use of IsEmptyOperation, just use size to reduce the amount
     // of code
     IsEmptyOperationFactory factory = new IsEmptyOperationFactory(name);
     Map<Integer, Object> results = operationService.invokeOnAllPartitions(SERVICE_NAME, factory);
     for (Object result : results.values()) {
       if (!(Boolean) toObject(result)) {
         return false;
       }
     }
     return true;
   } catch (Throwable t) {
     throw rethrow(t);
   }
 }
Exemplo n.º 10
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);
   }
 }
Exemplo n.º 11
0
  public void waitUntilLoaded() {
    try {
      int mapNamePartition = partitionService.getPartitionId(name);
      Operation op = new PartitionCheckIfLoadedOperation(name, false, true);
      Future loadingFuture = operationService.invokeOnPartition(SERVICE_NAME, op, mapNamePartition);
      // wait for keys to be loaded - it's insignificant since it doesn't trigger the keys loading
      // it's just waiting for them to be loaded. Timeout failure doesn't mean anything negative
      // here.
      // This call just introduces some ordering of requests.
      FutureUtil.waitWithDeadline(
          singleton(loadingFuture),
          CHECK_IF_LOADED_TIMEOUT_SECONDS,
          SECONDS,
          logAllExceptions(WARNING));

      OperationFactory opFactory = new PartitionCheckIfLoadedOperationFactory(name);
      Map<Integer, Object> results =
          operationService.invokeOnAllPartitions(SERVICE_NAME, opFactory);
      // wait for all the data to be loaded on all partitions - wait forever
      waitAllTrue(results, opFactory);
    } catch (Throwable t) {
      throw rethrow(t);
    }
  }