List of usage examples for java.util.concurrent ExecutionException ExecutionException
public ExecutionException(Throwable cause)
From source file:org.springside.modules.utils.concurrent.type.BasicFuture.java
private T getResult() throws ExecutionException { if (this.ex != null) { throw new ExecutionException(this.ex); }//from w w w . j ava2 s .c om if (cancelled) { throw new CancellationException(); } return this.result; }
From source file:org.drftpd.protocol.speedtest.net.slave.SpeedTestCallable.java
@Override public Long call() throws Exception { Long bytes = 0L;//from w w w . jav a 2s .c o m try { if (httpPost != null) { response = httpClient.execute(httpPost); final int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { throw new Exception("Error code " + statusCode + " while running upload test."); } HttpEntity entity = response.getEntity(); String data = EntityUtils.toString(entity); EntityUtils.consume(entity); if (!data.startsWith("size=")) { throw new Exception( "Wrong return result from upload messurement from test server.\nReceived: " + data); } bytes = Long.parseLong(data.replaceAll("\\D", "")); } else if (httpGet != null) { response = httpClient.execute(httpGet); final int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { throw new Exception("Error code " + statusCode + " while running upload test."); } HttpEntity entity = response.getEntity(); InputStream instream = entity.getContent(); int bufferSize = 10240; byte[] buffer = new byte[bufferSize]; int len; while ((len = instream.read(buffer)) != -1) { bytes = bytes + len; } EntityUtils.consume(entity); } } catch (Exception e) { throw new ExecutionException(e); } finally { try { if (response != null) { response.close(); } } catch (IOException e) { // Must already be closed, ignore. } } return bytes; }
From source file:io.vertigo.dynamo.impl.search.WritableFuture.java
private V getResult() throws ExecutionException { if (futureException != null) { throw new ExecutionException(futureException); }// ww w . j av a 2 s . c o m return futureResult; }
From source file:com.wolvereness.overmapped.lib.MultiProcessor.java
@Override public <T> Future<T> submit(final Callable<T> task) { super.checkShutdown(); try {/* ww w. j ava 2 s . com*/ final T object = task.call(); return new Future<T>() { @Override public boolean cancel(final boolean mayInterruptIfRunning) { return false; } @Override public boolean isCancelled() { return false; } @Override public boolean isDone() { return true; } @Override public T get() throws InterruptedException, ExecutionException { return object; } @Override public T get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return object; } }; } catch (final Exception exception) { final Exception ex = exception; return new Future<T>() { @Override public boolean cancel(final boolean mayInterruptIfRunning) { return false; } @Override public boolean isCancelled() { return false; } @Override public boolean isDone() { return true; } @Override public T get() throws InterruptedException, ExecutionException { throw new ExecutionException(ex); } @Override public T get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { throw new ExecutionException(ex); } }; } }
From source file:name.martingeisse.common.util.PassthroughCache.java
@Override public V get(K key) throws ExecutionException { try {/* ww w . j a va2s.com*/ return loader.load(key); } catch (Exception e) { throw new ExecutionException(e); } }
From source file:org.diorite.impl.scheduler.DioriteFuture.java
@Override public synchronized T get(long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { timeout = unit.toMillis(timeout);/*from w w w . j a v a 2 s.c om*/ long period = this.getPeriod(); long timestamp = (timeout > 0) ? System.currentTimeMillis() : 0; while (true) { if ((period == STATE_SINGLE) || (period == STATE_FUTURE)) { this.wait(timeout); period = this.getPeriod(); if ((period == -STATE_SINGLE) || (period == STATE_FUTURE)) { if (timeout == 0) { continue; } timeout += timestamp - (timestamp = System.currentTimeMillis()); if (timeout > 0) { continue; } throw new TimeoutException(); } } if (period == -STATE_CANCEL) { throw new CancellationException(); } if (period == STATE_FUTURE_DONE) { if (this.exception == null) { return this.value; } throw new ExecutionException(this.exception); } throw new IllegalStateException("Expected from -1 to -4, but got " + period); } }
From source file:org.limewire.mojito.concurrent.DHTFutureTask.java
public void run() { try {/*from w w w . jav a 2 s . co m*/ synchronized (exchanger) { if (isDone()) { return; } taskIsActive = true; } task.start(exchanger); synchronized (exchanger) { if (!isDone()) { initWatchdog(); } } } catch (Throwable t) { exchanger.setException(new ExecutionException(t)); } }
From source file:name.martingeisse.common.util.PassthroughCache.java
@Override public ImmutableMap<K, V> getAll(Iterable<? extends K> keys) throws ExecutionException { try {//from w w w . j ava 2 s. c o m return ImmutableMap.copyOf(loader.loadAll(keys)); } catch (Exception e) { throw new ExecutionException(e); } }
From source file:abfab3d.shapejs.ScriptManager.java
private ScriptManager() { cache = CacheBuilder.newBuilder().softValues().expireAfterAccess(JOB_RETAIN_MS, TimeUnit.MILLISECONDS) .removalListener(new RemovalListener<String, ScriptResources>() { @Override/*from w ww. j ava 2 s .c o m*/ public void onRemoval(RemovalNotification<String, ScriptResources> removal) { // ignore replacements if (removal.getCause() == RemovalCause.REPLACED) return; ScriptResources ce = removal.getValue(); if (ce != null) ce.clear(); } }).build(new CacheLoader<String, ScriptResources>() { public ScriptResources load(String key) throws ExecutionException { throw new ExecutionException(new IllegalArgumentException("Can't load key: " + key)); } }); }
From source file:net.tirasa.wink.client.asynchttpclient.FutureClientResponse.java
@Override public ClientResponse get() throws InterruptedException, ExecutionException { synchronized (this) { if (this.clientResponse == null) { try { createClientResponse(this.futureResponse.get()); } catch (IOException e) { throw new ExecutionException(e); }//ww w .j a v a2 s .c o m } } return this.clientResponse; }