Package com.volantis.shared.net.impl

Examples of com.volantis.shared.net.impl.TimingOutTask


    private FileContent readImpl(File toRead, Period timeout) throws IOException {

        FileInputStream fileInputStream = new FileInputStream(toRead);
        FileChannel fileChannel = fileInputStream.getChannel();

        TimingOutTask task = null;
        FileContent fileContents = null;
        TimeLimitedInputStream timeLimitedInputStream = null;

        // Don't read the whole file now, we will typically be reading
        // potentially large XML files so lets just get create a
View Full Code Here


     *
     * @return the scheduled timeout task.
     */
    private TimingOutTask createAndScheduleTimingOutTask(Period timeout) {
        // Lets handle the timeout.
        TimingOutTask task = new ThreadInterruptingTimingOutTask();
        if (timeout != null && timeout != Period.INDEFINITELY) {
            TIMER.schedule(new RunnableTimerTask(task),
                        timeout.inMillis());
        }
        return task;
View Full Code Here

        // of the caller to release this connection by calling
        // HttpMethod#releaseConnection.
        HttpConnection connection = manager.getConnection(configuration);
        prepareConnection(connection);

        TimingOutTask task = null;
        int statusCode;
        URI uri = null;
        try {
            // Get the URI now so that it can be used to report errors if
            // necessary.
            uri = new URI(connection.getProtocol().getScheme(), null,
                    configuration.getHost(), connection.getPort(),
                    method.getPath(), method.getQueryString(), null);

            if (roundTripTimeout != Period.INDEFINITELY) {
                task = createTimingOutTask(connection);
                TIMER.schedule(new RunnableTimerTask(task),
                        roundTripTimeout.inMillis());
            }


            // Normally HttpClient takes care or opening collection
            // but since we use our own HttpClient we need to do
            // it manually
            if (!connection.isOpen()) {
                connection.open();
            }
            statusCode = method.execute(httpState, connection);
           
        } catch (Exception e) {
            if (task != null && task.timedOut()) {

                // Assume that the exception occurred because of the
                // timeout.
                // todo create a more specific exception that encapsulates the
                // todo URL, the timeout and the actual elapsed time.
                InterruptedIOException exception =
                        wrapException("Request to '" + uri +
                        "' timed out after " + roundTripTimeout, e);

                throw exception;
            } else if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else if (e instanceof IOException) {
                throw (IOException) e;
            } else {
                throw new UndeclaredThrowableException(e);
            }
        } finally {
            if (task != null) {
                // Make sure that any existing timeouts are ignored.
                task.deactivate();
            }
        }

        return HttpStatusCode.getStatusCode(statusCode);
    }
View Full Code Here

TOP

Related Classes of com.volantis.shared.net.impl.TimingOutTask

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.