Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.sakaiproject.component.app.scheduler.jobs;
 
 import java.util.List;
 
 import  org.quartz.StatefulJob;
 import  org.quartz.JobExecutionContext;
import  org.quartz.JobExecutionException;
public class ScheduledInvocationRunner implements StatefulJob {
	private static final Log LOG = LogFactory.getLog(ScheduledInvocationRunner.class);
	/* (non-Javadoc)
	 * @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
	 */
	@SuppressWarnings("unchecked")
	public void execute(JobExecutionContext arg0throws JobExecutionException {
		SqlService sqlService = ((SqlService) ComponentManager.get("org.sakaiproject.db.api.SqlService"));
		Time now = ((TimeService) ComponentManager.get("org.sakaiproject.time.api.TimeService")).newTime();
		String sql = "SELECT INVOCATION_ID, INVOCATION_TIME, COMPONENT, CONTEXT FROM SCHEDULER_DELAYED_INVOCATION WHERE INVOCATION_TIME < ?";
		Object[] fields = new Object[1];
		fields[0] = now;
		.debug("SQL: " + sql + " NOW:" + now);
		List<DelayedInvocationinvocations = sqlService.dbRead(sqlfieldsnew DelayedInvocationReader());
		for (Iterator<DelayedInvocationi = invocations.iterator(); i.hasNext();) {
			DelayedInvocation invocation = (DelayedInvocationi.next();
			if (invocation != null) {
				.debug("processing invocation: [" + invocation + "]");
				try {
					ScheduledInvocationCommand command = (ScheduledInvocationCommand) ComponentManager.get(invocation.componentId);
					command.execute(invocation.contextId);
catch (Exception e) {
					.error("Failed to execute component: [" + invocation.componentId + "]: " + e);
finally {
					sql = "DELETE FROM SCHEDULER_DELAYED_INVOCATION WHERE INVOCATION_ID = ?";
					fields[0] = invocation.uuid;
					.debug("SQL: " + sql);
					sqlService.dbWrite(sqlfields);
				}
			}
		}
	}
New to GrepCode? Check out our FAQ X