org.quartz.JobListener Java Examples

The following examples show how to use org.quartz.JobListener. 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 File: QuartzScheduler.java    From AsuraFramework with Apache License 2.0 7 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 #2
Source File: QuartzScheduler.java    From AsuraFramework with 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 #3
Source File: QuartzAdapter.java    From javamelody with 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 #4
Source File: Quartz2Adapter.java    From javamelody with 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 #5
Source File: QuartzScheduler.java    From AsuraFramework with 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 #6
Source File: QuartzScheduler.java    From AsuraFramework with 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 #7
Source File: QuartzScheduler.java    From lams with 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 #8
Source File: QuartzScheduler.java    From lams with 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 #9
Source File: QuartzScheduler.java    From lams with 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 #10
Source File: ListenerManagerImpl.java    From lams with 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 #11
Source File: ListenerManagerImpl.java    From lams with 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 #12
Source File: BroadcastJobListener.java    From lams with 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 #13
Source File: FilterAndBroadcastJobListener.java    From AsuraFramework with Apache License 2.0 5 votes vote down vote up
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 #14
Source File: BroadcastJobListener.java    From lams with 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 #15
Source File: SchedulerManagerImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void setGlobalJobListeners (final List<JobListener> listeners)
{
    globalJobListeners.clear();

    if (listeners != null)
    {
        globalJobListeners.addAll(listeners);
    }
}
 
Example #16
Source File: BroadcastJobListener.java    From lams with 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 #17
Source File: BroadcastJobListener.java    From lams with 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 #18
Source File: QuartzAdapter.java    From javamelody with Apache License 2.0 5 votes vote down vote up
public void addGlobalJobListener(JobListener jobGlobalListener) throws SchedulerException {
	final Scheduler defaultScheduler;
	if (Parameter.QUARTZ_DEFAULT_LISTENER_DISABLED.getValueAsBoolean()) {
		defaultScheduler = null;
		LOG.debug("Initialization of Quartz default listener has been disabled");
	} else {
		defaultScheduler = StdSchedulerFactory.getDefaultScheduler();
		defaultScheduler.addGlobalJobListener(jobGlobalListener);
	}
	for (final Scheduler scheduler : JobInformations.getAllSchedulers()) {
		if (scheduler != defaultScheduler) {
			scheduler.addGlobalJobListener(jobGlobalListener);
		}
	}
}
 
Example #19
Source File: BroadcastJobListener.java    From lams with 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 #20
Source File: QuartzScheduler.java    From lams with 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 #21
Source File: QuartzScheduler.java    From lams with 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 #22
Source File: QuartzScheduler.java    From lams with 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 #23
Source File: QuartzScheduler.java    From lams with 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 #24
Source File: RemoteMBeanScheduler.java    From AsuraFramework with 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 #25
Source File: RemoteMBeanScheduler.java    From AsuraFramework with 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 #26
Source File: FilterAndBroadcastJobListener.java    From AsuraFramework with Apache License 2.0 5 votes vote down vote up
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 #27
Source File: RemoteScheduler.java    From AsuraFramework with 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 #28
Source File: SchedulerManagerImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void setGlobalJobListeners (final List<JobListener> listeners)
{
    globalJobListeners.clear();

    if (listeners != null)
    {
        globalJobListeners.addAll(listeners);
    }
}
 
Example #29
Source File: Quartz2Adapter.java    From javamelody with Apache License 2.0 5 votes vote down vote up
@Override
public void removeGlobalJobListener(Class<? extends JobListener> jobListenerClass)
		throws SchedulerException {
	for (final Scheduler scheduler : JobInformations.getAllSchedulers()) {
		final ListenerManager listenerManager = scheduler.getListenerManager();
		final List<JobListener> globalJobListeners = listenerManager.getJobListeners();
		for (final JobListener jobListener : new ArrayList<JobListener>(globalJobListeners)) {
			if (jobListenerClass.isInstance(jobListener)) {
				listenerManager.removeJobListener(jobListener.getName());
			}
		}
	}
}
 
Example #30
Source File: RemoteScheduler.java    From AsuraFramework with 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);
}