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() 

Source Link

Document

Constructs an InterruptedIOException with null as its error detail message.

Usage

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

@Override
public boolean isTableOnlineState(TableName tableName, boolean enabled) throws IOException {
    ZooKeeperKeepAliveConnection zkw = hci.getKeepAliveZooKeeperWatcher();
    try {/*  ww w.j  a v a  2 s .co  m*/
        if (enabled) {
            return ZKTableStateClientSideReader.isEnabledTable(zkw, tableName);
        }
        return ZKTableStateClientSideReader.isDisabledTable(zkw, tableName);
    } catch (KeeperException e) {
        throw new IOException("Enable/Disable failed", e);
    } catch (InterruptedException e) {
        throw new InterruptedIOException();
    } finally {
        zkw.close();
    }
}

From source file:org.apache.hadoop.hbase.master.TableNamespaceManager.java

public void start() throws IOException {
    if (!MetaReader.tableExists(masterServices.getCatalogTracker(), TableName.NAMESPACE_TABLE_NAME)) {
        LOG.info("Namespace table not found. Creating...");
        createNamespaceTable(masterServices);
    }//from   w w w. ja v  a2  s.  c  o  m

    try {
        // Wait for the namespace table to be assigned.
        // If timed out, we will move ahead without initializing it.
        // So that it should be initialized later on lazily.
        long startTime = EnvironmentEdgeManager.currentTimeMillis();
        int timeout = conf.getInt(NS_INIT_TIMEOUT, DEFAULT_NS_INIT_TIMEOUT);
        while (!isTableAssigned()) {
            if (EnvironmentEdgeManager.currentTimeMillis() - startTime + 100 > timeout) {
                LOG.warn("Timedout waiting for namespace table to be assigned.");
                return;
            }
            Thread.sleep(100);
        }
    } catch (InterruptedException e) {
        throw (InterruptedIOException) new InterruptedIOException().initCause(e);
    }

    // initialize namespace table
    isTableAvailableAndInitialized();
}

From source file:com.asakusafw.runtime.stage.temporary.TemporaryFileOutputHelper.java

@Override
public synchronized void close() throws IOException {
    try {//  w w w  .  ja  va2  s. c o m
        try {
            flushBuffer();
        } catch (InterruptedException e) {
            throw (IOException) new InterruptedIOException().initCause(e);
        }
    } finally {
        executor.shutdownNow();
        output.close();
    }
}

From source file:org.apache.hadoop.yarn.client.api.impl.TimelineWriter.java

private ClientResponse doPosting(final Object obj, final String path) throws IOException, YarnException {
    ClientResponse resp;/*from  w  ww .  j a  v  a2 s.c om*/
    try {
        resp = authUgi.doAs(new PrivilegedExceptionAction<ClientResponse>() {
            @Override
            public ClientResponse run() throws Exception {
                return doPostingObject(obj, path);
            }
        });
    } catch (UndeclaredThrowableException e) {
        Throwable cause = e.getCause();
        if (cause instanceof IOException) {
            throw (IOException) cause;
        } else {
            throw new IOException(cause);
        }
    } catch (InterruptedException ie) {
        throw (IOException) new InterruptedIOException().initCause(ie);
    }
    if (resp == null || resp.getClientResponseStatus() != ClientResponse.Status.OK) {
        String msg = "Failed to get the response from the timeline server.";
        LOG.error(msg);
        if (resp != null) {
            msg += " HTTP error code: " + resp.getStatus();
            if (LOG.isDebugEnabled()) {
                String output = resp.getEntity(String.class);
                LOG.debug("HTTP error code: " + resp.getStatus() + " Server response : \n" + output);
            }
        }
        throw new YarnException(msg);
    }
    return resp;
}

From source file:org.apache.hadoop.hbase.zookeeper.lock.TestHReadWriteLockImpl.java

@Test(timeout = 30000)
public void testWriteLockExcludesWriters() throws Exception {
    final String testName = "testWriteLockExcludesWriters";
    final HReadWriteLockImpl readWriteLock = getReadWriteLock(testName);
    List<Future<Void>> results = Lists.newArrayList();
    for (int i = 0; i < NUM_THREADS; ++i) {
        final String threadDesc = testName + i;
        results.add(executor.submit(new Callable<Void>() {
            @Override/*from w  w w.ja v a  2  s.  c om*/
            public Void call() throws IOException {
                HWriteLockImpl writeLock = readWriteLock.writeLock(Bytes.toBytes(threadDesc));
                try {
                    writeLock.acquire();
                    try {
                        // No one else should hold the lock
                        assertTrue(isLockHeld.compareAndSet(false, true));
                        Thread.sleep(1000);
                        // No one else should have released the lock
                        assertTrue(isLockHeld.compareAndSet(true, false));
                    } finally {
                        isLockHeld.set(false);
                        writeLock.release();
                    }
                } catch (InterruptedException e) {
                    LOG.warn(threadDesc + " interrupted", e);
                    Thread.currentThread().interrupt();
                    throw new InterruptedIOException();
                }
                return null;
            }
        }));

    }
    MultiThreadedTestUtils.assertOnFutures(results);
}

From source file:org.apache.hadoop.hbase.master.procedure.ProcedureSyncWait.java

protected static void waitMetaRegions(final MasterProcedureEnv env) throws IOException {
    int timeout = env.getMasterConfiguration().getInt("hbase.client.catalog.timeout", 10000);
    try {//from  w ww  .j a v  a2  s .  c o  m
        if (env.getMasterServices().getMetaTableLocator()
                .waitMetaRegionLocation(env.getMasterServices().getZooKeeper(), timeout) == null) {
            throw new NotAllMetaRegionsOnlineException();
        }
    } catch (InterruptedException e) {
        throw (InterruptedIOException) new InterruptedIOException().initCause(e);
    }
}

From source file:org.apache.hadoop.hbase.zookeeper.lock.TestZKInterProcessReadWriteLock.java

@Test(timeout = 30000)
public void testWriteLockExcludesWriters() throws Exception {
    final String testName = "testWriteLockExcludesWriters";
    final ZKInterProcessReadWriteLock readWriteLock = getReadWriteLock(testName);
    List<Future<Void>> results = Lists.newArrayList();
    for (int i = 0; i < NUM_THREADS; ++i) {
        final String threadDesc = testName + i;
        results.add(executor.submit(new Callable<Void>() {
            @Override//from   w  w w  . j  a v  a  2 s. c  o  m
            public Void call() throws IOException {
                ZKInterProcessWriteLock writeLock = readWriteLock.writeLock(Bytes.toBytes(threadDesc));
                try {
                    writeLock.acquire();
                    try {
                        // No one else should hold the lock
                        assertTrue(isLockHeld.compareAndSet(false, true));
                        Thread.sleep(1000);
                        // No one else should have released the lock
                        assertTrue(isLockHeld.compareAndSet(true, false));
                    } finally {
                        isLockHeld.set(false);
                        writeLock.release();
                    }
                } catch (InterruptedException e) {
                    LOG.warn(threadDesc + " interrupted", e);
                    Thread.currentThread().interrupt();
                    throw new InterruptedIOException();
                }
                return null;
            }
        }));

    }
    MultithreadedTestUtil.assertOnFutures(results);
}

From source file:com.splout.db.dnode.Fetcher.java

private File hdfsFetch(Path fromPath, Reporter reporter) throws IOException, InterruptedException {
    UUID uniqueId = UUID.randomUUID();
    File toFile = new File(tempDir, uniqueId.toString() + "/" + fromPath.getName());
    File toDir = new File(toFile.getParent());
    if (toDir.exists()) {
        FileUtils.deleteDirectory(toDir);
    }/*from ww w  .java 2s  .  c o  m*/
    toDir.mkdirs();
    Path toPath = new Path(toFile.getCanonicalPath());

    FileSystem fS = fromPath.getFileSystem(hadoopConf);
    FileSystem tofS = FileSystem.getLocal(hadoopConf);

    Throttler throttler = new Throttler((double) bytesPerSecThrottle);
    try {
        for (FileStatus fStatus : fS.globStatus(fromPath)) {
            log.info("Copying " + fStatus.getPath() + " to " + toPath);
            long bytesSoFar = 0;

            FSDataInputStream iS = fS.open(fStatus.getPath());
            FSDataOutputStream oS = tofS.create(toPath);

            byte[] buffer = new byte[downloadBufferSize];

            int nRead;
            while ((nRead = iS.read(buffer, 0, buffer.length)) != -1) {
                // Needed to being able to be interrupted at any moment.
                if (Thread.interrupted()) {
                    iS.close();
                    oS.close();
                    cleanDirNoExceptions(toDir);
                    throw new InterruptedException();
                }
                bytesSoFar += nRead;
                oS.write(buffer, 0, nRead);
                throttler.incrementAndThrottle(nRead);
                if (bytesSoFar >= bytesToReportProgress) {
                    reporter.progress(bytesSoFar);
                    bytesSoFar = 0l;
                }
            }

            if (reporter != null) {
                reporter.progress(bytesSoFar);
            }

            oS.close();
            iS.close();
        }

        return toDir;
    } catch (ClosedByInterruptException e) {
        // This can be thrown by the method read.
        cleanDirNoExceptions(toDir);
        throw new InterruptedIOException();
    }
}

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

/**
 * Start the cluster.  Waits until there is a primary master initialized
 * and returns its address.// w w w .j a v  a  2s . c  o  m
 * @param masters
 * @param regionservers
 * @return Address to use contacting primary master.
 */
public static String startup(final List<JVMClusterUtil.MasterThread> masters,
        final List<JVMClusterUtil.RegionServerThread> regionservers) throws IOException {

    if (masters == null || masters.isEmpty()) {
        return null;
    }

    for (JVMClusterUtil.MasterThread t : masters) {
        t.start();
    }

    // Wait for an active master
    //  having an active master before starting the region threads allows
    //  then to succeed on their connection to master
    long startTime = System.currentTimeMillis();
    while (findActiveMaster(masters) == null) {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            throw (InterruptedIOException) new InterruptedIOException().initCause(e);
        }
        if (System.currentTimeMillis() > startTime + 30000) {
            throw new RuntimeException("Master not active after 30 seconds");
        }
    }

    if (regionservers != null) {
        for (JVMClusterUtil.RegionServerThread t : regionservers) {
            t.start();
        }
    }

    // Wait for an active master to be initialized (implies being master)
    //  with this, when we return the cluster is complete
    startTime = System.currentTimeMillis();
    final int maxwait = 200000;
    while (true) {
        JVMClusterUtil.MasterThread t = findActiveMaster(masters);
        if (t != null && t.master.isInitialized()) {
            return t.master.getServerName().toString();
        }
        // REMOVE
        if (System.currentTimeMillis() > startTime + 10000) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw (InterruptedIOException) new InterruptedIOException().initCause(e);
            }
        }
        if (System.currentTimeMillis() > startTime + maxwait) {
            String msg = "Master not initialized after " + maxwait + "ms seconds";
            ReflectionUtils.printThreadInfo(new PrintWriter(System.out), "Thread dump because: " + msg);
            throw new RuntimeException(msg);
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            throw (InterruptedIOException) new InterruptedIOException().initCause(e);
        }
    }
}

From source file:org.apache.http.impl.client.AutoRetryHttpClient.java

public HttpResponse execute(final HttpHost target, final HttpRequest request, final HttpContext context)
        throws IOException {
    for (int c = 1;; c++) {
        final HttpResponse response = backend.execute(target, request, context);
        try {/*  ww  w.ja  v  a  2 s  .  c  o  m*/
            if (retryStrategy.retryRequest(response, c, context)) {
                EntityUtils.consume(response.getEntity());
                final long nextInterval = retryStrategy.getRetryInterval();
                try {
                    log.trace("Wait for " + nextInterval);
                    Thread.sleep(nextInterval);
                } catch (final InterruptedException e) {
                    Thread.currentThread().interrupt();
                    throw new InterruptedIOException();
                }
            } else {
                return response;
            }
        } catch (final RuntimeException ex) {
            try {
                EntityUtils.consume(response.getEntity());
            } catch (final IOException ioex) {
                log.warn("I/O error consuming response content", ioex);
            }
            throw ex;
        }
    }
}