use of com.tvd12.ezyfox.concurrent.EzyFuture in project ezyhttp by youngmonkeys.
the class HttpClientProxy method request.
public ResponseEntity request(Request request, int timeout) throws Exception {
EzyFuture future = new EzyFutureTask();
futures.addFuture(request, future);
try {
addRequest(request);
} catch (Exception e) {
futures.removeFuture(request);
throw e;
}
return future.get(timeout);
}
use of com.tvd12.ezyfox.concurrent.EzyFuture in project ezyhttp by youngmonkeys.
the class ResourceUploadManager method loop.
private void loop() {
byte[] buffer = new byte[bufferSize];
while (active) {
Entry entry = null;
boolean done = true;
boolean isMaxUploaded = false;
Exception exception = null;
try {
entry = queue.take();
if (entry == POISON) {
break;
}
InputStream inputStream = entry.inputStream;
OutputStream outputStream = entry.outputStream;
int read = inputStream.read(buffer);
if (entry.increaseUploadedSize(read)) {
if (read > 0) {
outputStream.write(buffer, 0, read);
done = false;
}
} else {
isMaxUploaded = true;
}
} catch (Exception e) {
exception = e;
logger.info("upload error", e);
} catch (Throwable e) {
exception = new IllegalStateException(e);
logger.info("upload fatal error", e);
}
if (entry == null) {
continue;
}
if (isMaxUploaded) {
exception = new MaxUploadSizeException(entry.maxUploadSize);
}
try {
if (done) {
EzyFuture future = futureMap.removeFuture(entry);
if (future == null) {
continue;
}
if (exception != null) {
future.setException(exception);
} else {
future.setResult(Boolean.TRUE);
}
} else {
if (!queue.offer(entry)) {
EzyFuture future = futureMap.removeFuture(entry);
if (future != null) {
future.setException(new MaxResourceUploadCapacity(capacity));
}
}
}
} catch (Throwable e) {
logger.info("handle upload result error", e);
}
}
}
Aggregations