List of usage examples for java.util.concurrent ExecutionException ExecutionException
public ExecutionException(Throwable cause)
From source file:org.limewire.mojito.concurrent.DHTFutureTask.java
/** * Starts the Watchdog//from www . ja v a 2 s . c o m */ private void initWatchdog() { Runnable r = new Runnable() { public void run() { boolean timeout = false; synchronized (exchanger) { if (!isDone()) { if (LOG.isDebugEnabled()) { LOG.debug("Watchdog is canceling " + task); } timeout = taskIsActive; exchanger.setException(new ExecutionException(new LockTimeoutException(task.toString()))); } } if (timeout) { task.cancel(); } } }; watchdog = context.getDHTExecutorService().schedule(r, task.getWaitOnLockTimeout(), TimeUnit.MILLISECONDS); }
From source file:net.myrrix.online.eval.AUCEvaluator.java
public EvaluationResult evaluate(final MyrrixRecommender recommender, final FastByIDMap<FastIDSet> testData) throws TasteException { final AtomicInteger underCurve = new AtomicInteger(0); final AtomicInteger total = new AtomicInteger(0); final long[] allItemIDs = recommender.getAllItemIDs().toArray(); Processor<Long> processor = new Processor<Long>() { private final RandomGenerator random = RandomManager.getRandom(); @Override/*from ww w.ja va2 s . co m*/ public void process(Long userID, long count) throws ExecutionException { FastIDSet testItemIDs = testData.get(userID); int numTest = testItemIDs.size(); for (int i = 0; i < numTest; i++) { long randomTestItemID; long randomTrainingItemID; synchronized (random) { randomTestItemID = RandomUtils.randomFrom(testItemIDs, random); do { randomTrainingItemID = allItemIDs[random.nextInt(allItemIDs.length)]; } while (testItemIDs.contains(randomTrainingItemID)); } float relevantEstimate; float nonRelevantEstimate; try { relevantEstimate = recommender.estimatePreference(userID, randomTestItemID); nonRelevantEstimate = recommender.estimatePreference(userID, randomTrainingItemID); } catch (NoSuchItemException nsie) { // OK; it's possible item only showed up in test split continue; } catch (NoSuchUserException nsie) { // OK; it's possible user only showed up in test split continue; } catch (TasteException te) { throw new ExecutionException(te); } if (relevantEstimate > nonRelevantEstimate) { underCurve.incrementAndGet(); } total.incrementAndGet(); if (count % 100000 == 0) { log.info("AUC: {}", (double) underCurve.get() / total.get()); } } } }; try { new Paralleler<Long>(testData.keySetIterator(), processor, "AUCEval").runInParallel(); } catch (InterruptedException ie) { throw new TasteException(ie); } catch (ExecutionException e) { throw new TasteException(e.getCause()); } double score = (double) underCurve.get() / total.get(); log.info("AUC: {}", score); return new EvaluationResultImpl(score); }
From source file:net.tirasa.wink.client.asynchttpclient.FutureClientResponse.java
@Override public ClientResponse get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { synchronized (this) { if (this.clientResponse == null) { try { createClientResponse(this.futureResponse.get(timeout, unit)); } catch (IOException e) { throw new ExecutionException(e); }// w w w . jav a 2 s. c o m } } return this.clientResponse; }
From source file:com.delphix.session.module.rmi.impl.RmiFactoryImpl.java
@Override public <T> T createProxy(final Class<T> type, final ServiceNexus nexus, final UUID objectId) { Object proxy = Proxy.newProxyInstance(RmiFactoryImpl.class.getClassLoader(), new Class[] { type }, new InvocationHandler() { private RmiMethodOrdering ifm = new RmiMethodOrdering(type); @Override//from w w w .j a v a 2 s . c o m public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (args == null) { args = new Object[0]; } if (method.getName().equals("close") && args.length == 0) { ObjectDestroyRequest request = new ObjectDestroyRequest(); request.setObjectId(objectId); try { nexus.execute(request).get(); } catch (InterruptedException e) { throw new DelphixInterruptedException(e); } catch (ExecutionException e) { throw new RuntimeException(ExceptionUtil.unwrap(e)); } return null; } else { MethodCallRequest request = new MethodCallRequest(); request.setObjectId(objectId); request.setMethod(ifm.getPlacement(method)); request.setArguments(args); MethodCallResponse response; try { response = (MethodCallResponse) nexus.execute(request).get(); } catch (InterruptedException e) { throw new DelphixInterruptedException(e); } catch (ExecutionException e) { throw new RuntimeException(ExceptionUtil.unwrap(e)); } if (response.getException()) { throw ExceptionUtil.unwrap(new ExecutionException((Throwable) response.getValue())); } else { return response.getValue(); } } } }); return type.cast(proxy); }
From source file:com.ning.http.client.providers.apache.ApacheResponseFuture.java
public V get() throws InterruptedException, ExecutionException { try {/*from w ww . j a v a 2 s. c om*/ return get(responseTimeoutInMs, TimeUnit.MILLISECONDS); } catch (TimeoutException e) { throw new ExecutionException(e); } }
From source file:de.uni_rostock.goodod.owl.OntologyCache.java
private synchronized FutureTask<OWLOntology> getOntologyFutureAtURI(final URI u) throws OWLOntologyCreationException { FutureTask<OWLOntology> future = null; future = futures.get(u);/*w ww .j a v a2 s . co m*/ if (null != future) { return future; } future = new FutureTask<OWLOntology>(new Callable<OWLOntology>() { public OWLOntology call() throws ExecutionException { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); if (null != mappers) { for (OWLOntologyIRIMapper m : mappers) { manager.addIRIMapper(m); } } FileDocumentSource source = new FileDocumentSource(new File(u)); OWLOntology ontology; try { ontology = manager.loadOntologyFromOntologyDocument(source, config); markOriginalClasses(ontology); logger.info("Loading and normalizing ontology from " + u.toString() + "."); if (null != normalizerFactory) { normalizerFactory.normalize(ontology); } } catch (OWLOntologyCreationException e) { throw new ExecutionException(e); } // Mark this future as done. futureDone(); return ontology; } }); futures.put(u, future); // We track our pending futures pendingFutures.incrementAndGet(); executor.execute(future); return future; }
From source file:org.apache.axis2.jaxws.client.async.AsyncResponse.java
/** * @param flt Throwable fault that occurred * @param faultCtx MessageContext if fault is a SOAP Fault *///from www . j ava2s . c o m protected void onError(Throwable flt, MessageContext faultCtx) { // Note: // This code is hardened to prevent a secondary exception from being // thrown back to the caller of onError. It is likely that a // thrown exception will cause other errors leading to // system fragility. if (log.isDebugEnabled()) { log.debug("AsyncResponse received a fault."); } Throwable t = null; try { fault = flt; faultMessageContext = faultCtx; if (faultMessageContext != null) { faultMessageContext.setEndpointDescription(endpointDescription); } else { if (log.isDebugEnabled()) { log.debug("The faultMessageContext is not available because the error likely occurred on" + " the client and is not the result of a SOAP Fault"); } } // Probably a good idea to invalidate the cache cacheValid = false; cachedObject = null; t = processFaultResponse(); } catch (Throwable unexpected) { // An unexpected error occurred while processing the fault. // The Response's throwable is set to this unexpected exception. if (log.isDebugEnabled()) { log.debug("A secondary exception occurred during onError processing: " + unexpected); } t = unexpected; } // JAXWS 4.3.3 conformance bullet says to throw an ExecutionException from here savedException = new ExecutionException(t); try { // Countdown so that the Future object will know that procesing is complete. latch.countDown(); if (log.isDebugEnabled()) { log.debug("New latch count = [" + latch.getCount() + "]"); } } catch (Throwable unexpected) { // An unexpected error occurred after processing the fault response // The Response's throwable has already been set to the savedException if (log.isDebugEnabled()) { log.debug("A secondary exception occurred during onError processing " + "after the fault is processed: " + unexpected); } } }
From source file:com.ning.http.client.providers.apache.ApacheResponseFuture.java
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { V content = null;//from w ww.j a va 2 s . c om try { if (innerFuture != null) { content = innerFuture.get(timeout, unit); } } catch (TimeoutException t) { if (!contentProcessed.get() && timeout != -1 && ((System.currentTimeMillis() - touch.get()) <= responseTimeoutInMs)) { return get(timeout, unit); } if (exception.get() == null) { timedOut.set(true); throw new ExecutionException( new TimeoutException(String.format("No response received after %s", responseTimeoutInMs))); } } catch (CancellationException ce) { } if (exception.get() != null) { throw new ExecutionException(exception.get()); } return content; }
From source file:org.asynchttpclient.providers.apache.ApacheResponseFuture.java
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { V content = null;//from w w w.j a v a 2 s.c om try { if (innerFuture != null) { content = innerFuture.get(timeout, unit); } } catch (TimeoutException t) { if (!contentProcessed.get() && timeout != -1 && ((millisTime() - touch.get()) <= responseTimeoutInMs)) { return get(timeout, unit); } if (exception.get() == null) { timedOut.set(true); throw new ExecutionException( new TimeoutException(String.format("No response received after %s", responseTimeoutInMs))); } } catch (CancellationException ce) { } if (exception.get() != null) { throw new ExecutionException(exception.get()); } return content; }
From source file:net.myrrix.online.eval.ParameterOptimizer.java
/** * @return a {@link Map} between the values of the given {@link System} properties and the best value found * during search/*from w w w . j ava 2s . c o m*/ * @throws ExecutionException if an error occurs while calling {@code evaluator}; the cause is the * underlying exception */ public Map<String, Number> findGoodParameterValues() throws ExecutionException { int numProperties = parameterRanges.size(); String[] propertyNames = new String[numProperties]; Number[][] parameterValuesToTry = new Number[numProperties][]; int index = 0; for (Map.Entry<String, ParameterRange> entry : parameterRanges.entrySet()) { propertyNames[index] = entry.getKey(); parameterValuesToTry[index] = entry.getValue().buildSteps(numSteps); index++; } int numTests = 1; for (Number[] toTry : parameterValuesToTry) { numTests *= toTry.length; } List<Pair<Double, String>> testResultLinesByValue = Lists.newArrayListWithCapacity(numTests); Map<String, Number> bestParameterValues = Maps.newHashMap(); double bestValue = minimize ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY; for (int test = 0; test < numTests; test++) { StringBuilder testResultLine = new StringBuilder(); for (int prop = 0; prop < numProperties; prop++) { String property = propertyNames[prop]; Number parameterValue = getParameterValueToTry(parameterValuesToTry, test, prop); String propertyString = parameterValue.toString(); log.info("Setting {}={}", property, propertyString); System.setProperty(property, propertyString); testResultLine.append('[').append(property).append('=').append(propertyString).append("] "); } Number evaluatorResult; try { evaluatorResult = evaluator.call(); } catch (Exception e) { throw new ExecutionException(e); } if (evaluatorResult == null) { continue; } double testValue = evaluatorResult.doubleValue(); testResultLine.append("= ").append(testValue); testResultLinesByValue.add(new Pair<Double, String>(testValue, testResultLine.toString())); log.info("{}", testResultLine); if (minimize ? testValue < bestValue : testValue > bestValue) { log.info("New best value {}", testValue); bestValue = testValue; for (int prop = 0; prop < numProperties; prop++) { String property = propertyNames[prop]; Number parameterValue = getParameterValueToTry(parameterValuesToTry, test, prop); bestParameterValues.put(property, parameterValue); } } Collections.sort(testResultLinesByValue, new Comparator<Pair<Double, String>>() { @Override public int compare(Pair<Double, String> a, Pair<Double, String> b) { if (a.getFirst() > b.getFirst()) { return -1; } if (a.getFirst() < b.getFirst()) { return 1; } return 0; } }); for (Pair<Double, String> result : testResultLinesByValue) { log.info("{}", result.getSecond()); } log.info("Best parameter values so far are {}", bestParameterValues); } log.info("Final best parameter values are {}", bestParameterValues); return bestParameterValues; }