Example usage for java.util.concurrent RejectedExecutionException getLocalizedMessage

List of usage examples for java.util.concurrent RejectedExecutionException getLocalizedMessage

Introduction

In this page you can find the example usage for java.util.concurrent RejectedExecutionException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:it.geosolutions.tools.io.file.Copy.java

/**
 * Copy a list of files asynchronously to a destination (which can be on
 * nfs) each thread wait (at least) 'seconds' seconds for each file
 * propagation.// ww w  .  j  a v  a2s  .  c  o  m
 * 
 * @param ex
 *            the thread pool executor
 * @param baseDestDir
 * @param overwrite
 *            if false and destination exists() do not overwrite the file
 * @param seconds
 * @return the resulting moved file list or null
 * @note this function could not use overwrite boolean flag to avoid file
 *       lock on the same section when 2 thread are called to write the same
 *       file name
 */
public static List<FutureTask<File>> asynchCopyListFileToNFS(final ExecutorService ex, final List<File> list,
        final File baseDestDir, final int seconds) {
    // list
    if (list == null) {
        if (LOGGER.isErrorEnabled())
            LOGGER.error("Failed to copy file list using a NULL list");
        return null;
    }
    final int size = list.size();
    if (size == 0) {
        if (LOGGER.isErrorEnabled())
            LOGGER.error("Failed to copy file list using an empty list");
        return null;
    }
    // baseDestDir
    if (baseDestDir == null) {
        if (LOGGER.isErrorEnabled())
            LOGGER.error("Failed to copy file list using a NULL baseDestDir");
        return null;
    } else if (!baseDestDir.isDirectory() || !baseDestDir.canWrite()) {
        if (LOGGER.isErrorEnabled())
            LOGGER.error("Failed to copy file list using a not " + "writeable directory as baseDestDir: "
                    + baseDestDir.getAbsolutePath());
        return null;
    }
    // Asynch executor check
    if (ex == null || ex.isTerminated()) {
        if (LOGGER.isErrorEnabled())
            LOGGER.error("Unable to run asynchronously using a terminated or null ThreadPoolExecutor");
        return null;
    }

    final List<FutureTask<File>> asyncRes = new ArrayList<FutureTask<File>>(size);
    for (File file : list) {
        if (file != null) {
            if (file.exists()) {
                try {
                    asyncRes.add(asynchFileCopyToNFS(ex, file, new File(baseDestDir, file.getName()), seconds));
                } catch (RejectedExecutionException e) {
                    if (LOGGER.isWarnEnabled())
                        LOGGER.warn("SKIPPING file:\n" + file.getAbsolutePath() + ".\nError: "
                                + e.getLocalizedMessage());
                } catch (IllegalArgumentException e) {
                    if (LOGGER.isWarnEnabled())
                        LOGGER.warn("SKIPPING file:\n" + file.getAbsolutePath() + ".\nError: "
                                + e.getLocalizedMessage());
                }

            } else {
                if (LOGGER.isWarnEnabled())
                    LOGGER.warn("SKIPPING file:\n" + file.getAbsolutePath()
                            + "\nUnable to copy a not existent file.");
            }
        }
    }

    return asyncRes;
}

From source file:it.geosolutions.geobatch.flow.file.FileBasedFlowManager.java

/**
 * Run the given consumer into the threadpool.
 * //  www . j  ava  2  s .  co  m
 * @param consumer The instance to be executed.
 * @throws Exception 
 * @throws IllegalStateException if the consumer is not in the EXECUTING state.
 * @throws IllegalArgumentException if the consumer is not in the {@link #eventConsumers} list of this FlowManager.
 */
Future<Queue<FileSystemEvent>> execute(FileBasedEventConsumer consumer) throws Exception {
    if (consumer.getStatus() != EventConsumerStatus.EXECUTING) {
        final String message = "Consumer " + consumer + " is not in an EXECUTING state.";
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error(message);
        }
        throw new IllegalStateException(message);
    }

    if (!eventConsumers.containsKey(consumer.getId())) {
        final String message = "Consumer " + consumer + " is not handled by the current flow manager.";
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error(message);
        }
        throw new IllegalArgumentException(message);
    }
    try {
        return this.executor.submit(consumer);
    } catch (RejectedExecutionException r) {

        /*
         * + "Will be rejected when the Executor has been shut down, and also " +
         * "when the Executor uses finite bounds for both maximum threads and " + "work queue capacity, and is saturated." +
         * " In either case, the execute method invokes the "
         */
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error("Unable to submit the consumer (id:" + consumer.getId() + ") to the flow manager (id:"
                    + this.getId() + ") queue.\nMessage is:" + r.getLocalizedMessage()
                    + "\nThread pool executor info:" + "\nMaximum allowed number of threads: "
                    + executor.getMaximumPoolSize() + "\nWorking Queue size: " + executor.getQueue().size()
                    + "\nWorking Queue remaining capacity: " + executor.getQueue().remainingCapacity()
                    + "\nCurrent number of threads: " + executor.getPoolSize()
                    + "\nApproximate number of threads that are actively executing : "
                    + executor.getActiveCount() + "\nCore number of threads: " + executor.getCorePoolSize()
                    + "\nKeepAliveTime [secs]: " + executor.getKeepAliveTime(TimeUnit.SECONDS), r);
        }

        // forwarding error to consumer's listentes
        for (IProgressListener listener : consumer.getListeners()) {
            listener.failed(r);
        }

        throw r;
    } catch (Exception t) {
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error("Unable to submit the consumer (id:" + consumer.getId() + ") to the flow manager (id:"
                    + this.getId() + ") queue.\nMessage is:" + t.getLocalizedMessage(), t);
        }
        throw t;
    }
}

From source file:dev.ukanth.ufirewall.Api.java

/**
 * Runs a script as root (multiple commands separated by "\n")
* @param ctx mandatory context//from w  w w.j  a  v a  2s .c o  m
 * @param script the script to be executed
 * @param res the script output response (stdout + stderr)
 * @return the script exit code
 * @throws IOException on any error executing the script, or writing it to disk
 */
public static int runScriptAsRoot(Context ctx, List<String> script, StringBuilder res) throws IOException {
    int returnCode = -1;

    if ((Looper.myLooper() != null) && (Looper.myLooper() == Looper.getMainLooper())) {
        Log.e(TAG, "runScriptAsRoot should not be called from the main thread\nCall Trace:\n");
        for (StackTraceElement e : new Throwable().getStackTrace()) {
            Log.e(TAG, e.toString());
        }
    }

    try {
        returnCode = new RunCommand().execute(script, res, ctx).get();
    } catch (RejectedExecutionException r) {
        Log.e(TAG, "runScript failed: " + r.getLocalizedMessage());
    } catch (InterruptedException e) {
        Log.e(TAG, "Caught InterruptedException");
    } catch (ExecutionException e) {
        Log.e(TAG, "runScript failed: " + e.getLocalizedMessage());
    } catch (Exception e) {
        Log.e(TAG, "runScript failed: " + e.getLocalizedMessage());
    }

    return returnCode;
}