Example usage for java.lang IllegalThreadStateException toString

List of usage examples for java.lang IllegalThreadStateException toString

Introduction

In this page you can find the example usage for java.lang IllegalThreadStateException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.emc.vipr.sync.source.FilesystemSource.java

protected void delete(File file) {
    // Try to lock the file first.  If this fails, the file is
    // probably open for write somewhere.
    // Note that on a mac, you can apparently delete files that
    // someone else has open for writing, and can lock files
    // too./*from  ww w .j a va2 s . c  o  m*/
    // Must make sure to throw exceptions when necessary to flag actual failures as opposed to skipped files.
    if (file.isDirectory()) {
        File metaDir = getMetaFile(file).getParentFile();
        if (metaDir.exists())
            metaDir.delete();
        // Just try and delete dir
        if (!file.delete()) {
            LogMF.warn(l4j, "Failed to delete directory {0}", file);
        }
    } else {
        boolean tryDelete = true;
        if (deleteOlderThan > 0) {
            if (System.currentTimeMillis() - file.lastModified() < deleteOlderThan) {
                LogMF.info(l4j, "not deleting {0}; it is not at least {1} ms old", file, deleteOlderThan);
                tryDelete = false;
            }
        }
        if (deleteCheckScript != null) {
            String[] args = new String[] { deleteCheckScript.getAbsolutePath(), file.getAbsolutePath() };
            try {
                l4j.debug("delete check: " + Arrays.asList(args));
                Process p = Runtime.getRuntime().exec(args);
                while (true) {
                    try {
                        int exitCode = p.exitValue();

                        if (exitCode == 0) {
                            LogMF.debug(l4j, "delete check OK, exit code {0}", exitCode);
                        } else {
                            LogMF.info(l4j, "delete check failed, exit code {0}.  Not deleting file.",
                                    exitCode);
                            tryDelete = false;
                        }
                        break;
                    } catch (IllegalThreadStateException e) {
                        // Ignore.
                    }
                }
            } catch (IOException e) {
                LogMF.info(l4j, "error executing delete check script: {0}.  Not deleting file.", e.toString());
                tryDelete = false;
            }
        }
        RandomAccessFile raf = null;
        if (tryDelete) {
            try {
                raf = new RandomAccessFile(file, "rw");
                FileChannel fc = raf.getChannel();
                FileLock flock = fc.lock();
                // If we got here, we should be good.
                flock.release();
                if (!file.delete()) {
                    throw new RuntimeException(MessageFormat.format("Failed to delete {0}", file));
                }
            } catch (IOException e) {
                throw new RuntimeException(MessageFormat
                        .format("File {0} not deleted, it appears to be open: {1}", file, e.getMessage()));
            } finally {
                if (raf != null) {
                    try {
                        raf.close();
                    } catch (IOException e) {
                        // Ignore.
                    }
                }
            }
        }
    }
}

From source file:org.smartfrog.avalanche.client.sf.exec.simple.StartComponent.java

public void stopApplication() throws IOException, InterruptedException {
    readOutput();/*from w  ww.j av a  2 s  .  c  o m*/
    try {
        proc.destroy();
        proc.waitFor();
        log.debug("Destroyed Process " + command + " forcibly");

        stdInput.close();
        stdError.close();
        log.info(componentName + " : Process exited with return value " + proc.exitValue());
    } catch (IOException ioe) {
        log.error("Unable to close InputStream and ErrorStream for " + command, ioe);
        throw new IOException(ioe.toString());
    } catch (IllegalThreadStateException ite) {
        log.error("Unable to kill the process " + command, ite);
        throw new IllegalStateException(ite.toString());
    } catch (InterruptedException ie) {
        log.error("Interrupted. Waiting for process " + command + " to die", ie);
        throw new InterruptedException(ie.toString());
    }
}