Example usage for java.util.concurrent ExecutionException printStackTrace

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

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.soulgalore.crawler.core.impl.DefaultCrawler.java

/**
 * Verify that all urls in allUrls returns 200. If not, they will be removed from that set and
 * instead added to the nonworking list.
 * /*  w  ww  . j ava 2s.c  o m*/
 * @param allUrls all the links that has been fetched
 * @param nonWorkingUrls links that are not working
 */
private void verifyUrls(Set<CrawlerURL> allUrls, Set<HTMLPageResponse> verifiedUrls,
        Set<HTMLPageResponse> nonWorkingUrls, Map<String, String> requestHeaders) {

    Set<CrawlerURL> urlsThatNeedsVerification = new LinkedHashSet<CrawlerURL>(allUrls);

    urlsThatNeedsVerification.removeAll(verifiedUrls);

    final Set<Callable<HTMLPageResponse>> tasks = new HashSet<Callable<HTMLPageResponse>>(
            urlsThatNeedsVerification.size());

    for (CrawlerURL testURL : urlsThatNeedsVerification) {
        tasks.add(new HTMLPageResponseCallable(testURL, responseFetcher, true, requestHeaders, false));
    }

    try {
        // wait for all urls to verify
        List<Future<HTMLPageResponse>> responses = service.invokeAll(tasks);

        for (Future<HTMLPageResponse> future : responses) {
            if (!future.isCancelled()) {
                HTMLPageResponse response = future.get();
                if (response.getResponseCode() == HttpStatus.SC_OK
                        && response.getResponseType().indexOf("html") > 0) {
                    // remove, way of catching interrupted / execution e
                    urlsThatNeedsVerification.remove(response.getPageUrl());
                    verifiedUrls.add(response);
                } else if (response.getResponseCode() == HttpStatus.SC_OK) {
                    // it is not HTML
                    urlsThatNeedsVerification.remove(response.getPageUrl());
                } else {
                    nonWorkingUrls.add(response);
                }
            }
        }

    } catch (InterruptedException e1) {
        // TODO add some logging
        e1.printStackTrace();
    } catch (ExecutionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // TODO: We can have a delta here if the exception occur

}

From source file:com.github.jillesvangurp.persistentcachingmap.PersistentCachingMap.java

@SuppressWarnings("unchecked")
// Map.get is unchecked
@Override// w  ww  .  jav  a2s  .  com
public Value get(Object key) {
    try {
        long bucketId = codec.bucketId((Key) key);
        if (bucketIds.contains(bucketId)) {
            Value value = cache.get(bucketId).get((Key) key);
            // return a clone,  this ensures people don't accidentally modify objects in the map.
            if (value != null) {
                return codec.deserializeValue(codec.serializeValue(value));
            }
        }
    } catch (ExecutionException e) {
        e.printStackTrace();
        return null;
    }
    return null;
}

From source file:com.googlecode.icegem.cacheutils.regioncomparator.CompareTool.java

public void execute(String[] args, boolean debugEnabled, boolean quiet) {
    AdminDistributedSystem adminDs = AdminDistributedSystemFactory
            .getDistributedSystem(AdminDistributedSystemFactory.defineDistributedSystem());
    adminDs.connect();/* w w  w.j a v a  2 s.co m*/

    parseCommandLineArguments(args);

    List<Pool> poolList = new ArrayList<Pool>();
    if (serversOption != null && serversOption.length() > 0)
        for (String serverOption : serversOption.split(",")) {
            String serverHost = serverOption.substring(0, serverOption.indexOf("["));
            String serverPort = serverOption.substring(serverOption.indexOf("[") + 1,
                    serverOption.indexOf("]"));
            poolList.add(PoolManager.createFactory().addServer(serverHost, Integer.parseInt(serverPort))
                    .create("poolTo" + serverHost + serverPort));
        }
    if (locatorsProperties != null && !locatorsProperties.isEmpty())
        for (Object poolOption : locatorsProperties.keySet()) {
            String locator = (String) locatorsProperties.get(poolOption);
            String serverHost = locator.substring(0, locator.indexOf("["));
            String serverPort = locator.substring(locator.indexOf("[") + 1, locator.indexOf("]"));
            poolList.add(PoolManager.createFactory().addLocator(serverHost, Integer.parseInt(serverPort)) //todo: check when we have two identical locators options: exception a pool name already exist
                    .create("poolTo" + serverHost + serverPort));
        }

    //todo: insert checking that each cluster contains region and one's type is equal (Partitioned, Replicated)

    boolean partitioned = false; //todo: insert CLI usage  + throw exception if real region has another type

    List<ServerLocation> serverFromPool = new ArrayList<ServerLocation>();
    List<Pool> emptyPools = new ArrayList<Pool>(); //contains pool with no available servers
    for (Pool pool : poolList) {
        List<ServerLocation> allServers = null;
        if (!pool.getLocators().isEmpty())
            allServers = ((AutoConnectionSourceImpl) ((PoolImpl) pool).getConnectionSource()).findAllServers(); //todo: ConnectionError if locator doesn't exist
        else if (!pool.getServers().isEmpty())
            allServers = Arrays
                    .asList((((PoolImpl) pool).getConnectionSource()).findServer(Collections.emptySet()));

        if (allServers != null)
            serverFromPool.addAll(allServers);
        else {
            log.info("not found servers on locator {}", pool);
            emptyPools.add(pool);
        }
    }
    poolList.removeAll(emptyPools);

    if (serverFromPool.size() == 0) {
        log.info("no servers available");
        return;
    }

    printServerLocationDetails(serverFromPool);

    //source for comparison //todo: if this node doesn't contain region! it's problem
    Pool sourcePool;
    if (!partitioned) {
        int randomServerLocation = new Random().nextInt(serverFromPool.size());
        sourcePool = PoolManager.createFactory()
                .addServer(serverFromPool.get(randomServerLocation).getHostName(),
                        serverFromPool.get(randomServerLocation).getPort())
                .create("target");
    } else {
        sourcePool = poolList.get(0);
        poolList.remove(0);
    }

    FunctionService.registerFunction(new RegionInfoFunction());
    ResultCollector regionInfoResult = FunctionService.onServers(sourcePool).withArgs(regionName)
            .execute(new RegionInfoFunction());

    Map regionInfo = (HashMap) ((ArrayList) regionInfoResult.getResult()).get(0);
    System.out.println("region info: " + regionInfo);

    int totalNumBuckets = (Integer) regionInfo.get("totalNumBuckets");
    //log.debug("total keys' batch counts is ", totalNumBuckets);
    System.out.println("total keys' batch counts is " + totalNumBuckets);
    KeyExtractor keyExtractor = new KeyExtractor(regionName, sourcePool, partitioned, totalNumBuckets);

    Map<String, Map<String, Set>> clusterDifference = new HashMap<String, Map<String, Set>>(); //key: memeberId list: absent keys, diff values

    List<PoolResult> taskResults = new ArrayList<PoolResult>();
    List<Future<PoolResult>> collectTasks = new ArrayList<Future<PoolResult>>(poolList.size());
    ExecutorService executorService = Executors.newFixedThreadPool(poolList.size());
    while (keyExtractor.hasKeys()) {
        Set keys = keyExtractor.getNextKeysBatch();
        System.out.println("keys to check: " + keys);
        for (Pool nextPool : poolList)
            collectTasks.add(executorService.submit(new CollectorTask(keys, nextPool, regionName)));
        System.out.println("active tasks: " + collectTasks.size());
        try {
            //for (Future<ResultCollector> futureTask : collectTasks) {
            for (Future<PoolResult> futureTask : collectTasks) {
                taskResults.add(futureTask.get());
            }
        } catch (InterruptedException ie) {
            ie.printStackTrace();
        } catch (ExecutionException ee) {
            ee.printStackTrace();
        }
        collectTasks.clear();

        System.out.println("compare contents..");
        //getting source contents
        Map sourceData = new HashMap();

        //getting source map
        FutureTask<PoolResult> ft = new FutureTask<PoolResult>(new CollectorTask(keys, sourcePool, regionName));
        ft.run();
        try {
            PoolResult rc = ft.get();
            List poolResult = (List) rc.getResultCollector().getResult();
            for (Object singleResult : poolResult) {
                sourceData.putAll((Map) ((HashMap) singleResult).get("map"));
            }
        } catch (Exception e) {
            throw new RuntimeException("error getting key-hash from pool: " + sourcePool, e);
        }
        //todo: aggregate members' data from one cluster

        System.out.println("source data is: " + sourceData);
        //for (ResultCollector taskResultFromPool : taskResults) {
        for (PoolResult taskResultFromPool : taskResults) {
            List poolResult = (ArrayList) taskResultFromPool.getResultCollector().getResult();
            if (!partitioned) {
                for (Object resultFromMember : poolResult) {
                    Map result = (HashMap) resultFromMember;
                    String memberId = (String) result.get("memberId");
                    if (regionInfo.get("id").equals(result.get("memberId"))) //for replicated region
                        continue;
                    Map<String, Set> aggregationInfo = compareAndAggregate(sourceData,
                            (HashMap) result.get("map"));
                    System.out.println("result of comparing is: " + aggregationInfo);
                    if (!clusterDifference.containsKey(memberId)) {
                        aggregationInfo.put("absentKeys", new HashSet());
                        clusterDifference.put(memberId, aggregationInfo);
                    } else {
                        Map<String, Set> difference = clusterDifference.get(memberId);
                        difference.get("absentKeys").addAll((Set) result.get("absentKeys"));
                        difference.get("diffValues").addAll(aggregationInfo.get("diffValues"));
                        clusterDifference.put(memberId, difference);
                    }
                }
            } else {
                Map targetData = new HashMap();
                Set absentKeysFromPool = new HashSet();

                //aggregate data from different members with partition region
                for (Object resultFromMember : poolResult) {
                    targetData.putAll((Map) ((HashMap) resultFromMember).get("map"));
                    absentKeysFromPool.addAll((Set) ((HashMap) resultFromMember).get("absentKeys"));
                }

                Map<String, Set> aggregationInfo = compareAndAggregate(sourceData, targetData);
                System.out.println("result of comparing is: " + aggregationInfo);
                String keyForPartitionRegionType = taskResultFromPool.getPool().toString();
                if (!clusterDifference.containsKey(keyForPartitionRegionType)) {
                    clusterDifference.put(keyForPartitionRegionType, aggregationInfo);
                } else {
                    Map<String, Set> difference = clusterDifference.get(keyForPartitionRegionType);
                    difference.get("absentKeys").addAll(aggregationInfo.get("absentKeys"));
                    difference.get("diffValues").addAll(aggregationInfo.get("diffValues"));
                    clusterDifference.put(keyForPartitionRegionType, difference);
                }
            }
        }

        taskResults.clear();
    }

    System.out.println("____________________________");
    System.out.println("difference: ");
    System.out.println(clusterDifference);
    executorService.shutdown();
    adminDs.disconnect();
}

From source file:org.apache.zeppelin.interpreter.SnappyDataSqlZeppelinInterpreter.java

@Override
public InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter) {

    if (concurrentSQL()) {
        sc.setLocalProperty("spark.scheduler.pool", "fair");
    } else {/*from  w  ww  .j a v a  2  s.  com*/
        sc.setLocalProperty("spark.scheduler.pool", null);
    }

    sc.setJobGroup(getJobGroup(contextInterpreter), "Zeppelin", false);

    Thread.currentThread().setContextClassLoader(org.apache.spark.util.Utils.getSparkClassLoader());
    //SnappyContext snc = new SnappyContext(sc);
    String id = contextInterpreter.getParagraphId();
    SnappyContext snc = null;
    try {
        snc = paragraphContextCache.get(id);
        if (null != getProperty(Constants.SPARK_SQL_SHUFFLE_PARTITIONS)) {
            snc.setConf(Constants.SPARK_SQL_SHUFFLE_PARTITIONS,
                    getProperty(Constants.SPARK_SQL_SHUFFLE_PARTITIONS));
        }
    } catch (ExecutionException e) {
        logger.error("Error initializing SnappyContext");
        e.printStackTrace();
    }

    cmd = cmd.trim();
    if (cmd.startsWith(SHOW_APPROX_RESULTS_FIRST)) {
        cmd = cmd.replaceFirst(SHOW_APPROX_RESULTS_FIRST, EMPTY_STRING);

        /**
         * As suggested by Jags and suyog
         * This will allow user to execute multiple queries in same paragraph.
         * But will return results of the last query.This is mainly done to
         * allow user to set properties for JDBC connection
         *
         */
        String queries[] = cmd.split(SEMI_COLON);
        for (int i = 0; i < queries.length - 1; i++) {
            InterpreterResult result = executeSql(snc, queries[i], contextInterpreter, false);
            if (result.code().equals(InterpreterResult.Code.ERROR)) {
                sc.clearJobGroup();
                return result;
            }
        }
        if (shouldExecuteApproxQuery(id)) {

            for (InterpreterContextRunner r : contextInterpreter.getRunners()) {
                if (id.equals(r.getParagraphId())) {

                    String query = queries[queries.length - 1] + " with error";
                    final InterpreterResult res = executeSql(snc, query, contextInterpreter, true);
                    exService.submit(new QueryExecutor(r));
                    sc.clearJobGroup();
                    return res;
                }
            }

        } else {
            String query = queries[queries.length - 1];
            sc.clearJobGroup();
            return executeSql(snc, query, contextInterpreter, false);
        }
        return null;
    } else {
        String queries[] = cmd.split(SEMI_COLON);
        for (int i = 0; i < queries.length - 1; i++) {
            InterpreterResult result = executeSql(snc, queries[i], contextInterpreter, false);
            if (result.code().equals(InterpreterResult.Code.ERROR)) {
                sc.clearJobGroup();
                return result;
            }
        }
        sc.clearJobGroup();
        return executeSql(snc, queries[queries.length - 1], contextInterpreter, false);

    }

}

From source file:com.dryver.Activities.ActivityRequestMap.java

/**
 * Helper function used to convert {@link LatLng} to {@link Address}
 * This is accomplished through the use of {@link Geocoder}
 *
 * @return ArrayList of addresses/*from w  w w  .  j a  v  a2  s  .co  m*/
 * @see Geocoder
 * @see AsyncTask
 */
private ArrayList<String> mRouteToAddress() {
    String fromAddress = null;
    String toAddress = null;
    GetAddressTask fromAddressTask;
    GetAddressTask toAddressTask;
    ArrayList<Location> toFromLocation = mRouteToLocation();
    ArrayList<String> returnAddressArrayList = new ArrayList<String>();

    fromAddressTask = new GetAddressTask(toFromLocation.get(0));
    toAddressTask = new GetAddressTask(toFromLocation.get(1));
    fromAddressTask.execute();
    toAddressTask.execute();

    try {
        fromAddress = fromAddressTask.get();
        toAddress = toAddressTask.get();
    } catch (InterruptedException ie) {
        ie.printStackTrace();
    } catch (ExecutionException ee) {
        ee.printStackTrace();
    }

    returnAddressArrayList.add(fromAddress);
    returnAddressArrayList.add(toAddress);

    return returnAddressArrayList;
}

From source file:foundme.uniroma2.it.professore.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    context = this;

    swipeView = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
    swipeView.setEnabled(false);//from w  ww .jav a  2s .c o  m

    modeCallBack = new ActionMode.Callback() {

        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            switch (item.getItemId()) {
            case R.id.edit:
                if (!toEdit.equalsIgnoreCase(Variables_it.NO_COURSE)) {
                    Intent i = new Intent(HomeActivity.this, EditCourseActivity.class);
                    i.putExtra(Variables_it.COURSE, toEdit);
                    i.putExtra(Variables_it.NAME, name);
                    startActivity(i);
                }
                toEdit = null;
                mode.finish(); // Automatically exists the action mode, when the user selects this action
                break;
            case R.id.delete:
                if (!toEdit.equalsIgnoreCase(Variables_it.NO_COURSE)) {
                    try {
                        manageCourse(name, toEdit);
                    } catch (ExecutionException e) {
                        e.printStackTrace();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                toEdit = null;
                mode.finish();
                break;
            }
            return false;
        }

        public void onDestroyActionMode(ActionMode mode) {
            viewList.setBackgroundColor(Color.TRANSPARENT);
            mode = null;
        }

        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            mode.setTitle(Variables_it.OPTION);
            mode.getMenuInflater().inflate(R.menu.context_menu, menu);
            return true;
        }
    };

    Bundle passed = getIntent().getExtras();
    name = passed.getString(Variables_it.NAME);
    TAGRead = passed.getString(Variables_it.TAG);

    imgUniroma2 = (ImageButton) findViewById(R.id.ivLogo2);
    imgUniroma2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Variables_it.SITE_TV));
            startActivity(browserIntent);
        }
    });

    nfctest = (TextView) findViewById(R.id.tvNFC);
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    if (mNfcAdapter == null) {
        Toast.makeText(this, Variables_it.NFC_UNSUPPORTED, Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    if (!mNfcAdapter.isEnabled()) {
        Toast.makeText(this, Variables_it.NFC_DISABLED, Toast.LENGTH_LONG).show();
    }

    lvCourses = (ListView) findViewById(R.id.lvCourses);

    if (name != null /*&& courses == null*/) {
        try {
            getCourse(true);
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    profName = (TextView) findViewById(R.id.tvUserName);
    profName.setText(name);
    nfctest.setText(TAGRead);
    handleIntent(getIntent());
}

From source file:gdsc.core.ij.Utils.java

/**
 * Waits for all threads to complete computation.
 * // ww w.j  ava2 s.c o  m
 * @param futures
 */
public static void waitForCompletion(List<Future<?>> futures) {
    try {
        for (Future<?> f : futures) {
            f.get();
        }
    } catch (ExecutionException ex) {
        ex.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:oculus.aperture.graph.aggregation.impl.ModularityAggregator.java

@Override
public void run() {

    logger.debug("Running kSnap clustering algorithm on " + nodeMap.size() + " nodes and " + linkMap.size()
            + " links...");

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();//from w  w w . j a  va2s . c  o m
    HashMap<String, ModularityNode> linklookup = new HashMap<String, ModularityAggregator.ModularityNode>();

    for (Node n : nodeMap.values()) {
        ModularityNode mn = new ModularityNode(n);
        linklookup.put(n.getId(), mn);
        groups.add(mn);

    }
    links = new ArrayList<ModularityLink>();

    for (Link l : linkMap.values()) {
        if (linklookup.containsKey(l.getSourceId()) && linklookup.containsKey(l.getTargetId())) {
            //if this is not true we have links pointing to an invalid node...
            ModularityLink ml = new ModularityLink(linklookup.get(l.getSourceId()),
                    linklookup.get(l.getTargetId()));
            links.add(ml);

            ModularityNode start = linklookup.get(l.getSourceId());
            ModularityNode end = linklookup.get(l.getSourceId());
            start.addLink(ml);
            end.addLink(ml);
        }

    }

    boolean notterminate = true;

    int linksize;

    while (notterminate) {
        final List<Future<?>> futures = new ArrayList<Future<?>>();
        notterminate = false;
        final PriorityBlockingQueue<ModularityLink> linksort = new PriorityBlockingQueue<ModularityLink>();
        linksize = links.size();
        final int itrsize = linksize / nThreads;
        for (int i = 0; i < nThreads; i++) {

            final int passval = i;

            Future<?> foo = executor.submit(new Callable<Boolean>() {
                @Override
                public Boolean call() throws Exception {
                    boolean nt = false;
                    for (int lnknum = 0; lnknum < itrsize; lnknum++) {
                        ModularityLink ln = links.get(passval * itrsize + lnknum);
                        long nc = 0;
                        if (ln.source.neighbourcounts.containsKey(ln.target)) {
                            nc = ln.source.neighbourcounts.get(ln.target).intValue();
                        } else {
                            System.out.println("Oooops");
                        }

                        long q = nc - (ln.source.totalvolume * ln.target.totalvolume) / 2;

                        if (q > 0)
                            nt = true;
                        ln.q.set(q);
                        linksort.add(ln);
                    }
                    return nt;
                }
            });

            futures.add(foo);

        }

        for (Future<?> foo : futures) {
            try {
                notterminate = (Boolean) foo.get();
            } catch (InterruptedException interruptedCancellingAndSignalling) {
                Thread.currentThread().interrupt();
            } catch (ExecutionException wtf) {
                wtf.printStackTrace();
            }
        }

        if (!notterminate)
            break;
        //Now we take each link in the queue and add it to maximal matching 
        ConcurrentLinkedQueue<ModularityLink> maximalmatching = new ConcurrentLinkedQueue<ModularityAggregator.ModularityLink>();
        ConcurrentSkipListSet<ModularityNode> vertexcheck = new ConcurrentSkipListSet<ModularityAggregator.ModularityNode>();
        ModularityLink top = linksort.poll();
        maximalmatching.add(top);
        vertexcheck.add(top.source);
        vertexcheck.add(top.target);
        while (!linksort.isEmpty()) {
            ModularityLink nlnk = linksort.poll();
            if (nlnk.q.intValue() < 0)
                continue;

            if (vertexcheck.contains(nlnk.source) || vertexcheck.contains(nlnk.target))
                continue;
            maximalmatching.add(nlnk);
            vertexcheck.add(nlnk.source);
            vertexcheck.add(nlnk.target);
        }

        //Now we take all the pairs in maximal matching and fuse them
        for (ModularityLink ln : maximalmatching) {
            ModularityNode so = ln.source;
            ModularityNode tr = ln.target;
            so.assimilate(tr);
            groups.remove(tr);

            links.remove(ln);
        }
        linksize = links.size();
        if (linksize == 1)
            notterminate = false;
    }

    /*
    final List<Future<?>> futures = new ArrayList<Future<?>>();
            
    Future<?> foo = executor.submit(new Runnable(){
            
       @Override
       public void run() {
            
       }});
            
    futures.add(foo);
    */
    clusterSet = new ArrayList<Set<Node>>();

    for (ModularityNode g : groups) {

        if (cancel) {
            setStatusWaiting();
            return;
        }
        Set<Node> set = new HashSet<Node>();
        clusterSet.add(set);

        for (Node n : g.nodes) {

            if (cancel) {
                setStatusWaiting();
                return;
            }

            set.add(n);

        }

    }
    if (clusterer != null) {
        graphResult = clusterer.convertClusterSet(clusterSet);
    }
    stopWatch.stop();
    System.out.println("Finished Modularity clustering algorithm.");
    System.out.println("Algorithm took " + stopWatch.toString());//30 = 33.487
    stopWatch.reset();
    this.result = result;
}

From source file:voldemort.tools.KeyVersionFetcherCLI.java

public boolean sampleStore(StoreDefinition storeDefinition) {
    String storeName = storeDefinition.getName();

    String keysFileName = inDir + System.getProperty("file.separator") + storeName + ".keys";
    File keysFile = new File(keysFileName);
    if (!keysFile.exists()) {
        logger.error("Keys file " + keysFileName + " does not exist!");
        return false;
    }//from   w  w w .jav a2  s.  c om

    String kvFileName = outDir + System.getProperty("file.separator") + storeName + ".kvs";
    File kvFile = new File(kvFileName);
    if (kvFile.exists()) {
        logger.info("Key-Version file " + kvFileName + " exists, so will not sample keys from file "
                + keysFileName + ".");
        return true;
    }

    BaseStoreRoutingPlan storeRoutingPlan = new BaseStoreRoutingPlan(cluster, storeDefinition);
    BufferedReader keyReader = null;
    BufferedWriter kvWriter = null;
    try {
        keyReader = new BufferedReader(new FileReader(keysFileName));
        kvWriter = new BufferedWriter(new FileWriter(kvFileName));

        boolean readAllKeys = false;
        while (!readAllKeys) {
            Queue<Future<String>> futureKVs = new LinkedList<Future<String>>();
            for (int numFetchTasks = 0; numFetchTasks < this.outputBatchSize; numFetchTasks++) {
                String keyLine = keyReader.readLine();
                if (keyLine == null) {
                    readAllKeys = true;
                    break;
                }
                byte[] keyInBytes = ByteUtils.fromHexString(keyLine.trim());
                FetchKeyVersionsTask kvFetcher = new FetchKeyVersionsTask(storeRoutingPlan, keyInBytes);
                Future<String> future = kvFetcherService.submit(kvFetcher);
                futureKVs.add(future);
            }

            if (futureKVs.size() > 0) {
                while (!futureKVs.isEmpty()) {
                    Future<String> future = futureKVs.poll();
                    String keyVersions = future.get();
                    kvWriter.append(keyVersions);
                }
            }
        }
        return true;
    } catch (DecoderException de) {
        logger.error("Could not decode key to sample for store " + storeName, de);
        return false;
    } catch (IOException ioe) {
        logger.error("IOException caught while sampling store " + storeName, ioe);
        return false;
    } catch (InterruptedException ie) {
        logger.error("InterruptedException caught while sampling store " + storeName, ie);
        return false;
    } catch (ExecutionException ee) {
        logger.error("Encountered an execution exception while sampling " + storeName, ee);
        ee.printStackTrace();
        return false;
    } finally {
        if (keyReader != null) {
            try {
                keyReader.close();
            } catch (IOException e) {
                logger.error("IOException caught while trying to close keyReader for store " + storeName, e);
                e.printStackTrace();
            }
        }
        if (kvWriter != null) {
            try {
                kvWriter.close();
            } catch (IOException e) {
                logger.error("IOException caught while trying to close kvWriter for store " + storeName, e);
                e.printStackTrace();
            }
        }
    }
}

From source file:org.apache.usergrid.persistence.Schema.java

public static String defaultCollectionName(String entityType) {
    try {//from  www  .  j  a  v  a 2 s  . co  m
        return collectionNameCache.get(entityType);
    } catch (ExecutionException ex) {
        ex.printStackTrace();
    }
    return _defaultCollectionName(entityType);
}