Example usage for java.lang InterruptedException getCause

List of usage examples for java.lang InterruptedException getCause

Introduction

In this page you can find the example usage for java.lang InterruptedException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:Main.java

public static void edtSmartInvokeAndWait(Runnable block) {
    if (!SwingUtilities.isEventDispatchThread())
        try {/*w ww  .  ja  va 2 s . c om*/
            SwingUtilities.invokeAndWait(block);
        } catch (InterruptedException e) {
        } catch (InvocationTargetException e) {
            if (e.getCause() instanceof RuntimeException)
                throw (RuntimeException) e.getCause();
        }
    else
        block.run();
}

From source file:Main.java

/**
 * Invoke and wait for the result. /*from  ww w. java  2s . co  m*/
 */
public static void invokeAndWait(Runnable runnable) {
    if (SwingUtilities.isEventDispatchThread()) {
        runnable.run();
    } else {
        try {
            SwingUtilities.invokeAndWait(runnable);
        } catch (InterruptedException e) {
            throw new RuntimeException("AWT queue job interrupted.");
        } catch (InvocationTargetException e) {
            throw new RuntimeException("Unhandled exception in the AWT event queue.", e.getCause());
        }
    }
}

From source file:cn.clxy.codes.upload.UploadFileService.java

private static String checkFuture(Future<String> future) {

    try {// w  ww .  ja  va 2  s.  co m
        String result = future.get();
        log.debug(result + " is done.");
        return result;
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return null;
    } catch (ExecutionException e) {
        throw new RuntimeException(e.getCause());
    }
}

From source file:org.apache.hadoop.hbase.snapshot.SnapshotManifestV2.java

static List<SnapshotRegionManifest> loadRegionManifests(final Configuration conf, final Executor executor,
        final FileSystem fs, final Path snapshotDir, final SnapshotDescription desc) throws IOException {
    FileStatus[] manifestFiles = FSUtils.listStatus(fs, snapshotDir, new PathFilter() {
        @Override/*from   www .  ja v a2 s .c  o m*/
        public boolean accept(Path path) {
            return path.getName().startsWith(SNAPSHOT_MANIFEST_PREFIX);
        }
    });

    if (manifestFiles == null || manifestFiles.length == 0)
        return null;

    final ExecutorCompletionService<SnapshotRegionManifest> completionService = new ExecutorCompletionService<SnapshotRegionManifest>(
            executor);
    for (final FileStatus st : manifestFiles) {
        completionService.submit(new Callable<SnapshotRegionManifest>() {
            @Override
            public SnapshotRegionManifest call() throws IOException {
                FSDataInputStream stream = fs.open(st.getPath());
                try {
                    return SnapshotRegionManifest.parseFrom(stream);
                } finally {
                    stream.close();
                }
            }
        });
    }

    ArrayList<SnapshotRegionManifest> regionsManifest = new ArrayList<SnapshotRegionManifest>(
            manifestFiles.length);
    try {
        for (int i = 0; i < manifestFiles.length; ++i) {
            regionsManifest.add(completionService.take().get());
        }
    } catch (InterruptedException e) {
        throw new InterruptedIOException(e.getMessage());
    } catch (ExecutionException e) {
        IOException ex = new IOException();
        ex.initCause(e.getCause());
        throw ex;
    }
    return regionsManifest;
}

From source file:org.opentox.toxotis.factory.PropertyFactory.java

public static Feature createAndPublishProperty(String title, String units, SubstanceDataset ds,
        VRI featureService, AuthenticationToken token) throws ServiceInvocationException {
    Feature brandNewProperty = new Feature();
    MetaInfo mi = new MetaInfoImpl();
    mi.addTitle(title);//www.  ja va  2s.co  m
    brandNewProperty.setMeta(mi);
    brandNewProperty.setUnits(units);

    //TODO custom enanomapper
    // Publish the property. Inside the substanceDataset there is a csv containing 
    // the header info of a property and a dummy substance

    Future<VRI> predictedFeatureUri = ds.publish(featureService, token);
    /* Wait for remote server to respond */
    try {
        while (!predictedFeatureUri.isDone()) {
            Thread.sleep(1000);
        }
        // Publishing a property is not available. Thus we post to /substance, which returns a substance
        // From that substance we get the substanceOwner and then get the dataset (created only for publishing properties)

        VRI resultUri = predictedFeatureUri.get();

        String host = SubstanceDataset.getHostFromVRI(ds.getUri().toString());
        String ownerUUID = Substance.getSubstanceKey(token, resultUri.getUri(), "ownerUUID");

        //TODO custom enanomapper
        // Get the dataset of the substance
        String datasetUri = SubstanceDataset.getDatasetFromUUIDOwner(ownerUUID, host);

        VRI input = new VRI(datasetUri);
        DatasetJsonDownloader jsn = new DatasetJsonDownloader(input);
        JSONObject obj = jsn.getJSON(token);

        // Get the info from the first (and only one) property of the dataset 
        // There the property's URI is returned.

        String property = jsn.getFirstProperty(obj, host);

        brandNewProperty.setUri(new VRI(property));
        return brandNewProperty;
    } catch (InterruptedException ex) {
        throw new IllegalArgumentException("Interrupted", ex);
    } catch (URISyntaxException ex) {
        throw new IllegalArgumentException("Invalid URI", ex);
    } catch (ExecutionException ex) {
        if (ex.getCause() != null && ex.getCause() instanceof ServiceInvocationException) {
            throw (ServiceInvocationException) ex.getCause();
        }
        throw new ServiceInvocationException(ex);
    }
}

From source file:org.apache.hadoop.hbase.snapshot.SnapshotManifestV1.java

static List<SnapshotRegionManifest> loadRegionManifests(final Configuration conf, final Executor executor,
        final FileSystem fs, final Path snapshotDir, final SnapshotDescription desc) throws IOException {
    FileStatus[] regions = FSUtils.listStatus(fs, snapshotDir, new FSUtils.RegionDirFilter(fs));
    if (regions == null) {
        LOG.info("No regions under directory:" + snapshotDir);
        return null;
    }/*from   w  w w  .j a  v a2 s.co m*/

    final ExecutorCompletionService<SnapshotRegionManifest> completionService = new ExecutorCompletionService<SnapshotRegionManifest>(
            executor);
    for (final FileStatus region : regions) {
        completionService.submit(new Callable<SnapshotRegionManifest>() {
            @Override
            public SnapshotRegionManifest call() throws IOException {
                HRegionInfo hri = HRegionFileSystem.loadRegionInfoFileContent(fs, region.getPath());
                return buildManifestFromDisk(conf, fs, snapshotDir, hri);
            }
        });
    }

    ArrayList<SnapshotRegionManifest> regionsManifest = new ArrayList<SnapshotRegionManifest>(regions.length);
    try {
        for (int i = 0; i < regions.length; ++i) {
            regionsManifest.add(completionService.take().get());
        }
    } catch (InterruptedException e) {
        throw new InterruptedIOException(e.getMessage());
    } catch (ExecutionException e) {
        IOException ex = new IOException();
        ex.initCause(e.getCause());
        throw ex;
    }
    return regionsManifest;
}

From source file:org.apache.hadoop.hbase.util.ModifyRegionUtils.java

/**
 * Execute the task on the specified set of regions.
 *
 * @param exec Thread Pool Executor/*from   w w w . j a v a2s .  c  o m*/
 * @param regions {@link HRegionInfo} that describes the regions to edit
 * @param task {@link RegionFillTask} custom code to edit the region
 * @throws IOException
 */
public static void editRegions(final ThreadPoolExecutor exec, final Collection<HRegionInfo> regions,
        final RegionEditTask task) throws IOException {
    final ExecutorCompletionService<Void> completionService = new ExecutorCompletionService<Void>(exec);
    for (final HRegionInfo hri : regions) {
        completionService.submit(new Callable<Void>() {
            @Override
            public Void call() throws IOException {
                task.editRegion(hri);
                return null;
            }
        });
    }

    try {
        for (HRegionInfo hri : regions) {
            completionService.take().get();
        }
    } catch (InterruptedException e) {
        throw new InterruptedIOException(e.getMessage());
    } catch (ExecutionException e) {
        IOException ex = new IOException();
        ex.initCause(e.getCause());
        throw ex;
    }
}

From source file:org.onosproject.store.consistent.impl.ConsistentMapImpl.java

private static <T> T complete(CompletableFuture<T> future) {
    try {/* w ww.ja v a2s .  com*/
        return future.get(OPERATION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new ConsistentMapException.Interrupted();
    } catch (TimeoutException e) {
        throw new ConsistentMapException.Timeout();
    } catch (ExecutionException e) {
        throw new ConsistentMapException(e.getCause());
    }
}

From source file:org.apache.hadoop.hbase.snapshot.SnapshotReferenceUtil.java

public static void concurrentVisitReferencedFiles(final Configuration conf, final FileSystem fs,
        final SnapshotManifest manifest, final StoreFileVisitor visitor) throws IOException {
    final SnapshotDescription snapshotDesc = manifest.getSnapshotDescription();
    final Path snapshotDir = manifest.getSnapshotDir();

    List<SnapshotRegionManifest> regionManifests = manifest.getRegionManifests();
    if (regionManifests == null || regionManifests.size() == 0) {
        LOG.debug("No manifest files present: " + snapshotDir);
        return;//from   ww  w. j a  va  2 s  .  c om
    }

    ExecutorService exec = SnapshotManifest.createExecutor(conf, "VerifySnapshot");
    final ExecutorCompletionService<Void> completionService = new ExecutorCompletionService<Void>(exec);
    try {
        for (final SnapshotRegionManifest regionManifest : regionManifests) {
            completionService.submit(new Callable<Void>() {
                @Override
                public Void call() throws IOException {
                    visitRegionStoreFiles(regionManifest, visitor);
                    return null;
                }
            });
        }
        try {
            for (int i = 0; i < regionManifests.size(); ++i) {
                completionService.take().get();
            }
        } catch (InterruptedException e) {
            throw new InterruptedIOException(e.getMessage());
        } catch (ExecutionException e) {
            if (e.getCause() instanceof CorruptedSnapshotException) {
                throw new CorruptedSnapshotException(e.getCause().getMessage(), snapshotDesc);
            } else {
                IOException ex = new IOException();
                ex.initCause(e.getCause());
                throw ex;
            }
        }
    } finally {
        exec.shutdown();
    }
}

From source file:org.commonjava.indy.ftest.core.fixture.ThreadDumper.java

public static TestRule timeoutRule(int timeout, TimeUnit units) {
    return (base, description) -> new Statement() {
        public void evaluate() throws Throwable {
            System.out.printf("Setting up timeout: %d %s to wrap: %s\n", timeout, units, base);
            AtomicReference<Throwable> error = new AtomicReference<>();
            CountDownLatch latch = new CountDownLatch(1);
            FutureTask<Void> task = new FutureTask<>(() -> {
                try {
                    latch.countDown();/* www . j a  va  2s. c o m*/
                    base.evaluate();
                } catch (Throwable t) {
                    error.set(t);
                }

                return null;
            });

            ThreadGroup tg = new ThreadGroup("Test Timeout Group");
            Thread t = new Thread(tg, task, "Test Timeout Thread");
            t.setDaemon(true);
            t.start();

            try {
                System.out.println("Waiting for test to start.");
                latch.await();
            } catch (InterruptedException e) {
                error.set(e);
            }

            if (error.get() == null) {
                try {
                    System.out.println("Waiting for test to complete (or timeout)");
                    task.get(timeout, units);
                } catch (InterruptedException e) {
                    error.set(e);
                } catch (ExecutionException e) {
                    error.set(e.getCause());
                } catch (TimeoutException e) {
                    System.out.printf("Test timeout %d %s expired!\n", timeout, units.name());
                    dumpThreads();
                    StackTraceElement[] stackTrace = t.getStackTrace();
                    Exception currThreadException = new TestTimedOutException(timeout, units);
                    if (stackTrace != null) {
                        currThreadException.setStackTrace(stackTrace);
                        t.interrupt();
                    }

                    throw currThreadException;
                }
            }

            Throwable throwable = error.get();
            if (throwable != null) {
                throw throwable;
            }
        }
    };
}