List of usage examples for java.lang InterruptedException getCause
public synchronized Throwable getCause()
From source file:org.yccheok.jstock.gui.OptionsAlertJPanel.java
private void initCredentialEx() { SwingWorker swingWorker = new SwingWorker<Pair<Credential, String>, Void>() { @Override//from w ww .j a va 2 s . c o m protected Pair<Credential, String> doInBackground() throws Exception { final Pair<Credential, String> pair = org.yccheok.jstock.google.Utils.authorizeGmailOffline(); return pair; } @Override public void done() { Pair<Credential, String> pair = null; try { pair = this.get(); } catch (InterruptedException ex) { log.error(null, ex); } catch (ExecutionException ex) { Throwable throwable = ex.getCause(); if (throwable instanceof com.google.api.client.googleapis.json.GoogleJsonResponseException) { com.google.api.client.googleapis.json.GoogleJsonResponseException ge = (com.google.api.client.googleapis.json.GoogleJsonResponseException) throwable; for (GoogleJsonError.ErrorInfo errorInfo : ge.getDetails().getErrors()) { if ("insufficientPermissions".equals(errorInfo.getReason())) { org.yccheok.jstock.google.Utils.logoutGmail(); break; } } } log.error(null, ex); } if (pair != null) { credentialEx = pair; jCheckBox2.setSelected(JStock.instance().getJStockOptions().isSendEmail()); } updateGUIState(); } }; swingWorker.execute(); }
From source file:com.microsoft.azure.keyvault.extensions.test.KeyVaultKeyResolverDefaultProviderTest.java
@Test public void KeyVault_KeyVaultKeyResolver_Secret256Base64() throws InterruptedException, ExecutionException { // Arrange/* w w w .j a v a 2 s . c o m*/ byte[] keyBytes = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F }; byte[] CEK = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, (byte) 0x88, (byte) 0x99, (byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD, (byte) 0xEE, (byte) 0xFF }; byte[] EK = { 0x64, (byte) 0xE8, (byte) 0xC3, (byte) 0xF9, (byte) 0xCE, 0x0F, 0x5B, (byte) 0xA2, 0x63, (byte) 0xE9, 0x77, 0x79, 0x05, (byte) 0x81, (byte) 0x8A, 0x2A, (byte) 0x93, (byte) 0xC8, 0x19, 0x1E, 0x7D, 0x6E, (byte) 0x8A, (byte) 0xE7 }; try { SetSecretRequest request = new SetSecretRequest.Builder(getVaultUri(), SECRET_NAME, _base64.encodeAsString(keyBytes)).withContentType("application/octet-stream").build(); SecretBundle secretBundle = keyVaultClient.setSecret(request); if (secretBundle != null) { try { // ctor with client KeyVaultKeyResolver resolver = new KeyVaultKeyResolver(keyVaultClient); IKey baseKey = resolver.resolveKeyAsync(secretBundle.secretIdentifier().baseIdentifier()).get(); IKey versionKey = resolver.resolveKeyAsync(secretBundle.secretIdentifier().identifier()).get(); // Check for correct key identifiers Assert.assertEquals(baseKey.getKid(), versionKey.getKid()); // Ensure key operations give the expected results byte[] encrypted = null; try { encrypted = baseKey.wrapKeyAsync(CEK, "A256KW").get().getLeft(); if (!_unlimited) fail("Expected ExecutionException"); } catch (InterruptedException e) { fail("InterrupedException"); } catch (ExecutionException e) { // In the limited case, the failure should be InvalidKeyException // In the unlimited case, this should not fail if (!_unlimited) { Throwable cause = e.getCause(); if (cause == null || !(cause instanceof InvalidKeyException)) fail("ExecutionException"); } else { fail("ExecutionException"); } } catch (NoSuchAlgorithmException e) { fail("NoSuchAlgorithmException"); } if (_unlimited) { // Assert assertArrayEquals(EK, encrypted); try { encrypted = versionKey.wrapKeyAsync(CEK, "A256KW").get().getLeft(); } catch (InterruptedException e) { fail("InterrupedException"); } catch (ExecutionException e) { fail("ExecutionException"); } catch (NoSuchAlgorithmException e) { fail("NoSuchAlgorithmException"); } // Assert assertArrayEquals(EK, encrypted); } } finally { // Delete the key keyVaultClient.deleteSecret(getVaultUri(), SECRET_NAME); } } } catch (Exception ex) { fail(ex.getMessage()); } }
From source file:de.blizzy.documentr.search.PageIndex.java
Bits getVisibleDocIds(IndexSearcher searcher, Authentication authentication) throws IOException, TimeoutException { Future<BitSet> branchPagesFuture = taskExecutor .submit(new GetVisibleBranchDocIdsTask(searcher, authentication, permissionEvaluator)); Future<BitSet> inaccessibleDocsFuture = taskExecutor.submit(new GetInaccessibleDocIdsTask(searcher, Permission.VIEW, authentication, userStore, permissionEvaluator)); try {/* w w w. j av a 2 s. c om*/ BitSet docIds = branchPagesFuture.get(INTERACTIVE_TIMEOUT, TimeUnit.SECONDS); docIds.andNot(inaccessibleDocsFuture.get(INTERACTIVE_TIMEOUT, TimeUnit.SECONDS)); return new DocIdBitSet(docIds); } catch (InterruptedException e) { throw new RuntimeException(e); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof IOException) { throw (IOException) cause; } else { throw Util.toRuntimeException(cause); } } finally { branchPagesFuture.cancel(false); inaccessibleDocsFuture.cancel(false); } }
From source file:com.amazonaws.services.kinesis.leases.impl.LeaseRenewer.java
/** * {@inheritDoc}/*w w w . j av a2 s.com*/ */ @Override public void renewLeases() throws DependencyException, InvalidStateException { if (LOG.isDebugEnabled()) { // Due to the eventually consistent nature of ConcurrentNavigableMap iterators, this log entry may become // inaccurate during iteration. LOG.debug(String.format("Worker %s holding %d leases: %s", workerIdentifier, ownedLeases.size(), ownedLeases)); } /* * Lease renewals are done in parallel so many leases can be renewed for short lease fail over time * configuration. In this case, metrics scope is also shared across different threads, so scope must be thread * safe. */ IMetricsScope renewLeaseTaskMetricsScope = new ThreadSafeMetricsDelegatingScope( MetricsHelper.getMetricsScope()); /* * We iterate in descending order here so that the synchronized(lease) inside renewLease doesn't "lead" calls * to getCurrentlyHeldLeases. They'll still cross paths, but they won't interleave their executions. */ int lostLeases = 0; List<Future<Boolean>> renewLeaseTasks = new ArrayList<Future<Boolean>>(); for (T lease : ownedLeases.descendingMap().values()) { renewLeaseTasks.add(executorService.submit(new RenewLeaseTask(lease, renewLeaseTaskMetricsScope))); } int leasesInUnknownState = 0; Exception lastException = null; for (Future<Boolean> renewLeaseTask : renewLeaseTasks) { try { if (!renewLeaseTask.get()) { lostLeases++; } } catch (InterruptedException e) { LOG.info("Interrupted while waiting for a lease to renew."); leasesInUnknownState += 1; Thread.currentThread().interrupt(); } catch (ExecutionException e) { LOG.error("Encountered an exception while renewing a lease.", e.getCause()); leasesInUnknownState += 1; lastException = e; } } renewLeaseTaskMetricsScope.addData("LostLeases", lostLeases, StandardUnit.Count, MetricsLevel.SUMMARY); renewLeaseTaskMetricsScope.addData("CurrentLeases", ownedLeases.size(), StandardUnit.Count, MetricsLevel.SUMMARY); if (leasesInUnknownState > 0) { throw new DependencyException( String.format( "Encountered an exception while renewing leases. " + "The number of leases which might not have been renewed is %d", leasesInUnknownState), lastException); } }
From source file:org.grouplens.lenskit.eval.script.ConfigMethodInvoker.java
public Object invokeConfigurationMethod(final Object target, final String name, Object... args) { Preconditions.checkNotNull(target, "target object"); if (args.length == 1 && args[0] instanceof Future) { Future<?> f = (Future<?>) args[0]; if (f.isDone()) { try { Object arg = f.get(); return invokeConfigurationMethod(target, name, arg); } catch (InterruptedException e) { throw new RuntimeException("interrupted waiting for dependency", e); } catch (ExecutionException e) { throw new RuntimeException(e.getCause()); }//w w w. j a v a2 s . c om } else { Function<Object, Object> recur = new Function<Object, Object>() { @Nullable @Override public Object apply(@Nullable Object input) { return invokeConfigurationMethod(target, name, input); } }; ListenableFuture<?> f2 = Futures.transform(listenInPoolThread(f), recur); registerDep(target, f2); return f2; } } final String setterName = "set" + StringUtils.capitalize(name); final String adderName = "add" + StringUtils.capitalize(name); Supplier<Object> inv; // directly invoke inv = findMethod(target, name, args); if (inv == null) { inv = findBuildableMethod(target, name, args); } // invoke a setter if (inv == null) { inv = findMethod(target, setterName, args); } // invoke a buildable setter if (inv == null) { inv = findBuildableMethod(target, setterName, args); } // invoke an adder if (inv == null) { inv = findMethod(target, adderName, args); } // add from a list if (inv == null) { inv = findMultiMethod(target, adderName, args); } // invoke a buildable adder if (inv == null) { inv = findBuildableMethod(target, adderName, args); } if (inv != null) { return inv.get(); } else { // try to invoke the method directly return DefaultGroovyMethods.invokeMethod(target, name, args); } }
From source file:io.fabric8.jenkins.openshiftsync.GlobalPluginConfiguration.java
private void configChange() { if (!enabled) { if (buildConfigWatcher != null) { buildConfigWatcher.stop();// w ww . j ava 2s.co m } if (buildWatcher != null) { buildWatcher.stop(); } OpenShiftUtils.shutdownOpenShiftClient(); return; } try { OpenShiftUtils.initializeOpenShiftClient(server); this.namespaces = getNamespaceOrUseDefault(namespaces, getOpenShiftClient()); Runnable task = new SafeTimerTask() { @Override protected void doRun() throws Exception { logger.info("Waiting for Jenkins to be started"); while (true) { Computer[] computers = Jenkins.getActiveInstance().getComputers(); boolean ready = false; for (Computer c : computers) { // Jenkins.isAcceptingTasks() results in hudson.model.Node.isAcceptingTasks() getting called, and that always returns true; // the Computer.isAcceptingTasks actually introspects various Jenkins data structures to determine readiness if (c.isAcceptingTasks()) { ready = true; break; } } if (ready) { break; } try { Thread.sleep(500); } catch (InterruptedException e) { // ignore } } buildConfigWatcher = new BuildConfigWatcher(namespaces); buildConfigWatcher.start(); buildWatcher = new BuildWatcher(namespaces); buildWatcher.start(); } }; // lets give jenkins a while to get started ;) Timer.get().schedule(task, 1, TimeUnit.SECONDS); } catch (KubernetesClientException e) { if (e.getCause() != null) { logger.log(Level.SEVERE, "Failed to configure OpenShift Jenkins Sync Plugin: " + e.getCause()); } else { logger.log(Level.SEVERE, "Failed to configure OpenShift Jenkins Sync Plugin: " + e); } } }
From source file:gda.scan.ConcurrentScanChild.java
/** * Blocks while detectors are readout and point is added to pipeline. Throws an exception if one was * thrown while reading out the detectors or adding the point to the pipeline. *//*from www. jav a2s .c o m*/ @Override public void waitForDetectorReadoutAndPublishCompletion() throws InterruptedException, ExecutionException { try { if (detectorReadoutTask != null) { detectorReadoutTask.get(); // exceptions, for example from readout, will be thrown here } } catch (InterruptedException e) { setStatus(ScanStatus.TIDYING_UP_AFTER_STOP); cancelReadoutAndPublishCompletion(); throw e; } catch (ExecutionException e) { cancelReadoutAndPublishCompletion(); if (e.getCause() instanceof InterruptedException) { setStatus(ScanStatus.TIDYING_UP_AFTER_STOP); throw (InterruptedException) e.getCause(); } setStatus(ScanStatus.TIDYING_UP_AFTER_FAILURE); throw e; } }
From source file:de.blizzy.documentr.search.PageIndex.java
public SearchResult findPages(final String searchText, final int page, final Authentication authentication) throws ParseException, IOException, TimeoutException { Assert.hasLength(searchText);/*from www. j a v a 2 s . c o m*/ Assert.isTrue(page >= 1); Assert.notNull(authentication); IndexSearcher searcher = null; Future<SearchResult> findFuture = null; try { searcher = searcherManager.acquire(); final IndexSearcher indexSearcher = searcher; Callable<SearchResult> findCallable = new Callable<SearchResult>() { @Override public SearchResult call() throws ParseException, IOException, TimeoutException { return findPages(searchText, page, authentication, indexSearcher); } }; findFuture = taskExecutor.submit(findCallable); SearchTextSuggestion suggestion = getSearchTextSuggestion(searchText, authentication, indexSearcher); SearchResult result = findFuture.get(INTERACTIVE_TIMEOUT, TimeUnit.SECONDS); result.setSuggestion(suggestion); return result; } catch (InterruptedException e) { throw new RuntimeException(e); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof ParseException) { throw (ParseException) cause; } else if (cause instanceof IOException) { throw (IOException) cause; } else if (cause instanceof TimeoutException) { throw (TimeoutException) cause; } else { throw Util.toRuntimeException(cause); } } finally { if (findFuture != null) { findFuture.cancel(false); } if (searcher != null) { searcherManager.release(searcher); } } }
From source file:org.apache.nutchbase.searcher.NutchBeanHbase.java
@Override public Summary[] getSummary(HitDetails[] details, Query query) throws IOException { final List<Callable<Summary>> tasks = new ArrayList<Callable<Summary>>(details.length); for (int i = 0; i < details.length; i++) { tasks.add(new SummaryTask(details[i], query)); }/*from w w w. ja va2 s.c o m*/ List<Future<Summary>> summaries; try { summaries = executor.invokeAll(tasks); } catch (final InterruptedException e) { throw new RuntimeException(e); } final Summary[] results = new Summary[details.length]; for (int i = 0; i < details.length; i++) { final Future<Summary> f = summaries.get(i); Summary summary; try { summary = f.get(); } catch (final Exception e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new RuntimeException(e); } results[i] = summary; } return results; }
From source file:de.blizzy.documentr.search.PageIndex.java
private SearchResult findPages(String searchText, int page, Authentication authentication, IndexSearcher searcher) throws ParseException, IOException, TimeoutException { Future<Query> queryFuture = taskExecutor.submit(new ParseQueryTask(searchText, analyzer)); Bits visibleDocIds = getVisibleDocIds(searcher, authentication); Query query;//from w w w .j a v a2s . c om try { query = queryFuture.get(INTERACTIVE_TIMEOUT, TimeUnit.SECONDS); } catch (InterruptedException e) { throw new RuntimeException(e); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof ParseException) { throw (ParseException) cause; } else { throw Util.toRuntimeException(cause); } } finally { queryFuture.cancel(false); } TopDocs docs = searcher.search(query, new PagePermissionFilter(visibleDocIds), HITS_PER_PAGE * page); int start = HITS_PER_PAGE * (page - 1); int end = Math.min(HITS_PER_PAGE * page, docs.scoreDocs.length); IndexReader reader = searcher.getIndexReader(); List<ListenableFuture<SearchHit>> hitFutures = Lists.newArrayList(); for (int i = start; i < end; i++) { ListenableFuture<SearchHit> hitFuture = taskExecutor .submit(new GetSearchHitTask(query, reader, docs.scoreDocs[i].doc, analyzer)); hitFutures.add(hitFuture); } try { ListenableFuture<List<SearchHit>> allHitsFuture = Futures.allAsList(hitFutures); List<SearchHit> hits = allHitsFuture.get(INTERACTIVE_TIMEOUT, TimeUnit.SECONDS); return new SearchResult(hits, docs.totalHits, HITS_PER_PAGE); } catch (InterruptedException e) { throw new RuntimeException(e); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof IOException) { throw (IOException) cause; } else { throw Util.toRuntimeException(cause); } } finally { for (ListenableFuture<SearchHit> hitFuture : hitFutures) { hitFuture.cancel(false); } } }