Example usage for java.util.concurrent TimeoutException toString

List of usage examples for java.util.concurrent TimeoutException toString

Introduction

In this page you can find the example usage for java.util.concurrent TimeoutException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:org.apache.cassandra.service.StorageProxy.java

public static List<Row> getRangeSlice(RangeSliceCommand command, ConsistencyLevel consistency_level)
        throws IOException, UnavailableException, TimeoutException {
    if (logger.isDebugEnabled())
        logger.debug(command.toString());
    long startTime = System.nanoTime();
    List<Row> rows;/*w w  w  .j a  v a2 s . com*/
    // now scan until we have enough results
    try {
        rows = new ArrayList<Row>(command.max_keys);
        List<AbstractBounds> ranges = getRestrictedRanges(command.range);
        for (AbstractBounds range : ranges) {
            List<InetAddress> liveEndpoints = StorageService.instance.getLiveNaturalEndpoints(command.keyspace,
                    range.right);
            DatabaseDescriptor.getEndpointSnitch().sortByProximity(FBUtilities.getLocalAddress(),
                    liveEndpoints);

            if (consistency_level == ConsistencyLevel.ONE && !liveEndpoints.isEmpty()
                    && liveEndpoints.get(0).equals(FBUtilities.getLocalAddress())) {
                if (logger.isDebugEnabled())
                    logger.debug("local range slice");
                ColumnFamilyStore cfs = Table.open(command.keyspace)
                        .getColumnFamilyStore(command.column_family);
                try {
                    rows.addAll(cfs.getRangeSlice(command.super_column, range, command.max_keys,
                            QueryFilter.getFilter(command.predicate, cfs.getComparator())));
                } catch (ExecutionException e) {
                    throw new RuntimeException(e.getCause());
                } catch (InterruptedException e) {
                    throw new AssertionError(e);
                }
            } else {
                RangeSliceCommand c2 = new RangeSliceCommand(command.keyspace, command.column_family,
                        command.super_column, command.predicate, range, command.max_keys);

                // collect replies and resolve according to consistency level
                RangeSliceResponseResolver resolver = new RangeSliceResponseResolver(command.keyspace,
                        liveEndpoints);
                ReadCallback<Iterable<Row>> handler = getReadCallback(resolver, command, consistency_level,
                        liveEndpoints);
                handler.assureSufficientLiveNodes();
                for (InetAddress endpoint : liveEndpoints) {
                    MessagingService.instance().sendRR(c2, endpoint, handler);
                    if (logger.isDebugEnabled())
                        logger.debug("reading " + c2 + " from " + endpoint);
                }

                try {
                    for (Row row : handler.get()) {
                        rows.add(row);
                        logger.debug("range slices read {}", row.key);
                    }
                } catch (TimeoutException ex) {
                    if (logger.isDebugEnabled())
                        logger.debug("Range slice timeout: {}", ex.toString());
                    throw ex;
                } catch (DigestMismatchException e) {
                    throw new AssertionError(e); // no digests in range slices yet
                }
            }

            // if we're done, great, otherwise, move to the next range
            if (rows.size() >= command.max_keys)
                break;
        }
    } finally {
        rangeStats.addNano(System.nanoTime() - startTime);
    }
    return rows.size() > command.max_keys ? rows.subList(0, command.max_keys) : rows;
}

From source file:org.apache.cassandra.service.StorageProxy.java

public static List<Row> scan(final String keyspace, String column_family, IndexClause index_clause,
        SlicePredicate column_predicate, ConsistencyLevel consistency_level)
        throws IOException, TimeoutException, UnavailableException {
    IPartitioner p = StorageService.getPartitioner();

    Token leftToken = index_clause.start_key == null ? p.getMinimumToken() : p.getToken(index_clause.start_key);
    List<AbstractBounds> ranges = getRestrictedRanges(new Bounds(leftToken, p.getMinimumToken()));
    logger.debug("scan ranges are " + StringUtils.join(ranges, ","));

    // now scan until we have enough results
    List<Row> rows = new ArrayList<Row>(index_clause.count);
    for (AbstractBounds range : ranges) {
        List<InetAddress> liveEndpoints = StorageService.instance.getLiveNaturalEndpoints(keyspace,
                range.right);/* ww  w.  j a va 2 s  .  c  o  m*/
        DatabaseDescriptor.getEndpointSnitch().sortByProximity(FBUtilities.getLocalAddress(), liveEndpoints);

        // collect replies and resolve according to consistency level
        RangeSliceResponseResolver resolver = new RangeSliceResponseResolver(keyspace, liveEndpoints);
        IReadCommand iCommand = new IReadCommand() {
            public String getKeyspace() {
                return keyspace;
            }
        };
        ReadCallback<Iterable<Row>> handler = getReadCallback(resolver, iCommand, consistency_level,
                liveEndpoints);
        handler.assureSufficientLiveNodes();

        IndexScanCommand command = new IndexScanCommand(keyspace, column_family, index_clause, column_predicate,
                range);
        MessageProducer producer = new CachingMessageProducer(command);
        for (InetAddress endpoint : liveEndpoints) {
            MessagingService.instance().sendRR(producer, endpoint, handler);
            if (logger.isDebugEnabled())
                logger.debug("reading " + command + " from " + endpoint);
        }

        try {
            for (Row row : handler.get()) {
                rows.add(row);
                logger.debug("read {}", row);
            }
        } catch (TimeoutException ex) {
            if (logger.isDebugEnabled())
                logger.debug("Index scan timeout: {}", ex.toString());
            throw ex;
        } catch (DigestMismatchException e) {
            throw new RuntimeException(e);
        }
        if (rows.size() >= index_clause.count)
            return rows.subList(0, index_clause.count);
    }

    return rows;
}

From source file:org.apache.slider.common.tools.SliderUtils.java

/**
 * Execute a command for a test operation
 * @param name name in error/*from w w w. j a va 2s  .  com*/
 * @param status status code expected
 * @param timeoutMillis timeout in millis for process to finish
 * @param logger
 * @param outputString optional string to grep for (must not span a line)
 * @param commands commands   @return the process
 * @throws IOException on any failure.
 */
public static ForkedProcessService execCommand(String name, int status, long timeoutMillis, Logger logger,
        String outputString, String... commands) throws IOException, SliderException {
    Preconditions.checkArgument(isSet(name), "no name");
    Preconditions.checkArgument(commands.length > 0, "no commands");
    Preconditions.checkArgument(isSet(commands[0]), "empty command");

    ForkedProcessService process;

    process = new ForkedProcessService(name, new HashMap<String, String>(), Arrays.asList(commands));
    process.setProcessLog(logger);
    process.init(new Configuration());
    String errorText = null;
    process.start();
    try {
        if (!process.waitForServiceToStop(timeoutMillis)) {
            throw new TimeoutException("Process did not stop in " + timeoutMillis + "mS");
        }
        int exitCode = process.getExitCode();
        List<String> recentOutput = process.getRecentOutput();
        if (status != exitCode) {
            // error condition
            errorText = "Expected exit code={" + status + "}, " + "actual exit code={" + exitCode + "}";
        } else {
            if (isSet(outputString)) {
                boolean found = false;
                for (String line : recentOutput) {
                    if (line.contains(outputString)) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    errorText = "Did not find \"" + outputString + "\"" + " in output";
                }
            }
        }
        if (errorText == null) {
            return process;
        }

    } catch (TimeoutException e) {
        errorText = e.toString();
    }
    // error text: non null ==> operation failed
    log.warn(errorText);
    List<String> recentOutput = process.getRecentOutput();
    for (String line : recentOutput) {
        log.info(line);
    }
    throw new SliderException(LauncherExitCodes.EXIT_OTHER_FAILURE, "Process %s failed: %s", name, errorText);

}