List of usage examples for java.util.concurrent ExecutionException getCause
public synchronized Throwable getCause()
From source file:io.scigraph.owlapi.loader.BatchOwlLoader.java
public void loadOntology() throws InterruptedException, ExecutionException { CompletionService<Long> completionService = new ExecutorCompletionService<Long>(exec); Set<Future<?>> futures = new HashSet<>(); if (!ontologies.isEmpty()) { for (int i = 0; i < numConsumers; i++) { futures.add(completionService.submit(consumerProvider.get())); }/*from w ww .j a v a 2s . c o m*/ for (int i = 0; i < numProducers; i++) { futures.add(completionService.submit(producerProvider.get())); } for (OntologySetup ontology : ontologies) { urlQueue.offer(ontology); } for (int i = 0; i < numProducers; i++) { urlQueue.offer(POISON_STR); } } while (futures.size() > 0) { Future<?> completedFuture = completionService.take(); futures.remove(completedFuture); try { completedFuture.get(); } catch (ExecutionException e) { logger.log(Level.SEVERE, "Stopping batchLoading due to: " + e.getMessage(), e); e.printStackTrace(); exec.shutdownNow(); throw new InterruptedException(e.getCause().getMessage()); } } exec.shutdown(); exec.awaitTermination(10, TimeUnit.DAYS); graph.shutdown(); logger.info("Postprocessing..."); postprocessorProvider.get().postprocess(); if (cliqueConfiguration.isPresent()) { postprocessorProvider.runCliquePostprocessor(cliqueConfiguration.get()); } postprocessorProvider.shutdown(); }
From source file:sh.isaac.mojo.profileSync.ProfilesMojoBase.java
/** * Gets the username./*from w w w. j ava 2s .c om*/ * * @return the username * @throws MojoExecutionException the mojo execution exception */ protected String getUsername() throws MojoExecutionException { if (username == null) { username = System.getProperty(PROFILE_SYNC_USERNAME_PROPERTY); // still blank, try property if (StringUtils.isBlank(username)) { username = this.profileSyncUsername; } // still no username, prompt if allowed if (StringUtils.isBlank(username) && !Boolean.valueOf(System.getProperty(PROFILE_SYNC_NO_PROMPTS))) { final Callable<Void> callable = () -> { if (!ProfilesMojoBase.this.disableHintGiven) { System.out.println("To disable remote sync during build, add '-D" + PROFILE_SYNC_DISABLE + "=true' to your maven command"); ProfilesMojoBase.this.disableHintGiven = true; } try { System.out.println("Enter the " + ProfilesMojoBase.this.changeSetURLType + " username for the Profiles/Changset remote store (" + ProfilesMojoBase.this.changeSetURL + "):"); final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); username = br.readLine(); } catch (final IOException e) { throw new MojoExecutionException("Error reading username from console"); } return null; }; try { Executors.newSingleThreadExecutor(r -> { final Thread t = new Thread(r, "User Prompt Thread"); t.setDaemon(true); return t; }).submit(callable).get(2, TimeUnit.MINUTES); } catch (TimeoutException | InterruptedException e) { throw new MojoExecutionException("Username not provided within timeout"); } catch (final ExecutionException ee) { throw ((ee.getCause() instanceof MojoExecutionException) ? (MojoExecutionException) ee.getCause() : new MojoExecutionException("Unexpected", ee.getCause())); } } } return username; }
From source file:org.jclouds.atmosonline.saas.AtmosStorageClientLiveTest.java
protected void retryAndCheckSystemMetadataAndPutIfPresentReplaceStrategy(AtmosObject object) throws Exception { int failures = 0; while (true) { try {/*www . ja v a 2s . c om*/ checkSystemMetadataAndPutIfPresentReplaceStrategy(object); break; } catch (ExecutionException e1) {// bug if (!(e1.getCause() instanceof KeyAlreadyExistsException)) throw e1; else failures++; } } if (failures > 0) System.err.printf("%d failures create/replacing %s%n", failures, object.getData() instanceof InputStream ? "stream" : "string"); }
From source file:org.opennms.core.rpc.camel.EchoRpcIT.java
@Test(timeout = CamelRpcClientPreProcessor.CAMEL_JMS_REQUEST_TIMEOUT_DEFAULT * 4) public void throwsRequestTimedOutExceptionOnTimeout() throws Exception { assertNotEquals(REMOTE_LOCATION_NAME, identity.getLocation()); EchoRpcModule echoRpcModule = new EchoRpcModule(); SimpleRegistry registry = new SimpleRegistry(); CamelContext context = new DefaultCamelContext(registry); context.getShutdownStrategy().setTimeout(5); context.getShutdownStrategy().setTimeUnit(TimeUnit.SECONDS); context.addComponent("queuingservice", queuingservice); CamelRpcServerRouteManager routeManager = new CamelRpcServerRouteManager(context, new MockMinionIdentity(REMOTE_LOCATION_NAME)); routeManager.bind(echoRpcModule);//from ww w.j a v a 2 s . c o m EchoRequest request = new EchoRequest("HELLO!!!"); request.setLocation(REMOTE_LOCATION_NAME); request.setDelay(CamelRpcClientPreProcessor.CAMEL_JMS_REQUEST_TIMEOUT_DEFAULT * 2); try { echoClient.execute(request).get(); fail("Did not get ExecutionException"); } catch (ExecutionException e) { assertTrue("Cause is not of type RequestTimedOutException: " + ExceptionUtils.getStackTrace(e), e.getCause() instanceof RequestTimedOutException); } routeManager.unbind(echoRpcModule); context.stop(); }
From source file:sh.isaac.mojo.profileSync.ProfilesMojoBase.java
/** * Gets the password.//w w w. j av a 2 s .c o m * * @return the password * @throws MojoExecutionException the mojo execution exception */ protected char[] getPassword() throws MojoExecutionException // protected String getPassword() throws MojoExecutionException { if (pwd == null) { pwd = System.getProperty(PROFILE_SYNC_PWD_PROPERTY).toCharArray(); // still blank, try the passed in param if (pwd.length == 0) // if (StringUtils.isBlank(pwd)) { pwd = this.profileSyncPassword.toCharArray(); } // still no password, prompt if allowed if ((pwd.length == 0) && !Boolean.valueOf(System.getProperty(PROFILE_SYNC_NO_PROMPTS))) { final Callable<Void> callable = () -> { try { if (!ProfilesMojoBase.this.disableHintGiven) { System.out.println("To disable remote sync during build, add '-D" + PROFILE_SYNC_DISABLE + "=true' to your maven command"); ProfilesMojoBase.this.disableHintGiven = true; } System.out.println("Enter the " + ProfilesMojoBase.this.changeSetURLType + " password for the Profiles/Changset remote store: (" + ProfilesMojoBase.this.changeSetURL + "):"); // Use console if available, for password masking final Console console = System.console(); if (console != null) { pwd = console.readPassword(); } else { final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); pwd = br.readLine().toCharArray(); } } catch (final IOException e) { throw new MojoExecutionException("Error reading password from console"); } return null; }; try { Executors.newSingleThreadExecutor(r -> { final Thread t = new Thread(r, "User Password Prompt Thread"); t.setDaemon(true); return t; }).submit(callable).get(2, TimeUnit.MINUTES); } catch (TimeoutException | InterruptedException e) { throw new MojoExecutionException("Password not provided within timeout"); } catch (final ExecutionException ee) { throw ((ee.getCause() instanceof MojoExecutionException) ? (MojoExecutionException) ee.getCause() : new MojoExecutionException("Unexpected", ee.getCause())); } } } return pwd; }
From source file:org.jactr.core.model.six.DefaultCycleProcessor6.java
/** * using the current contents of the buffer, derive the conflict set and * select the best production. Request it to be fired, and eventually return * the result.//from w ww . j av a2s .co m * * @return firing time (or NaN if we should quit) or -inf if no production was * fired */ protected double evaluateAndFireProduction(BasicModel model, double currentTime) throws InterruptedException, ExecutionException { if (_nextPossibleProductionFiringTime > currentTime) return Double.NEGATIVE_INFINITY; /* * get the buffers and their contents */ Collection<IActivationBuffer> buffers = model.getActivationBuffers(); /* * and the procedural module since we'll be using him quite frequently */ IProceduralModule procMod = model.getProceduralModule(); /* * snag the conflict set, procMod should fire the notification events itself * this and selectInstantiation should not be separate methods, or better * yet, provide a third method */ Future<Collection<IInstantiation>> conflictSet = procMod.getConflictSet(buffers); /* * figure out who is the best production.. */ IInstantiation instantiation = null; instantiation = procMod.selectInstantiation(conflictSet.get()).get(); if (LOGGER.isDebugEnabled()) LOGGER.debug("Conflict resolution selected " + instantiation); /* * and fire his arse.. and snag his return time -inf if no production was * fired, NaN if we should quit */ double firingDuration = Double.NEGATIVE_INFINITY; if (instantiation != null) try { if (LOGGER.isDebugEnabled()) LOGGER.debug("Firing " + instantiation); firingDuration = procMod.fireProduction(instantiation, currentTime).get(); _nextPossibleProductionFiringTime = currentTime + firingDuration; } catch (ExecutionException e) { throw new ExecutionException("Failed to execute " + instantiation, e.getCause()); } else _nextPossibleProductionFiringTime = currentTime + procMod.getDefaultProductionFiringTime(); return firingDuration; }
From source file:com.uber.hoodie.func.TestBoundedInMemoryQueue.java
@SuppressWarnings("unchecked") @Test(timeout = 60000)/*from w w w . j a va 2 s.c o m*/ public void testException() throws Exception { final int numRecords = 256; final List<HoodieRecord> hoodieRecords = hoodieTestDataGenerator.generateInserts(commitTime, numRecords); final SizeEstimator<Tuple2<HoodieRecord, Optional<IndexedRecord>>> sizeEstimator = new DefaultSizeEstimator<>(); // queue memory limit final long objSize = sizeEstimator .sizeEstimate(getTransformFunction(HoodieTestDataGenerator.avroSchema).apply(hoodieRecords.get(0))); final long memoryLimitInBytes = 4 * objSize; // first let us throw exception from queueIterator reader and test that queueing thread // stops and throws // correct exception back. BoundedInMemoryQueue<HoodieRecord, Tuple2<HoodieRecord, Optional<IndexedRecord>>> queue1 = new BoundedInMemoryQueue( memoryLimitInBytes, getTransformFunction(HoodieTestDataGenerator.avroSchema)); // Produce Future<Boolean> resFuture = executorService.submit(() -> { new IteratorBasedQueueProducer<>(hoodieRecords.iterator()).produce(queue1); return true; }); // waiting for permits to expire. while (!isQueueFull(queue1.rateLimiter)) { Thread.sleep(10); } // notify queueing thread of an exception and ensure that it exits. final Exception e = new Exception("Failing it :)"); queue1.markAsFailed(e); try { resFuture.get(); Assert.fail("exception is expected"); } catch (ExecutionException e1) { Assert.assertEquals(HoodieException.class, e1.getCause().getClass()); Assert.assertEquals(e, e1.getCause().getCause()); } // second let us raise an exception while doing record queueing. this exception should get // propagated to // queue iterator reader. final RuntimeException expectedException = new RuntimeException("failing record reading"); final Iterator<HoodieRecord> mockHoodieRecordsIterator = mock(Iterator.class); when(mockHoodieRecordsIterator.hasNext()).thenReturn(true); when(mockHoodieRecordsIterator.next()).thenThrow(expectedException); BoundedInMemoryQueue<HoodieRecord, Tuple2<HoodieRecord, Optional<IndexedRecord>>> queue2 = new BoundedInMemoryQueue( memoryLimitInBytes, getTransformFunction(HoodieTestDataGenerator.avroSchema)); // Produce Future<Boolean> res = executorService.submit(() -> { try { new IteratorBasedQueueProducer<>(mockHoodieRecordsIterator).produce(queue2); } catch (Exception ex) { queue2.markAsFailed(ex); throw ex; } return true; }); try { queue2.iterator().hasNext(); Assert.fail("exception is expected"); } catch (Exception e1) { Assert.assertEquals(expectedException, e1.getCause()); } // queueing thread should also have exited. make sure that it is not running. try { res.get(); Assert.fail("exception is expected"); } catch (ExecutionException e2) { Assert.assertEquals(expectedException, e2.getCause()); } }
From source file:org.apache.hive.spark.client.rpc.TestRpc.java
@Test public void testClientTimeout() throws Exception { Map<String, String> conf = ImmutableMap.<String, String>builder().putAll(emptyConfig).build(); RpcServer server = autoClose(new RpcServer(conf)); String secret = server.createSecret(); try {/*from w w w .j a v a 2s. c o m*/ autoClose(server.registerClient("client", secret, new TestDispatcher(), 1L).get()); fail("Server should have timed out client."); } catch (ExecutionException ee) { assertTrue(ee.getCause() instanceof TimeoutException); } NioEventLoopGroup eloop = new NioEventLoopGroup(); Future<Rpc> clientRpcFuture = Rpc.createClient(conf, eloop, "localhost", server.getPort(), "client", secret, new TestDispatcher()); try { autoClose(clientRpcFuture.get()); fail("Client should have failed to connect to server."); } catch (ExecutionException ee) { // Error should not be a timeout. assertFalse(ee.getCause() instanceof TimeoutException); } }
From source file:com.yahoo.pulsar.client.impl.PulsarClientImpl.java
@Override public void close() throws PulsarClientException { try {// w w w . j a va 2 s . c o m closeAsync().get(); } catch (ExecutionException e) { Throwable t = e.getCause(); if (t instanceof PulsarClientException) { throw (PulsarClientException) t; } else { throw new PulsarClientException(t); } } catch (InterruptedException e) { throw new PulsarClientException(e); } }
From source file:de.metas.procurement.webui.ui.model.ProductQtyReportRepository.java
public final ProductQtyReportContainer getDailyProductQtyReportContainer(Date day) { day = DateUtils.truncToDay(day);//from w w w . j av a2 s . co m try { return day2productQtyReportContainer.get(day); } catch (final ExecutionException e) { throw new RuntimeException(e.getCause()); // shall not happen } }