use of java.util.concurrent.CancellationException in project linuxtools by eclipse.
the class AbstractRegistry method retrieveTagsFromRegistryV1.
/**
* Retrieves the list of tags for a given repository, assuming that the
* target registry is a registry v2 instance.
*
* @param client
* the client to use
* @param repository
* the repository to look-up
* @return the list of tags for the given repository
* @throws CancellationException
* - if the computation was cancelled
* @throws ExecutionException
* - if the computation threw an exception
* @throws InterruptedException
* - if the current thread was interrupted while waiting
*/
private List<IRepositoryTag> retrieveTagsFromRegistryV1(final Client client, final String repository) throws InterruptedException, ExecutionException {
final GenericType<Map<String, String>> REPOSITORY_TAGS_RESULT_LIST = new GenericType<Map<String, String>>() {
};
final WebTarget queryTagsResource = client.target(getHTTPServerAddress()).path(// $NON-NLS-1$
"v1").path("repositories").path(repository).path(// $NON-NLS-1$ //$NON-NLS-2$
"tags");
return queryTagsResource.request(APPLICATION_JSON_TYPE).async().method(GET, REPOSITORY_TAGS_RESULT_LIST).get().entrySet().stream().map(e -> new RepositoryTag(e.getKey(), e.getValue())).collect(Collectors.toList());
}
use of java.util.concurrent.CancellationException in project pravega by pravega.
the class FutureReadResultEntryCollection method cancelAll.
/**
* Cancels all Reads in this collection..
*/
void cancelAll() {
List<FutureReadResultEntry> toCancel;
synchronized (this.reads) {
toCancel = new ArrayList<>(this.reads);
this.reads.clear();
}
CancellationException ce = new CancellationException();
toCancel.forEach(e -> e.fail(ce));
}
use of java.util.concurrent.CancellationException in project cruise-control by linkedin.
the class OperationFutureTest method testCancelInProgressFuture.
@Test
public void testCancelInProgressFuture() throws InterruptedException, ExecutionException {
OperationFuture<Integer> future = new OperationFuture<>("testCancelInProgressFuture");
AtomicBoolean interrupted = new AtomicBoolean(false);
// An execution thread that should be interrupted before completing the future.
Thread executionThread = new Thread(new OperationRunnable<Integer>(null, future) {
@Override
protected Integer getResult() throws Exception {
try {
synchronized (this) {
while (!interrupted.get()) {
this.wait();
}
}
return 100;
} catch (InterruptedException ie) {
interrupted.set(true);
throw ie;
}
}
});
executionThread.start();
TestThread t = new TestThread(future::get);
t.start();
future.cancel(true);
t.join();
executionThread.join();
assertEquals(0, t.result());
assertTrue(t.exception() instanceof CancellationException);
assertTrue(future.isDone());
assertTrue(future.isCancelled());
assertTrue(interrupted.get());
}
use of java.util.concurrent.CancellationException in project assertj-core by joel-costigliola.
the class StandardRepresentation method toStringOf.
protected String toStringOf(CompletableFuture<?> future) {
String className = future.getClass().getSimpleName();
if (!future.isDone())
return concat(className, "[Incomplete]");
try {
Object joinResult = future.join();
// avoid stack overflow error if future join on itself or another future that cycles back to the first
Object joinResultRepresentation = joinResult instanceof CompletableFuture ? joinResult : toStringOf(joinResult);
return concat(className, "[Completed: ", joinResultRepresentation, "]");
} catch (CompletionException e) {
return concat(className, "[Failed: ", toStringOf(e.getCause()), "]", String.format("%n%s", getStackTrace(e)));
} catch (CancellationException e) {
return concat(className, "[Cancelled]");
}
}
use of java.util.concurrent.CancellationException in project android_packages_apps_Dialer by LineageOS.
the class ActivationTask method onExecuteInBackgroundThread.
@Override
@WorkerThread
public void onExecuteInBackgroundThread() {
Assert.isNotMainThread();
LoggerUtils.logImpressionOnMainThread(getContext(), DialerImpression.Type.VVM_ACTIVATION_STARTED);
PhoneAccountHandle phoneAccountHandle = getPhoneAccountHandle();
if (phoneAccountHandle == null) {
// This should never happen
VvmLog.e(TAG, "null PhoneAccountHandle");
return;
}
PreOMigrationHandler.migrate(getContext(), phoneAccountHandle);
if (!VisualVoicemailSettingsUtil.isEnabled(getContext(), phoneAccountHandle)) {
VvmLog.i(TAG, "VVM is disabled");
return;
}
OmtpVvmCarrierConfigHelper helper = new OmtpVvmCarrierConfigHelper(getContext(), phoneAccountHandle);
if (!helper.isValid()) {
VvmLog.i(TAG, "VVM not supported on phoneAccountHandle " + phoneAccountHandle);
VvmAccountManager.removeAccount(getContext(), phoneAccountHandle);
return;
}
// a good chance of being started up.
if (!VoicemailStatus.edit(getContext(), phoneAccountHandle).setType(helper.getVvmType()).apply()) {
VvmLog.e(TAG, "Failed to configure content provider - " + helper.getVvmType());
fail();
}
VvmLog.i(TAG, "VVM content provider configured - " + helper.getVvmType());
if (VvmAccountManager.isAccountActivated(getContext(), phoneAccountHandle)) {
VvmLog.i(TAG, "Account is already activated");
onSuccess(getContext(), phoneAccountHandle);
return;
}
helper.handleEvent(VoicemailStatus.edit(getContext(), phoneAccountHandle), OmtpEvents.CONFIG_ACTIVATING);
if (!hasSignal(getContext(), phoneAccountHandle)) {
VvmLog.i(TAG, "Service lost during activation, aborting");
// Restore the "NO SIGNAL" state since it will be overwritten by the CONFIG_ACTIVATING
// event.
helper.handleEvent(VoicemailStatus.edit(getContext(), phoneAccountHandle), OmtpEvents.NOTIFICATION_SERVICE_LOST);
// Don't retry, a new activation will be started after the signal returned.
return;
}
helper.activateSmsFilter();
VoicemailStatus.Editor status = mRetryPolicy.getVoicemailStatusEditor();
VisualVoicemailProtocol protocol = helper.getProtocol();
Bundle data;
if (mMessageData != null) {
// The content of STATUS SMS is provided to launch this task, no need to request it
// again.
data = mMessageData;
} else {
try (StatusSmsFetcher fetcher = new StatusSmsFetcher(getContext(), phoneAccountHandle)) {
protocol.startActivation(helper, fetcher.getSentIntent());
// Both the fetcher and OmtpMessageReceiver will be triggered, but
// OmtpMessageReceiver will just route the SMS back to ActivationTask, which will be
// rejected because the task is still running.
data = fetcher.get();
} catch (TimeoutException e) {
// The carrier is expected to return an STATUS SMS within STATUS_SMS_TIMEOUT_MILLIS
// handleEvent() will do the logging.
helper.handleEvent(status, OmtpEvents.CONFIG_STATUS_SMS_TIME_OUT);
fail();
return;
} catch (CancellationException e) {
VvmLog.e(TAG, "Unable to send status request SMS");
fail();
return;
} catch (InterruptedException | ExecutionException | IOException e) {
VvmLog.e(TAG, "can't get future STATUS SMS", e);
fail();
return;
}
}
StatusMessage message = new StatusMessage(data);
VvmLog.d(TAG, "STATUS SMS received: st=" + message.getProvisioningStatus() + ", rc=" + message.getReturnCode());
if (message.getProvisioningStatus().equals(OmtpConstants.SUBSCRIBER_READY)) {
VvmLog.d(TAG, "subscriber ready, no activation required");
updateSource(getContext(), phoneAccountHandle, message);
} else {
if (helper.supportsProvisioning()) {
VvmLog.i(TAG, "Subscriber not ready, start provisioning");
helper.startProvisioning(this, phoneAccountHandle, status, message, data);
} else if (message.getProvisioningStatus().equals(OmtpConstants.SUBSCRIBER_NEW)) {
VvmLog.i(TAG, "Subscriber new but provisioning is not supported");
// Ignore the non-ready state and attempt to use the provided info as is.
// This is probably caused by not completing the new user tutorial.
updateSource(getContext(), phoneAccountHandle, message);
} else {
VvmLog.i(TAG, "Subscriber not ready but provisioning is not supported");
helper.handleEvent(status, OmtpEvents.CONFIG_SERVICE_NOT_AVAILABLE);
}
}
LoggerUtils.logImpressionOnMainThread(getContext(), DialerImpression.Type.VVM_ACTIVATION_COMPLETED);
}
Aggregations