예제 #1
0
  /**
   * If my peer is responsible, I'll issue a put if absent to make sure all replicas are stored.
   *
   * @param locationKey The location key
   * @param domainKey The domain key
   * @param dataMapConverted The data to store
   * @return The future of the put
   */
  protected FutureDone<?> send(final Number160 locationKey) {
    int replicationFactor = replication.replicationFactor() - 1;
    List<PeerAddress> closePeers = new ArrayList<PeerAddress>();
    SortedSet<PeerStatistic> sortedSet =
        peer.peerBean().peerMap().closePeers(locationKey, replicationFactor);
    int count = 0;
    List<FutureDone<?>> retVal = new ArrayList<FutureDone<?>>(replicationFactor);
    for (PeerStatistic peerStatistic : sortedSet) {
      if (replication.rejectReplication(peerStatistic.peerAddress())) {
        continue;
      }

      count++;
      closePeers.add(peerStatistic.peerAddress());
      // this must be inside the loop as we need to retain the data for every peer

      Number640 min = new Number640(locationKey, Number160.ZERO, Number160.ZERO, Number160.ZERO);
      Number640 max =
          new Number640(locationKey, Number160.MAX_VALUE, Number160.MAX_VALUE, Number160.MAX_VALUE);
      final NavigableMap<Number640, Data> dataMap = peer.storageLayer().get(min, max, -1, true);

      retVal.add(replicationSender.sendDirect(peerStatistic.peerAddress(), locationKey, dataMap));
      if (count == replicationFactor) {
        break;
      }
    }
    LOG.debug(
        "[storage refresh] I ({}) restore {} to {}", peer.peerAddress(), locationKey, closePeers);
    return FutureDone.whenAll(retVal);
  }
예제 #2
0
 public FutureDone<Void> close() {
   // cc is not null if we opened the connection
   if (cc != null) {
     FutureDone<Void> future = cc.shutdown();
     // Maybe done on arrival? Set close future in any case
     future.addListener(
         new BaseFutureAdapter<FutureDone<Void>>() {
           @Override
           public void operationComplete(FutureDone<Void> future) throws Exception {
             closeFuture.setDone();
           }
         });
   } else {
     // cc is null if its an incoming connection. We can close it here, or it will be closed when
     // the dispatcher
     // is shutdown
     channelFuture.channel().close();
   }
   return closeFuture;
 }