예제 #1
0
  public IndirectReplication start() {

    if (intervalMillis == -1) {
      intervalMillis = 60 * 1000;
    }
    if (delayMillis == -1) {
      delayMillis = 30 * 1000;
    }
    if (blockSize == -1) {
      blockSize = 700;
    }

    if (autoReplication) {
      replicationFactor = new AutoReplication(peer.peer());
    } else if (replicationFactor == null) {
      replicationFactor =
          new ReplicationFactor() {
            @Override
            public int replicationFactor() {
              return DEFAULT_REPLICATION_FACTOR;
            }
          };
    }

    if (replicationFilters == null) {
      replicationFilters = new HashSet<ReplicationFilter>(0);
    }

    this.replication =
        new Replication(
            peer, replicationFactor.replicationFactor(), nRoot, keepData, replicationFilters);
    this.replication.addResponsibilityListener(this);
    if (responsibilityListeners != null) {
      for (ResponsibilityListener responsibilityListener : responsibilityListeners) {
        this.replication.addResponsibilityListener(responsibilityListener);
      }
      responsibilityListeners = null;
    }
    peer.storeRPC().replicationListener(replication);

    if (rsync) {
      replicationSender = new PeerSync(peer, replication, blockSize);
    } else if (replicationSender == null) {
      replicationSender = new DefaultReplicationSender(peer);
    }

    scheduledFuture =
        peer.peer()
            .connectionBean()
            .timer()
            .scheduleAtFixedRate(this, intervalMillis, intervalMillis, TimeUnit.MILLISECONDS);
    return this;
  }
예제 #2
0
 private void printStats() {
   StringBuilder sb = new StringBuilder("*************************\n");
   sb.append("Stats of peer ").append(peerDHT.peer().peerID()).append(": \n");
   sb.append("PUT:  count: ")
       .append(putStats.getCount())
       .append(" | avgtime: ")
       .append(putStats.getAverageTime())
       .append("ms | success: ")
       .append(putStats.getSuccessRate())
       .append("\n");
   sb.append("GET:  count: ")
       .append(putStats.getCount())
       .append(" | avgtime: ")
       .append(getStats.getAverageTime())
       .append("ms | success: ")
       .append(getStats.getSuccessRate())
       .append("\n");
   sb.append("RMV:  count: ")
       .append(putStats.getCount())
       .append(" | avgtime: ")
       .append(rmvStats.getAverageTime())
       .append("ms | success: ")
       .append(rmvStats.getSuccessRate());
   System.out.println(sb.toString());
 }
예제 #3
0
  public IndirectReplication(PeerDHT peer) {
    this.peer = peer;

    peer.peer()
        .addShutdownListener(
            new Shutdown() {
              @Override
              public BaseFuture shutdown() {
                IndirectReplication.this.shutdown();
                return new FutureDone<Void>().done();
              }
            });
  }
예제 #4
0
 /**
  * If an other peer is responsible, we send this peer our data, so that the other peer can take
  * care of this.
  *
  * @param other The other peer
  * @param locationKey The location key
  * @param domainKey The domain key
  * @param dataMapConvert The data to store
  */
 public FutureDone<Void> sendDirect(
     final PeerAddress other,
     final Number160 locationKey,
     final NavigableMap<Number640, Data> dataMap) {
   final FutureDone<Void> futureDone = new FutureDone<Void>();
   FutureChannelCreator futureChannelCreator =
       peer.peer().connectionBean().reservation().create(0, 1);
   Utils.addReleaseListener(futureChannelCreator, futureDone);
   futureChannelCreator.addListener(
       new BaseFutureAdapter<FutureChannelCreator>() {
         @Override
         public void operationComplete(final FutureChannelCreator future) throws Exception {
           if (future.isSuccess()) {
             PutBuilder putBuilder = new PutBuilder(peer, locationKey);
             putBuilder.dataMap(dataMap);
             FutureResponse futureResponse =
                 storageRPC.putReplica(other, putBuilder, future.channelCreator());
             futureResponse.addListener(
                 new BaseFutureAdapter<FutureResponse>() {
                   @Override
                   public void operationComplete(FutureResponse future) throws Exception {
                     if (future.isSuccess()) {
                       futureDone.done();
                     } else {
                       futureDone.failed(future);
                     }
                   }
                 });
             peer.peer().notifyAutomaticFutures(futureResponse);
           } else {
             futureDone.failed(future);
             LOG.error("otherResponsible failed {}", future.failedReason());
           }
         }
       });
   return futureDone;
 }