package retrofit.sharehttp;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
 * Created by dementrock on 3/20/15.
 */
public abstract class ShareHttpClient {

    private static ShareHttpClientFactory sFactory;

    public static ShareHttpClientFactory getFactory() {
        return sFactory;
    }

    public static void setFactory(ShareHttpClientFactory factory) {
        sFactory = factory;
    }

    public static ShareHttpClient newInstance() {
        if (sFactory != null) {
            return sFactory.newInstance();
        }
        throw new RuntimeException("Need to set Factory before instantiating ShareHttpClient " +
                "instance!");
    }

    public abstract void setConnectTimeout(long timeout, TimeUnit unit);

    public abstract void setReadTimeout(long timeout, TimeUnit unit);

    public abstract void setWriteTimeout(long timeout, TimeUnit unit);

    public abstract Response executeSync(Request request) throws IOException;

    public abstract void executeAsync(Request request, ResponseCallback callback);
}

@@ -50,16 +50,55 @@
 eption;%0A
+import java.util.concurrent.Semaphore;%0A
 import j
@@ -127,16 +127,16 @@
 meUnit;%0A
-
 %0A/**%0A * 
@@ -953,39 +953,311 @@
    p
-ublic abstract Response
+rivate static class Out%3CT%3E %7B%0A        T obj;%0A    %7D%0A%0A    public Response executeSync(Request request) throws IOException %7B%0A        final Semaphore waitSem = new Semaphore(0);%0A        final Out%3CResponse%3E responseWrapper = new Out%3C%3E();%0A        final Out%3CIOException%3E exWrapper = new Out%3C%3E();%0A       
  execute
 Sync
@@ -1256,49 +1256,667 @@
 cute
-S
+As
 ync(
-Request request) throws IOException;
+request, new ResponseCallback() %7B%0A            @Override%0A            public void onFailure(Request request, IOException e) %7B%0A                exWrapper.obj = e;%0A                waitSem.release();%0A            %7D%0A%0A            @Override%0A            public void onResponse(Response response) %7B%0A                responseWrapper.obj = response;%0A                waitSem.release();%0A            %7D%0A        %7D);%0A        try %7B%0A            waitSem.acquire();%0A        %7D catch (InterruptedException e) %7B%0A            throw new IOException(e);%0A        %7D%0A        if (exWrapper.obj != null) %7B%0A            throw exWrapper.obj;%0A        %7D%0A        return responseWrapper.obj;%0A    %7D
 %0A%0A  

simplify executeSync