use of java.util.concurrent.CancellationException in project streamsupport by stefan-zobel.
the class ForkJoinTaskTest method testCancelledInvokeSingleton.
/**
* invoke task throws exception when task cancelled
*/
public void testCancelledInvokeSingleton() {
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
AsyncFib f = new AsyncFib(8);
assertTrue(f.cancel(true));
try {
f.invoke();
shouldThrow();
} catch (CancellationException success) {
checkCancelled(f);
}
}
};
testInvokeOnPool(singletonPool(), a);
}
use of java.util.concurrent.CancellationException in project streamsupport by stefan-zobel.
the class ForkJoinTaskTest method testCancelledForkTimedGetSingleton.
/**
* timed get of a forked task throws exception when task cancelled
*/
public void testCancelledForkTimedGetSingleton() throws Exception {
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() throws Exception {
AsyncFib f = new AsyncFib(8);
assertTrue(f.cancel(true));
assertSame(f, f.fork());
try {
f.get(LONG_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (CancellationException success) {
checkCancelled(f);
}
}
};
testInvokeOnPool(singletonPool(), a);
}
use of java.util.concurrent.CancellationException in project robotcode by OutoftheBoxFTC.
the class MonitoredUsbDeviceConnection method controlTransfer.
public int controlTransfer(int requestType, int request, int value, int index, byte[] buffer, int offset, int length, int timeout) throws RobotUsbException {
synchronized (// concurrency paranoia
monitor) {
this.callResult = FtDevice.RC_PARANOIA;
try {
if (acquireUsbWriteLock()) {
try {
this.requestType = requestType;
this.request = request;
this.value = value;
this.index = index;
this.buffer = buffer;
this.offset = offset;
this.length = length;
this.timeout = timeout;
failureType = FailureType.CONTROL_TRANSFER;
RobotUsbException timedOutException = monitor.monitor(controlTransferAction, failureAction, msUsbWriteDurationMax, TimeUnit.MILLISECONDS);
if (timedOutException != null) {
throw timedOutException;
}
} catch (ExecutionException | CancellationException e) {
// We should have ruled out all of these cases with the above logic
throw RobotUsbUnspecifiedException.createChained(e, "control transfer: internal error: unexpected exception from future");
} finally {
releaseUsbWriteLock();
}
} else {
throw unableToAcquireWriteLockException();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (RuntimeException e) {
throw RobotUsbFTDIException.createChained(e, "runtime exception %s during controlTransfer() of %d bytes on %s", e.getClass().getSimpleName(), length, serialNumber);
}
return callResult;
}
}
use of java.util.concurrent.CancellationException in project h2database by h2database.
the class LazyFuture method get.
@Override
public T get() throws InterruptedException, ExecutionException {
switch(state) {
case S_READY:
try {
result = run();
state = S_DONE;
} catch (Exception e) {
error = e;
if (e instanceof InterruptedException) {
throw (InterruptedException) e;
}
throw new ExecutionException(e);
} finally {
if (state != S_DONE) {
state = S_ERROR;
}
}
return result;
case S_DONE:
return result;
case S_ERROR:
throw new ExecutionException(error);
case S_CANCELED:
throw new CancellationException();
default:
throw DbException.throwInternalError("" + state);
}
}
use of java.util.concurrent.CancellationException in project box-android-sdk by box.
the class RealTimeServerConnection method connect.
/**
* Returns a message once a change has been detected or error occurs. Otherwise this method will continue reconnecting.
* @return A BoxSimpleMessage with a simple message indicating a change in the user's account.
*/
public BoxSimpleMessage connect() {
mRetries = 0;
try {
BoxIteratorRealTimeServers servers = (BoxIteratorRealTimeServers) mRequest.send();
mBoxRealTimeServer = servers.get(0);
} catch (BoxException e) {
mChangeListener.onException(e, this);
return null;
}
BoxRequestsEvent.LongPollMessageRequest messageRequest = new BoxRequestsEvent.LongPollMessageRequest(mBoxRealTimeServer.getUrl(), mSession);
messageRequest.setTimeOut(mBoxRealTimeServer.getFieldRetryTimeout().intValue() * 1000);
boolean shouldRetry = true;
do {
BoxFutureTask<BoxSimpleMessage> task = null;
try {
task = messageRequest.toTask().addOnCompletedListener(this);
mExecutor.submit(task);
BoxResponse<BoxSimpleMessage> response = task.get(mBoxRealTimeServer.getFieldRetryTimeout().intValue(), TimeUnit.SECONDS);
if (response.isSuccess() && !response.getResult().getMessage().equals(BoxSimpleMessage.MESSAGE_RECONNECT)) {
return response.getResult();
}
} catch (TimeoutException e) {
if (task != null) {
try {
// if the timeout is coming from the task then cancel the task (as httpurlconnection timeout is unreliable).
task.cancel(true);
} catch (CancellationException e1) {
}
}
} catch (InterruptedException e) {
mChangeListener.onException(e, this);
} catch (ExecutionException e) {
mChangeListener.onException(e, this);
}
mRetries++;
if (mBoxRealTimeServer.getMaxRetries() < mRetries) {
shouldRetry = false;
}
} while (shouldRetry);
mChangeListener.onException(new BoxException.MaxAttemptsExceeded("Max retries exceeded, ", mRetries), this);
return null;
}
Aggregations