mn8 Language Reference | Index    

Timer

SUMMARY: NO ATTRIBUTES  ELEMENTS SUMMARY  NO CONSTRUCTORS  NO OPERATORS  METHODS SUMMARYDETAIL: NO ATTRIBUTES  ELEMENT DETAILS  NO CONSTRUCTORS  NO OPERATORS  METHOD DETAILS

Description

With this concept can you schedule and execute periodically your jobs. The timer task having an offset (miliseconds when you want to start the task) and a period parameter (milliseconds between the task executions).

Usage

      # The timer is Singleton, you have only one instance on your terminal
      $y=Timer.getInstance

      # Starting after 10 sec (from after the mn8 script init.)
      # and every 30 sec will execute the "Google ..." script
      Timer.addTask(10000, 30000, "Google rsearch Antal Attila atech")

      # Starting after 1 min (from after the mn8 script init.)
      # and every 10 min will execute the method onlytest from the
      # Test concept with parameter "Helo World!"
      $ser typeof Series
      $ser.add("Helo World")
      Timer.addTask(60000, 600000, "Test.onlytest", $ser)

      # looking after my timer tasks
      print $y.toXML

      # getting the tasks into the series
      $tasks = Timer.getTasks

      # Ugly task with id=1, I remove it
      Timer.removeTask(1)

      # How many tasks I have?
      print "" + Timer.getTasks@length

      # Be happy I starting the scheduler
      Timer.start

      # The system is hanging up and holds the scheduler to work
      System.pause(0)

      # Is something working bad or need to shut down the scheduler
      Timer.stop

Version: 0.1
Authors:Antal Attila ()
Location:

Element List

 task TYPEOF Series LABEL "task"
top

Method List

static IntegeraddTask (Integer $offs, Integer $period, String $target)
static IntegeraddTask (Integer $offs, Integer $period, String $target, Series $params)
static TimergetInstance
static SeriesgetTasks
static removeTask (Integer $taskId)
static start
static stop
top

Detailed Element Info

task

Label:task
Type:Series
Is Static:false
Is Hidden:false
Is Multi:false
Show Empty:true

Task element to hold informations with its attributes

top

Detailed Method Info

static addTask (Integer $offs, Integer $period, String $target)
Parameters:
$offs :The offset value
$period :The periods value
$target :Execution string in order by ConceptName followed by it self attributes
Returns: Integer
Exceptions:
errorAddingTask :
(Error)
If unable to add task to the Timer concept.

Adding task into your tasks.

    Timer.addTask(10000, 60000, "Google rsearch regexp syntax flags")

    # This will execute the "Google rsearch ..." command every
    #  minute starting on 10 sec after system init
    

top
static addTask (Integer $offs, Integer $period, String $target, Series $params)
Parameters:
$offs :The offset value
$period :The periods value
$target :Execution string like an mn8 static method call, Concept.method
$params :A series for method parameters
Returns: Integer
Exceptions:
errorAddingTask :
(Error)
If unable to add task to the Timer concept.

Adding task into your tasks.

    $ser typeod Series
    $ser.add("Hello World")
    Timer.addTask(10000, 60000, "Echo.echoString", $ser)

    # This will execute the "Echo echoString" command with
    # a "Hello World" parameter, every min starting 10 sec after
    # system ini
    

top
static getInstance
Returns: Timer

The timer concept is Singleton, with this method you can get an instance.

    Timer.addTask(60000, 600000, "Google rsearch regexp syntax flags")
    Timer.getInstance
    -- the result is --
    Timer
    tasks
    task
        id: 1   offset:60000  period:600000    CommandString: Google rsearch regexp syntax flags
    

top
static getTasks
Returns: Series

Returns all the tasks.

    Timer.addTask(60000, 600000, "Google rsearch regexp syntax flags")
    Timer.addTask(10000, 600000, "Test.testmethod", $ser)
    Timer.getTasks
    -- the result is --
    task
        id: 1   offset: 60000    period: 600000   CommandString: Google rsearch regexp syntax flags
    task
        id: 2   offset: 10000    period: 600000   CommandString: Test.testmethod
    

top
static removeTask (Integer $taskId)
Parameters:
$taskId :Task id, what returns the addTask method
Returns:

Remove the specified task.

    Timer.addTask(10000, 600000, "Google rsearch regexp syntax flags")
    Timer.addTask(1, 3600000, "Google rsearch Gnome 2.0 distribution")
    Time.removeTask(1)
    Timer.getTasks
    -- the result is --
    task
        id: 2   offset: 1   period: 3600000      CommandString: Google rsearch Gnome 2.0 distribution
    

top
static start
Returns:
Exceptions:
onStartException :
(Error)
If the scheduler can't be started.

Starting the scheduler.

    Timer.addTask(10000, 600000, "Google rsearch regexp syntax flags")
    Timer.addTask(1, 3600000, "Google rsearch Gnome 2.0 distribution")
    Timer.start
    

top
static stop
Returns:

Stops the scheduler.

    Timer.stop
    

top