com.alarexgroup.m2mplf.adapters.schedule
Class ScheduleAdapter

java.lang.Object
  extended by com.alarexgroup.m2mplf.adapters.schedule.ScheduleAdapter
public class ScheduleAdapter
extends java.lang.Object

Adapter serves as automatic task dispatcher on scheduled times.

Example:

import com.alarexgroup.m2mplf.M2Mlet;
import com.alarexgroup.m2mplf.adapters.schedule.ScheduleAdapter;
import com.alarexgroup.m2mplf.adapters.schedule.ScheduleAdapterListener;
import com.alarexgroup.m2mplf.adapters.schedule.Task;
import com.alarexgroup.m2mplf.logging.Logger;
import com.alarexgroup.m2mplf.util.DateTime;


public class ScheduleExample extends M2Mlet implements ScheduleAdapterListener{
    ScheduleAdapter schedule;
    
    public ScheduleExample() {
    }

  

    public void appStart() {
        ScheduleAdapter.getScheduleAdapter(this);
        //periodic task
        schedule.scheduleTask("period",1,0,30000);
        //Specified timed task - alarm
        //24.3.2007 v 16:00
        schedule.scheduleTask("alarm",2,new DateTime(24,3,2007,16,00,00,00));
    }

  
    public void onShedulerEvent(Task task) {
        //event from ScheduleAdapter
        //Determine what kind of event it is
        switch (task.getId()){
            case 
                //period
                //here you do what you need
                Logger.logInfo(Periodic task running);
                break;
            case :
                //alarm
                //response to alarm
                Logger.logInfo(Alarm task running);
                break;
        }
    }

    public void appStop(boolean unconditional) {
    }
   
    public void appPause() {
    }
    
    
}

Constructor Summary
ScheduleAdapter()
           
 
Method Summary
static ScheduleAdapter getScheduleAdapter(ScheduleAdapterListener listener)
          Method returns active instance of this adapter
 void scheduleTask(java.lang.String taskName, int taskId, DateTime startTime)
          Runs the task on scheduled time
 void scheduleTask(java.lang.String taskName, int taskId, int numberOfOccurrences, long period)
          Running task with period
 void unScheduleTask(int id)
          Cancel specified task
 void unScheduleTask(java.lang.String taskName)
          Cancel specified task
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScheduleAdapter

public ScheduleAdapter()
Method Detail

getScheduleAdapter

public static ScheduleAdapter getScheduleAdapter(ScheduleAdapterListener listener)
Method returns active instance of this adapter

Parameters:
listener - listener
Returns:
instance of adapteru

scheduleTask

public void scheduleTask(java.lang.String taskName,
                         int taskId,
                         int numberOfOccurrences,
                         long period)
Running task with period

Parameters:
taskId - numeric task identificator
taskName - text task identificator
numberOfOccurrences - how many times the task should be run. 0 means infinite
period - period in miliseconds
See Also:
ScheduleAdapter, ScheduleAdapterListener

scheduleTask

public void scheduleTask(java.lang.String taskName,
                         int taskId,
                         DateTime startTime)
Runs the task on scheduled time

Parameters:
taskName - text task identificator
taskId - numeric task identificator
startTime - time on which the task is scheduled. Time is DateTime format

unScheduleTask

public void unScheduleTask(java.lang.String taskName)
Cancel specified task

Parameters:
taskName - text task identificator

unScheduleTask

public void unScheduleTask(int id)
Cancel specified task

Parameters:
id - numeric task identificator