Multiple RestAdapters Modifications

I have several endpoints and should have different ErrorHandler& RequestInterceptorfor some of them. In this answer, JakeWharton (one of the developers Retrofit) says it RestAdaptershould be considered as a singleton. In the same message, another message says that a RequestInterceptorssingleton map is used to reach the end point .

To make sure everyone RestAdaptersuses the same connection pool when using OkHttp, I use mine OkHttpClientamong all adapters such as

OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setConnectTimeout(10000, TimeUnit.MILLISECONDS);
okHttpClient.setReadTimeout(10000, TimeUnit.MILLISECONDS);

OkClient okClient = new OkClient(okHttpClient);

RestAdapter restAdapter1 = new RestAdapter.Builder()
        .setClient(okClient)
        .setLogLevel(RestAdapter.LogLevel.FULL)
        .setEndpoint("http://example.com/)
        .setErrorHandler(ErrHandlerFactory.get(Endpoint1.class))
        .setRequestInterceptor(ReqInterceptorFactory.get(Endpoint1.class))
        .build();

RestAdapter restAdapter2 = new RestAdapter.Builder()
        .setClient(okClient)
        .setLogLevel(RestAdapter.LogLevel.FULL)
        .setEndpoint("http://example.com/)
        .setErrorHandler(ErrHandlerFactory.get(Endpoint2.class))
        .setRequestInterceptor(ReqInterceptorFactory.get(Endpoint2.class))
        .build();

Endpoint1 Endpoint2 - interface, . RestAdapters api. - ?

+4

All Articles