java - Multiple Retrofit RestAdapters -
i have number of endpoints , have have different errorhandler
s & requestinterceptor
s few of them. in this reply jakewharton (one of devs of retrofit
) says restadapter
should treated singleton. in same post answer says map of singletons used accomplish endpoint specific requestinterceptors
.
to create sure restadapters
utilize same connection pool when using okhttp
, sharing okhttpclient
s among adapters this
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();
where endpoint1
& endpoint2
interface
s follow retrofit's annotations. build restadapters used farther api calls. best way have endpoint specific operations or missing something?
java retrofit okhttp
No comments:
Post a Comment