Example usage for java.net SocketException getCause

List of usage examples for java.net SocketException getCause

Introduction

In this page you can find the example usage for java.net SocketException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:com.googlecode.jcimd.TcpNetConnection.java

@Override
public void run() {
    logger.debug("Ready for replies...");
    Packet reply;/*  www  .ja v a  2  s.c  o  m*/
    while (true) {
        try {
            reply = this.serializer.deserialize(this.socket.getInputStream());
        } catch (SocketException e) {
            break;
        } catch (Exception e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Read exception " + e.getClass().getName() + ": " + e.getCause() + ": "
                        + e.getMessage());
            }
            // since it's a socket exception, let's close without sending a logout operation
            closeSocket();
            break; // get out of this while-loop
        }
        AsyncReply asyncReply = pendingReplies.get("");
        asyncReply.setReply(reply);
    }
}

From source file:dk.netarkivet.common.distribute.IntegrityTestsFTP.java

public void setUp() {
    rs.setUp();// ww w .j ava2s  . co  m
    if (!TestInfo.TEMPDIR.exists()) {
        dk.netarkivet.common.utils.TestInfo.TEMPDIR.mkdir();
    }

    FileUtils.removeRecursively(TestInfo.TEMPDIR);
    TestFileUtils.copyDirectoryNonCVS(TestInfo.DATADIR, TestInfo.TEMPDIR);

    /* make 3 duplicates of TestInfo.TESTXML: test1.xml, test2.xml, test3.xml */
    testFile1 = new File(TestInfo.TEMPDIR, "test1.xml");
    testFile2 = new File(TestInfo.TEMPDIR, "test2.xml");
    testFile3 = new File(TestInfo.TEMPDIR, "test3.xml");
    assertTrue("The test xml file must exist", TestInfo.TESTXML.exists());
    FileUtils.copyFile(TestInfo.TESTXML, testFile1);
    FileUtils.copyFile(TestInfo.TESTXML, testFile2);
    FileUtils.copyFile(TestInfo.TESTXML, testFile3);

    /* Read ftp-related settings from settings.xml. */
    final String ftpServerName = Settings.get(CommonSettings.FTP_SERVER_NAME);
    final int ftpServerPort = Integer.parseInt(Settings.get(CommonSettings.FTP_SERVER_PORT));
    final String ftpUserName = Settings.get(CommonSettings.FTP_USER_NAME);
    final String ftpUserPassword = Settings.get(CommonSettings.FTP_USER_PASSWORD);

    /* Connect to test ftp-server. */
    theFTPClient = new FTPClient();

    try {
        theFTPClient.connect(ftpServerName, ftpServerPort);
        assertTrue(
                "Could not login to ' + " + ftpServerName + ":" + ftpServerPort + "' with username,password="
                        + ftpUserName + "," + ftpUserPassword,
                theFTPClient.login(ftpUserName, ftpUserPassword));
        assertTrue("Must be possible to set the file type to binary after login",
                theFTPClient.setFileType(FTPClient.BINARY_FILE_TYPE));
    } catch (SocketException e) {
        throw new IOFailure("Connect to " + ftpServerName + ":" + ftpServerPort + " failed", e.getCause());
    } catch (IOException e) {
        throw new IOFailure("Connect to " + ftpServerName + ":" + ftpServerPort + " failed", e.getCause());
    }

    /** Do not send notification by email. Print them to STDOUT. */
    Settings.set(CommonSettings.NOTIFICATIONS_CLASS, RememberNotifications.class.getName());
}

From source file:org.apache.hadoop.raid.RaidShell.java

/**
 * //from   w  ww .  java 2s.c o m
 * @param dfs
 * @param filePath
 * @param cntMissingBlksPerStrp
 * @param numNonRaidedMissingBlks
 * @param numStrpMissingBlksMap
 * @return
 * @throws java.io.IOException
 */
public static boolean isFileCorrupt(final DistributedFileSystem dfs, final FileStatus fileStat,
        final boolean cntMissingBlksPerStrp, final Configuration conf, AtomicLong numNonRaidedMissingBlks,
        Map<String, AtomicLongArray> numStrpMissingBlksMap) throws IOException {
    if (fileStat == null) {
        return false;
    }
    Path filePath = fileStat.getPath();
    try {
        // corruptBlocksPerStripe: 
        // map stripe # -> # of corrupt blocks in that stripe (data + parity)
        HashMap<Integer, Integer> corruptBlocksPerStripe = new LinkedHashMap<Integer, Integer>();
        boolean fileCorrupt = false;
        // Har checking requires one more RPC to namenode per file
        // skip it for performance. 
        RaidInfo raidInfo = RaidUtils.getFileRaidInfo(fileStat, conf, true);
        if (raidInfo.codec == null) {
            raidInfo = RaidUtils.getFileRaidInfo(fileStat, conf, false);
        }
        if (raidInfo.codec == null) {
            // Couldn't find out the parity file, so the file is corrupt
            int count = collectNumCorruptBlocksInFile(dfs, filePath);
            if (cntMissingBlksPerStrp && numNonRaidedMissingBlks != null) {
                numNonRaidedMissingBlks.addAndGet(count);
            }
            return true;
        }

        if (raidInfo.codec.isDirRaid) {
            RaidUtils.collectDirectoryCorruptBlocksInStripe(conf, dfs, raidInfo, fileStat,
                    corruptBlocksPerStripe);
        } else {
            RaidUtils.collectFileCorruptBlocksInStripe(dfs, raidInfo, fileStat, corruptBlocksPerStripe);
        }

        final int maxCorruptBlocksPerStripe = raidInfo.parityBlocksPerStripe;

        for (Integer corruptBlocksInStripe : corruptBlocksPerStripe.values()) {
            if (corruptBlocksInStripe == null) {
                continue;
            }
            //detect if the file has any stripes which cannot be fixed by Raid
            if (LOG.isDebugEnabled()) {
                LOG.debug("file " + filePath.toString() + " has corrupt blocks per Stripe value "
                        + corruptBlocksInStripe);
            }
            if (!fileCorrupt) {
                if (corruptBlocksInStripe > maxCorruptBlocksPerStripe) {
                    fileCorrupt = true;
                }
            }
            if (cntMissingBlksPerStrp && numStrpMissingBlksMap != null) {
                numStrpMissingBlksMap.get(raidInfo.codec.id).incrementAndGet(corruptBlocksInStripe - 1);
            }
        }
        return fileCorrupt;
    } catch (SocketException e) {
        // Re-throw network-related exceptions.
        throw e;
    } catch (SocketTimeoutException e) {
        throw e;
    } catch (IOException e) {
        // re-throw local exceptions.
        if (e.getCause() != null && !(e.getCause() instanceof RemoteException)) {
            throw e;
        }

        LOG.error("While trying to check isFileCorrupt " + filePath + " got exception ", e);
        return true;
    }
}