Skip to content

Commit

Permalink
adapted PutBuilder for confirming and rejecting prepared puts
Browse files Browse the repository at this point in the history
  • Loading branch information
ippes committed Jun 4, 2014
1 parent 044d462 commit 3db803c
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion core/src/main/java/net/tomp2p/p2p/builder/PutBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class PutBuilder extends DHTBuilder<PutBuilder> {

private boolean putMeta = false;

private boolean putConfim = false;
private boolean putReject = false;

private PublicKey changePublicKey = null;

public PutBuilder(Peer peer, Number160 locationKey) {
Expand Down Expand Up @@ -180,7 +183,25 @@ public PutBuilder changePublicKey(PublicKey changePublicKey) {
setSign();
return this;
}


public boolean isPutConfirm() {
return putConfim;
}

public PutBuilder putConfirm() {
this.putConfim = true;
return this;
}

public boolean isPutReject() {
return putReject;
}

public PutBuilder putReject() {
this.putReject = true;
return this;
}

public PublicKey changePublicKey() {
return changePublicKey;
}
Expand All @@ -200,6 +221,18 @@ public FuturePut start() {
throw new IllegalArgumentException(
"You must either set data via setDataMap() or setData(). Cannot add nothing.");
}
if (!putConfim && dataMap == null && dataMapConvert == null) {
throw new IllegalArgumentException(
"You must either set data via setDataMap() or setData(). Cannot add nothing.");
}
if (!putReject && dataMap == null && dataMapConvert == null) {
throw new IllegalArgumentException(
"You must either set data via setDataMap() or setData(). Cannot add nothing.");
}
if (putConfim && putReject) {
throw new IllegalArgumentException(
"You can't confirm and reject a put.");
}
if (locationKey == null) {
throw new IllegalArgumentException("You must provide a location key.");
}
Expand Down

0 comments on commit 3db803c

Please sign in to comment.