Work in progress. Do not rely on this commit
[pithos-web-client] / src / gr / grnet / pithos / web / client / rest / HeadRequest.java
index ddbab44..1148554 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2011 GRNET S.A. All rights reserved.
+ * Copyright 2011-2012 GRNET S.A. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or
  * without modification, are permitted provided that the following
@@ -35,7 +35,8 @@
 
 package gr.grnet.pithos.web.client.rest;
 
-import gr.grnet.pithos.web.client.foldertree.Resource;
+import gr.grnet.pithos.web.client.Pithos;
+import gr.grnet.pithos.web.client.Resource;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -49,6 +50,12 @@ import com.google.gwt.http.client.Response;
 
 public abstract class HeadRequest<T extends Resource> implements ScheduledCommand {
 
+       protected static final int MAX_RETRIES = 3; 
+
+    private final Pithos app;
+
+       protected int retries = 0; 
+
        protected Class<T> aClass;
 
     private String api;
@@ -69,7 +76,8 @@ public abstract class HeadRequest<T extends Resource> implements ScheduledComman
 
     public abstract void onError(Throwable t);
 
-    public HeadRequest(Class<T> aClass, String api, String owner, String path, int okCode, T result) {
+    public HeadRequest(Pithos app, Class<T> aClass, String api, String owner, String path, int okCode, T result) {
+        this.app = app;
         this.aClass = aClass;
         this.api = api;
         this.owner = owner;
@@ -78,12 +86,12 @@ public abstract class HeadRequest<T extends Resource> implements ScheduledComman
         this.result = result;
     }
 
-    public HeadRequest(Class<T> aClass, String api, String owner, String path) {
-        this(aClass, api, owner, path, Response.SC_NO_CONTENT, null);
+    public HeadRequest(Pithos app, Class<T> aClass, String api, String owner, String path) {
+        this(app, aClass, api, owner, path, Response.SC_NO_CONTENT, null);
     }
 
-    public HeadRequest(Class<T> aClass, String api, String owner, String path, T result) {
-        this(aClass, api, owner, path, Response.SC_NO_CONTENT, result);
+    public HeadRequest(Pithos app, Class<T> aClass, String api, String owner, String path, T result) {
+        this(app, aClass, api, owner, path, Response.SC_NO_CONTENT, result);
     }
 
     @Override
@@ -105,7 +113,7 @@ public abstract class HeadRequest<T extends Resource> implements ScheduledComman
 
                 @Override
                 public T deserialize(Response response) {
-                    return Resource.createFromResponse(aClass, owner, response, result);
+                    return Resource.createFromResponse(app, aClass, owner, response, result);
                 }
 
                 @Override
@@ -125,6 +133,7 @@ public abstract class HeadRequest<T extends Resource> implements ScheduledComman
                                        HeadRequest.this.onUnauthorized(response);
                                }
             });
+            retries++;
         }
         catch (RequestException e) {
         }