Java Code Examples for org.quartz.JobListener

The following examples show how to use org.quartz.JobListener. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: lams   Source File: ListenerManagerImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void addJobListener(JobListener jobListener, List<Matcher<JobKey>> matchers) {
    if (jobListener.getName() == null || jobListener.getName().length() == 0) {
        throw new IllegalArgumentException(
                "JobListener name cannot be empty.");
    }
    
    synchronized (globalJobListeners) {
        globalJobListeners.put(jobListener.getName(), jobListener);
        LinkedList<Matcher<JobKey>> matchersL = new  LinkedList<Matcher<JobKey>>();
        if(matchers != null && matchers.size() > 0)
            matchersL.addAll(matchers);
        else
            matchersL.add(EverythingMatcher.allJobs());
        
        globalJobListenersMatchers.put(jobListener.getName(), matchersL);
    }
}
 
Example 2
Source Project: lams   Source File: ListenerManagerImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void addJobListener(JobListener jobListener, Matcher<JobKey> matcher) {
    if (jobListener.getName() == null || jobListener.getName().length() == 0) {
        throw new IllegalArgumentException(
                "JobListener name cannot be empty.");
    }
    
    synchronized (globalJobListeners) {
        globalJobListeners.put(jobListener.getName(), jobListener);
        LinkedList<Matcher<JobKey>> matchersL = new  LinkedList<Matcher<JobKey>>();
        if(matcher != null)
            matchersL.add(matcher);
        else
            matchersL.add(EverythingMatcher.allJobs());
        
        globalJobListenersMatchers.put(jobListener.getName(), matchersL);
    }
}
 
Example 3
Source Project: lams   Source File: QuartzScheduler.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void notifyJobListenersToBeExecuted(JobExecutionContext jec)
    throws SchedulerException {
    // build a list of all job listeners that are to be notified...
    List<JobListener> jobListeners = buildJobListenerList();

    // notify all job listeners
    for(JobListener jl: jobListeners) {
        try {
            if(!matchJobListener(jl, jec.getJobDetail().getKey()))
                continue;
            jl.jobToBeExecuted(jec);
        } catch (Exception e) {
            SchedulerException se = new SchedulerException(
                    "JobListener '" + jl.getName() + "' threw exception: "
                            + e.getMessage(), e);
            throw se;
        }
    }
}
 
Example 4
Source Project: lams   Source File: QuartzScheduler.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void notifyJobListenersWasVetoed(JobExecutionContext jec)
    throws SchedulerException {
    // build a list of all job listeners that are to be notified...
    List<JobListener> jobListeners = buildJobListenerList();

    // notify all job listeners
    for(JobListener jl: jobListeners) {
        try {
            if(!matchJobListener(jl, jec.getJobDetail().getKey()))
                continue;
            jl.jobExecutionVetoed(jec);
        } catch (Exception e) {
            SchedulerException se = new SchedulerException(
                    "JobListener '" + jl.getName() + "' threw exception: "
                    + e.getMessage(), e);
            throw se;
        }
    }
}
 
Example 5
Source Project: lams   Source File: QuartzScheduler.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void notifyJobListenersWasExecuted(JobExecutionContext jec,
        JobExecutionException je) throws SchedulerException {
    // build a list of all job listeners that are to be notified...
    List<JobListener> jobListeners = buildJobListenerList();

    // notify all job listeners
    for(JobListener jl: jobListeners) {
        try {
            if(!matchJobListener(jl, jec.getJobDetail().getKey()))
                continue;
            jl.jobWasExecuted(jec, je);
        } catch (Exception e) {
            SchedulerException se = new SchedulerException(
                    "JobListener '" + jl.getName() + "' threw exception: "
                            + e.getMessage(), e);
            throw se;
        }
    }
}
 
Example 6
Source Project: AsuraFramework   Source File: QuartzScheduler.java    License: Apache License 2.0 6 votes vote down vote up
private List buildJobListenerList(String[] additionalLstnrs)
    throws SchedulerException {
    List jobListeners = getGlobalJobListeners();
    for (int i = 0; i < additionalLstnrs.length; i++) {
        JobListener jl = getJobListener(additionalLstnrs[i]);

        if (jl != null) {
            jobListeners.add(jl);
        } else {
            throw new SchedulerException("JobListener '"
                    + additionalLstnrs[i] + "' not found.",
                    SchedulerException.ERR_JOB_LISTENER_NOT_FOUND);
        }
    }

    return jobListeners;
}
 
Example 7
Source Project: AsuraFramework   Source File: QuartzScheduler.java    License: Apache License 2.0 6 votes vote down vote up
public void notifyJobListenersToBeExecuted(JobExecutionContext jec)
    throws SchedulerException {
    // build a list of all job listeners that are to be notified...
    List jobListeners = buildJobListenerList(jec.getJobDetail()
            .getJobListenerNames());

    // notify all job listeners
    java.util.Iterator itr = jobListeners.iterator();
    while (itr.hasNext()) {
        JobListener jl = (JobListener) itr.next();
        try {
            jl.jobToBeExecuted(jec);
        } catch (Exception e) {
            SchedulerException se = new SchedulerException(
                    "JobListener '" + jl.getName() + "' threw exception: "
                            + e.getMessage(), e);
            se.setErrorCode(SchedulerException.ERR_JOB_LISTENER);
            throw se;
        }
    }
}
 
Example 8
Source Project: AsuraFramework   Source File: QuartzScheduler.java    License: Apache License 2.0 6 votes vote down vote up
public void notifyJobListenersWasVetoed(JobExecutionContext jec)
    throws SchedulerException {
    // build a list of all job listeners that are to be notified...
    List jobListeners = buildJobListenerList(jec.getJobDetail()
            .getJobListenerNames());

    // notify all job listeners
    java.util.Iterator itr = jobListeners.iterator();
    while (itr.hasNext()) {
        JobListener jl = (JobListener) itr.next();
        try {
            jl.jobExecutionVetoed(jec);
        } catch (Exception e) {
            SchedulerException se = new SchedulerException(
                    "JobListener '" + jl.getName() + "' threw exception: "
                    + e.getMessage(), e);
            se.setErrorCode(SchedulerException.ERR_JOB_LISTENER);
            throw se;
        }
    }
}
 
Example 9
Source Project: AsuraFramework   Source File: QuartzScheduler.java    License: Apache License 2.0 6 votes vote down vote up
public void notifyJobListenersWasExecuted(JobExecutionContext jec,
        JobExecutionException je) throws SchedulerException {
    // build a list of all job listeners that are to be notified...
    List jobListeners = buildJobListenerList(jec.getJobDetail()
            .getJobListenerNames());

    // notify all job listeners
    java.util.Iterator itr = jobListeners.iterator();
    while (itr.hasNext()) {
        JobListener jl = (JobListener) itr.next();
        try {
            jl.jobWasExecuted(jec, je);
        } catch (Exception e) {
            SchedulerException se = new SchedulerException(
                    "JobListener '" + jl.getName() + "' threw exception: "
                            + e.getMessage(), e);
            se.setErrorCode(SchedulerException.ERR_JOB_LISTENER);
            throw se;
        }
    }
}
 
Example 10
Source Project: javamelody   Source File: QuartzAdapter.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void removeGlobalJobListener(Class<? extends JobListener> jobListenerClass)
		throws SchedulerException {
	for (final Scheduler scheduler : JobInformations.getAllSchedulers()) {
		final List<JobListener> globalJobListeners = scheduler.getGlobalJobListeners();
		for (final JobListener jobListener : new ArrayList<JobListener>(globalJobListeners)) {
			if (jobListenerClass.isInstance(jobListener)) {
				try {
					scheduler.removeGlobalJobListener(jobListener);
				} catch (final NoSuchMethodError e1) {
					// pour Quartz 1.7, 1.8 et +,
					// cette méthode n'existe pas avant Quartz 1.6
					try {
						final Class<? extends Scheduler> schedulerClass = scheduler.getClass();
						schedulerClass.getMethod("removeGlobalJobListener", String.class)
								.invoke(scheduler, jobListener.getName());
					} catch (final Exception e2) {
						throw new IllegalArgumentException(e2);
					}
				}
			}
		}
	}
}
 
Example 11
Source Project: javamelody   Source File: Quartz2Adapter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void addGlobalJobListener(JobListener jobGlobalListener) throws SchedulerException {
	final Scheduler defaultScheduler;
	final List<Matcher<JobKey>> allJobs = new ArrayList<Matcher<JobKey>>();
	allJobs.add(EverythingMatcher.allJobs());
	if (Parameter.QUARTZ_DEFAULT_LISTENER_DISABLED.getValueAsBoolean()) {
		defaultScheduler = null;
		LOG.debug("Initialization of Quartz default listener has been disabled");
	} else {
		defaultScheduler = StdSchedulerFactory.getDefaultScheduler();
		defaultScheduler.getListenerManager().addJobListener(jobGlobalListener, allJobs);
	}
	for (final Scheduler scheduler : JobInformations.getAllSchedulers()) {
		if (scheduler != defaultScheduler) {
			scheduler.getListenerManager().addJobListener(jobGlobalListener, allJobs);
		}
	}
}
 
Example 12
Source Project: lams   Source File: BroadcastJobListener.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct an instance with the given name.
 *
 * (Remember to add some delegate listeners!)
 *
 * @param name the name of this instance
 */
public BroadcastJobListener(String name) {
    if(name == null) {
        throw new IllegalArgumentException("Listener name cannot be null!");
    }
    this.name = name;
    listeners = new LinkedList<JobListener>();
}
 
Example 13
Source Project: lams   Source File: BroadcastJobListener.java    License: GNU General Public License v2.0 5 votes vote down vote up
public boolean removeListener(String listenerName) {
    Iterator<JobListener> itr = listeners.iterator();
    while(itr.hasNext()) {
        JobListener jl = itr.next();
        if(jl.getName().equals(listenerName)) {
            itr.remove();
            return true;
        }
    }
    return false;
}
 
Example 14
Source Project: lams   Source File: BroadcastJobListener.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void jobToBeExecuted(JobExecutionContext context) {

        Iterator<JobListener> itr = listeners.iterator();
        while(itr.hasNext()) {
            JobListener jl = itr.next();
            jl.jobToBeExecuted(context);
        }
    }
 
Example 15
Source Project: lams   Source File: BroadcastJobListener.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void jobExecutionVetoed(JobExecutionContext context) {

        Iterator<JobListener> itr = listeners.iterator();
        while(itr.hasNext()) {
            JobListener jl = itr.next();
            jl.jobExecutionVetoed(context);
        }
    }
 
Example 16
Source Project: lams   Source File: BroadcastJobListener.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) {

        Iterator<JobListener> itr = listeners.iterator();
        while(itr.hasNext()) {
            JobListener jl = itr.next();
            jl.jobWasExecuted(context, jobException);
        }
    }
 
Example 17
Source Project: lams   Source File: QuartzScheduler.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Create a <code>QuartzScheduler</code> with the given configuration
 * properties.
 * </p>
 * 
 * @see QuartzSchedulerResources
 */
public QuartzScheduler(QuartzSchedulerResources resources, long idleWaitTime, @Deprecated long dbRetryInterval)
    throws SchedulerException {
    this.resources = resources;
    if (resources.getJobStore() instanceof JobListener) {
        addInternalJobListener((JobListener)resources.getJobStore());
    }

    this.schedThread = new QuartzSchedulerThread(this, resources);
    ThreadExecutor schedThreadExecutor = resources.getThreadExecutor();
    schedThreadExecutor.execute(this.schedThread);
    if (idleWaitTime > 0) {
        this.schedThread.setIdleWaitTime(idleWaitTime);
    }

    jobMgr = new ExecutingJobsManager();
    addInternalJobListener(jobMgr);
    errLogger = new ErrorLogger();
    addInternalSchedulerListener(errLogger);

    signaler = new SchedulerSignalerImpl(this, this.schedThread);
    
    if(shouldRunUpdateCheck()) 
        updateTimer = scheduleUpdateCheck();
    else
        updateTimer = null;
    
    getLog().info("Quartz Scheduler v." + getVersion() + " created.");
}
 
Example 18
Source Project: lams   Source File: QuartzScheduler.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Add the given <code>{@link org.quartz.JobListener}</code> to the
 * <code>Scheduler</code>'s <i>internal</i> list.
 * </p>
 */
public void addInternalJobListener(JobListener jobListener) {
    if (jobListener.getName() == null
            || jobListener.getName().length() == 0) {
        throw new IllegalArgumentException(
                "JobListener name cannot be empty.");
    }
    
    synchronized (internalJobListeners) {
        internalJobListeners.put(jobListener.getName(), jobListener);
    }
}
 
Example 19
Source Project: lams   Source File: QuartzScheduler.java    License: GNU General Public License v2.0 5 votes vote down vote up
private List<JobListener> buildJobListenerList()
    throws SchedulerException {
    List<JobListener> allListeners = new LinkedList<JobListener>();
    allListeners.addAll(getListenerManager().getJobListeners());
    allListeners.addAll(getInternalJobListeners());

    return allListeners;
}
 
Example 20
Source Project: lams   Source File: QuartzScheduler.java    License: GNU General Public License v2.0 5 votes vote down vote up
private boolean matchJobListener(JobListener listener, JobKey key) {
    List<Matcher<JobKey>> matchers = getListenerManager().getJobListenerMatchers(listener.getName());
    if(matchers == null)
        return true;
    for(Matcher<JobKey> matcher: matchers) {
        if(matcher.isMatch(key))
            return true;
    }
    return false;
}
 
Example 21
Source Project: AsuraFramework   Source File: RemoteMBeanScheduler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>.
 * </p>
 */
public void addGlobalJobListener(JobListener jobListener)
    throws SchedulerException {
    throw new SchedulerException(
            "Operation not supported for remote schedulers.",
            SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION);
}
 
Example 22
Source Project: AsuraFramework   Source File: RemoteMBeanScheduler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>.
 * </p>
 */
public void addJobListener(JobListener jobListener)
    throws SchedulerException {
    throw new SchedulerException(
            "Operation not supported for remote schedulers.",
            SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION);
}
 
Example 23
Source Project: AsuraFramework   Source File: RemoteScheduler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>.
 * </p>
 */
public void addGlobalJobListener(JobListener jobListener)
    throws SchedulerException {
    throw new SchedulerException(
            "Operation not supported for remote schedulers.",
            SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION);
}
 
Example 24
Source Project: AsuraFramework   Source File: RemoteScheduler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>.
 * </p>
 */
public void addJobListener(JobListener jobListener)
    throws SchedulerException {
    throw new SchedulerException(
            "Operation not supported for remote schedulers.",
            SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION);
}
 
Example 25
public boolean removeListener(String listenerName) {
    Iterator itr = listeners.iterator();
    while(itr.hasNext()) {
        JobListener jl = (JobListener) itr.next();
        if(jl.getName().equals(listenerName)) {
            itr.remove();
            return true;
        }
    }
    return false;
}
 
Example 26
public void jobToBeExecuted(JobExecutionContext context) {

        if(!shouldDispatch(context)) {
            return;
        }

        Iterator itr = listeners.iterator();
        while(itr.hasNext()) {
            JobListener jl = (JobListener) itr.next();
            jl.jobToBeExecuted(context);
        }
    }
 
Example 27
public void jobExecutionVetoed(JobExecutionContext context) {

        if(!shouldDispatch(context)) {
            return;
        }

        Iterator itr = listeners.iterator();
        while(itr.hasNext()) {
            JobListener jl = (JobListener) itr.next();
            jl.jobExecutionVetoed(context);
        }
    }
 
Example 28
public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) {

        if(!shouldDispatch(context)) {
            return;
        }

        Iterator itr = listeners.iterator();
        while(itr.hasNext()) {
            JobListener jl = (JobListener) itr.next();
            jl.jobWasExecuted(context, jobException);
        }
    }
 
Example 29
Source Project: AsuraFramework   Source File: QuartzScheduler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Add the given <code>{@link org.quartz.JobListener}</code> to the
 * <code>Scheduler</code>'s<i>global</i> list.
 * </p>
 * 
 * <p>
 * Listeners in the 'global' list receive notification of execution events
 * for ALL <code>{@link org.quartz.Job}</code>s.
 * </p>
 */
public void addGlobalJobListener(JobListener jobListener) {
    if (jobListener.getName() == null
            || jobListener.getName().length() == 0) {
        throw new IllegalArgumentException(
                "JobListener name cannot be empty.");
    }
    
    synchronized (globalJobListeners) {
        globalJobListeners.put(jobListener.getName(), jobListener);
    }
}
 
Example 30
Source Project: AsuraFramework   Source File: QuartzScheduler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Add the given <code>{@link org.quartz.JobListener}</code> to the
 * <code>Scheduler</code>'s list, of registered <code>JobListener</code>s.
 */
public void addJobListener(JobListener jobListener) {
    if (jobListener.getName() == null
            || jobListener.getName().length() == 0) {
        throw new IllegalArgumentException(
                "JobListener name cannot be empty.");
    }

    synchronized (jobListeners) {
        jobListeners.put(jobListener.getName(), jobListener);
    }
}