Package sos.scheduler.file

Source Code of sos.scheduler.file.JobSchedulerNotExistsFile

/********************************************************* begin of preamble
**
** Copyright (C) 2003-2010 Software- und Organisations-Service GmbH.
** All rights reserved.
**
** This file may be used under the terms of either the
**
**   GNU General Public License version 2.0 (GPL)
**
**   as published by the Free Software Foundation
**   http://www.gnu.org/licenses/gpl-2.0.txt and appearing in the file
**   LICENSE.GPL included in the packaging of this file.
**
** or the
** 
**   Agreement for Purchase and Licensing
**
**   as offered by Software- und Organisations-Service GmbH
**   in the respective terms of supply that ship with this file.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
** IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
** THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
** BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
** POSSIBILITY OF SUCH DAMAGE.
********************************************************** end of preamble*/
package sos.scheduler.file;


import java.util.regex.Pattern;

import sos.spooler.Job_impl;
import sos.spooler.Variable_set;
import sos.util.SOSLogger;
import sos.util.SOSSchedulerLogger;
import sos.util.SOSFileOperations;

/**
* This job checks for file non-existence of one file or several files of a directory.
* It can be used standalone or as an order driven job.
*
* @author Florian Schreiber <fs@sos-berlin.com>
* @since  2006-12-08
*/
public class JobSchedulerNotExistsFile extends Job_impl {
 
  private SOSLogger logger = null;
 
 
  /**
   * Implementierung f�r Spooler API.
   * Initialisierungmethode f�r den Scheduler.
   * @return boolean
   */
  public boolean spooler_init() {
   
    try {
     
      try {
        this.logger = new SOSSchedulerLogger(this.spooler_log);
      } catch (Exception e) {
        throw new Exception("error occurred instantiating logger: " + e.getMessage());
      }
     
      return true;
    } catch (Exception e) {
      try {
        if ( logger!=null ) logger.error("error occurred in spooler_init(): " + e.getMessage());
      } catch (Exception x) {}
     
      return false;
    }
  }
 
  /**
   * Implementierung f�r Spooler API. L�uft bis return = false
   * @return boolean
   */
  public boolean spooler_process() {
   
        boolean rc = false;
    String name = null;
   
    String file = null;
    String fileSpec = null;
   
    String minFileAge = "0";
    String maxFileAge = "0";
   
    String minFileSize = "-1";
    String maxFileSize = "-1";
   
    int skipFirstFiles = 0;
    int skipLastFiles = 0;
   
    try {
     
      // Job oder Order
      Variable_set params = spooler.create_variable_set();
      if (spooler_task.params() != null) params.merge(spooler_task.params());
      if (spooler_job.order_queue() != null && spooler_task.order().params() != null)
        params.merge(spooler_task.order().params());
     
      // mandatory parameters
      name = "file";
      if ( params.var(name)!=null && params.var(name).length()>0 ) {       
        file = params.var(name);
       
        // To make orderparams available for substitution in orderparam value
        while (file.matches("^.*%[^%]+%.*$")) {
          String p = file.replaceFirst("^.*%([^%]+)%.*$", "$1");
          String s = params.var(p);
          s = s.replace('\\','/');
          file = file.replaceAll("%"+p+"%", s);
          logger.debug("processing job parameter ["+name+"]: substitute %"+p+"% with "+s);
        }
      }
      else
        throw new Exception("job parameter is missing: ["+name+"]");
     
      logger.info(".. job parameter ["+name+"]: " + file);
     
     
      // optional parameters
      name = "file_spec";
      if ( params.var(name)!=null && params.var(name).length()>0 ) {       
        fileSpec = params.var(name);
        logger.info(".. job parameter ["+name+"]: " + fileSpec);
      }
     
      name = "min_file_age";
      if ( params.var(name)!=null && params.var(name).length()>0 ) {
        minFileAge = params.var(name);
        logger.info(".. job parameter ["+name+"]: " + minFileAge);
      }
     
      name = "max_file_age";
      if ( params.var(name)!=null && params.var(name).length()>0 ) {
        maxFileAge = params.var(name);
        logger.info(".. job parameter ["+name+"]: " + maxFileAge);
      }
     
      name = "min_file_size";
      if ( params.var(name)!=null && params.var(name).length()>0 ) {
        minFileSize = params.var(name);
        logger.info(".. job parameter ["+name+"]: " + minFileSize);
      }
     
      name = "max_file_size";
      if ( params.var(name)!=null && params.var(name).length()>0 ) {
        maxFileSize = params.var(name);
        logger.info(".. job parameter ["+name+"]: " + maxFileSize);
      }
     
      name="skip_first_files";
      if ( params.var(name)!=null && params.var(name).length()>0 ) {
        try {
          skipFirstFiles = Integer.parseInt(params.var(name));
        } catch (Exception ex) {
          throw new Exception("invalid, non-numeric value for parameter [" + name + "]: " + ex.getMessage());
        }
        logger.info(".. job parameter ["+name+"]: " + skipFirstFiles);
      }
     
      name="skip_last_files";
      if ( params.var(name)!=null && params.var(name).length()>0 ) {
        try {
          skipLastFiles = Integer.parseInt(params.var(name));
        } catch (Exception ex) {
          throw new Exception("invalid, non-numeric value for parameter [" + name + "]: " + ex.getMessage());
        }
        logger.info(".. job parameter ["+name+"]: " + skipLastFiles);
      }
     
      rc = !SOSFileOperations.existsFile(file, fileSpec, Pattern.CASE_INSENSITIVE, minFileAge, maxFileAge, minFileSize, maxFileSize, skipFirstFiles, skipLastFiles, logger);
     
      if (!rc && params.value("gracious") != null && params.value("gracious").equalsIgnoreCase("all")) {
        return (spooler_job.order_queue() != null);
      }
      else
      if (!rc && params.value("gracious") != null &&
      (params.value("gracious").equalsIgnoreCase("yes") || params.value("gracious").equalsIgnoreCase("true") || params.value("gracious").equals("1") ) ) {
        return false;
      }
      else
      if ( !rc ) {
        throw new Exception("check for absence failed for file: " + file);
      }
      else {
        return (spooler_job.order_queue() != null) ? rc : false;
      }
     
    } catch (Exception e) {
      try {
        logger.error("error occurred in JobSchedulerNotExistsFile: " + e.getMessage());
      } catch(Exception x) {}
     
      return false;
    }
  }
 
 
  /**
   * Implementierung f�r Spooler API. Wird beim Entladen aufgerufen und
   * schlie�t die Datenbankverbindung.
   */
  public void spooler_exit() {
   
    try {
     
    } catch (Exception e) {
      // no error processing at job level
    } finally {
    }
  }
}
TOP

Related Classes of sos.scheduler.file.JobSchedulerNotExistsFile

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.