]> iEval git - fonbot.git/commitdiff
Add request ID
authorMarius Gavrilescu <marius@ieval.ro>
Sun, 28 Jul 2013 15:24:25 +0000 (18:24 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Sun, 28 Jul 2013 15:24:25 +0000 (18:24 +0300)
Each HTTP Address now sports an optional request ID, which is prepended
to each message sent to that address.

src/ro/ieval/fonbot/Address.java
src/ro/ieval/fonbot/PollResultCallback.java
src/ro/ieval/fonbot/Utils.java

index 59fc0d74ccf6f055b21965c0e72a435712e3a4da..5777cfe54978799a41e3582222adc3150f465429 100644 (file)
@@ -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;
        }
 
        /**
index d3c84cebc1a2dde5eaacbbabba9b7801bfe0a6ed..370ec11d9b8582fcc9bca6696f846caf11d035c4 100644 (file)
@@ -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<args.length;j++)
                                        args[j]=jsonargs.getString(j);
index f37773a2a98b8de22711d1568e157755be611d7c..5f7f69c464bdd72c408d7caf2e6025963b9780e7 100644 (file)
@@ -295,8 +295,7 @@ public final class Utils {
        public static void sendMessage(final Context context, final Address address, final String message){
                switch(address.protocol){
                case HTTP:
-                       new HttpCallExecutableRunnable("/send", toNonNull(Arrays.asList(
-                                       new Header("X-Destination", toNonNull(address.data)))), context, null, true, message).execute();
+                       new HttpCallExecutableRunnable("/send", toNonNull(Arrays.asList(new Header("X-Destination", toNonNull(address.data)))), context, null, true, address.requestId == null ? message : address.requestId + " " + message).execute();
                        break;
 
                case SMS:
This page took 0.034867 seconds and 4 git commands to generate.