Show TOC Start of Content Area

Background documentation Excluding Scheduled Job Executions from a Scheduler Task  Locate the document in its SAP Library structure

This section outlines the attributes and the use of the Filter class and shows how you can create and apply a filters to a scheduler task.

Filters

The Filter class has two attributes - start time and end time - which specify the boundaries of a time frame.

You use Filter objects in a scheduler task to instruct the NetWeaver Scheduler for Java not to execute the jobs that fall into the specified time frame. For example, you can instruct the scheduler not to run a particular job on holidays.

Note

In this document, the term filter and Filter object are used in the sense of a time frame within which the Scheduler is instructed not to execute instances of a job definition scheduled by a scheduler task.

A filter is bound to a scheduler task, not to a particular RecurringEntry or CronEntry in a scheduler task. Conversely, a filter applies to the whole task, not to the individual RecurringEntry and/ or CronEntry objects in it. In effect, in a scheduler task containing multiple RecurringEntry and/ or CronEntry objects, you cannot filter out the job executions of just one of those RecurringEntry and/ or CronEntry objects

You can apply multiple filters to the same scheduler task. To apply the same filter to all scheduler tasks, and thus instruct the scheduler not to execute any tasks at all within the time frame, you have to add the same Filter object to each scheduler task individually.

Applying Filter

You can apply filters by using both constructors that the Scheduler API offers for creating a scheduler task.

The constructor from the snippet below does not contain a Filter object as its attribute.

SchedulerTask(SchedulerTaskID taskId, JobDefinitionID jobDefinitionId, JobParameter[] jobParameters, RecurringEntry[] recs, CronEntry[] crons)

When you use this constructor, you apply filters to the scheduler task by using the addFilters(SchedulerTaskID id, Filter[] f)or the setFilters(SchedulerTaskID id, Filter[] f) methods. addFilters ()adds a filter to the filters already added to the task. setFilters ()removes the current filters from the task and applies the filters you pass as arguments of the method.

 

The constructor from the snippet below contains a Filter object as its attribute.

SchedulerTask(SchedulerTaskID taskId, JobDefinitionID jobDefinitionId, JobParameter[] jobParameters, RecurringEntry[] recs, CronEntry[] crons, Filter[] filters, int retentionPeriod)

When using this constructor, you can also add or set Filter objects to the task. Since both addFilters ()and setFilters () methods take a SchedulerTaskID as an argument, you call these methods after you have created the SchedulerTask object and its ID.

 

The following snippet shows how you can create and add filters to a scheduler task.

The scheduler task contains a RecurringEntryobject that defines a start time and a period for the recurrence of jobs.

//Create Calendar instance for RecurringEntry start time

java.util.Calendar calendar = java.util.Calendar.getInstance();

calendar.setYear (...)

...           

java.util.Date recEntryStartTime = calendar.getDate();

 

//Create SchedulerTime for the RecurringEntry start time

SchedulerTime startTime = new SchedulerTime(recEntryStartTime, TimeZone.getDefault());

 

//Create Calendar instances for the start time and the end time of Filter1

java.util.Calendar calendar = java.util.Calendar.getInstance();

...           

java.util.Date filter1StartTime = calendar.getDate();

 

java.util.Calendar calendar = java.util.Calendar.getInstance();

...           

java.util.Date filter1EndTime = calendar.getDate();

//Create Calendar instances for the start time and the end time of Filter2

        //...

//Create SchedulerTime objects for the start time and the end time of Filter1

SchedulerTime recEntryFilterStartTime = new SchedulerTime(filterStartTime, TimeZone.getDefault());

SchedulerTime recEntryFilterEndTime = new SchedulerTime(filterEndTime, TimeZone.getDefault());

//Create SchedulerTime objects for the start time and the end time of Filter2

        //...

 

//Create Filter1

Filter myFilter1 = new Filter (recEntryFilterStartTime, recEntryFilterEndTime);

//Create Filter2

        //...

 

//Create recurring entry

RecurringEntry myEntry = new RecurringEntry (startTime, (long) 24*3600*1000)

 

//Create SchedulerTask

SchedulerTask task = new SchedulerTask(

      SchedulerTaskID id = new SchedulerTask.newID,

      helloWorldJobDef.getJobDefinitionId(),

      new JobParameter[],

      new RecurringEntry[] {myEntry},

      new CronEntry[] {}

      new Filter [] {myFilter1}

      new retentionPeriod (-2))

 

//Add Filter2

scheduler.addFilters (id, [] myFilter2)

 

//Schedule the task

scheduler.schedule(task);

 

 

End of Content Area