protected Set<Data> keySetInternal() {
    final NodeEngine nodeEngine = getNodeEngine();
    try {

      Map<Integer, Object> results =
          nodeEngine
              .getOperationService()
              .invokeOnAllPartitions(
                  CollectionService.SERVICE_NAME,
                  new MultiMapOperationFactory(proxyId, OperationFactoryType.KEY_SET));
      Set<Data> keySet = new HashSet<Data>();
      for (Object result : results.values()) {
        if (result == null) {
          continue;
        }
        CollectionResponse response = nodeEngine.toObject(result);
        if (response.getCollection() != null) {
          keySet.addAll(response.getCollection());
        }
      }
      return keySet;
    } catch (Throwable throwable) {
      throw ExceptionUtil.rethrow(throwable);
    }
  }
Exemple #2
0
 public Object toObject(Object data) {
   if (data == null) return null;
   if (data instanceof Data) {
     return nodeEngine.toObject(data);
   } else {
     return data;
   }
 }
 private Collection<E> getAll() {
   final CollectionGetAllOperation operation = new CollectionGetAllOperation(name);
   final SerializableCollection result = invoke(operation);
   final Collection<Data> collection = result.getCollection();
   final List<E> list = new ArrayList<E>(collection.size());
   final NodeEngine nodeEngine = getNodeEngine();
   for (Data data : collection) {
     list.add(nodeEngine.<E>toObject(data));
   }
   return list;
 }
 protected <T> T invoke(CollectionOperation operation) {
   final NodeEngine nodeEngine = getNodeEngine();
   try {
     Invocation inv =
         nodeEngine
             .getOperationService()
             .createInvocationBuilder(getServiceName(), operation, partitionId)
             .build();
     Future f = inv.invoke();
     return nodeEngine.toObject(f.get());
   } catch (Throwable throwable) {
     throw ExceptionUtil.rethrow(throwable);
   }
 }
 private Object invokeData(CollectionOperation operation, Data dataKey) {
   final NodeEngine nodeEngine = getNodeEngine();
   try {
     int partitionId = nodeEngine.getPartitionService().getPartitionId(dataKey);
     Invocation inv =
         nodeEngine
             .getOperationService()
             .createInvocationBuilder(CollectionService.SERVICE_NAME, operation, partitionId)
             .build();
     Future f = inv.invoke();
     return nodeEngine.toObject(f.get());
   } catch (Throwable throwable) {
     throw ExceptionUtil.rethrow(throwable);
   }
 }
 public int size() {
   final NodeEngine nodeEngine = getNodeEngine();
   try {
     Map<Integer, Object> results =
         nodeEngine
             .getOperationService()
             .invokeOnAllPartitions(
                 CollectionService.SERVICE_NAME,
                 new MultiMapOperationFactory(proxyId, OperationFactoryType.SIZE));
     int size = 0;
     for (Object obj : results.values()) {
       if (obj == null) {
         continue;
       }
       Integer result = nodeEngine.toObject(obj);
       size += result;
     }
     return size;
   } catch (Throwable throwable) {
     throw ExceptionUtil.rethrow(throwable);
   }
 }
 private <T> T invoke(Operation operation, Data dataKey) {
   final NodeEngine nodeEngine = getNodeEngine();
   try {
     int partitionId = nodeEngine.getPartitionService().getPartitionId(dataKey);
     Invocation invocation =
         nodeEngine
             .getOperationService()
             .createInvocationBuilder(CollectionService.SERVICE_NAME, operation, partitionId)
             .build();
     Future f;
     Object o;
     if (config.isStatisticsEnabled()) {
       long time = System.currentTimeMillis();
       f = invocation.invoke();
       o = f.get();
       if (operation instanceof PutOperation) {
         getService()
             .getLocalMultiMapStatsImpl(proxyId)
             .incrementPuts(System.currentTimeMillis() - time);
       } else if (operation instanceof RemoveOperation
           || operation instanceof RemoveAllOperation) {
         getService()
             .getLocalMultiMapStatsImpl(proxyId)
             .incrementRemoves(System.currentTimeMillis() - time);
       } else if (operation instanceof GetAllOperation) {
         getService()
             .getLocalMultiMapStatsImpl(proxyId)
             .incrementGets(System.currentTimeMillis() - time);
       }
     } else {
       f = invocation.invoke();
       o = f.get();
     }
     return (T) nodeEngine.toObject(o);
   } catch (Throwable throwable) {
     throw ExceptionUtil.rethrow(throwable);
   }
 }
 protected boolean containsInternal(Data key, Data value) {
   final NodeEngine nodeEngine = getNodeEngine();
   try {
     Map<Integer, Object> results =
         nodeEngine
             .getOperationService()
             .invokeOnAllPartitions(
                 CollectionService.SERVICE_NAME,
                 new MultiMapOperationFactory(proxyId, OperationFactoryType.CONTAINS, key, value));
     for (Object obj : results.values()) {
       if (obj == null) {
         continue;
       }
       Boolean result = nodeEngine.toObject(obj);
       if (result) {
         return true;
       }
     }
     return false;
   } catch (Throwable throwable) {
     throw ExceptionUtil.rethrow(throwable);
   }
 }