]> iEval git - fonbot.git/commitdiff
Add retries to message sending
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 23 Mar 2013 11:56:06 +0000 (13:56 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 23 Mar 2013 11:56:06 +0000 (13:56 +0200)
HttpCallExecutableRunnable now takes a new parameter which determines whether it should be retried if it fails. The flag is currently set for calls that send messages to the user (since these are very important).

src/ro/ieval/fonbot/FonBotMainActivity.java
src/ro/ieval/fonbot/HttpCallExecutableRunnable.java
src/ro/ieval/fonbot/RemoteCrashdumpHandler.java
src/ro/ieval/fonbot/Utils.java

index 342606a506b8186d75c4badeec4068eaa65fb251..d7581fab0c7fab8875263c2e78271f924b72a8d8 100644 (file)
@@ -218,7 +218,7 @@ public final class FonBotMainActivity extends ListActivity {
                super.onStart();
                resultTextView.setText(logging_in);
                new HttpCallExecutableRunnable("/ok", null,
-                               toNonNull(getApplicationContext()), toNonNull(updateResultCallback)).execute();
+                               toNonNull(getApplicationContext()), toNonNull(updateResultCallback), false).execute();
                connection.refreshAdapter();
        }
 
index d41c7efee78b4988dfe755480e47add1a61791b8..3782accb400f6cdda466b66f2a35aa374126a4ed 100644 (file)
@@ -172,6 +172,8 @@ public final class HttpCallExecutableRunnable extends ExecutableRunnable{
         * Callback to run after the request returns
         */
        private final ResultCallback callback;
+       /** If true, the task should be retried if it fails */
+       private final boolean mustRetryTask;
 
        /**
         * Constructs a SendHttpMessageAsyncTask which sends a binary message.
@@ -180,13 +182,15 @@ public final class HttpCallExecutableRunnable extends ExecutableRunnable{
         * @param headers the extra headers
         * @param context the context instance
         * @param resultCallback {@link ResultCallback} instance
+        * @param mustRetryTask true if this task should be retried if it fails
         * @param data the message to send
         */
-       public HttpCallExecutableRunnable(final String path, final @Nullable Collection<Header> headers, final Context context, final @Nullable ResultCallback resultCallback, final byte[] data){//NOPMD array is supposed to be immutable.
+       public HttpCallExecutableRunnable(final String path, final @Nullable Collection<Header> headers, final Context context, final @Nullable ResultCallback resultCallback, final boolean mustRetryTask, final byte[] data){//NOPMD array is supposed to be immutable.
                this.path=path;
                this.headers=headers;
                this.context=context;
                this.callback=resultCallback;
+               this.mustRetryTask=mustRetryTask;
                this.data=data;
        }
 
@@ -197,13 +201,15 @@ public final class HttpCallExecutableRunnable extends ExecutableRunnable{
         * @param headers the extra headers
         * @param context the context instance
         * @param resultCallback {@link ResultCallback} instance
+        * @param mustRetryTask true if this task should be retried if it fails
         * @param message message to send
         */
-       public HttpCallExecutableRunnable(final String path, final @Nullable Collection<Header> headers, final Context context, final @Nullable ResultCallback resultCallback, final String... message){
+       public HttpCallExecutableRunnable(final String path, final @Nullable Collection<Header> headers, final Context context, final @Nullable ResultCallback resultCallback, final boolean mustRetryTask, final String... message){
                this.path=path;
                this.headers=headers;
                this.context=context;
                this.callback=resultCallback;
+               this.mustRetryTask=mustRetryTask;
                if(message.length == 0)
                        this.data=null;//NOPMD final field
                else
@@ -255,6 +261,8 @@ public final class HttpCallExecutableRunnable extends ExecutableRunnable{
                        e.printStackTrace();
                        if(callback != null)
                                callback.onError(toNonNull(context.getString(connection_error)));
+                       if(mustRetryTask)
+                               retry();
                }
        }
 }
index e09e31e36f1e7325109174a1ec8d4bcb4aa68d74..56911b68b59d8c48e736a7d6b7c609b7838ce02c 100644 (file)
@@ -60,7 +60,7 @@ final class RemoteCrashdumpHandler implements UncaughtExceptionHandler {
                pw.close();
 
                new HttpCallExecutableRunnable("/crashdump", toNonNull(Collections.<Header>emptyList()),
-                               toNonNull(context), null, toNonNull(baos.toByteArray())).execute();
+                               toNonNull(context), null, false, toNonNull(baos.toByteArray())).execute();
 
                try {
                        baos.close();
index ddb506bfdbabe17d80e81b002742ad2604c5146b..1262513a3a477a2358c54eb603e57647b6cec9d3 100644 (file)
@@ -317,7 +317,7 @@ public final class Utils {
                switch(address.protocol){
                case HTTP:
                        new HttpCallExecutableRunnable("/send", toNonNull(Arrays.asList(
-                                       new Header("X-Destination", toNonNull(address.data)))), context, null, message).execute();
+                                       new Header("X-Destination", toNonNull(address.data)))), context, null, true, message).execute();
                        break;
 
                case SMS:
@@ -416,7 +416,7 @@ public final class Utils {
         * @param context Context instance
         */
        public static void pollServer(final Context context){
-               new HttpCallExecutableRunnable("/get", null, context, new PollResultCallback(context)).execute();
+               new HttpCallExecutableRunnable("/get", null, context, new PollResultCallback(context), false).execute();
        }
 
        /**
This page took 0.023591 seconds and 4 git commands to generate.