@Override public boolean isExecuted() { return delegate.isExecuted(); }
@Override public boolean isExecuted() { return call.isExecuted(); }
@Override public boolean isExecuted() { return delegate.isExecuted(); }
@Override public boolean isExecuted() { return getDelegate().isExecuted(); }
@Test public void passThroughCallsToDecoratedObject() throws IOException { final Call<String> call = mock(StringCall.class); final Call<String> decorated = new DecoratedCall<>(call); decorated.cancel(); Mockito.verify(call).cancel(); decorated.enqueue(null); Mockito.verify(call).enqueue(any()); decorated.isExecuted(); Mockito.verify(call).isExecuted(); decorated.isCanceled(); Mockito.verify(call).isCanceled(); decorated.clone(); Mockito.verify(call).clone(); decorated.request(); Mockito.verify(call).request(); decorated.execute(); Mockito.verify(call).execute(); }
@Override public boolean isExecuted() { return delegate.isExecuted(); }
@Override public boolean isExecuted() { return delegate.isExecuted(); }
@Override public boolean isExecuted() { return mCall.isExecuted() || mExecuted; }
@Override public void refresh(final Callback<T> callback) { if (callback == null) { throw new NullPointerException("callback == null"); } if (mExecuted || mCall.isExecuted()) { throw new IllegalStateException("Already executed."); } mExecuted = true; if (mCachingActive) { new Thread(new Runnable() { @Override public void run() { networkLoad(callback, true); } }).start(); return; } delegate(callback); }
CachedCall(Executor executor, Call<T> call, Type responseType, Annotation[] annotations, Retrofit retrofit, Cache<String, byte[]> cachingSystem) { this.mExecutor = executor; this.mCall = call; this.mResponseType = responseType; this.mAnnotations = annotations; this.mRetrofit = retrofit; this.mCachingSystem = cachingSystem; this.mRequest = RequestBuilder.build(call); mCachingActive = mRequest != null && mRequest.method().equals("GET"); mExecuted = mCall.isExecuted(); mCanceled = mCall.isCanceled(); }
@Override public void enqueue(final Callback<T> callback) { if (callback == null) { throw new NullPointerException("callback == null"); } if (mExecuted || mCall.isExecuted()) { throw new IllegalStateException("Already executed."); } mExecuted = true; if (mCachingActive) { // Look in cache if we are in a GET method new Thread(new Runnable() { @Override public void run() { if (!cacheLoad(callback)) { networkLoad(callback, false); } } }).start(); return; } delegate(callback); }
if (requestCall.isExecuted()) { call = requestCall.clone(); } else {
public <T> T syncRequest(final Call<T> requestCall) { Call<T> call; if (requestCall.isExecuted()) { call = requestCall.clone(); } else { call = requestCall; } try{ Response<T> response = call.execute(); if (response.isSuccessful()) { T result = response.body(); return result; }else { return null; } } catch (IOException e) { Logger.e(e.getMessage()); } return null; } //
@Override public Response<T> execute() throws IOException { if (mExecuted || mCall.isExecuted()) { throw new IllegalStateException("Already executed."); } mExecuted = true; if (mCachingActive) { byte[] data = mCachingSystem.get(CacheUtils.urlToKey(mCall.request().url())); if (data == null) { // Response is not cached Response<T> response = mCall.execute(); if (response.isSuccessful()) { mCachingSystem.put( CacheUtils.urlToKey(mCall.request().url()), CacheUtils.responseToBytes(mRetrofit, response.body(), responseType(), mAnnotations)); } return response; } // Response is cached final T convertedData = CacheUtils.bytesToResponse( mRetrofit, mResponseType, mAnnotations, data); return Response.success(convertedData); } return mCall.execute(); }
if (requestCall.isExecuted()) { call = requestCall.clone(); } else {