|
i-net Clear Reports | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.inet.report.schedule.ScheduleTask
public class ScheduleTask
An object of this class defines a task - running a report on a specific date or on multiple dates and performing a certain action if the rendering process of the report has been finished successfully.
addReport.addAction.ScheduleExecutionFactory.
We wish to create a task called "My First Task", which, starting on April 15th, 2005, executes the report
"myReport.rpt" as well as exporting it to PS format and and send the exported PostScript file per email to
myself@nosuchhost.com. It is to do this every 4 days at 1:12 p.m.
Here is the code for accomplishing this:
// We start by getting a scheduler object:
Scheduler scheduler = Scheduler.getInstance();
// We then create a task by the name "My First Task" and add it to the scheduler:
ScheduleTask task = scheduler.addTask( "My First Task" );
//Now we define a report to be executed with this task
//To do this, we create a properties object for the report we want to add
Properties properties=new Properties();
//each report defined for a task at least needs the property "report"
properties.put("report","myReport.rpt");
//Now we add a new report to our task with the properties we set
ScheduleReport report=task.addReport("My First Report",properties);
//Now we specify that we want the report to be rendered with export format "ps"
report.addProperty("export_fmt","ps"); //use property "export_fmt" to specify export format
//We now define the action which should be executed after the task has finished
EmailAction emailAction = new EmailAction();
emailAction.setTo("myself@nosuchhost.com");
emailAction.setSubject("Some kind of subject line.");
emailAction.setMessage("This is the body text of the email which will be sent at report creation.");
emailAction.setAttachReport(true);
//...then add the action to the task
task.addAction(emailAction);
// We now set the execution time details of the task - starting on April 15th, every 4 days, at 1:12p.m.
task.setExecutionTime(ScheduleExecutionFactory.createDaily(new Date(2005,4,15),4,13,12);
// Now we tell the scheduler to start its service.
scheduler.start();
We wish to create a task called "My Second Task", which, starting on April 8th, 2005, executes the report
"myReport.rpt" as well as exporting it to PDF format and emailing the exported PDF file to
myself@nosuchhost.com. It is to do this every Monday and Friday at 8 a.m. and 6 p.m.
Here is the code for accomplishing this:
// We start by getting a scheduler object:
Scheduler scheduler = Scheduler.getInstance();
// We then create a task by the name "My Second Task" and add it to the scheduler:
ScheduleTask task = scheduler.addTask( "My Second Task" );
//Now we define a report to be executed with this task
//To do this, we create a properties object for the report we want to add
Properties properties=new Properties();
//each report defined for a task at least needs the property "report"
properties.put("report","myReport.rpt");
//Now we add a new report to our task with the properties we set
ScheduleReport report=task.addReport("My Second Report",properties);
//Now we specify that we want the report to be rendered with export format "pdf"
report.addProperty("export_fmt","pdf"); //use property "export_fmt" to specify export format
//We now define the action which should be executed after the task has finished
EmailAction emailAction = new EmailAction();
emailAction.setTo("myself@nosuchhost.com");
emailAction.setSubject("Some kind of subject line.");
emailAction.setMessage("This is the body text of the email which will be sent at report creation.");
emailAction.setAttachReport(true);
//...then add the action to the task
task.addAction(emailAction);
// We now set the task's execution time details - starting on April 8th, 2005, every 2 weeks, on
// Monday and Wednesday, from 8am to 6pm every 10 hours.
task.setExecutionTime(ScheduleExecutionFactory.createWeekly(new Date(2005,4,8),2,
new int[] {ScheduleExecution.MONDAY, ScheduleExecution.WEDNESDAY},8,18,10,0));
// Now we tell the scheduler to start its service.
scheduler.start();
We wish to create a task called "My Third Task", which, starting on April 8th, 2005, executes the report
"myReport.rpt" as well as exporting it to Excel format and and emailing the exported Excel file to
myself@nosuchhost.com.. It is to do this on every 8th and 23rd day of every month, at 2, 4, 6, and 8 p.m.
Here is the code for accomplishing this:
// We start by getting a scheduler object:
Scheduler scheduler = Scheduler.getInstance();
// We then create a task by the name "My Third Task" and add it to the scheduler:
ScheduleTask task = scheduler.addTask( "My Third Task" );
//Now we define a report to be executed with this task
//To do this, we create a properties object for the report we want to add
Properties properties=new Properties();
//each report defined for a task at least needs the property "report"
properties.put("report","myReport.rpt");
//Now we add a new report to our task with the properties we set
ScheduleReport report=task.addReport("My Third Report",properties);
//Now we specify that we want the report to be rendered with export format "xls"
report.addProperty("export_fmt","xls"); //use property "export_fmt" to specify export format
//We now define the action which should be executed after the task has finished
EmailAction emailAction = new EmailAction();
emailAction.setTo("myself@nosuchhost.com");
emailAction.setSubject("Some kind of subject line.");
emailAction.setMessage("This is the body text of the email which will be sent at report creation.");
emailAction.setAttachReport(true);
//...then add the action to the task
task.addAction(emailAction);
// We now set the task's execution time details - starting on April 8th, 2005, every month, on
// the 8th and 23rd day, at 2, 4, 6, and 8pm.
task.setExecutionTime(ScheduleExecutionFactory.createMonthly(new Date(2005,4,8), new int[]{0,1,2,3,4,5,6,7,8,9,10,11},
new int[] {8,23},14,20,2,0));
// Now we tell the scheduler to start its service.
scheduler.start();
We wish to create a task called "My Fourth Task", which, on May 31st, 2005, executes the report "myReport.rpt" as
well as exporting it to plain text format and and emailing the exported text file to myself@nosuchhost.com.. It
is to do this only on this one day, at 2:12, 3:12, 4:12, and 5:12 p.m.
Here is the code for accomplishing this:
// We start by getting a scheduler object:
Scheduler scheduler = Scheduler.getInstance();
// We then create a task by the name "My Fourth Task" and add it to the scheduler:
ScheduleTask task = scheduler.addTask( "My Fourth Task" );
//Now we define a report to be executed with this task
//To do this, we create a properties object for the report we want to add
Properties properties=new Properties();
//each report defined for a task at least needs the property "report"
properties.put("report","myReport.rpt");
//Now we add a new report to our task with the properties we set
ScheduleReport report=task.addReport("My Fourth Report",properties);
//Now we specify that we want the report to be rendered with export format "txt"
report.addProperty("export_fmt","txt"); //use property "export_fmt" to specify export format
//We now define the action which should be executed after the task has finished
EmailAction emailAction = new EmailAction();
emailAction.setTo("myself@nosuchhost.com");
emailAction.setSubject("Some kind of subject line.");
emailAction.setMessage("This is the body text of the email which will be sent at report creation.");
emailAction.setAttachReport(true);
//...then add the action to the task
task.addAction(emailAction);
// We now set the task's execution time details - only on May 31st, 2005, at 2:12,3:12,4:12, and 5:12 p.m.
task.setExecutionTime(ScheduleExecutionFactory.createOneDayExecution(new Date(2005,5,31),14,17,1,12));// Now, we can set the task's start date - May 31st, 2005
// Now we tell the scheduler to start its service.
scheduler.start();
| Nested Class Summary | |
|---|---|
static class |
ScheduleTask.LastGeneratedReportInstance
Contains information about a report that has been rendered and it's files. |
| Field Summary | |
|---|---|
static int |
STATUS_EXECUTING
This status means that this task is in execution. |
static int |
STATUS_SCHEDULED
This status means that the execution of this task has already been scheduled. |
static int |
STATUS_UNSCHEDULED
This status means that this task has not been scheduled for execution. |
static int |
STATUS_WAITING_FOR_EXECUTION
This status means that this task should have been executed now but that there are currently too much other tasks in execution. |
| Method Summary | |
|---|---|
void |
addAction(ScheduleAction action)
Adds this action to the task. |
void |
addExecutionError(java.lang.String source,
java.lang.String message)
Adds an error message for the current execution of this task. |
ScheduleReport |
addReport(java.lang.String scheduleName,
java.util.Properties properties)
Returns a report that is associated with this task using the name supplied and initialized using the supplied properties. |
boolean |
containsReport(java.lang.String scheduleName)
Returns whether a report by that name is associated with this task. |
ScheduleAction |
getAction(int index)
Returns the ScheduleAction associated with the specified index. |
ScheduleAction |
getAction(java.lang.String className)
Returns the ScheduleAction with the specified class name. |
int |
getActionCount()
Returns the number of ScheduleAction associated with this task. |
java.lang.String |
getDescription()
Returns the description for this task. |
java.lang.String[] |
getErrorMessage()
Returns an error message if start and end date are in an illegal configuration. |
java.lang.String[] |
getExecutionErrors()
Returns an array of messages of the last execution of this task. |
ExecutionTimeProvider |
getExecutionTime()
Returns this task's ScheduleExecution object, which contains start date, interval type, etc. information |
java.lang.Integer |
getId()
Returns the unique id identifying this task. |
java.util.Date |
getLastRun()
Returns the date of the last run. |
java.lang.String |
getName()
Returns the name identifying this task uniquely. |
java.util.Date |
getNextStart()
Returns the date of the next execution of this task, depending on the date of the last run. |
ScheduleReport |
getReport(int index)
Returns the report at a certain index. |
ScheduleReport |
getReport(java.lang.String scheduleName)
Allows you to retrieve a report using the name that was supplied when creating/adding the report. |
int |
getReportCount()
Tells you how many reports are associated with this task. |
boolean |
isDeleteIfExpired()
Returns if the task will be removed from the i-net Scheduler if it is expired, which means that there are no more execution dates for this task. |
boolean |
isEnabled()
Checks if this task is currently enabled. |
boolean |
isValid()
Checks whether this task is valid. |
void |
markForExecution()
This will mark this task to be executed shortly. |
ScheduleAction |
removeAction(int idx)
Removes the ScheduleAction with the specified index from this task. |
ScheduleAction |
removeAction(ScheduleAction action)
Removes the specified ScheduleAction from this task. |
void |
removeReport(java.lang.String scheduleName)
Removes the report by the specified name from this task. |
void |
setDeleteIfExpired(boolean deleteIfExpired)
Sets whether the task should be removed from the i-net Scheduler if it is expired or not. |
void |
setDescription(java.lang.String description)
Use this method to set the description of the task. |
void |
setEnabled(boolean enabled)
Enables or disables this task. |
void |
setExecutionTime(ExecutionTimeProvider executionTime)
Sets this task's ScheduleExecution object - to create a ScheduleExecution, please use ScheduleExecutionFactory's factory methods. |
void |
setName(java.lang.String taskName)
Sets the name of this task. |
java.lang.String |
toString()
Returns a string representation of this ScheduleTask containing its name and description if available. |
| Field Detail |
|---|
public static final int STATUS_EXECUTING
public static final int STATUS_WAITING_FOR_EXECUTION
Scheduler.PROPERTY_MAX_WORKER.
public static final int STATUS_SCHEDULED
public static final int STATUS_UNSCHEDULED
| Method Detail |
|---|
public java.lang.String getDescription()
setDescription(String)public void setDescription(java.lang.String description)
description - A description of the task.getDescription()public java.lang.String getName()
public java.lang.Integer getId()
public java.lang.String[] getErrorMessage()
public boolean isValid()
true if the task is valid, otherwise false.public boolean isEnabled()
true if the task can be executed, false if the task is "sleeping".setEnabled(boolean)public void setEnabled(boolean enabled)
enabled - If true this task will be enabled and executed at the configured time. If
false this task will be disabled and will not be executed. The task is "sleeping".isEnabled()public int getReportCount()
getReport(int),
getReport(String),
containsReport(String),
addReport(String, Properties),
removeReport(String)public ScheduleReport getReport(int index)
index - The index of the report you want to be returned from the list.
getReportCount(),
getReport(String),
addReport(String, Properties),
containsReport(String),
removeReport(String)public ScheduleReport getReport(java.lang.String scheduleName)
scheduleName - The name of the report which should be returned.
getReportCount(),
getReport(int),
containsReport(String),
addReport(String, Properties),
removeReport(String)public boolean containsReport(java.lang.String scheduleName)
scheduleName - The name of the report which should be find.
True if there is a report defined for this task with the given scheduleName, otherwise
false.addReport(String, Properties),
getReport(int),
getReport(String),
getReportCount(),
removeReport(String)
public ScheduleReport addReport(java.lang.String scheduleName,
java.util.Properties properties)
throws ScheduleException
scheduleName - A name for the report which should be added to the task.properties - A properties object containing at least the property "report".
ScheduleException - getReport(int),
getReport(String),
getReportCount(),
containsReport(String),
removeReport(String)public void removeReport(java.lang.String scheduleName)
scheduleName - The name of the report which should be removed.containsReport(String),
getReportCount(),
getReport(int),
getReport(String),
addReport(String, Properties)public ScheduleAction removeAction(int idx)
idx - The index of the action which should be removed.
removeAction(ScheduleAction),
getActionCount(),
getAction(int),
getAction(String),
addAction(ScheduleAction)
public void addAction(ScheduleAction action)
throws ScheduleException
Scheduler.addCustomAction(String, String, String) then you
should be sure that this class is in class path when the i-net Scheduler is loaded. Otherwise the class can not
be found.
action - The action object which should be added to this task.
ScheduleException - CacheAction but you don not have hard disk cache or database cache enabled for
i-net Clear Reports. (SE0025)getAction(int),
getAction(String),
getActionCount(),
removeAction(int),
removeAction(ScheduleAction)public int getActionCount()
getAction(int),
getAction(String),
addAction(ScheduleAction),
removeAction(int),
removeAction(ScheduleAction)public ScheduleAction getAction(int index)
index - The index of the action to retrieve from the list-
getActionCount(),
getAction(String),
addAction(ScheduleAction),
removeAction(int),
removeAction(ScheduleAction)public ScheduleAction getAction(java.lang.String className)
className - The class name of the action which should be returned.
null.getAction(int),
getActionCount(),
addAction(ScheduleAction),
removeAction(int),
removeAction(ScheduleAction)public ScheduleAction removeAction(ScheduleAction action)
action - The action which should be removed from the task.
null if the action was not defined for this task.removeAction(int),
getActionCount(),
getAction(int),
getAction(String),
addAction(ScheduleAction)public java.util.Date getNextStart()
public ExecutionTimeProvider getExecutionTime()
public final void setExecutionTime(ExecutionTimeProvider executionTime)
executionTime - The ScheduleExecution object
public void setName(java.lang.String taskName)
throws ScheduleException
taskName - the name of the task
ScheduleException - if an other task with the given name already exists (SE0002).public java.lang.String toString()
toString in class java.lang.Objectpublic boolean isDeleteIfExpired()
True if the task will be removed, otherwise false.setDeleteIfExpired(boolean)public void setDeleteIfExpired(boolean deleteIfExpired)
deleteIfExpired - True if the task should be removed, otherwise false.isDeleteIfExpired()
public void addExecutionError(java.lang.String source,
java.lang.String message)
source - The name of the source where the error occurred. Here you should specify the name of your custom
action class.message - The message text of the error which occurred.public java.util.Date getLastRun()
public java.lang.String[] getExecutionErrors()
1 will be returned containing the string of the last execution date. If there are more
messages then these describe errors occurred during the last execution.
public void markForExecution()
STATUS_WAITING_FOR_EXECUTION. Shortly means that the task will not be executed immediately. If there are
not more than Scheduler.PROPERTY_MAX_WORKER task currently running this execution of this task will be
started within the next 10 seconds. This call will have no effect if the task is currently executing or already
in the queue of waiting tasks. (That means that the status of the task is either
STATUS_EXECUTING or STATUS_WAITING_FOR_EXECUTION.
|
i-net Clear Reports | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||