Пример #1
0
 private InboundTransferTask addTransfer(Address source, Set<Integer> segmentsFromSource) {
   synchronized (this) {
     segmentsFromSource.removeAll(
         transfersBySegment.keySet()); // already in progress segments are excluded
     if (!segmentsFromSource.isEmpty()) {
       InboundTransferTask inboundTransfer =
           new InboundTransferTask(
               segmentsFromSource,
               source,
               cacheTopology.getTopologyId(),
               this,
               rpcManager,
               commandsFactory,
               timeout,
               cacheName);
       for (int segmentId : segmentsFromSource) {
         transfersBySegment.put(segmentId, inboundTransfer);
       }
       List<InboundTransferTask> inboundTransfers =
           transfersBySource.get(inboundTransfer.getSource());
       if (inboundTransfers == null) {
         inboundTransfers = new ArrayList<InboundTransferTask>();
         transfersBySource.put(inboundTransfer.getSource(), inboundTransfers);
       }
       inboundTransfers.add(inboundTransfer);
       taskQueue.add(inboundTransfer);
       return inboundTransfer;
     } else {
       return null;
     }
   }
 }
Пример #2
0
  @Stop(priority = 20)
  @Override
  public void stop() {
    if (trace) {
      log.tracef(
          "Shutting down StateConsumer of cache %s on node %s", cacheName, rpcManager.getAddress());
    }

    try {
      synchronized (this) {
        // cancel all inbound transfers
        taskQueue.clear();
        for (Iterator<List<InboundTransferTask>> it = transfersBySource.values().iterator();
            it.hasNext(); ) {
          List<InboundTransferTask> inboundTransfers = it.next();
          it.remove();
          for (InboundTransferTask inboundTransfer : inboundTransfers) {
            inboundTransfer.cancel();
          }
        }
        transfersBySource.clear();
        transfersBySegment.clear();
      }
    } catch (Throwable t) {
      log.errorf(
          t,
          "Failed to stop StateConsumer of cache %s on node %s",
          cacheName,
          rpcManager.getAddress());
    }
  }
Пример #3
0
 private boolean removeTransfer(InboundTransferTask inboundTransfer) {
   synchronized (this) {
     taskQueue.remove(inboundTransfer);
     List<InboundTransferTask> transfers = transfersBySource.get(inboundTransfer.getSource());
     if (transfers != null) {
       if (transfers.remove(inboundTransfer)) {
         if (transfers.isEmpty()) {
           transfersBySource.remove(inboundTransfer.getSource());
         }
         transfersBySegment.keySet().removeAll(inboundTransfer.getSegments());
         return true;
       }
     }
   }
   return false;
 }