From: Marius Gavrilescu Date: Sun, 28 Jul 2013 15:24:25 +0000 (+0300) Subject: Add request ID X-Git-Tag: 0.000_001~19 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=10f7c6fc77bfbaba1f1d8c429173cf55671118e3;p=fonbot.git Add request ID Each HTTP Address now sports an optional request ID, which is prepended to each message sent to that address. --- diff --git a/src/ro/ieval/fonbot/Address.java b/src/ro/ieval/fonbot/Address.java index 59fc0d7..5777cfe 100644 --- a/src/ro/ieval/fonbot/Address.java +++ b/src/ro/ieval/fonbot/Address.java @@ -65,6 +65,9 @@ final class Address { */ public final String data; + /** The ID of this request. Used in annotations. Can be null */ + public final transient String requestId; + /** * Construct an Address from its parts * @@ -74,6 +77,20 @@ final class Address { public Address(final Protocol protocol, final @Nullable String data){ this.protocol=protocol; this.data=data; + this.requestId=null; + } + + /** + * Construct an Address from its parts + * + * @param protocol the protocol part of the Address + * @param data the data part of the Address + * @param requestId the request ID + */ + public Address(final Protocol protocol, final @Nullable String data, final String requestId){ + this.protocol=protocol; + this.data=data; + this.requestId=requestId; } /** @@ -86,6 +103,7 @@ final class Address { final String[] parts=address.split(" ", 2); this.protocol=Protocol.valueOf(parts[0]); this.data=parts[1]; + this.requestId=null; } /** diff --git a/src/ro/ieval/fonbot/PollResultCallback.java b/src/ro/ieval/fonbot/PollResultCallback.java index d3c84ce..370ec11 100644 --- a/src/ro/ieval/fonbot/PollResultCallback.java +++ b/src/ro/ieval/fonbot/PollResultCallback.java @@ -73,7 +73,7 @@ final class PollResultCallback implements ResultCallback { final JSONArray jsonargs=object.getJSONArray("args"); final String command=object.getString("command"); - final Address replyTo=new Address(toNonNull(Protocol.HTTP), object.getString("replyto"));//NOPMD address depends on command + final Address replyTo=new Address(toNonNull(Protocol.HTTP), object.getString("replyto"), object.has("requestid") ? object.getString("requestid") : null);//NOPMD address depends on command final String[] args=new String[jsonargs.length()]; for(int j=0;j