Example usage for java.io InterruptedIOException InterruptedIOException

List of usage examples for java.io InterruptedIOException InterruptedIOException

Introduction

In this page you can find the example usage for java.io InterruptedIOException InterruptedIOException.

Prototype

public InterruptedIOException(String s) 

Source Link

Document

Constructs an InterruptedIOException with the specified detail message.

Usage

From source file:org.psikeds.common.services.AbstractBaseService.java

protected Object handleRequest(final String reqId, final Executable reqExec, final Object reqData)
        throws InterruptedIOException {
    Object respData = null;//from w w w. j a va  2s . c  om
    try {
        getLogger().trace("--> handleRequest({}, {}, {})", reqId, reqExec, reqData);
        final Continuation cont = getContinuation(reqId);
        if (cont == null) {
            if (this.asyncSupported) {
                getLogger().warn(
                        "Continuations and asynchronous invocation of requests are configured (asyncSupported = {}), but not supported by Execution-Platform!\nFalling back to synchronous Execution-Strategy: {}",
                        this.asyncSupported, DEFAULT_SYNCHRONOUS_STRATEGY.getClass().getName());
                this.asyncSupported = false;
                this.executionStrategy = DEFAULT_SYNCHRONOUS_STRATEGY;
            }
            // new request, synchronous invocation, blocking and waiting for the result
            respData = invokeSynchronous(reqId, reqExec, reqData);
            return respData;
        }
        synchronized (cont) {
            if (cont.isNew()) {
                // new request, start asynchronous invocation, non blocking
                invokeAsync(reqId, cont, reqExec, reqData);
            } else {
                final Callback cb = (Callback) cont.getObject();
                if (cont.isResumed() && cb.isFinished()) {
                    // asynchronous execution finished, callback received
                    respData = cb.getPayload();
                    removeContinuation(reqId);
                } else {
                    // Callback not received yet, request timed out. Check
                    // timeout settings if this happens very often.
                    removeContinuation(reqId);
                    final StringBuilder sb = new StringBuilder("Timeout reached after ");
                    sb.append(this.suspensionTimeout);
                    sb.append("ms for ");
                    sb.append(reqId);
                    sb.append(" [");
                    sb.append(reqExec);
                    sb.append(']');
                    final String msg = sb.toString();
                    getLogger().info(msg);
                    throw new InterruptedIOException(msg);
                }
            }
            return respData;
        }
    } finally {
        getLogger().trace("<-- handleRequest({}, {}, {}); respData = {}", reqId, reqExec, reqData, respData);
    }
}

From source file:org.apache.cxf.transport.http.asyncclient.SharedOutputBuffer.java

private void flushContent() throws IOException {
    this.lock.lock();
    try {/*w  w  w . j  a v a2 s.c om*/
        try {
            while ((largeWrapper != null && largeWrapper.hasRemaining()) || super.hasData()) {
                if (this.shutdown) {
                    throw new InterruptedIOException("Output operation aborted");
                }
                if (this.ioctrl != null) {
                    this.ioctrl.requestOutput();
                }
                this.condition.await();
            }
        } catch (InterruptedException ex) {
            throw new IOException("Interrupted while flushing the content buffer");
        }
    } finally {
        this.lock.unlock();
    }
}

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

/**
 * Triggers a bulk assignment of the specified regions
 *
 * @param assignmentManager the Assignment Manger
 * @param regionInfos the list of regions to assign
 * @throws IOException if an error occurred during the assignment
 *//*from  w  w w . ja  v a 2  s  .  co  m*/
public static void assignRegions(final AssignmentManager assignmentManager, final List<HRegionInfo> regionInfos)
        throws IOException {
    try {
        assignmentManager.getRegionStates().createRegionStates(regionInfos);
        assignmentManager.assign(regionInfos);
    } catch (InterruptedException e) {
        LOG.error("Caught " + e + " during round-robin assignment");
        InterruptedIOException ie = new InterruptedIOException(e.getMessage());
        ie.initCause(e);
        throw ie;
    }
}

From source file:com.epam.reportportal.apache.http.impl.execchain.MinimalClientExec.java

public CloseableHttpResponse execute(final HttpRoute route, final HttpRequestWrapper request,
        final HttpClientContext context, final HttpExecutionAware execAware) throws IOException, HttpException {
    Args.notNull(route, "HTTP route");
    Args.notNull(request, "HTTP request");
    Args.notNull(context, "HTTP context");

    rewriteRequestURI(request, route);/*from   w  w  w . j a v  a2  s. c  om*/

    final ConnectionRequest connRequest = connManager.requestConnection(route, null);
    if (execAware != null) {
        if (execAware.isAborted()) {
            connRequest.cancel();
            throw new RequestAbortedException("Request aborted");
        } else {
            execAware.setCancellable(connRequest);
        }
    }

    final RequestConfig config = context.getRequestConfig();

    final HttpClientConnection managedConn;
    try {
        final int timeout = config.getConnectionRequestTimeout();
        managedConn = connRequest.get(timeout > 0 ? timeout : 0, TimeUnit.MILLISECONDS);
    } catch (final InterruptedException interrupted) {
        Thread.currentThread().interrupt();
        throw new RequestAbortedException("Request aborted", interrupted);
    } catch (final ExecutionException ex) {
        Throwable cause = ex.getCause();
        if (cause == null) {
            cause = ex;
        }
        throw new RequestAbortedException("Request execution failed", cause);
    }

    final ConnectionHolder releaseTrigger = new ConnectionHolder(log, connManager, managedConn);
    try {
        if (execAware != null) {
            if (execAware.isAborted()) {
                releaseTrigger.close();
                throw new RequestAbortedException("Request aborted");
            } else {
                execAware.setCancellable(releaseTrigger);
            }
        }

        if (!managedConn.isOpen()) {
            final int timeout = config.getConnectTimeout();
            this.connManager.connect(managedConn, route, timeout > 0 ? timeout : 0, context);
            this.connManager.routeComplete(managedConn, route, context);
        }
        final int timeout = config.getSocketTimeout();
        if (timeout >= 0) {
            managedConn.setSocketTimeout(timeout);
        }

        HttpHost target = null;
        final HttpRequest original = request.getOriginal();
        if (original instanceof HttpUriRequest) {
            final URI uri = ((HttpUriRequest) original).getURI();
            if (uri.isAbsolute()) {
                target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
            }
        }
        if (target == null) {
            target = route.getTargetHost();
        }

        context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, target);
        context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
        context.setAttribute(HttpCoreContext.HTTP_CONNECTION, managedConn);
        context.setAttribute(HttpClientContext.HTTP_ROUTE, route);

        httpProcessor.process(request, context);
        final HttpResponse response = requestExecutor.execute(request, managedConn, context);
        httpProcessor.process(response, context);

        // The connection is in or can be brought to a re-usable state.
        if (reuseStrategy.keepAlive(response, context)) {
            // Set the idle duration of this connection
            final long duration = keepAliveStrategy.getKeepAliveDuration(response, context);
            releaseTrigger.setValidFor(duration, TimeUnit.MILLISECONDS);
            releaseTrigger.markReusable();
        } else {
            releaseTrigger.markNonReusable();
        }

        // check for entity, release connection if possible
        final HttpEntity entity = response.getEntity();
        if (entity == null || !entity.isStreaming()) {
            // connection not needed and (assumed to be) in re-usable state
            releaseTrigger.releaseConnection();
            return Proxies.enhanceResponse(response, null);
        } else {
            return Proxies.enhanceResponse(response, releaseTrigger);
        }
    } catch (final ConnectionShutdownException ex) {
        final InterruptedIOException ioex = new InterruptedIOException("Connection has been shut down");
        ioex.initCause(ex);
        throw ioex;
    } catch (final HttpException ex) {
        releaseTrigger.abortConnection();
        throw ex;
    } catch (final IOException ex) {
        releaseTrigger.abortConnection();
        throw ex;
    } catch (final RuntimeException ex) {
        releaseTrigger.abortConnection();
        throw ex;
    }
}

From source file:com.reactive.hzdfs.dll.AbstractFileSharingService.java

@Override
public Future<FileShareResponse> distribute(File f) throws IOException {
    try {//  w  w  w  . ja v a  2 s . com
        if (tryLock(lockAwaitSecs, TimeUnit.SECONDS)) {
            if (!initSendFileRequest())
                throw new IOException(
                        "Unable to initiate a cluster wide send file request in " + lockAwaitSecs + " secs");

            Future<FileShareResponse> response = waitForFileReceiptAckAsync();

            try (FileChunkHandler reader = newReadHandler(f)) {
                FileChunk fc = null;
                while ((fc = reader.readNext()) != null) {
                    sender.sendMessage(fc);
                }
            }

            return response;
        } else {
            throw new IOException(
                    "Operation not allowed at this time. Probably some other sharing is running.");
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new InterruptedIOException("Interrupted while trying to acquire cluster lock.");
    } finally {
        unlock();
    }

}

From source file:org.apache.hadoop.registry.server.services.RegistryAdminService.java

/**
 * Create the home path for a user if it does not exist.
 *
 * This uses {@link #initUserRegistryAsync(String)} and then waits for the
 * result ... the code path is the same as the async operation; this just
 * picks up and relays/converts exceptions
 * @param username username// w ww .  j  av a  2s  . co  m
 * @return the path created
 * @throws IOException any failure
 *
 */
public String initUserRegistry(final String username) throws IOException {

    try {
        Future<Boolean> future = initUserRegistryAsync(username);
        future.get();
    } catch (InterruptedException e) {
        throw (InterruptedIOException) (new InterruptedIOException(e.toString()).initCause(e));
    } catch (ExecutionException e) {
        Throwable cause = e.getCause();
        if (cause instanceof IOException) {
            throw (IOException) (cause);
        } else {
            throw new IOException(cause.toString(), cause);
        }
    }

    return homeDir(username);
}

From source file:org.apache.synapse.transport.nhttp.NhttpSharedOutputBuffer.java

/**
 * Flushes the content in the buffer if any.
 *
 * @throws IOException Thrown if the thread was interrupted while flushing
 *///w w  w.  j  a va2 s . co  m
private void flushContent() throws IOException {
    this.lock.lock();
    try {
        try {
            // hasData sets the buffer to read mode and calls hasRemaining method and returns the result.
            // if position (= initially 0, incremented as data is read) < limit(= how much bytes have been written
            // to the buffer) -> true i.e. there is data to be read
            while (super.hasData()) {
                if (this.shutdown) {
                    throw new InterruptedIOException("Output operation aborted");
                }
                // Request event notifications to be triggered when the underlying
                // channel is ready for output operations.
                if (this.ioctrl != null) {
                    this.ioctrl.requestOutput();
                }
                // Ask the thread which is reading this buffer to wait for a notification to
                // write data out
                awaitInterrupted = this.condition.await(timeout, TimeUnit.MILLISECONDS);
                // If socket timeout happens before the thread is notified, then we don't care whether there is
                // data or not, but honor the socket timeout config and break the loop
                if (!awaitInterrupted) {
                    break;
                }
            }
        } catch (final InterruptedException ex) {
            throw new IOException("Interrupted while flushing the content buffer");
        }
    } finally {
        this.lock.unlock();
    }
}

From source file:org.apache.hadoop.hbase.client.SimpleRequestController.java

@Override
public void waitForMaximumCurrentTasks(long max, long id, int periodToTrigger, Consumer<Long> trigger)
        throws InterruptedIOException {
    assert max >= 0;
    long lastLog = EnvironmentEdgeManager.currentTime();
    long currentInProgress, oldInProgress = Long.MAX_VALUE;
    while ((currentInProgress = tasksInProgress.get()) > max) {
        if (oldInProgress != currentInProgress) { // Wait for in progress to change.
            long now = EnvironmentEdgeManager.currentTime();
            if (now > lastLog + periodToTrigger) {
                lastLog = now;//from   ww  w  .  j  ava2  s.co  m
                if (trigger != null) {
                    trigger.accept(currentInProgress);
                }
                logDetailsOfUndoneTasks(currentInProgress);
            }
        }
        oldInProgress = currentInProgress;
        try {
            synchronized (tasksInProgress) {
                if (tasksInProgress.get() == oldInProgress) {
                    tasksInProgress.wait(10);
                }
            }
        } catch (InterruptedException e) {
            throw new InterruptedIOException(
                    "#" + id + ", interrupted." + " currentNumberOfTask=" + currentInProgress);
        }
    }
}

From source file:org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKStore.java

@Override
public synchronized ApplicationStore createApplicationStore(ApplicationId application,
        ApplicationSubmissionContext context) throws IOException {
    if (!doneWithRecovery)
        return new ZKApplicationStore(application);

    ApplicationSubmissionContextPBImpl contextPBImpl = (ApplicationSubmissionContextPBImpl) context;
    String appString = APPS + ConverterUtils.toString(application);

    ApplicationMasterPBImpl masterPBImpl = new ApplicationMasterPBImpl();
    ContainerPBImpl container = new ContainerPBImpl();
    try {/*from   w  w  w  . j  a  va 2  s  . c  om*/
        zkClient.create(appString, contextPBImpl.getProto().toByteArray(), null, CreateMode.PERSISTENT);
        zkClient.create(appString + ZK_PATH_SEPARATOR + APP_MASTER, masterPBImpl.getProto().toByteArray(), null,
                CreateMode.PERSISTENT);
        zkClient.create(appString + ZK_PATH_SEPARATOR + APP_MASTER_CONTAINER,
                container.getProto().toByteArray(), null, CreateMode.PERSISTENT);
    } catch (InterruptedException ie) {
        LOG.info("Interrupted", ie);
        throw new InterruptedIOException(ie.getMessage());
    } catch (KeeperException ke) {
        LOG.info("Keeper exception", ke);
        throw convertToIOException(ke);
    }
    return new ZKApplicationStore(application);
}

From source file:org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKStore.java

@Override
public synchronized void removeApplication(ApplicationId application) throws IOException {
    if (!doneWithRecovery)
        return;// w  ww. j  a va  2  s. c  o m

    try {
        zkClient.delete(APPS + ConverterUtils.toString(application), -1);
    } catch (InterruptedException ie) {
        LOG.info("Interrupted", ie);
        throw new InterruptedIOException(ie.getMessage());
    } catch (KeeperException ke) {
        LOG.info("Keeper Exception", ke);
        throw convertToIOException(ke);
    }
}