use of aQute.bnd.service.progress.ProgressPlugin.Task in project bnd by bndtools.
the class HttpClient method getTask.
ProgressPlugin.Task getTask(final HttpRequest<?> request) {
final String name = (request.upload == null ? "Download " : "Upload ") + request.url;
final int size = 100;
final ProgressPlugin.Task task;
final List<ProgressPlugin> progressPlugins = registry != null ? registry.getPlugins(ProgressPlugin.class) : null;
if (progressPlugins != null && progressPlugins.size() > 1) {
final List<ProgressPlugin.Task> multiplexedTasks = new ArrayList<>();
for (ProgressPlugin progressPlugin : progressPlugins) {
multiplexedTasks.add(progressPlugin.startTask(name, size));
}
task = new ProgressPlugin.Task() {
@Override
public void worked(int units) {
for (ProgressPlugin.Task task : multiplexedTasks) {
task.worked(units);
}
}
@Override
public void done(String message, Throwable e) {
for (ProgressPlugin.Task task : multiplexedTasks) {
task.done(message, e);
}
}
@Override
public boolean isCanceled() {
for (ProgressPlugin.Task task : multiplexedTasks) {
if (task.isCanceled()) {
return true;
}
}
return false;
}
};
} else if (progressPlugins != null && progressPlugins.size() == 1) {
task = progressPlugins.get(0).startTask(name, size);
} else {
task = new ProgressPlugin.Task() {
@Override
public void worked(int units) {
}
@Override
public void done(String message, Throwable e) {
}
@Override
public boolean isCanceled() {
return Thread.currentThread().isInterrupted();
}
};
}
return task;
}
use of aQute.bnd.service.progress.ProgressPlugin.Task in project bnd by bndtools.
the class HttpClient method send0.
public TaggedData send0(final HttpRequest<?> request) throws Exception {
final ProxySetup proxy = getProxySetup(request.url);
final URLConnection con = getProxiedAndConfiguredConnection(request.url, proxy);
final HttpURLConnection hcon = (HttpURLConnection) (con instanceof HttpURLConnection ? con : null);
if (request.ifNoneMatch != null) {
request.headers.put("If-None-Match", entitytag(request.ifNoneMatch));
}
if (request.ifMatch != null) {
request.headers.put("If-Match", "\"" + entitytag(request.ifMatch));
}
if (request.ifModifiedSince > 0) {
request.headers.put("If-Modified-Since", httpDateFormat().format(new Date(request.ifModifiedSince)));
}
if (request.ifUnmodifiedSince != 0) {
request.headers.put("If-Unmodified-Since", httpDateFormat().format(new Date(request.ifUnmodifiedSince)));
}
setHeaders(request.headers, con);
configureHttpConnection(request.verb, hcon);
final ProgressPlugin.Task task = getTask(request);
try {
TaggedData td = connectWithProxy(proxy, new Callable<TaggedData>() {
@Override
public TaggedData call() throws Exception {
return doConnect(request.upload, request.download, con, hcon, request, task);
}
});
logger.debug("result {}", td);
return td;
} catch (Throwable t) {
task.done("Failed " + t, t);
throw t;
}
}
Aggregations