List of usage examples for java.lang IllegalArgumentException getLocalizedMessage
public String getLocalizedMessage()
From source file:nl.b3p.viewer.stripes.MergeFeaturesActionBean.java
public Resolution merge() throws JSONException { JSONObject json = new JSONObject(); json.put("success", Boolean.FALSE); String error = null;/*from w ww.j a v a 2s .com*/ if (appLayer == null) { error = getBundle().getString("viewer.mergefeaturesactionbean.1"); } else if (unauthorized) { error = getBundle().getString("viewer.mergefeaturesactionbean.2"); } else { FeatureSource fs = null; try { if (this.fidA == null || this.fidB == null) { throw new IllegalArgumentException(getBundle().getString("viewer.mergefeaturesactionbean.3")); } if (this.strategy == null) { throw new IllegalArgumentException(getBundle().getString("viewer.mergefeaturesactionbean.4")); } fs = this.layer.getFeatureType().openGeoToolsFeatureSource(); if (!(fs instanceof SimpleFeatureStore)) { throw new IllegalArgumentException(getBundle().getString("viewer.mergefeaturesactionbean.5")); } this.store = (SimpleFeatureStore) fs; List<FeatureId> ids = this.mergeFeatures(); if (ids.isEmpty()) { throw new IllegalArgumentException(getBundle().getString("viewer.mergefeaturesactionbean.6")); } if (ids.size() > 1) { throw new IllegalArgumentException(getBundle().getString("viewer.mergefeaturesactionbean.7")); } json.put("fids", ids); json.put("success", Boolean.TRUE); } catch (IllegalArgumentException e) { LOG.warn("Merge error", e); error = e.getLocalizedMessage(); } catch (Exception e) { LOG.error(MessageFormat.format(getBundle().getString("viewer.mergefeaturesactionbean.8"), this.fidB, this.fidA, e)); error = e.toString(); if (e.getCause() != null) { error += "; cause: " + e.getCause().toString(); } } finally { if (fs != null) { fs.getDataStore().dispose(); } } } if (error != null) { json.put("error", error); } return new StreamingResolution("application/json", new StringReader(json.toString())); }
From source file:org.apache.hadoop.ha.HAAdmin.java
@Override public int run(String[] argv) throws Exception { try {//from ww w.j a va2 s .c o m return runCmd(argv); } catch (IllegalArgumentException iae) { errOut.println("Illegal argument: " + iae.getLocalizedMessage()); return -1; } catch (IOException ioe) { errOut.println("Operation failed: " + ioe.getLocalizedMessage()); if (LOG.isDebugEnabled()) { LOG.debug("Operation failed", ioe); } return -1; } }
From source file:nl.b3p.viewer.stripes.SplitFeatureActionBean.java
public Resolution split() throws JSONException { JSONObject json = new JSONObject(); json.put("success", Boolean.FALSE); String error = null;//from ww w . j a v a 2 s . c om if (appLayer == null) { error = "Invalid parameters"; } else if (unauthorized) { error = "Not authorized"; } else { FeatureSource fs = null; try { if (this.splitFeatureFID == null) { throw new IllegalArgumentException(getBundle().getString("viewer.splitfeatureactionbean.1")); } if (this.toSplitWithFeature == null) { throw new IllegalArgumentException(getBundle().getString("viewer.splitfeatureactionbean.2")); } fs = this.layer.getFeatureType().openGeoToolsFeatureSource(); if (!(fs instanceof SimpleFeatureStore)) { throw new IllegalArgumentException(getBundle().getString("viewer.splitfeatureactionbean.3")); } this.store = (SimpleFeatureStore) fs; List<FeatureId> ids = this.splitFeature(); if (ids.size() < 2) { throw new IllegalArgumentException(getBundle().getString("viewer.splitfeatureactionbean.4")); } json.put("fids", ids); json.put("success", Boolean.TRUE); } catch (IllegalArgumentException e) { log.warn("Split error", e); error = e.getLocalizedMessage(); } catch (Exception e) { log.error(String.format("Exception splitting feature %s", this.splitFeatureFID), e); error = e.toString(); if (e.getCause() != null) { error += "; cause: " + e.getCause().toString(); } } finally { if (fs != null) { fs.getDataStore().dispose(); } } } if (error != null) { json.put("error", error); } return new StreamingResolution("application/json", new StringReader(json.toString())); }
From source file:org.apache.hadoop.hdfs.AvatarZKShell.java
/** * run// w w w. j av a 2s . c o m */ public int run(String argv[]) throws Exception { if (argv.length < 1) { printUsage(""); return -1; } int exitCode = 0; String zkCmd = null; String serviceName = null; String instance = null; boolean force = false; // enforce to specify service if configured if (!AvatarShell.isServiceSpecified("AvatarZKShell", conf, argv)) { return -1; } for (int i = 0; i < argv.length; i++) { String cmd = argv[i]; // // verify that we have enough command line parameters // if ("-service".equals(cmd)) { if (i + 1 == argv.length) { printUsage(cmd); return -1; } serviceName = argv[++i]; } else if ("-updateZK".equals(cmd)) { zkCmd = cmd; if (i + 1 == argv.length) { printUsage(cmd); return -1; } instance = argv[++i]; if (i + 1 < argv.length && argv[i + 1].equals("-force")) { force = true; i++; } } else if ("-clearZK".equals(cmd)) { zkCmd = cmd; } else if ("-createZK".equals(cmd)) { zkCmd = cmd; if (i + 1 == argv.length) { printUsage(cmd); return -1; } instance = argv[++i]; } else if ("-getZK".equals(cmd)) { zkCmd = cmd; } else { exitCode = -1; System.err.println(cmd.substring(1) + ": Unknown command"); printUsage(""); } } // make sure that command is provided if (zkCmd == null) { printUsage(""); return -1; } Collection<String> services; if (serviceName != null) { // for one service if (!AvatarNode.validateServiceName(conf, serviceName)) { return -1; } services = new ArrayList<String>(1); services.add(serviceName); } else { // for all configured services services = DFSUtil.getNameServiceIds(conf); if (services.size() == 0) { //non-federation services.add(""); } } try { for (String service : services) { AvatarNode.initializeGenericKeys(originalConf, service); if ("-updateZK".equals(zkCmd) || "-createZK".equals(zkCmd)) { if (instance == null || (conf = updateConf(instance, originalConf)) == null) { printUsage(zkCmd); return -1; } } if ("-updateZK".equals(zkCmd)) { updateZooKeeper(force, service, instance); } else if ("-clearZK".equals(zkCmd)) { clearZooKeeper(service); } else if ("-createZK".equals(zkCmd)) { updateZooKeeper(true, false, service, instance); } else if ("-getZK".equals(zkCmd)) { getZooKeeper(service); } } } catch (IllegalArgumentException arge) { exitCode = -1; arge.printStackTrace(); System.err.println(zkCmd.substring(1) + ": " + arge.getLocalizedMessage()); printUsage(zkCmd); } catch (RemoteException e) { exitCode = -1; try { String[] content; content = e.getLocalizedMessage().split("\n"); System.err.println(zkCmd.substring(1) + ": " + content[0]); } catch (Exception ex) { System.err.println(zkCmd.substring(1) + ": " + ex.getLocalizedMessage()); } } catch (IOException e) { // // IO exception encountered locally. // exitCode = -1; System.err.println(zkCmd.substring(1) + ": " + e.getLocalizedMessage()); e.printStackTrace(); } catch (Throwable re) { exitCode = -1; System.err.println(zkCmd.substring(1) + ": " + re.getLocalizedMessage()); re.printStackTrace(); } finally { } return exitCode; }
From source file:it.geosolutions.geobatch.actions.freemarker.FreeMarkerAction.java
/** * Removes TemplateModelEvents from the queue and put *///from w w w .j a va 2 s .c om public Queue<EventObject> execute(Queue<EventObject> events) throws ActionException { listenerForwarder.started(); listenerForwarder.setTask("initializing the FreeMarker engine"); if (!initialized) { try { initialize(); } catch (IllegalArgumentException e) { throw new ActionException(this, e.getLocalizedMessage(), e.getCause()); } catch (IOException e) { throw new ActionException(this, e.getLocalizedMessage(), e.getCause()); } } listenerForwarder.setTask("build the output absolute file name"); // build the output absolute file name File outputDir = computeOutputDir(); // may throw ActionEx // return final Queue<EventObject> ret = new LinkedList<EventObject>(); listenerForwarder.setTask("Building/getting the root data structure"); /* * Building/getting the root data structure */ final Map<String, Object> root = conf.getRoot() != null ? conf.getRoot() : new HashMap<String, Object>(); // list of incoming event to inject into the root datamodel final List<TemplateModel> list; if (conf.isNtoN()) { list = new ArrayList<TemplateModel>(events.size()); } else { list = new ArrayList<TemplateModel>(1); } // append the list of adapted event objects root.put(TemplateModelEvent.EVENT_KEY, list); while (!events.isEmpty()) { // the adapted event final TemplateModelEvent ev; final TemplateModel dataModel; try { if ((ev = adapter(events.remove())) != null) { listenerForwarder.setTask("Try to get a Template DataModel from the Adapted event"); // try to get a Template DataModel from the Adapted event dataModel = ev.getModel(processor); } else { final String message = "Unable to append the event: unrecognized format. SKIPPING..."; if (LOGGER.isErrorEnabled()) { LOGGER.error(message); } if (conf.isFailIgnored()) { continue; } else { final ActionException e = new ActionException(this, message); listenerForwarder.failed(e); throw e; } } } catch (TemplateModelException tme) { final String message = "Unable to wrap the passed object: " + tme.getLocalizedMessage(); if (LOGGER.isErrorEnabled()) LOGGER.error(message); if (conf.isFailIgnored()) { continue; } else { listenerForwarder.failed(tme); throw new ActionException(this, tme.getLocalizedMessage()); } } catch (Exception ioe) { final String message = "Unable to produce the output: " + ioe.getLocalizedMessage(); if (LOGGER.isErrorEnabled()) LOGGER.error(message); if (conf.isFailIgnored()) { continue; } else { listenerForwarder.failed(ioe); throw new ActionException(this, ioe.getLocalizedMessage(), ioe); } } listenerForwarder.setTask("Generating the output"); /* * If getNtoN: For each data incoming event (Template DataModel) * build a file. Otherwise the entire queue of incoming object will * be transformed in a list of datamodel. In this case only one file * is generated. */ if (conf.isNtoN()) { if (list.size() > 0) { list.remove(0); } list.add(dataModel); final File outputFile; // append the incoming data structure try { outputFile = buildOutput(outputDir, root); } catch (ActionException e) { if (LOGGER.isErrorEnabled()) LOGGER.error(e.getLocalizedMessage(), e); if (conf.isFailIgnored()) { continue; } else { listenerForwarder.failed(e); throw e; } } // add the file to the return ret.add(new FileSystemEvent(outputFile.getAbsoluteFile(), FileSystemEventType.FILE_ADDED)); } else { list.add(dataModel); } } if (!conf.isNtoN()) { final File outputFile; // append the incoming data structure try { outputFile = buildOutput(outputDir, root); } catch (ActionException e) { if (LOGGER.isErrorEnabled()) LOGGER.error(e.getLocalizedMessage(), e); listenerForwarder.failed(e); throw e; } // add the file to the return ret.add(new FileSystemEvent(outputFile.getAbsoluteFile(), FileSystemEventType.FILE_ADDED)); } listenerForwarder.completed(); return ret; }
From source file:nl.opengeogroep.dbk.DBKAPI.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException { String method = null;/*w w w .j ava2s .c o m*/ OutputStream out = response.getOutputStream(); try { String requestedUri = request.getRequestURI(); method = requestedUri.substring(requestedUri.indexOf(API_PART) + API_PART.length()); JSONObject output = new JSONObject(); if (method.contains(FEATURES) || method.contains(OBJECT) || method.contains(GEBIED)) { if (method.contains(FEATURES)) { output = processFeatureRequest(request); } else if (method.contains(OBJECT)) { output = processObjectRequest(request, method); } else { output = processGebiedRequest(request, method); } response.setContentType("application/json;charset=UTF-8"); out.write(output.toString().getBytes("UTF-8")); } else if (method.contains(MEDIA)) { processMedia(method, request, response, out); } else { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); output.put("success", Boolean.FALSE); output.put("message", "Requested method not understood. Method was: " + method + " but expected are: " + FEATURES + ", " + OBJECT + " or " + MEDIA); out.write(output.toString().getBytes()); } } catch (IllegalArgumentException ex) { response.setContentType("text/plain;charset=UTF-8"); log.error("Error happened with " + method + ":", ex); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); out.write(ex.getLocalizedMessage().getBytes()); } catch (Exception e) { log.error("Error happened with " + method + ":", e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); out.write(("Exception occured:" + e.getLocalizedMessage()).getBytes()); } finally { out.flush(); out.close(); } }
From source file:org.apache.hadoop.fs.FsShell.java
/** * run//from w w w. jav a 2 s .c om */ @Override public int run(String argv[]) throws Exception { // initialize FsShell init(); int exitCode = -1; if (argv.length < 1) { printUsage(System.err); } else { String cmd = argv[0]; Command instance = null; try { instance = commandFactory.getInstance(cmd); if (instance == null) { throw new UnknownCommandException(); } TraceScope scope = tracer.newScope(instance.getCommandName()); if (scope.getSpan() != null) { String args = StringUtils.join(" ", argv); if (args.length() > 2048) { args = args.substring(0, 2048); } scope.getSpan().addKVAnnotation("args", args); } try { exitCode = instance.run(Arrays.copyOfRange(argv, 1, argv.length)); } finally { scope.close(); } } catch (IllegalArgumentException e) { if (e.getMessage() == null) { displayError(cmd, "Null exception message"); e.printStackTrace(System.err); } else { displayError(cmd, e.getLocalizedMessage()); } printUsage(System.err); if (instance != null) { printInstanceUsage(System.err, instance); } } catch (Exception e) { // instance.run catches IOE, so something is REALLY wrong if here LOG.debug("Error", e); displayError(cmd, "Fatal internal error"); e.printStackTrace(System.err); } } tracer.close(); return exitCode; }
From source file:it.geosolutions.geobatch.geotiff.overview.GeotiffOverviewsEmbedder.java
public Queue<FileSystemEvent> execute(Queue<FileSystemEvent> events) throws ActionException { try {//from w ww . ja va 2 s .c om // 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 {/* ww w .ja va2s . c om*/ // 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 ww w . j a v a2 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"); 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; } }