Create a HTTP client per instance (#86)
Create javax HTTP client once per instance instead of per request. Fixes #82
This commit is contained in:
parent
f45ae1833e
commit
d8c47603d9
@ -43,6 +43,19 @@ import com.scylladb.jmx.utils.SnapshotDetailsTabularData;
|
||||
|
||||
public class APIClient {
|
||||
private Map<String, CacheEntry> cache = new HashMap<String, CacheEntry>();
|
||||
private final APIConfig config;
|
||||
private final ClientConfig clientConfig;
|
||||
private final Client client;
|
||||
private JsonReaderFactory factory = Json.createReaderFactory(null);
|
||||
|
||||
private static final Logger logger = Logger.getLogger(APIClient.class.getName());
|
||||
|
||||
public APIClient(APIConfig config) {
|
||||
this.config = config;
|
||||
this.clientConfig = new ClientConfig();
|
||||
clientConfig.register(new JacksonJaxbJsonProvider());
|
||||
this.client = ClientBuilder.newClient(clientConfig);
|
||||
}
|
||||
|
||||
private String getCacheKey(String key, MultivaluedMap<String, String> param, long duration) {
|
||||
if (duration <= 0) {
|
||||
@ -75,24 +88,12 @@ public class APIClient {
|
||||
return (value != null && value.valid(duration)) ? value.jsonObject() : null;
|
||||
}
|
||||
|
||||
private JsonReaderFactory factory = Json.createReaderFactory(null);
|
||||
private static final Logger logger = Logger.getLogger(APIClient.class.getName());
|
||||
|
||||
private final APIConfig config;
|
||||
private final ClientConfig clientConfig;
|
||||
|
||||
public APIClient(APIConfig config) {
|
||||
this.config = config;
|
||||
this.clientConfig = new ClientConfig();
|
||||
clientConfig.register(new JacksonJaxbJsonProvider());
|
||||
}
|
||||
|
||||
private String getBaseUrl() {
|
||||
return config.getBaseUrl();
|
||||
}
|
||||
|
||||
public Invocation.Builder get(String path, MultivaluedMap<String, String> queryParams) {
|
||||
Client client = ClientBuilder.newClient(clientConfig);
|
||||
WebTarget webTarget = client.target(getBaseUrl()).path(path);
|
||||
if (queryParams != null) {
|
||||
for (Entry<String, List<String>> qp : queryParams.entrySet()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user