Package java.util.concurrent

Examples of java.util.concurrent.ExecutionException


         if (s == CANCELLED)
            throw new CancellationException();
         if (s != EXCEPTIONAL)
            throw new TimeoutException();
         if ((ex = getThrowableException()) != null)
            throw new ExecutionException(ex);
      }
      return getRawResult();
   }
View Full Code Here


        }
    }

    private Void handleResult() throws ExecutionException {
        if (exception != null) {
            throw new ExecutionException(exception);
        }
        return null;
    }
View Full Code Here

      // loop.

      try {
         // Record exceptions so that if we fail to obtain any
         // result, we can throw the last exception we got.
         ExecutionException ee = null;
         long lastTime = (timed) ? System.nanoTime() : 0;
         Iterator<? extends Callable<T>> it = tasks.iterator();

         // Start one task for sure; the rest incrementally
         futures.add(ecs.submit(it.next()));
         --ntasks;
         int active = 1;

         for (;;) {
            Future<T> f = ecs.poll();
            if (f == null) {
               if (ntasks > 0) {
                  --ntasks;
                  futures.add(ecs.submit(it.next()));
                  ++active;
               } else if (active == 0)
                  break;
               else if (timed) {
                  f = ecs.poll(nanos, TimeUnit.NANOSECONDS);
                  if (f == null)
                     throw new TimeoutException();
                  long now = System.nanoTime();
                  nanos -= now - lastTime;
                  lastTime = now;
               } else
                  f = ecs.take();
            }
            if (f != null) {
               --active;
               try {
                  return f.get();
               } catch (InterruptedException ie) {
                  throw ie;
               } catch (ExecutionException eex) {
                  ee = eex;
               } catch (RuntimeException rex) {
                  ee = new ExecutionException(rex);
               }
            }
         }

         if (ee == null)
            ee = new ExecutionException() {
               private static final long serialVersionUID = 200818694545553992L;
            };
         throw ee;

      } finally {
View Full Code Here

         this.f = future;
      }
     
      private V retrieveResult(Object response) throws ExecutionException {
         if (response instanceof Exception) {
            throw new ExecutionException((Exception) response);
         }
        
         Map<Address, Response> mapResult = (Map<Address, Response>) response;
         for (Entry<Address, Response> e : mapResult.entrySet()) {
            if (e.getValue() instanceof SuccessfulResponse) {
               return (V) ((SuccessfulResponse) e.getValue()).getResponseValue();
            }
         }
         throw new ExecutionException(new IllegalStateException("Invalid response " + response));
      }
View Full Code Here

      public V get() throws InterruptedException, ExecutionException {
         V result = null;
         try {
            result = innerGet(0, TimeUnit.MILLISECONDS);
         } catch (TimeoutException e) {
            throw new ExecutionException(e);
         } finally {
            done = true;
         }
         return result;
      }
View Full Code Here

     
      protected ExecutionException wrapIntoExecutionException(Exception e){
         if (e instanceof ExecutionException) {
            return (ExecutionException) e;
         } else {
            return new ExecutionException(e);
         }
      }
View Full Code Here

    }

    public Object get() throws InterruptedException,
                       ExecutionException {
        if ( this.future.exceptionThrown() ) {
            throw new ExecutionException( this.future.getException() );
        }
        return this.future.getObject();
    }
View Full Code Here

                            intr = true;
                        }
                    }
                }
                if (exception != null) {
                    throw new ExecutionException(exception);
                }
                return result;
            } finally {
                if (intr) Thread.currentThread().interrupt();
            }
View Full Code Here

    @Override
    public void setResult(Object result) {
        Object finalResult = result;
        if (finalResult instanceof Throwable && !(finalResult instanceof CancellationException)) {
            if (!(finalResult instanceof CancellationException)) {
                finalResult = new ExecutionException((Throwable) finalResult);
            }
            super.setResult(finalResult);
            latch.countDown();
            return;
        }
        // If collator is available we need to execute it now
        if (collator != null) {
            try {
                finalResult = collator.collate(((Map) finalResult).entrySet());
            } catch (Exception e) {
                // Possible exception while collating
                finalResult = e;
            }
        }
        if (finalResult instanceof Throwable && !(finalResult instanceof CancellationException)) {
            finalResult = new ExecutionException((Throwable) finalResult);
        }
        super.setResult(finalResult);
        latch.countDown();
    }
View Full Code Here

            if (response instanceof Error) {
                throw (Error) response;
            }

            // To obey Future contract, we should wrap unchecked exceptions with ExecutionExceptions.
            throw new ExecutionException((Throwable) response);
        }
View Full Code Here

TOP

Related Classes of java.util.concurrent.ExecutionException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.