Job Scheduling From Web Dynpro Java For CE 7.1 Using Java Scheduler API and EJB3.0
Job Scheduling From Web Dynpro Java For CE 7.1 Using Java Scheduler API and EJB3.0
Applies to:
SAP NetWeaver 7.1, Web Dynpro for java, JEE 5, Java Scheduler. For more information, visit the User
Interface Technology homepage.
Summary
A new job scheduler is now available as part of the SAP NetWeaver Application Server, Java EE 5 Edition.
Using EJB 3.0 job is implemented as Message-Driven Bean (MDB), which is invoked using Java Message
Service (JMS) technology.
Using scheduler API we can create tasks and set the job parameters through Web Dynpro.
Author:
Snehal Kendre
Author Bio
Snehal Kendre is an Web Dynpro consultant at L&T Infotech.
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
Table of Contents
Getting started ....................................................................................................................................................3
Scenario ..........................................................................................................................................................3
Creating an EJB 3.0 project................................................................................................................................3
Developing Job Bean class.............................................................................................................................5
Deploy EAR application project. .....................................................................................................................8
See The Job Definition in Java scheduler ....................................................................................................................8
Related Content................................................................................................................................................15
Disclaimer and Liability Notice..........................................................................................................................16
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
Getting started
Here we are going to create an EJB 3.0 project that includes a job bean.
The scheduler runtime service provides certain basic services to the job implementation. That is why, the
JobBean class cannot implement the onMessage() method, which is the standard business method of
message-driven beans. JobBeans have a single business method, the onJob() method. In the JobBean
class, you must provide an implementation of the onJob() method. The JobBean inherits from an
MDBJobImplementation base class which itself provides an implementation of the onMessage() method.
To set the job parameters and schedule we will create a Web Dynpro project
Scenario
We will create a job using job beans which is nothing but a message-driven bean inherited
from an MDBJobImplementation base class.
A web Dynpro project will provide basic functionality to schedule a job and to set the job parameters.
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
import com.sap.scheduler.runtime.JobContext;
import com.sap.scheduler.runtime.JobParameter;
import com.sap.scheduler.runtime.mdb.MDBJobImplementation;
import javax.ejb.MessageDriven;
import javax.ejb.ActivationConfigProperty;
/**
* @author Snehal Kendre
*
*/
@MessageDriven(
//TODO The JMS destination name (mapped name) must correspond to the resource name in the jmsresources.xml
name="JobBean", mappedName="MyDestination",
activationConfig={@ActivationConfigProperty(
propertyName="messageSelector",
propertyValue="JobDefinition='Schedule_JobBean'"),@ActivationConfigProperty(propertyName="de
stinationType", propertyValue="javax.jms.Queue")})
public class JobBean extends MDBJobImplementation implements MessageListener {
/* (non-Javadoc)
* @see
com.sap.scheduler.runtime.mdb.MDBJobImplementation#onJob(com.sap.scheduler.runtime.JobContext)
*/
@Override
public void onJob(JobContext arg0) throws Exception {
// TODO Auto-generated method stub
JobParameter parameter = arg0.getJobParameter("User");
Logger logger = arg0.getLogger();
logger.info("Hi"+parameter+"your job is scheduled");
}
}
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
Create an application.
Implementation of SchedulerCompView.
Create a New simple type Months
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
Assign simple type Months to the ctx_va_Month, String type to ctx_va_user and assign Integer to other
context.
Create a form to take inputs from user. For this use apply template.
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
wdComponentAPI.getMessageManager().reportSuccess(syncdef.getDescription());
Job syncjob;
java.util.Calendar calendar = java.util.Calendar.getInstance();
calendar.set(Calendar.YEAR,
wdContext.currentContextElement().getCtx_va_year());
calendar.set(Calendar.MONTH,wdContext.currentContextElement().getCtx_va_Month()-1);
calendar.set(Calendar.DAY_OF_MONTH,
wdContext.currentContextElement().getCtx_va_day());
calendar.set(Calendar.HOUR_OF_DAY,
wdContext.currentContextElement().getCtx_va_hour());
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
calendar.set(Calendar.MINUTE,
wdContext.currentContextElement().getCtx_va_min());
java.util.Date date = calendar.getTime();
wdComponentAPI.getMessageManager().reportSuccess("your task is scheduled
for date="+ date);
//Create SchedulerTime and pass to it the Calendar instance
SchedulerTime time = new SchedulerTime(date, TimeZone.getDefault());
//Create RecurringEntry and pass to it SchedulerTime instance
RecurringEntry re = new RecurringEntry(time);
//Create a SchedulerTask for the HelloJob
// set job paramater
JobParameterDefinition user = syncdef.getParameter("User");
JobParameter userparameter = new
JobParameter(user,wdContext.currentContextElement().getCtx_va_user());
SchedulerTask task = new
SchedulerTask(SchedulerTaskID.newID(),syncdef.getJobDefinitionId(),new JobParameter[]
{userparameter},new RecurringEntry[] {re}, new CronEntry[]
{},"Schedule_Job","scheduled by API");
syncscheduler.schedule(task);
//
task.createSchedulerTask(syncdef.getJobDefinitionId(),parm,recs,crons,filters,23,
"synctaskbywd","wd generated task",null);
//
syncscheduler.schedule(task);
} catch (Exception e) {
// TODO Auto-generated catch block
wdComponentAPI.getMessageManager().reportException("problem in
scheduler",true);
}
//@@end
}
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
Check log
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
Related Content
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/10fed553-0e01-0010-9bb8-ed55659e1236
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e8ab5056-0e01-0010-5581d3e51724ee21
http://help.sap.com/saphelp_nwce10/helpdata/en/44/03d66015ee10b3e10000000a11466f/frameset.htm
For more information, visit the User Interface Technology homepage.
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0