psdi.server

Class SimpleCronTask

  • java.lang.Object
    • psdi.server.SimpleCronTask
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      protected int dbSeed
      Seed for a task in the database
      protected long interval
      This is the interval specified in properties file
      protected boolean intervalFlag
      If interval is specified in properties file then flag is true
      protected long lastRun
      Used to track the time (ms from beginning of the epoch) since the cronAction() was called last.
      protected java.util.Date lastRunDate
      Last run time for a task
      protected int seed
      Seed to make sure only one server runs the task
      protected boolean shutdown
      A boolean set by shutdown() and ready by isShutdown().
      protected long sleepTime
      This is the time that the CronTaskManager will wait between wait between calls to cronAction().
      protected java.util.Vector valV
      vector containg invidual time values
    • Constructor Summary

      Constructors 
      Constructor and Description
      SimpleCronTask() 
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method and Description
      void beforeRemoval()
      Method to implement when there are actions involved when the crontask instance is about to be removed by the crontask manager when the crontask instance is auto removal and it is time to remove it.
      abstract void cronAction()
      This is the CORE METHOD of this class.
      java.lang.String getCronTaskHistoryMsg()
      Get message to be written to CronTaskHistory.
      CrontaskInstanceRemote getCrontaskInstance()
      Return the crontask instance object associated with this crontask object.
      MXLogger getCronTaskLogger()
      Returns a logger to log messages related to this task.
      MXLogger getCronTaskSqlLogger()
      Returns a logger to log SQL messages related to this task.
      int getDBLastSeed()
      Gets the last seed for the server for a task in database
      java.util.Vector getEnteredValueVector()
      Gets the vector containg invidual time values
      long getInterval()
      Returns the interval
      boolean getIntervalFlag()
      Gets flag for interval
      java.util.Date getLastRunDate()
      Gets the last Run Time for a task in database
      int getLastSeed()
      Gets the last seed for the server for a task
      java.lang.String getName()
      Should return the name of this CronTask.
      boolean getParamAsBoolean(java.lang.String parameter)
      It returns the value of the parameter of the instance this crontask object is instantiated for as boolean.
      java.util.Date getParamAsDate(java.lang.String parameter)
      It returns the value of the parameter of the instance this crontask object is instantiated for as date.
      double getParamAsDouble(java.lang.String parameter)
      It returns the value of the parameter of the instance this crontask object is instantiated for as double.
      int getParamAsInt(java.lang.String parameter)
      It returns the value of the parameter of the instance this crontask object is instantiated for as int.
      java.lang.String getParamAsString(java.lang.String parameter)
      It returns the value of the parameter getParameterValidationMbo(CrontaskInstanceRemote for as String.
      MboRemote getParameter(java.lang.String parameter)
      Get the MBO of crontaskparameter for the specified parameter for the instance this crontask object is instantiated for.
      CrontaskParamInfo[] getParameters()
      This method provides an array of CrontaskParamInfo() object to describe all the parameters of the crontask.
      MboRemote getParameterValidationMbo()
      This method can only be called after the crontask is initialized.
      MboRemote getParameterValidationMbo(CrontaskInstanceRemote inst)
      Default implementation.
      UserInfo getRunasUserInfo()
      Return the system user info of the user specified by the runasuserid on crontaskparameter.
      long getSleepTime()
      Gets the time for the server to sleep before the next task
      void init()
      Invoked by the CronTaskManager when the class is instantiated.
      boolean isOKToRun(MXServerRemote server)
      Default implementation of isOKToRun.
      boolean isShutdown()
      Getter for the shutdown variable.
      void setCronTaskHistoryMsg(java.lang.String val)
      Set message to be written to CronTaskHistory.
      void setCrontaskInstance(CrontaskInstanceRemote inst)
      Cache the crontask instance this crontask object is instantiated for.
      void setDBLastSeed(int dbseed)
      Sets the last seed for the server for a task in database
      void setEnteredValueVector(java.util.Vector v)
      Sets the vector containg invidual time values
      void setInterval(long interval)
      Sets the interval specified in properties file
      void setIntervalFlag(boolean flag)
      Sets the flag if interval is specified in properties file
      void setLastRunDate(java.util.Date d)
      Sets the last Run Time for a task in database
      void setLastSeed(int seed)
      Sets the last seed for the server for a task
      void setSleepTime(long time)
      Sets the time for the server to sleep before the next task
      void shutdown()
      Sets the shutdown variable.
      void start()
      Default implementation for start().
      void stop()
      Default implementation for stop().
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • interval

        protected long interval
        This is the interval specified in properties file
      • sleepTime

        protected long sleepTime
        This is the time that the CronTaskManager will wait between wait between calls to cronAction(). Each time a CronTask is invoked, the CronTaskManager waits for the time returned by getSleepTime() (in seconds) before calling cronAction() again.
      • intervalFlag

        protected boolean intervalFlag
        If interval is specified in properties file then flag is true
      • seed

        protected int seed
        Seed to make sure only one server runs the task
      • dbSeed

        protected int dbSeed
        Seed for a task in the database
      • lastRunDate

        protected java.util.Date lastRunDate
        Last run time for a task
      • lastRun

        protected long lastRun
        Used to track the time (ms from beginning of the epoch) since the cronAction() was called last. It is used for deciding when to call the store().
      • shutdown

        protected boolean shutdown
        A boolean set by shutdown() and ready by isShutdown(). Used to indicate to the cronAction() that it should not accept anymore requests for processing.
      • valV

        protected java.util.Vector valV
        vector containg invidual time values
    • Constructor Detail

      • SimpleCronTask

        public SimpleCronTask()
    • Method Detail

      • getParameters

        public CrontaskParamInfo[] getParameters()
                                          throws MXException,
                                                 java.rmi.RemoteException
        Description copied from interface: CronTask
        This method provides an array of CrontaskParamInfo() object to describe all the parameters of the crontask. Parameter name, default values and the description of the parameter should be set to the CrontaskParamInfo object for each parameter. If default value and description is not set, null will be the values.
        Specified by:
        getParameters in interface CronTask
        Returns:
        Throws:
        MXException
        java.rmi.RemoteException
        See Also:
        CrontaskParamInfo
      • isOKToRun

        public boolean isOKToRun(MXServerRemote server)
        Default implementation of isOKToRun. It always returns true.
        Specified by:
        isOKToRun in interface CronTask
        Returns:
        true if it is OK to run, false otherwise.
        See Also:
        psdi.server.CronTask#isOKToRun();
      • getParameterValidationMbo

        public MboRemote getParameterValidationMbo()
                                            throws MXException,
                                                   java.rmi.RemoteException
        This method can only be called after the crontask is initialized. It is one of the overloaded forms.
        Returns:
        Throws:
        MXException
        java.rmi.RemoteException
      • getParameter

        public MboRemote getParameter(java.lang.String parameter)
                               throws MXException,
                                      java.rmi.RemoteException
        Get the MBO of crontaskparameter for the specified parameter for the instance this crontask object is instantiated for.
        Parameters:
        parameter -
        Returns:
        Throws:
        MXException
        java.rmi.RemoteException
      • getParamAsString

        public java.lang.String getParamAsString(java.lang.String parameter)
                                          throws MXException,
                                                 java.rmi.RemoteException
        It returns the value of the parameter getParameterValidationMbo(CrontaskInstanceRemote for as String.
        Parameters:
        parameter -
        Returns:
        The parameter string. If the parameter doesn't exist, it will return null.
        Throws:
        MXException
        java.rmi.RemoteException
      • getParamAsBoolean

        public boolean getParamAsBoolean(java.lang.String parameter)
                                  throws MXException,
                                         java.rmi.RemoteException
        It returns the value of the parameter of the instance this crontask object is instantiated for as boolean. Exception will be thrown if it cannot be interpreted as boolean by MXFormat.
        Parameters:
        parameter -
        Returns:
        Throws:
        MXException
        java.rmi.RemoteException
      • getParamAsInt

        public int getParamAsInt(java.lang.String parameter)
                          throws MXException,
                                 java.rmi.RemoteException
        It returns the value of the parameter of the instance this crontask object is instantiated for as int. Exception will be thrown if it cannot be interpreted as int by MXFormat.
        Parameters:
        parameter -
        Returns:
        Throws:
        MXException
        java.rmi.RemoteException
      • getParamAsDouble

        public double getParamAsDouble(java.lang.String parameter)
                                throws MXException,
                                       java.rmi.RemoteException
        It returns the value of the parameter of the instance this crontask object is instantiated for as double. Exception will be thrown if it cannot be interpreted as double by MXFormat.
        Parameters:
        parameter -
        Returns:
        Throws:
        MXException
        java.rmi.RemoteException
      • getParamAsDate

        public java.util.Date getParamAsDate(java.lang.String parameter)
                                      throws MXException,
                                             java.rmi.RemoteException
        It returns the value of the parameter of the instance this crontask object is instantiated for as date. Exception will be thrown if it cannot be interpreted as date by MXFormat.
        Parameters:
        parameter -
        Returns:
        Throws:
        MXException
        java.rmi.RemoteException
      • getInterval

        public long getInterval()
        Returns the interval
      • setInterval

        public void setInterval(long interval)
        Sets the interval specified in properties file
      • setSleepTime

        public void setSleepTime(long time)
        Sets the time for the server to sleep before the next task
        Specified by:
        setSleepTime in interface CronTask
      • getSleepTime

        public long getSleepTime()
        Gets the time for the server to sleep before the next task
        Specified by:
        getSleepTime in interface CronTask
      • setIntervalFlag

        public void setIntervalFlag(boolean flag)
        Sets the flag if interval is specified in properties file
      • getIntervalFlag

        public boolean getIntervalFlag()
        Gets flag for interval
      • setLastSeed

        public void setLastSeed(int seed)
        Sets the last seed for the server for a task
        Specified by:
        setLastSeed in interface CronTask
      • getLastSeed

        public int getLastSeed()
        Gets the last seed for the server for a task
        Specified by:
        getLastSeed in interface CronTask
      • setDBLastSeed

        public void setDBLastSeed(int dbseed)
        Sets the last seed for the server for a task in database
        Specified by:
        setDBLastSeed in interface CronTask
      • getDBLastSeed

        public int getDBLastSeed()
        Gets the last seed for the server for a task in database
        Specified by:
        getDBLastSeed in interface CronTask
      • setLastRunDate

        public void setLastRunDate(java.util.Date d)
        Sets the last Run Time for a task in database
        Specified by:
        setLastRunDate in interface CronTask
      • getLastRunDate

        public java.util.Date getLastRunDate()
        Gets the last Run Time for a task in database
        Specified by:
        getLastRunDate in interface CronTask
      • setEnteredValueVector

        public void setEnteredValueVector(java.util.Vector v)
        Sets the vector containg invidual time values
        Specified by:
        setEnteredValueVector in interface CronTask
      • getEnteredValueVector

        public java.util.Vector getEnteredValueVector()
        Gets the vector containg invidual time values
        Specified by:
        getEnteredValueVector in interface CronTask
      • cronAction

        public abstract void cronAction()
                                 throws java.lang.Exception
        This is the CORE METHOD of this class. You should invoke whatever logic you want your CronTask to perform from this method. This method should
        1. check the shutdown variable before invoking any processing logic.
        2. call resetErrorCount() if processing proceeds w/out error.
        3. call incErrorCount() if a serious error occurs during the processing logic.
        Specified by:
        cronAction in interface CronTask
        Throws:
        java.lang.Exception
      • shutdown

        public void shutdown()
        Sets the shutdown variable. The cronAction() method should check the shutdown variable and stop processing once shutdown == true.
        Specified by:
        shutdown in interface CronTask
      • isShutdown

        public boolean isShutdown()
        Getter for the shutdown variable.
        Specified by:
        isShutdown in interface CronTask
      • getName

        public java.lang.String getName()
        Should return the name of this CronTask. Note: you should limit yourself to returning "file name friendly" characters, e.g. no '!', '.' or spaces, etc. because the sring returned is used to create a file name by the store() method.
      • setCronTaskHistoryMsg

        public void setCronTaskHistoryMsg(java.lang.String val)
        Set message to be written to CronTaskHistory. If the cron task is flagged for history to be written, then if an error is thrown to CronTaskManager it will be included in history; otherwise if a history message has been set on the cron task, then it will be written to history.
        Specified by:
        setCronTaskHistoryMsg in interface CronTask
      • getCronTaskLogger

        public MXLogger getCronTaskLogger()
        Returns a logger to log messages related to this task.
        Returns:
        MXLogger a logger to log messages related to this task.
      • getCronTaskSqlLogger

        public MXLogger getCronTaskSqlLogger()
        Returns a logger to log SQL messages related to this task.
        Returns:
        MXLogger a logger to log SQL messages related to this task.
      • getRunasUserInfo

        public final UserInfo getRunasUserInfo()
        Return the system user info of the user specified by the runasuserid on crontaskparameter. The user info is not cached. Everytime when this method is called, it will get a new UserInfo. If you want the crontask only to get a new user info when it is reloaded, you need to cache it in start().
        Returns:
        See Also:
        #runAsUserInfo
      • start

        public void start()
        Default implementation for start(). It does nothing.
        Specified by:
        start in interface CronTask
        See Also:
        CronTask.stop(), startup()
      • stop

        public void stop()
        Default implementation for stop(). It does nothing.
        Specified by:
        stop in interface CronTask
      • beforeRemoval

        public void beforeRemoval()
                           throws MXException,
                                  java.rmi.RemoteException
        Description copied from interface: CronTask
        Method to implement when there are actions involved when the crontask instance is about to be removed by the crontask manager when the crontask instance is auto removal and it is time to remove it. Method is called right before the crontask instance and parameters are marked for deletion. The DB operations implemented in this method will be in the same transaction as deleting the crontask instance.
        Specified by:
        beforeRemoval in interface CronTask
        Throws:
        MXException
        java.rmi.RemoteException