Monday, 30 September 2019

WCS Scheduler

    Scheduler in WebSphere Commerce is a background server which schedules and runs specified jobs both at the site and store level.

There are 2 types of scheduler jobs

Regular Scheduler Jobs: These jobs are like regular WCS commands which get triggered by WCS scheduler and perform a specific task based on our custom implementation and the jobs could be one time run only or can be executed at a regular frequency.

Broadcast Jobs: These jobs run on every single WCS JVM in the cluster at least once. For Example, Refresh registry is one such job that refreshes the registry which resides in WCS JVM on every instance.

Note: All WCS jobs need WCS runtime for their execution and cannot be executed outside of WCS server box or container.

Tables: In terms of datamodel, below are the key tables involved in schedulers
    • SCHCONFIG - Scheduler configuration
    • SCHSTATUS - Scheduler status
    • SCHACTIVE - Scheduler active
    • SCHBRDCST - Scheduler broadcast
    • SCHERRORLOG - Scheduler error log
    • SCHCMD - Scheduler commands store level
    • CHKCMD - Check cmd for a specific scheduler Eg: run only on Friday
Steps to create a custom scheduler job:
  • Define the custom scheduler interface
  • Define the custom scheduler implementation class and implement your custom logic
  • Make struts-config entry
  • Make DB entries to register the new scheduler job in SCHCONFIG & SCHACTIVE tables

//Define the custom scheduler interface
package com.ibm.commerce.samples;
import com.ibm.commerce.command.ControllerCommand;
public interface MyCustomSchedulerCmd extends ControllerCommand {
    public static final String defaultCommandClassName = "com.ibm.commerce.samples.MyCustomSchedulerCmdImpl";
}

//Define the custom scheduler implementation class
package com.ibm.commerce.samples;
import java.util.logging.Logger;
import com.ibm.commerce.command.ControllerCommandImpl;
import com.ibm.commerce.exception.ECException;

public class MyCustomSchedulerCmdImpl extends ControllerCommandImpl implements MyCustomSchedulerCmd {
    Logger logger = Logger.getLogger(MyCustomSchedulerCmdImpl.class.getName());
    public void performExecute() throws ECException {
    //implement custom logic
    logger.info("Hello World from custom scheduler");
    }

//Make following Struts Config entry
<action parameter="com.ibm.commerce.samples.MyCustomSchedulerCmd" path="/MyCustomScheduler" type="com.ibm.commerce.struts.BaseAction">
<set-property property="authenticate" value="0:0"/>
<set-property property="https" value="0:1"/>
</action>

//Make the following DB entries(Oracle DB) to register the new JOB.
  • insert into schconfig sccjobrefnum,scchost,member_id,storeent_id,sccrecdelay,sccrecatt,sccpathinfo,sccquery,sccstart,sccinterval,sccpriority,sccsequence,sccactive,sccapptype,interfacename,optcounter) values ((select Max(sccjobrefnum)+1 FROM schconfig),null, -1000,10051, 100,0,'MyCustomScheduler',null, CURRENT_TIMESTAMP, 100, 5,0,'A',default,'com.ibm.commerce.samples.MyCustomSchedulerCmd',0);
  • insert into schactive (scsinstrefnum,scsjobnbr,scsactlstart,scsattleft,scsend, scsinstrecov,scsprefstart,scsqueue,scsresult,scssequence,scsstate,scspriority,optcounter) values ((select Max(scsinstrefnum)+1 FROM schactive),(select max(sccjobrefnum) FROM schconfig), SYSDATE,1,null,null,CURRENT_TIMESTAMP,null,null,0,'I',default,0);

Java 7 Interview Question's

New Features introduced from  JAVA 7 : 1) Using strings in switch statements 2) Binary values with prefix 0B (Example: int n = 0b1101) 3) In...