Пример #1
0
 public <K, V> Set<Map.Entry<K, V>> getObjectEntrySet(NodeEngine nodeEngine) {
   Set<Map.Entry<K, V>> entrySet = new HashSet<Map.Entry<K, V>>();
   for (Map.Entry<Data, Collection<Data>> entry : map.entrySet()) {
     K key = nodeEngine.toObject(entry.getKey());
     Collection<Data> coll = entry.getValue();
     for (Data data : coll) {
       V val = nodeEngine.toObject(data);
       entrySet.add(new AbstractMap.SimpleEntry<K, V>(key, val));
     }
   }
   return entrySet;
 }
  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);
    }
  }
Пример #3
0
 @Override
 public Xid[] recover(int flag) throws XAException {
   NodeEngine nodeEngine = getNodeEngine();
   XAService xaService = getService();
   OperationService operationService = nodeEngine.getOperationService();
   ClusterService clusterService = nodeEngine.getClusterService();
   Collection<Member> memberList = clusterService.getMembers();
   List<InternalCompletableFuture<SerializableList>> futureList =
       new ArrayList<InternalCompletableFuture<SerializableList>>();
   for (Member member : memberList) {
     if (member.localMember()) {
       continue;
     }
     CollectRemoteTransactionsOperation op = new CollectRemoteTransactionsOperation();
     Address address = member.getAddress();
     InternalCompletableFuture<SerializableList> future =
         operationService.invokeOnTarget(SERVICE_NAME, op, address);
     futureList.add(future);
   }
   HashSet<SerializableXID> xids = new HashSet<SerializableXID>();
   xids.addAll(xaService.getPreparedXids());
   for (InternalCompletableFuture<SerializableList> future : futureList) {
     SerializableList xidSet = future.getSafely();
     for (Data xidData : xidSet) {
       SerializableXID xid = nodeEngine.toObject(xidData);
       xids.add(xid);
     }
   }
   return xids.toArray(new SerializableXID[xids.size()]);
 }
Пример #4
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;
 }
Пример #6
0
 private <T> T invoke(QueueOperation operation) {
   final NodeEngine nodeEngine = getNodeEngine();
   try {
     Invocation inv =
         nodeEngine
             .getOperationService()
             .createInvocationBuilder(QueueService.SERVICE_NAME, operation, getPartitionId())
             .build();
     Future f = inv.invoke();
     return (T) nodeEngine.toObject(f.get());
   } catch (Throwable throwable) {
     throw ExceptionUtil.rethrow(throwable);
   }
 }
 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);
   }
 }
Пример #9
0
  public void dispatchEvent(MultiMapEvent event, EventListener listener) {
    EntryListener entryListener = (EntryListener) listener;
    final MemberImpl member = nodeEngine.getClusterService().getMember(event.getCaller());
    EntryEvent entryEvent =
        new EntryEvent(
            event.getName(),
            member,
            event.getEventType().getType(),
            nodeEngine.toObject(event.getKey()),
            nodeEngine.toObject(event.getValue()));
    if (member == null) {
      if (logger.isLoggable(Level.INFO)) {
        logger.info("Dropping event " + entryEvent + " from unknown address:" + event.getCaller());
      }
      return;
    }

    if (event.getEventType().equals(EntryEventType.ADDED)) {
      entryListener.entryAdded(entryEvent);
    } else if (event.getEventType().equals(EntryEventType.REMOVED)) {
      entryListener.entryRemoved(entryEvent);
    }
    getLocalMultiMapStatsImpl(event.getName()).incrementReceivedEvents();
  }
Пример #10
0
 boolean offerInternal(Data data, long timeout) throws InterruptedException {
   throwExceptionIfNull(data);
   OfferOperation operation = new OfferOperation(name, timeout, data);
   final NodeEngine nodeEngine = getNodeEngine();
   try {
     Invocation inv =
         nodeEngine
             .getOperationService()
             .createInvocationBuilder(QueueService.SERVICE_NAME, operation, getPartitionId())
             .build();
     Future f = inv.invoke();
     return (Boolean) nodeEngine.toObject(f.get());
   } catch (Throwable throwable) {
     throw ExceptionUtil.rethrowAllowInterrupted(throwable);
   }
 }
Пример #11
0
 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);
   }
 }
Пример #12
0
 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);
   }
 }
Пример #13
0
 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);
   }
 }