Example usage for java.util.concurrent ExecutionException getMessage

List of usage examples for java.util.concurrent ExecutionException getMessage

Introduction

In this page you can find the example usage for java.util.concurrent ExecutionException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:Main.java

public static void main(String[] args) {
    Callable<Object> badTask = () -> {
        throw new RuntimeException("Throwing exception from task execution...");
    };//ww w . ja v  a  2  s.  co m
    ExecutorService exec = Executors.newSingleThreadExecutor();
    Future submittedTask = exec.submit(badTask);
    try {
        Object result = submittedTask.get();
    } catch (ExecutionException e) {
        System.out.println(e.getMessage());
        System.out.println(e.getCause().getMessage());
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    exec.shutdown();
}

From source file:gridool.db.partitioning.phihash.csv.normal.CsvPartitioningTask.java

private static void runShuffleJob(final GridKernel kernel, final PartitioningJobConf conf,
        final Map<GridNode, MutableLong> recMap, final String deploymentGroup) {
    PartitioningJobType jobType = conf.getJobConf().getJobType();
    Class<? extends GridJob<PartitioningJobConf, Map<GridNode, MutableInt>>> jobClass = jobType
            .getFirstPartitioningJobClass();
    //final GridJobFuture<Map<GridNode, MutableInt>> future = kernel.execute(CsvHashPartitioningJob.class, conf);
    //final GridJobFuture<Map<GridNode, MutableInt>> future = kernel.execute(GlobalCsvHashPartitioningJob.class, conf);
    final GridJobFuture<Map<GridNode, MutableInt>> future = kernel.execute(jobClass, conf);
    final Map<GridNode, MutableInt> map;
    try {/*from  w w  w  . j a va  2  s. c  o m*/
        map = future.get(); // wait for execution
    } catch (InterruptedException ie) {
        LOG.error(ie.getMessage(), ie);
        throw new IllegalStateException(ie);
    } catch (ExecutionException ee) {
        LOG.error(ee.getMessage(), ee);
        throw new IllegalStateException(ee);
    }
    synchronized (recMap) {
        for (final Map.Entry<GridNode, MutableInt> e : map.entrySet()) {
            GridNode node = e.getKey();
            MutableInt assigned = e.getValue();
            long v = assigned.longValue();
            MutableLong prev = recMap.get(node);
            if (prev == null) {
                recMap.put(node, new MutableLong(v));
            } else {
                prev.add(v);
            }
        }
    }
}

From source file:gridool.db.helpers.GridDbUtils.java

public static long invokeCsvLoadJob(final GridKernel kernel, final String csvFileName,
        final HashMap<GridNode, MutableLong> assignMap, final DBPartitioningJobConf jobConf) {
    String connectUrl = jobConf.getConnectUrl();
    String tableName = jobConf.getTableName();
    String createTableDDL = jobConf.getCreateTableDDL();
    String copyIntoQuery = generateCopyIntoQuery(tableName, jobConf);
    String alterTableDDL = jobConf.getAlterTableDDL();

    MonetDBCsvLoadOperation ops = new MonetDBCsvLoadOperation(connectUrl, tableName, csvFileName,
            createTableDDL, copyIntoQuery, alterTableDDL);
    ops.setAuth(jobConf.getUserName(), jobConf.getPassword());
    final Pair<MonetDBCsvLoadOperation, Map<GridNode, MutableLong>> pair = new Pair<MonetDBCsvLoadOperation, Map<GridNode, MutableLong>>(
            ops, assignMap);//from   w  ww  .j  ava2 s.  c  o  m

    final GridJobFuture<Long> future = kernel.execute(MonetDBInvokeCsvLoadJob.class, pair);
    final Long numInserted;
    try {
        numInserted = future.get();
    } catch (InterruptedException ie) {
        LOG.error(ie.getMessage(), ie);
        throw new IllegalStateException(ie);
    } catch (ExecutionException ee) {
        LOG.error(ee.getMessage(), ee);
        throw new IllegalStateException(ee);
    }
    return (numInserted == null) ? -1L : numInserted.longValue();
}

From source file:gridool.db.partitioning.phihash.csv.grace.CsvGraceHashPartitioningTask.java

private static void runShuffleJob(final GridKernel kernel, final PartitioningJobConf conf,
        final Map<GridNode, MutableLong> recMap, final Map<String, OutputStream> outputMap,
        final String deploymentGroup) {
    if (outputMap != null) {
        conf.setOutputMap(outputMap);/*from  ww w .j  a v  a2  s.c  om*/
    }
    PartitioningJobType jobType = conf.getJobConf().getJobType();
    Class<? extends GridJob<PartitioningJobConf, Map<GridNode, MutableInt>>> jobClass = jobType
            .getFirstPartitioningJobClass();
    //final GridJobFuture<Map<GridNode, MutableInt>> future = kernel.execute(CsvGraceHashPartitioningJob.class, conf);
    final GridJobFuture<Map<GridNode, MutableInt>> future = kernel.execute(jobClass, conf);
    final Map<GridNode, MutableInt> map;
    try {
        map = future.get(); // wait for execution
    } catch (InterruptedException ie) {
        LOG.error(ie.getMessage(), ie);
        throw new IllegalStateException(ie);
    } catch (ExecutionException ee) {
        LOG.error(ee.getMessage(), ee);
        throw new IllegalStateException(ee);
    }
    synchronized (recMap) {
        for (final Map.Entry<GridNode, MutableInt> e : map.entrySet()) {
            GridNode node = e.getKey();
            MutableInt assigned = e.getValue();
            long v = assigned.longValue();
            MutableLong prev = recMap.get(node);
            if (prev == null) {
                recMap.put(node, new MutableLong(v));
            } else {
                prev.add(v);
            }
        }
    }
}

From source file:org.onosproject.bmv2.ctl.Bmv2ThriftClient.java

/**
 * Returns a client object to control the passed device.
 *
 * @param deviceId device id/*from   w  w w .jav  a  2 s.co  m*/
 * @return bmv2 client object
 * @throws Bmv2RuntimeException if a connection to the device cannot be established
 */
public static Bmv2ThriftClient of(DeviceId deviceId) throws Bmv2RuntimeException {
    try {
        checkNotNull(deviceId, "deviceId cannot be null");
        LOG.debug("Getting a client from cache... > deviceId{}", deviceId);
        return CLIENT_CACHE.get(deviceId);
    } catch (ExecutionException e) {
        LOG.debug("Exception while getting a client from cache: {} > ", e, deviceId);
        throw new Bmv2RuntimeException(e.getMessage(), e.getCause());
    }
}

From source file:gridool.db.partitioning.phihash.monetdb.MonetDBGraceMultiCSVsLoadTask.java

@Override
protected HashMap<GridNode, MutableLong> execute() throws GridException {
    GridJobFuture<HashMap<GridNode, MutableLong>> future = kernel.execute(MonetDBGraceMultiCSVsLoadJob.class,
            jobConf);//ww  w  . j av  a2s  . c o m
    HashMap<GridNode, MutableLong> assigned;
    try {
        assigned = future.get();
    } catch (InterruptedException ie) {
        LOG.error(ie.getMessage(), ie);
        throw new IllegalStateException(ie);
    } catch (ExecutionException ee) {
        LOG.error(ee.getMessage(), ee);
        throw new IllegalStateException(ee);
    }
    return assigned;
}

From source file:gridool.mapred.db.DBMapReduceJob.java

@Override
public String reduce() throws GridException {
    final GridJobFuture<String> result = kernel.execute(DBReduceJob.class, jobConf);
    try {/* w ww .j a va  2 s . com*/
        return result.get();
    } catch (InterruptedException ie) {
        LogFactory.getLog(getClass()).error(ie.getMessage(), ie);
        throw new GridException(ie);
    } catch (ExecutionException ee) {
        LogFactory.getLog(getClass()).error(ee.getMessage(), ee);
        throw new GridException(ee);
    }
}

From source file:gridool.mapred.dht.DhtMapReduceJob.java

@Override
public String reduce() throws GridException {
    jobConf.setInputTableName(shuffleDestDhtName);
    final GridJobFuture<String> result = kernel.execute(DhtReduceJob.class, jobConf);
    try {/*from   w w w.j  av a2  s.c  o m*/
        return result.get();
    } catch (InterruptedException ie) {
        LogFactory.getLog(getClass()).error(ie.getMessage(), ie);
        throw new GridException(ie);
    } catch (ExecutionException ee) {
        LogFactory.getLog(getClass()).error(ee.getMessage(), ee);
        throw new GridException(ee);
    }
}

From source file:com.comcast.cdn.traffic_control.traffic_router.core.dns.ZoneManager.java

@SuppressWarnings("PMD.CyclomaticComplexity")
private static List<Record> createZone(final String domain, final Map<String, List<Record>> zoneMap,
        final Map<String, DeliveryService> dsMap, final TrafficRouter tr, final LoadingCache<ZoneKey, Zone> zc,
        final LoadingCache<ZoneKey, Zone> dzc, final ExecutorService initExecutor, final String hostname)
        throws IOException {
    final DeliveryService ds = dsMap.get(domain);
    final CacheRegister data = tr.getCacheRegister();
    final JSONObject trafficRouters = data.getTrafficRouters();
    final JSONObject config = data.getConfig();

    JSONObject ttl = null;/*  w ww  .  jav  a  2s.c o  m*/
    JSONObject soa = null;

    if (ds != null) {
        ttl = ds.getTtls();
        soa = ds.getSoa();
    } else {
        ttl = config.optJSONObject("ttls");
        soa = config.optJSONObject("soa");
    }

    final Name name = newName(domain);
    final List<Record> list = zoneMap.get(domain);
    final Name admin = newName(ZoneUtils.getAdminString(soa, "admin", "traffic_ops", domain));
    list.add(new SOARecord(name, DClass.IN, ZoneUtils.getLong(ttl, "SOA", 86400),
            getGlueName(ds, trafficRouters.optJSONObject(hostname), name, hostname), admin,
            ZoneUtils.getLong(soa, "serial", ZoneUtils.getSerial(data.getStats())),
            ZoneUtils.getLong(soa, "refresh", 28800), ZoneUtils.getLong(soa, "retry", 7200),
            ZoneUtils.getLong(soa, "expire", 604800), ZoneUtils.getLong(soa, "minimum", 60)));
    addTrafficRouters(list, trafficRouters, name, ttl, domain, ds);
    addStaticDnsEntries(list, ds, domain);

    final List<Record> records = new ArrayList<Record>();

    try {
        final long maxTTL = ZoneUtils.getMaximumTTL(list);
        records.addAll(signatureManager.generateDSRecords(name, maxTTL));
        list.addAll(signatureManager.generateDNSKEYRecords(name, maxTTL));
        initExecutor.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    final Zone zone = zc.get(signatureManager.generateZoneKey(name, list)); // cause the zone to be loaded into the new cache
                    final boolean primeDynCache = config.optBoolean("dynamic.cache.primer.enabled", true);
                    final int primerLimit = config.optInt("dynamic.cache.primer.limit", DEFAULT_PRIMER_LIMIT);

                    // prime the dynamic zone cache
                    if (primeDynCache && ds != null && ds.isDns()) {
                        final DNSRequest request = new DNSRequest();
                        final Name edgeName = newName(getDnsRoutingName(), domain);
                        request.setHostname(edgeName.toString(true)); // Name.toString(true) - omit the trailing dot

                        for (final CacheLocation cacheLocation : data.getCacheLocations()) {
                            final List<Cache> caches = tr.selectCachesByCZ(ds, cacheLocation);

                            if (caches == null) {
                                continue;
                            }

                            // calculate number of permutations if maxDnsIpsForLocation > 0 and we're not using consistent DNS routing
                            int p = 1;

                            if (ds.getMaxDnsIps() > 0 && !tr.isConsistentDNSRouting()
                                    && caches.size() > ds.getMaxDnsIps()) {
                                for (int c = caches.size(); c > (caches.size() - ds.getMaxDnsIps()); c--) {
                                    p *= c;
                                }
                            }

                            final Set<List<InetRecord>> pset = new HashSet<List<InetRecord>>();

                            for (int i = 0; i < primerLimit; i++) {
                                final List<InetRecord> records = tr.inetRecordsFromCaches(ds, caches, request);

                                if (!pset.contains(records)) {
                                    fillDynamicZone(dzc, zone, edgeName, records,
                                            signatureManager.isDnssecEnabled());
                                    pset.add(records);
                                    LOGGER.debug("Primed " + ds.getId() + " @ " + cacheLocation.getId()
                                            + "; permutation " + pset.size() + "/" + p);
                                }

                                if (pset.size() == p) {
                                    break;
                                }
                            }
                        }
                    }
                } catch (ExecutionException ex) {
                    LOGGER.fatal("Unable to load zone into cache: " + ex.getMessage(), ex);
                } catch (TextParseException ex) { // only occurs due to newName above
                    LOGGER.fatal("Unable to prime dynamic zone " + domain, ex);
                }
            }
        });
    } catch (NoSuchAlgorithmException ex) {
        LOGGER.fatal("Unable to create zone: " + ex.getMessage(), ex);
    }

    return records;
}

From source file:gridool.db.partitioning.phihash.monetdb.MonetDBCsvLoadTask.java

@Override
protected void postShuffle(int numShuffled) {
    super.postShuffle(numShuffled);
    assert (csvFileName != null);

    String connectUrl = jobConf.getConnectUrl();
    String tableName = jobConf.getTableName();
    String createTableDDL = jobConf.getCreateTableDDL();
    String copyIntoQuery = GridDbUtils.generateCopyIntoQuery(tableName, jobConf);
    String alterTableDDL = jobConf.getAlterTableDDL();

    MonetDBCsvLoadOperation ops = new MonetDBCsvLoadOperation(connectUrl, tableName, csvFileName,
            createTableDDL, copyIntoQuery, alterTableDDL);
    ops.setAuth(jobConf.getUserName(), jobConf.getPassword());
    final Pair<MonetDBCsvLoadOperation, Map<GridNode, MutableLong>> pair = new Pair<MonetDBCsvLoadOperation, Map<GridNode, MutableLong>>(
            ops, assignMap);/* ww w  . j  av  a2  s  . c o  m*/

    final StopWatch sw = new StopWatch();
    final GridJobFuture<Long> future = kernel.execute(MonetDBInvokeCsvLoadJob.class, pair);
    final Long numInserted;
    try {
        numInserted = future.get();
    } catch (InterruptedException ie) {
        LOG.error(ie.getMessage(), ie);
        throw new IllegalStateException(ie);
    } catch (ExecutionException ee) {
        LOG.error(ee.getMessage(), ee);
        throw new IllegalStateException(ee);
    }
    assert (numInserted != null);
    if (LOG.isInfoEnabled()) {
        LOG.info("Processed/Inserted " + numShuffled + '/' + numInserted.longValue() + " records into '"
                + tableName + "' table in " + sw.toString());
    }
}