Example usage for java.lang UnsupportedOperationException getLocalizedMessage

List of usage examples for java.lang UnsupportedOperationException getLocalizedMessage

Introduction

In this page you can find the example usage for java.lang UnsupportedOperationException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:it.geosolutions.geobatch.geotiff.overview.GeotiffOverviewsEmbedder.java

public Queue<FileSystemEvent> execute(Queue<FileSystemEvent> events) throws ActionException {

    try {/*  w w w.  j a  va2s. c o  m*/
        // looking for file
        if (events.size() == 0)
            throw new IllegalArgumentException(
                    "GeotiffOverviewsEmbedder::execute(): Wrong number of elements for this action: "
                            + events.size());

        listenerForwarder.setTask("config");
        listenerForwarder.started();

        // //
        //
        // data flow configuration and dataStore name must not be null.
        //
        // //
        if (configuration == null) {
            final String message = "GeotiffOverviewsEmbedder::execute(): DataFlowConfig is null.";
            if (LOGGER.isErrorEnabled())
                LOGGER.error(message);
            throw new IllegalStateException(message);
        }

        // //
        //
        // check the configuration and prepare the overviews embedder
        //
        // //
        final int downsampleStep = configuration.getDownsampleStep();
        if (downsampleStep <= 0)
            throw new IllegalArgumentException(
                    "GeotiffOverviewsEmbedder::execute(): Illegal downsampleStep: " + downsampleStep);

        int numberOfSteps = configuration.getNumSteps();
        if (numberOfSteps <= 0)
            throw new IllegalArgumentException("Illegal numberOfSteps: " + numberOfSteps);

        final OverviewsEmbedder oe = new OverviewsEmbedder();
        oe.setDownsampleStep(downsampleStep);
        oe.setNumSteps(configuration.getNumSteps());
        // SG: this way we are sure we use the standard tile cache
        oe.setTileCache(JAI.getDefaultInstance().getTileCache());

        String scaleAlgorithm = configuration.getScaleAlgorithm();
        if (scaleAlgorithm == null) {
            LOGGER.warn("No scaleAlgorithm defined. Using " + SubsampleAlgorithm.Nearest + " as default");
            scaleAlgorithm = SubsampleAlgorithm.Nearest.name();
        } else {
            final SubsampleAlgorithm algorithm = SubsampleAlgorithm.valueOf(scaleAlgorithm);
            if (algorithm == null) {
                throw new IllegalStateException("Bad scaleAlgorithm defined [" + scaleAlgorithm + "]");
            }
        }
        oe.setScaleAlgorithm(scaleAlgorithm);
        oe.setTileHeight(configuration.getTileH());
        oe.setTileWidth(configuration.getTileW());

        /*
         * TODO check this is formally wrong! this should be done into the
         * configuration.
         */
        // add logger/listener
        if (configuration.isLogNotification())
            oe.addProcessingEventListener(new ProcessingEventListener() {

                public void exceptionOccurred(ExceptionEvent event) {
                    if (LOGGER.isInfoEnabled())
                        LOGGER.info("GeotiffOverviewsEmbedder::execute(): " + event.getMessage(),
                                event.getException());
                }

                public void getNotification(ProcessingEvent event) {
                    if (LOGGER.isInfoEnabled())
                        LOGGER.info("GeotiffOverviewsEmbedder::execute(): " + event.getMessage());
                    listenerForwarder.progressing((float) event.getPercentage(), event.getMessage());
                }
            });

        // The return
        Queue<FileSystemEvent> ret = new LinkedList<FileSystemEvent>();

        while (events.size() > 0) {

            // run
            listenerForwarder.progressing(0, "Embedding overviews");

            final FileSystemEvent event = events.remove();

            final File eventFile = event.getSource();
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("Processing file " + eventFile);

            if (eventFile.exists() && eventFile.canRead() && eventFile.canWrite()) {
                /*
                 * If here: we can start retiler actions on the incoming
                 * file event
                 */

                if (eventFile.isDirectory()) {

                    final FileFilter filter = new RegexFileFilter(".+\\.[tT][iI][fF]([fF]?)");
                    final Collector collector = new Collector(filter);
                    final List<File> fileList = collector.collect(eventFile);
                    int size = fileList.size();
                    for (int progress = 0; progress < size; progress++) {

                        final File inFile = fileList.get(progress);

                        try {
                            oe.setSourcePath(inFile.getAbsolutePath());
                            oe.run();
                        } catch (UnsupportedOperationException uoe) {
                            listenerForwarder.failed(uoe);
                            if (LOGGER.isWarnEnabled())
                                LOGGER.warn("GeotiffOverviewsEmbedder::execute(): " + uoe.getLocalizedMessage(),
                                        uoe);
                        } catch (IllegalArgumentException iae) {
                            listenerForwarder.failed(iae);
                            if (LOGGER.isWarnEnabled())
                                LOGGER.warn("GeotiffOverviewsEmbedder::execute(): " + iae.getLocalizedMessage(),
                                        iae);
                        } finally {
                            listenerForwarder.setProgress((progress * 100) / ((size != 0) ? size : 1));
                            listenerForwarder.progressing();
                        }
                    }
                } else {
                    // file is not a directory
                    try {
                        oe.setSourcePath(eventFile.getAbsolutePath());
                        oe.run();
                    } catch (UnsupportedOperationException uoe) {
                        listenerForwarder.failed(uoe);
                        if (LOGGER.isWarnEnabled())
                            LOGGER.warn("GeotiffOverviewsEmbedder::execute(): " + uoe.getLocalizedMessage(),
                                    uoe);
                    } catch (IllegalArgumentException iae) {
                        listenerForwarder.failed(iae);
                        if (LOGGER.isWarnEnabled())
                            LOGGER.warn("GeotiffOverviewsEmbedder::execute(): " + iae.getLocalizedMessage(),
                                    iae);
                    } finally {
                        listenerForwarder.setProgress(100 / ((events.size() != 0) ? events.size() : 1));
                    }
                }

                // add the directory to the return
                ret.add(event);
            } else {
                final String message = "GeotiffOverviewsEmbedder::execute(): The passed file event refers to a not existent "
                        + "or not readable/writeable file! File: " + eventFile.getAbsolutePath();
                if (LOGGER.isWarnEnabled())
                    LOGGER.warn(message);

                throw new ActionException(this, message);

            }
        } // endwile
        listenerForwarder.completed();

        // return
        if (ret.size() > 0) {
            events.clear();
            return ret;
        } else {
            /*
             * If here: we got an error no file are set to be returned the
             * input queue is returned
             */
            return events;
        }
    } catch (Exception t) {
        final String message = "GeotiffOverviewsEmbedder::execute(): " + t.getLocalizedMessage();
        if (LOGGER.isErrorEnabled())
            LOGGER.error(message, t);
        final ActionException exc = new ActionException(this, message, t);
        listenerForwarder.failed(exc);
        throw exc;
    }
}

From source file:it.geosolutions.geobatch.geotiff.overview.GeotiffOverviewsEmbedderAction.java

@Override
public Queue<FileSystemEvent> execute(Queue<FileSystemEvent> events) throws ActionException {

    try {//from w ww  .j  a  va  2  s. c  o m
        // looking for file
        if (events.size() == 0)
            throw new IllegalArgumentException(
                    "GeotiffOverviewsEmbedder::execute(): Wrong number of elements for this action: "
                            + events.size());

        listenerForwarder.setTask("config");
        listenerForwarder.started();

        // //
        //
        // data flow configuration and dataStore name must not be null.
        //
        // //
        if (configuration == null) {
            final String message = "GeotiffOverviewsEmbedder::execute(): DataFlowConfig is null.";
            if (LOGGER.isErrorEnabled())
                LOGGER.error(message);
            throw new IllegalStateException(message);
        }

        // //
        //
        // check the configuration and prepare the overviews embedder
        //
        // //
        final int downsampleStep = configuration.getDownsampleStep();
        if (downsampleStep <= 0)
            throw new IllegalArgumentException(
                    "GeotiffOverviewsEmbedder::execute(): Illegal downsampleStep: " + downsampleStep);

        int numberOfSteps = configuration.getNumSteps();
        if (numberOfSteps <= 0)
            throw new IllegalArgumentException("Illegal numberOfSteps: " + numberOfSteps);

        final OverviewsEmbedder oe = new OverviewsEmbedder();
        oe.setDownsampleStep(downsampleStep);
        oe.setNumSteps(configuration.getNumSteps());
        // SG: this way we are sure we use the standard tile cache
        oe.setTileCache(JAI.getDefaultInstance().getTileCache());

        String scaleAlgorithm = configuration.getScaleAlgorithm();
        if (scaleAlgorithm == null) {
            LOGGER.warn("No scaleAlgorithm defined. Using " + SubsampleAlgorithm.Nearest + " as default");
            scaleAlgorithm = SubsampleAlgorithm.Nearest.name();
        } else {
            final SubsampleAlgorithm algorithm = SubsampleAlgorithm.valueOf(scaleAlgorithm);
            if (algorithm == null) {
                throw new IllegalStateException("Bad scaleAlgorithm defined [" + scaleAlgorithm + "]");
            }
        }
        oe.setScaleAlgorithm(scaleAlgorithm);
        oe.setTileHeight(configuration.getTileH());
        oe.setTileWidth(configuration.getTileW());

        /*
         * TODO check this is formally wrong! this should be done into the
         * configuration.
         */
        // add logger/listener
        if (configuration.isLogNotification())
            oe.addProcessingEventListener(new ProcessingEventListener() {

                public void exceptionOccurred(ExceptionEvent event) {
                    if (LOGGER.isInfoEnabled())
                        LOGGER.info("GeotiffOverviewsEmbedder::execute(): " + event.getMessage(),
                                event.getException());
                }

                public void getNotification(ProcessingEvent event) {
                    if (LOGGER.isInfoEnabled())
                        LOGGER.info("GeotiffOverviewsEmbedder::execute(): " + event.getMessage());
                    listenerForwarder.progressing((float) event.getPercentage(), event.getMessage());
                }
            });

        // The return
        Queue<FileSystemEvent> ret = new LinkedList<FileSystemEvent>();

        while (events.size() > 0) {

            // run
            listenerForwarder.progressing(0, "Embedding overviews");

            final FileSystemEvent event = events.remove();

            final File eventFile = event.getSource();
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("Processing file " + eventFile);

            if (eventFile.exists() && eventFile.canRead() && eventFile.canWrite()) {
                /*
                 * If here: we can start retiler actions on the incoming
                 * file event
                 */

                if (eventFile.isDirectory()) {

                    final FileFilter filter = new RegexFileFilter(".+\\.[tT][iI][fF]([fF]?)");
                    final Collector collector = new Collector(filter);
                    final List<File> fileList = collector.collect(eventFile);
                    int size = fileList.size();
                    for (int progress = 0; progress < size; progress++) {

                        final File inFile = fileList.get(progress);

                        try {
                            oe.setSourcePath(inFile.getAbsolutePath());
                            oe.run();
                        } catch (UnsupportedOperationException uoe) {
                            listenerForwarder.failed(uoe);
                            if (LOGGER.isWarnEnabled())
                                LOGGER.warn("GeotiffOverviewsEmbedder::execute(): " + uoe.getLocalizedMessage(),
                                        uoe);
                        } catch (IllegalArgumentException iae) {
                            listenerForwarder.failed(iae);
                            if (LOGGER.isWarnEnabled())
                                LOGGER.warn("GeotiffOverviewsEmbedder::execute(): " + iae.getLocalizedMessage(),
                                        iae);
                        } finally {
                            listenerForwarder.setProgress((progress * 100) / ((size != 0) ? size : 1));
                            listenerForwarder.progressing();
                        }
                    }
                } else {
                    // file is not a directory
                    try {
                        oe.setSourcePath(eventFile.getAbsolutePath());
                        oe.run();
                    } catch (UnsupportedOperationException uoe) {
                        listenerForwarder.failed(uoe);
                        if (LOGGER.isWarnEnabled())
                            LOGGER.warn("GeotiffOverviewsEmbedder::execute(): " + uoe.getLocalizedMessage(),
                                    uoe);
                    } catch (IllegalArgumentException iae) {
                        listenerForwarder.failed(iae);
                        if (LOGGER.isWarnEnabled())
                            LOGGER.warn("GeotiffOverviewsEmbedder::execute(): " + iae.getLocalizedMessage(),
                                    iae);
                    } finally {
                        listenerForwarder.setProgress(100 / ((events.size() != 0) ? events.size() : 1));
                    }
                }

                // add the directory to the return
                ret.add(event);
            } else {
                final String message = "GeotiffOverviewsEmbedder::execute(): The passed file event refers to a not existent "
                        + "or not readable/writeable file! File: " + eventFile.getAbsolutePath();
                if (LOGGER.isWarnEnabled())
                    LOGGER.warn(message);

                throw new ActionException(this, message);

            }
        } // endwile
        listenerForwarder.completed();

        // return
        if (ret.size() > 0) {
            events.clear();
            return ret;
        } else {
            /*
             * If here: we got an error no file are set to be returned the
             * input queue is returned
             */
            return events;
        }
    } catch (Exception t) {
        final String message = "GeotiffOverviewsEmbedder::execute(): " + t.getLocalizedMessage();
        if (LOGGER.isErrorEnabled())
            LOGGER.error(message, t);
        final ActionException exc = new ActionException(this, message, t);
        listenerForwarder.failed(exc);
        throw exc;
    }
}

From source file:it.geosolutions.geobatch.geotiff.retile.GeotiffRetilerAction.java

@Override
public Queue<FileSystemEvent> execute(Queue<FileSystemEvent> events) throws ActionException {
    try {/*from   w ww. j a  v a 2  s .  c  o m*/

        if (configuration == null) {
            final String message = "GeotiffRetiler::execute(): flow configuration is null.";
            if (LOGGER.isErrorEnabled())
                LOGGER.error(message);
            throw new ActionException(this, message);
        }
        if (events.size() == 0) {
            throw new ActionException(this,
                    "GeotiffRetiler::execute(): Unable to process an empty events queue.");
        }

        if (LOGGER.isInfoEnabled())
            LOGGER.info("GeotiffRetiler::execute(): Starting with processing...");

        listenerForwarder.started();

        // The return
        final Queue<FileSystemEvent> ret = new LinkedList<FileSystemEvent>();

        while (events.size() > 0) {

            FileSystemEvent event = events.remove();

            File eventFile = event.getSource();
            FileSystemEventType eventType = event.getEventType();

            if (eventFile.exists() && eventFile.canRead() && eventFile.canWrite()) {
                /*
                 * If here: we can start retiler actions on the incoming file event
                 */

                if (eventFile.isDirectory()) {

                    File[] fileList = eventFile.listFiles();
                    int size = fileList.length;
                    for (int progress = 0; progress < size; progress++) {

                        File inFile = fileList[progress];

                        final String absolutePath = inFile.getAbsolutePath();
                        final String inputFileName = FilenameUtils.getName(absolutePath);

                        if (LOGGER.isInfoEnabled())
                            LOGGER.info("is going to retile: " + inputFileName);

                        try {

                            listenerForwarder.setTask("GeotiffRetiler");
                            GeoTiffRetilerUtils.reTile(inFile, configuration, getTempDir());

                            // set the output
                            /*
                             * COMMENTED OUT 21 Feb 2011: simone: If the event represents a Dir
                             * we have to return a Dir. Do not matter failing files.
                             * 
                             * carlo: we may also want to check if a file is already tiled!
                             * 
                             * File outputFile=reTile(inFile); if (outputFile!=null){ //TODO:
                             * here we use the same event for each file in the ret.add(new
                             * FileSystemEvent(outputFile, eventType)); }
                             */

                        } catch (UnsupportedOperationException uoe) {
                            listenerForwarder.failed(uoe);
                            if (LOGGER.isWarnEnabled())
                                LOGGER.warn(uoe.getLocalizedMessage(), uoe);
                            continue;
                        } catch (IOException ioe) {
                            listenerForwarder.failed(ioe);
                            if (LOGGER.isWarnEnabled())
                                LOGGER.warn(ioe.getLocalizedMessage(), ioe);
                            continue;
                        } catch (IllegalArgumentException iae) {
                            listenerForwarder.failed(iae);
                            if (LOGGER.isWarnEnabled())
                                LOGGER.warn(iae.getLocalizedMessage(), iae);
                            continue;
                        } finally {
                            listenerForwarder.setProgress((progress * 100) / ((size != 0) ? size : 1));
                            listenerForwarder.progressing();
                        }
                    }

                    if (LOGGER.isInfoEnabled())
                        LOGGER.info("SUCCESSFULLY completed work on: " + event.getSource());

                    // add the directory to the return
                    ret.add(event);
                } else {
                    // file is not a directory
                    try {
                        listenerForwarder.setTask("GeotiffRetiler");
                        final File outputFile = GeoTiffRetilerUtils.reTile(eventFile, configuration,
                                getTempDir());

                        if (LOGGER.isInfoEnabled())
                            LOGGER.info("SUCCESSFULLY completed work on: " + event.getSource());
                        listenerForwarder.setProgress(100);
                        ret.add(new FileSystemEvent(outputFile, eventType));

                    } catch (UnsupportedOperationException uoe) {
                        listenerForwarder.failed(uoe);
                        if (LOGGER.isWarnEnabled())
                            LOGGER.warn(uoe.getLocalizedMessage(), uoe);
                        continue;
                    } catch (IOException ioe) {
                        listenerForwarder.failed(ioe);
                        if (LOGGER.isWarnEnabled())
                            LOGGER.warn(ioe.getLocalizedMessage(), ioe);
                        continue;
                    } catch (IllegalArgumentException iae) {
                        listenerForwarder.failed(iae);
                        if (LOGGER.isWarnEnabled())
                            LOGGER.warn(iae.getLocalizedMessage(), iae);
                        continue;
                    } finally {

                        listenerForwarder.setProgress((100) / ((events.size() != 0) ? events.size() : 1));
                        listenerForwarder.progressing();
                    }
                }
            } else {
                final String message = "The passed file event refers to a not existent "
                        + "or not readable/writeable file! File: " + eventFile.getAbsolutePath();
                if (LOGGER.isWarnEnabled())
                    LOGGER.warn(message);
                final IllegalArgumentException iae = new IllegalArgumentException(message);
                listenerForwarder.failed(iae);
            }
        } // endwile
        listenerForwarder.completed();

        // return
        if (ret.size() > 0) {
            events.clear();
            return ret;
        } else {
            /*
             * If here: we got an error no file are set to be returned the input queue is
             * returned
             */
            return events;
        }
    } catch (Exception t) {
        if (LOGGER.isErrorEnabled())
            LOGGER.error(t.getLocalizedMessage(), t);
        final ActionException exc = new ActionException(this, t.getLocalizedMessage(), t);
        listenerForwarder.failed(exc);
        throw exc;
    }
}

From source file:it.geosolutions.geobatch.geotiff.retile.GeotiffRetiler.java

public Queue<FileSystemEvent> execute(Queue<FileSystemEvent> events) throws ActionException {
    try {/*from  ww w  .  j a v a  2  s .c  om*/

        if (configuration == null) {
            final String message = "GeotiffRetiler::execute(): flow configuration is null.";
            if (LOGGER.isErrorEnabled())
                LOGGER.error(message);
            throw new ActionException(this, message);
        }
        if (events.size() == 0) {
            throw new ActionException(this,
                    "GeotiffRetiler::execute(): Unable to process an empty events queue.");
        }

        if (LOGGER.isInfoEnabled())
            LOGGER.info("GeotiffRetiler::execute(): Starting with processing...");

        listenerForwarder.started();

        // The return
        final Queue<FileSystemEvent> ret = new LinkedList<FileSystemEvent>();

        while (events.size() > 0) {

            FileSystemEvent event = events.remove();

            File eventFile = event.getSource();
            FileSystemEventType eventType = event.getEventType();

            if (eventFile.exists() && eventFile.canRead() && eventFile.canWrite()) {
                /*
                 * If here: we can start retiler actions on the incoming file event
                 */

                if (eventFile.isDirectory()) {

                    File[] fileList = eventFile.listFiles();
                    int size = fileList.length;
                    for (int progress = 0; progress < size; progress++) {

                        File inFile = fileList[progress];

                        final String absolutePath = inFile.getAbsolutePath();
                        final String inputFileName = FilenameUtils.getName(absolutePath);

                        if (LOGGER.isInfoEnabled())
                            LOGGER.info("is going to retile: " + inputFileName);

                        try {

                            listenerForwarder.setTask("GeotiffRetiler");

                            File tiledTiffFile = File.createTempFile(inFile.getName(), "_tiled.tif",
                                    getTempDir());
                            if (tiledTiffFile.exists()) {
                                // file already exists
                                // check write permission
                                if (!tiledTiffFile.canWrite()) {
                                    final String message = "Unable to over-write the temporary file called: "
                                            + tiledTiffFile.getAbsolutePath() + "\nCheck permissions.";
                                    if (LOGGER.isErrorEnabled()) {
                                        LOGGER.error(message);
                                    }
                                    throw new IllegalArgumentException(message);
                                }
                            } else if (!tiledTiffFile.createNewFile()) {
                                final String message = "Unable to create temporary file called: "
                                        + tiledTiffFile.getAbsolutePath();
                                if (LOGGER.isErrorEnabled()) {
                                    LOGGER.error(message);
                                }
                                throw new IllegalArgumentException(message);
                            }
                            final double compressionRatio = getConfiguration().getCompressionRatio();
                            final String compressionType = getConfiguration().getCompressionScheme();

                            reTile(inFile, tiledTiffFile, compressionRatio, compressionType,
                                    getConfiguration().getTileW(), getConfiguration().getTileH(),
                                    getConfiguration().isForceToBigTiff());

                            String extension = FilenameUtils.getExtension(inputFileName);
                            if (!extension.contains("tif")) {
                                extension = "tif";
                            }
                            final String outputFileName = FilenameUtils.getFullPath(absolutePath)
                                    + FilenameUtils.getBaseName(inputFileName) + "." + extension;
                            final File outputFile = new File(outputFileName);
                            // do we need to remove the input?
                            FileUtils.copyFile(tiledTiffFile, outputFile);
                            FileUtils.deleteQuietly(tiledTiffFile);

                            // set the output
                            /*
                             * COMMENTED OUT 21 Feb 2011: simone: If the event represents a Dir
                             * we have to return a Dir. Do not matter failing files.
                             * 
                             * carlo: we may also want to check if a file is already tiled!
                             * 
                             * File outputFile=reTile(inFile); if (outputFile!=null){ //TODO:
                             * here we use the same event for each file in the ret.add(new
                             * FileSystemEvent(outputFile, eventType)); }
                             */

                        } catch (UnsupportedOperationException uoe) {
                            listenerForwarder.failed(uoe);
                            if (LOGGER.isWarnEnabled())
                                LOGGER.warn(uoe.getLocalizedMessage(), uoe);
                            continue;
                        } catch (IOException ioe) {
                            listenerForwarder.failed(ioe);
                            if (LOGGER.isWarnEnabled())
                                LOGGER.warn(ioe.getLocalizedMessage(), ioe);
                            continue;
                        } catch (IllegalArgumentException iae) {
                            listenerForwarder.failed(iae);
                            if (LOGGER.isWarnEnabled())
                                LOGGER.warn(iae.getLocalizedMessage(), iae);
                            continue;
                        } finally {
                            listenerForwarder.setProgress((progress * 100) / ((size != 0) ? size : 1));
                            listenerForwarder.progressing();
                        }
                    }

                    if (LOGGER.isInfoEnabled())
                        LOGGER.info("SUCCESSFULLY completed work on: " + event.getSource());

                    // add the directory to the return
                    ret.add(event);
                } else {
                    // file is not a directory
                    try {
                        listenerForwarder.setTask("GeotiffRetiler");

                        File tiledTiffFile = File.createTempFile(eventFile.getName(), "_tiled.tif",
                                eventFile.getParentFile());
                        if (tiledTiffFile.exists()) {
                            // file already exists
                            // check write permission
                            if (!tiledTiffFile.canWrite()) {
                                final String message = "Unable to over-write the temporary file called: "
                                        + tiledTiffFile.getAbsolutePath() + "\nCheck permissions.";
                                if (LOGGER.isErrorEnabled()) {
                                    LOGGER.error(message);
                                }
                                throw new IllegalArgumentException(message);
                            }
                        } else if (!tiledTiffFile.createNewFile()) {
                            final String message = "Unable to create temporary file called: "
                                    + tiledTiffFile.getAbsolutePath();
                            if (LOGGER.isErrorEnabled()) {
                                LOGGER.error(message);
                            }
                            throw new IllegalArgumentException(message);
                        }
                        final double compressionRatio = getConfiguration().getCompressionRatio();
                        final String compressionType = getConfiguration().getCompressionScheme();

                        reTile(eventFile, tiledTiffFile, compressionRatio, compressionType,
                                getConfiguration().getTileW(), getConfiguration().getTileH(),
                                getConfiguration().isForceToBigTiff());

                        String extension = FilenameUtils.getExtension(eventFile.getName());
                        if (!extension.contains("tif")) {
                            extension = "tif";
                        }
                        final String outputFileName = FilenameUtils.getFullPath(eventFile.getAbsolutePath())
                                + FilenameUtils.getBaseName(eventFile.getName()) + "." + extension;
                        final File outputFile = new File(outputFileName);
                        // do we need to remove the input?
                        FileUtils.copyFile(tiledTiffFile, outputFile);
                        FileUtils.deleteQuietly(tiledTiffFile);

                        if (LOGGER.isInfoEnabled())
                            LOGGER.info("SUCCESSFULLY completed work on: " + event.getSource());
                        listenerForwarder.setProgress(100);
                        ret.add(new FileSystemEvent(outputFile, eventType));

                    } catch (UnsupportedOperationException uoe) {
                        listenerForwarder.failed(uoe);
                        if (LOGGER.isWarnEnabled())
                            LOGGER.warn(uoe.getLocalizedMessage(), uoe);
                        continue;
                    } catch (IOException ioe) {
                        listenerForwarder.failed(ioe);
                        if (LOGGER.isWarnEnabled())
                            LOGGER.warn(ioe.getLocalizedMessage(), ioe);
                        continue;
                    } catch (IllegalArgumentException iae) {
                        listenerForwarder.failed(iae);
                        if (LOGGER.isWarnEnabled())
                            LOGGER.warn(iae.getLocalizedMessage(), iae);
                        continue;
                    } finally {

                        listenerForwarder.setProgress((100) / ((events.size() != 0) ? events.size() : 1));
                        listenerForwarder.progressing();
                    }
                }
            } else {
                final String message = "The passed file event refers to a not existent "
                        + "or not readable/writeable file! File: " + eventFile.getAbsolutePath();
                if (LOGGER.isWarnEnabled())
                    LOGGER.warn(message);
                final IllegalArgumentException iae = new IllegalArgumentException(message);
                listenerForwarder.failed(iae);
            }
        } // endwile
        listenerForwarder.completed();

        // return
        if (ret.size() > 0) {
            events.clear();
            return ret;
        } else {
            /*
             * If here: we got an error no file are set to be returned the input queue is
             * returned
             */
            return events;
        }
    } catch (Exception t) {
        if (LOGGER.isErrorEnabled())
            LOGGER.error(t.getLocalizedMessage(), t);
        final ActionException exc = new ActionException(this, t.getLocalizedMessage(), t);
        listenerForwarder.failed(exc);
        throw exc;
    }
}

From source file:org.apache.hadoop.ha.HAAdmin.java

private int failover(CommandLine cmd) throws IOException, ServiceFailedException {
    boolean forceFence = cmd.hasOption(FORCEFENCE);
    boolean forceActive = cmd.hasOption(FORCEACTIVE);

    int numOpts = cmd.getOptions() == null ? 0 : cmd.getOptions().length;
    final String[] args = cmd.getArgs();

    if (numOpts > 3 || args.length != 2) {
        errOut.println("failover: incorrect arguments");
        printUsage(errOut, "-failover");
        return -1;
    }/*from  w  w w  . ja va  2  s .c o  m*/

    HAServiceTarget fromNode = resolveTarget(args[0]);
    HAServiceTarget toNode = resolveTarget(args[1]);

    // Check that auto-failover is consistently configured for both nodes.
    Preconditions.checkState(fromNode.isAutoFailoverEnabled() == toNode.isAutoFailoverEnabled(),
            "Inconsistent auto-failover configs between %s and %s!", fromNode, toNode);

    if (fromNode.isAutoFailoverEnabled()) {
        if (forceFence || forceActive) {
            // -forceActive doesn't make sense with auto-HA, since, if the node
            // is not healthy, then its ZKFC will immediately quit the election
            // again the next time a health check runs.
            //
            // -forceFence doesn't seem to have any real use cases with auto-HA
            // so it isn't implemented.
            errOut.println(FORCEFENCE + " and " + FORCEACTIVE + " flags not "
                    + "supported with auto-failover enabled.");
            return -1;
        }
        try {
            return gracefulFailoverThroughZKFCs(toNode);
        } catch (UnsupportedOperationException e) {
            errOut.println("Failover command is not supported with " + "auto-failover enabled: "
                    + e.getLocalizedMessage());
            return -1;
        }
    }

    FailoverController fc = new FailoverController(getConf(), requestSource);

    try {
        fc.failover(fromNode, toNode, forceFence, forceActive);
        out.println("Failover from " + args[0] + " to " + args[1] + " successful");
    } catch (FailoverFailedException ffe) {
        errOut.println("Failover failed: " + ffe.getLocalizedMessage());
        return -1;
    }
    return 0;
}

From source file:org.apache.openaz.xacml.admin.components.PolicyEditor.java

protected void initializeTree() {
    ///*from  ww  w.  j  av  a  2 s.  c  o  m*/
    // Create our container and set it as the tree's data source
    //
    this.tree.setContainerDataSource(this.policyContainer);
    this.tree.setItemIconPropertyId("Icon");
    this.tree.setVisibleColumns(VISIBLE_COLUMNS);
    this.tree.setColumnHeaders(COLUMN_HEADERS);
    this.tree.setSelectable(true);
    this.tree.setSizeFull();
    //
    // Expand it down a few items
    //
    for (Object id : this.tree.getItemIds()) {
        this.tree.setCollapsed(id, false);
        for (Object child : this.tree.getChildren(id)) {
            this.tree.setCollapsed(child, false);
        }
    }
    //
    // Respond to double-click's
    //
    this.tree.addItemClickListener(new ItemClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void itemClick(ItemClickEvent event) {
            if (event.isDoubleClick()) {
                if (self.isReadOnly()) {
                    AdminNotification.info("You are in read-only mode.");
                    return;
                }
                Object target = event.getItemId();
                if (target instanceof PolicySetType) {
                    self.editPolicySet((PolicySetType) target,
                            (PolicySetType) self.policyContainer.getParent(target));
                } else if (target instanceof PolicyType) {
                    self.editPolicy((PolicyType) target,
                            (PolicySetType) self.policyContainer.getParent(target));
                } else if (target instanceof RuleType) {
                    self.editRule((RuleType) target, (PolicyType) self.policyContainer.getParent(target));
                } else if (target instanceof ConditionType) {
                    self.editCondition((ConditionType) target,
                            (RuleType) self.policyContainer.getParent(target));
                } else if (target instanceof VariableDefinitionType) {
                    self.editVariable((VariableDefinitionType) target,
                            (PolicyType) self.policyContainer.getParent(target));
                } else if (target instanceof MatchType) {
                    self.editMatch((MatchType) target, (AllOfType) self.policyContainer.getParent(target), null,
                            null, "Edit Match");
                } else if (target instanceof ObligationExpressionType) {
                    self.editObAdvice(true, self.policyContainer.getParent(target));
                } else if (target instanceof AdviceExpressionType) {
                    self.editObAdvice(false, self.policyContainer.getParent(target));
                }
            }
        }

    });
    //
    // Respond to container changes
    //
    this.policyContainer.addItemSetChangeListener(new ItemSetChangeListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void containerItemSetChange(ItemSetChangeEvent event) {
            self.isModified = true;
            if (self.isAutoSave()) {
                self.savePolicy();
            } else {
                self.setupCaption();
                self.buttonSave.setEnabled(true);
            }
        }
    });
    //
    // Implement drag-n-drop
    //
    this.tree.setDropHandler(new DropHandler() {
        private static final long serialVersionUID = 1L;

        @Override
        public void drop(DragAndDropEvent event) {
            DataBoundTransferable t = (DataBoundTransferable) event.getTransferable();
            AbstractSelectTargetDetails target = (AbstractSelectTargetDetails) event.getTargetDetails();

            //
            // Get ids of the dragged item and the target item
            //
            Object sourceItemId = t.getData("itemId");
            Object targetItemId = target.getItemIdOver();
            VerticalDropLocation location = target.getDropLocation();
            if (logger.isDebugEnabled()) {
                logger.debug("Drop " + sourceItemId + " target " + targetItemId + " location " + location);
            }
            //
            // Tell our container what to do
            //
            try {
                if (location == VerticalDropLocation.MIDDLE) {
                    //
                    // Drop right on top of item making it a child
                    //
                    self.policyContainer.setParent(sourceItemId, targetItemId);
                }

                /*
                } else if (location == VerticalDropLocation.TOP) {
                   //
                   // Drop at the top of the tree making it the previous
                   //
                   Object parent = self.policyContainer.getParent(targetItemId);
                   self.policyContainer.setParent(sourceItemId, parent);
                   self.policyContainer.moveAfterSibling(sourceItemId, targetItemId);
                   self.policyContainer.moveAfterSibling(targetItemId, sourceItemId);
                } else if (location == VerticalDropLocation.BOTTOM) {
                   //
                   // Drop below another item
                   //
                   Object parent = self.policyContainer.getParent(targetItemId);
                   self.policyContainer.setParent(sourceItemId, targetItemId);
                   self.policyContainer.moveAfterSibling(sourceItemId, targetItemId);
                }
                */
            } catch (UnsupportedOperationException e) {
                logger.error("Unsupported " + e.getLocalizedMessage());
            }
        }

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }
    });
}

From source file:org.orbisgis.view.map.MapElement.java

private void setListeners(ILayer layer) {
    if (layer == null) {
        return;/*from   w ww.ja va2s . c o  m*/
    }
    layer.addLayerListener(layerUpdateListener);
    DataSource dataSource = layer.getDataSource();
    if (dataSource != null && dataSource.isEditable()) {
        try {
            layer.getDataSource().addEditionListener(sourceUpdateListener);
        } catch (UnsupportedOperationException ex) {
            LOGGER.warn(ex.getLocalizedMessage(), ex);
        }
    }
    ILayer[] layers = layer.getLayersRecursively();
    if (layers != null) {
        for (ILayer subLayer : layers) {
            setListeners(subLayer);
        }
    }
}

From source file:org.orbisgis.view.map.MapElement.java

private void removeListeners(ILayer layer) {
    if (layer == null) {
        return;//from   ww w.  ja v a2  s  .com
    }
    layer.removeLayerListener(layerUpdateListener);
    DataSource src = layer.getDataSource();
    if (src != null && src.isEditable()) {
        try {
            src.removeEditionListener(sourceUpdateListener);
        } catch (UnsupportedOperationException ex) {
            LOGGER.warn(ex.getLocalizedMessage(), ex);
        }
    }
    ILayer[] layers = layer.getLayersRecursively();
    if (layers != null) {
        for (ILayer subLayer : layers) {
            removeListeners(subLayer);
        }
    }
}

From source file:org.polymap.model2.store.geotools.FeatureStoreAdapter.java

public void init(StoreRuntimeContext _context) {
    this.context = _context;
    EntityRepository repo = context.getRepository();

    // check/create/update schemas
    if (createOrUpdateSchemas.get()) {
        //        FeatureStoreUnitOfWork uow = (FeatureStoreUnitOfWork)createUnitOfWork();
        for (Class<? extends Entity> entityClass : repo.getConfig().entities.get()) {

            // is entityClass complex?
            boolean isComplex = false;
            Class superClass = entityClass;
            for (; superClass != null; superClass = superClass.getSuperclass()) {
                for (Field field : superClass.getDeclaredFields()) {
                    if (CollectionProperty.class.isAssignableFrom(field.getType())) {
                        isComplex = true;
                        break;
                    }/*w  ww  . j  a v a  2  s . co  m*/
                    if (Property.class.isAssignableFrom(field.getType())) {
                        Class binding = (Class) ((ParameterizedType) field.getGenericType())
                                .getActualTypeArguments()[0];
                        if (Composite.class.isAssignableFrom(binding)) {
                            isComplex = true;
                            break;
                        }
                    }
                }
            }

            // check/update schema            
            FeatureType entitySchema = isComplex ? featureType(entityClass) : simpleFeatureType(entityClass);
            try {
                log.info("Checking FeatureSource: " + entitySchema.getName().getLocalPart() + " ...");
                FeatureSource fs = store.getFeatureSource(entitySchema.getName());
                // update
                if (fs != null && !entitySchema.equals(fs.getSchema())) {
                    try {
                        log.warn("FeatureType has been changed: " + entitySchema.getName() + " !!!");
                        store.updateSchema(entitySchema.getName(), entitySchema);
                    } catch (UnsupportedOperationException e) {
                        log.warn("", e);
                    }
                }
            }
            // create schema
            // fs.getSchema() throws RuntimeException for ShapefileDataSource
            catch (Exception e) {
                try {
                    log.info("No feature store found: " + e.getLocalizedMessage() + ". Creating schema: "
                            + entitySchema);
                    store.createSchema(entitySchema);
                } catch (IOException e1) {
                    throw new ModelRuntimeException(e1);
                }
            }
        }
    }
}