Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
themeEclipse
public class CustomJobServiceImpl extends SimpleServiceComponent implements CustomJobService, ConfigurationManagementListener {
   // The scheduler service, injected by the framework
   private SchedulerService mySchedulerService = null;

   // Name of the job
   private static String JOBNAME = WCBConstants.WCB_ID + “scheduled job”;

   public void onStart() {
   scheduleJob();
   }

    public void onStop() {
	   myConfigurationManagement.removeListener(this);
       unscheduleJob();
    }

	public void run(SchedulerJob job) {
	}

	public void run(SchedulerJob job) {
       // Check whether this instance is the cluster task master
       if (!myFrameworkConfig.isClusterTaskMaster()) {
          LOG.log(Level.INFO, "Execution of job '" + JOB_NAME + "' skipped on this server.");
          return;
       }

       // First create a session.
       try (Session session = mySessionManager.createSession(myConfigUtil.getWebsiteId(), myConfigUtil.getUsername())) {
          LOG.log(Level.INFO, "Execution of job '" + JOB_NAME + "' started.");
          LOG.log(Level.INFO, "Hi " + session.getContext().getUsername());
          LOG.log(Level.INFO, "Execution of job '" + JOB_NAME + "' finished.");
          }
       }
}



Note
Exception handling is omitted from this code example.

...