Skip to content

Commit 6a2c344

Browse files
author
danf
committed
Next development version - 0.6
1 parent 68c8a14 commit 6a2c344

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

impl/src/main/java/com/jfrog/bintray/client/impl/BintrayClient.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,37 @@
1414
*/
1515
public class BintrayClient {
1616

17-
public static final int DEFAULT_TIMEOUT = 15000;
17+
public static final int DEFAULT_TIMEOUT = 150000;
1818
public static final String BINTRAY_API_URL = "https://api.bintray.com";
1919
public static final String USER_AGENT = "BintrayJavaClient/0.5"; // TODO: make dynamic
20+
private static final int DEFAULT_THREAD_POOL_SIZE = 5; //Don't mess with this - its here for a reason
2021

2122
//Mainly used by Artifactory to avoid all of the configuration, but you can specify your own too
22-
static public Bintray create(CloseableHttpClient preConfiguredClient, String url) {
23-
return new BintrayImpl(preConfiguredClient, url);
23+
static public Bintray create(CloseableHttpClient preConfiguredClient, String url, int threadPoolSize) {
24+
return new BintrayImpl(preConfiguredClient, url, threadPoolSize);
2425
}
2526

2627
/**
2728
* Username and API key, no proxy
2829
*/
2930
static public Bintray create(String userName, String apiKey) {
3031
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(userName, apiKey);
31-
return new BintrayImpl(createClient(creds, null, BINTRAY_API_URL), BINTRAY_API_URL);
32+
return new BintrayImpl(createClient(creds, null, BINTRAY_API_URL), BINTRAY_API_URL, DEFAULT_THREAD_POOL_SIZE);
3233
}
3334

3435
/**
3536
* Username, API key, and custom url
3637
*/
3738
static public Bintray create(String url, String userName, String apiKey) {
3839
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(userName, apiKey);
39-
return new BintrayImpl(createClient(creds, null, BINTRAY_API_URL), BINTRAY_API_URL);
40+
return new BintrayImpl(createClient(creds, null, BINTRAY_API_URL), BINTRAY_API_URL, DEFAULT_THREAD_POOL_SIZE);
4041
}
4142

4243
/**
4344
* Credentials with proxy
4445
*/
4546
static public Bintray create(UsernamePasswordCredentials creds, HttpClientConfigurator.ProxyConfig proxyConfig) {
46-
return new BintrayImpl(createClient(creds, proxyConfig, BINTRAY_API_URL), BINTRAY_API_URL);
47+
return new BintrayImpl(createClient(creds, proxyConfig, BINTRAY_API_URL), BINTRAY_API_URL, DEFAULT_THREAD_POOL_SIZE);
4748
}
4849

4950
/**
@@ -52,7 +53,7 @@ static public Bintray create(UsernamePasswordCredentials creds, HttpClientConfig
5253
static public Bintray create(String bintrayUserName, String bintrayApiKey,
5354
HttpClientConfigurator.ProxyConfig proxyConfig, String url) {
5455
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(bintrayUserName, bintrayApiKey);
55-
return new BintrayImpl(createClient(creds, proxyConfig, url), url);
56+
return new BintrayImpl(createClient(creds, proxyConfig, url), url, DEFAULT_THREAD_POOL_SIZE);
5657
}
5758

5859

impl/src/main/java/com/jfrog/bintray/client/impl/handle/BintrayImpl.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@
3030
*/
3131
public class BintrayImpl implements Bintray {
3232
private static final Logger log = LoggerFactory.getLogger(BintrayImpl.class);
33-
ExecutorService executorService = Executors.newCachedThreadPool();
33+
ExecutorService executorService;
3434
private CloseableHttpClient client;
3535
private ResponseHandler<HttpResponse> responseHandler = new BintrayResponseHandler();
3636
private String baseUrl;
3737

3838

39-
public BintrayImpl(CloseableHttpClient client, String baseUrl) {
39+
public BintrayImpl(CloseableHttpClient client, String baseUrl, int threadPoolSize) {
4040
this.client = client;
4141
this.baseUrl = (baseUrl == null || baseUrl.isEmpty()) ? BintrayClient.BINTRAY_API_URL : baseUrl;
42+
this.executorService = Executors.newFixedThreadPool(threadPoolSize);
4243
}
4344

4445
static public void addContentTypeJsonHeader(Map<String, String> headers) {
@@ -202,7 +203,7 @@ private HttpResponse put(List<HttpPut> requests) throws MultipleBintrayCallExcep
202203
runners.add(runner);
203204
}
204205
try {
205-
executions = executorService.invokeAll(runners, BintrayClient.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
206+
executions = executorService.invokeAll(runners, 10, TimeUnit.MINUTES);
206207
} catch (InterruptedException e) {
207208
BintrayCallException bce = new BintrayCallException(400, e.getMessage(), (e.getCause() == null) ? "" : e.getCause().getMessage());
208209
log.error(bce.toString());
@@ -225,7 +226,7 @@ private HttpResponse put(List<HttpPut> requests) throws MultipleBintrayCallExcep
225226
bce = new BintrayCallException(400, e.getMessage(), (e.getCause() == null) ? "" : e.getCause().getMessage());
226227
}
227228
log.error(bce.toString());
228-
log.debug("{}", e);
229+
log.debug("{}", e.getMessage(), e);
229230
errors.add(bce);
230231
} finally {
231232
executionIter.remove(); //Remove completed execution from iteration
@@ -312,15 +313,18 @@ public String call() throws BintrayCallException {
312313
try {
313314
response = client.execute(request, responseHandler, context);
314315
} catch (BintrayCallException bce) {
315-
log.debug("{}", bce);
316+
log.debug("{}", bce.getMessage(), bce);
316317
errorResultBuilder.append(bce.getMessage());
317318
bce.setMessage(errorResultBuilder.toString());
318319
throw bce;
319320
} catch (IOException ioe) {
320-
log.debug("{}", ioe);
321-
String cause = (ioe.getCause() == null) ? "" : " : " + ioe.getCause().getMessage();
321+
log.debug("IOException occured: '{}'", ioe.getMessage(), ioe);
322+
String cause = (ioe.getCause() == null) ? ((ioe.getMessage() != null && !ioe.getMessage().equals("")) ? ioe.getMessage() : ioe.toString())
323+
: " : " + ((ioe.getCause().getMessage() != null && !ioe.getCause().getMessage().equals("")) ? ioe.getCause().getMessage() : ioe.getCause().toString());
322324
errorResultBuilder.append(ioe.getMessage()).append(cause);
323325
throw new BintrayCallException(HttpStatus.SC_BAD_REQUEST, ioe.getMessage(), errorResultBuilder.toString());
326+
} finally {
327+
request.releaseConnection();
324328
}
325329
if (statusNotOk(response.getStatusLine().getStatusCode())) {
326330
BintrayCallException bce = new BintrayCallException(response);

0 commit comments

Comments
 (0)