类org.quartz.JobListener源码实例Demo

下面列出了怎么用org.quartz.JobListener的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: lams   文件: ListenerManagerImpl.java
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);
    }
}
 
源代码2 项目: lams   文件: ListenerManagerImpl.java
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);
    }
}
 
源代码3 项目: lams   文件: QuartzScheduler.java
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;
        }
    }
}
 
源代码4 项目: lams   文件: QuartzScheduler.java
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;
        }
    }
}
 
源代码5 项目: lams   文件: QuartzScheduler.java
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;
        }
    }
}
 
源代码6 项目: AsuraFramework   文件: QuartzScheduler.java
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;
}
 
源代码7 项目: AsuraFramework   文件: QuartzScheduler.java
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;
        }
    }
}
 
源代码8 项目: AsuraFramework   文件: QuartzScheduler.java
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;
        }
    }
}
 
源代码9 项目: AsuraFramework   文件: QuartzScheduler.java
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;
        }
    }
}
 
源代码10 项目: javamelody   文件: QuartzAdapter.java
@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);
					}
				}
			}
		}
	}
}
 
源代码11 项目: javamelody   文件: Quartz2Adapter.java
@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);
		}
	}
}
 
源代码12 项目: lams   文件: BroadcastJobListener.java
/**
 * 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>();
}
 
源代码13 项目: lams   文件: BroadcastJobListener.java
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;
}
 
源代码14 项目: lams   文件: BroadcastJobListener.java
public void jobToBeExecuted(JobExecutionContext context) {

        Iterator<JobListener> itr = listeners.iterator();
        while(itr.hasNext()) {
            JobListener jl = itr.next();
            jl.jobToBeExecuted(context);
        }
    }
 
源代码15 项目: lams   文件: BroadcastJobListener.java
public void jobExecutionVetoed(JobExecutionContext context) {

        Iterator<JobListener> itr = listeners.iterator();
        while(itr.hasNext()) {
            JobListener jl = itr.next();
            jl.jobExecutionVetoed(context);
        }
    }
 
源代码16 项目: lams   文件: BroadcastJobListener.java
public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) {

        Iterator<JobListener> itr = listeners.iterator();
        while(itr.hasNext()) {
            JobListener jl = itr.next();
            jl.jobWasExecuted(context, jobException);
        }
    }
 
源代码17 项目: lams   文件: QuartzScheduler.java
/**
 * <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.");
}
 
源代码18 项目: lams   文件: QuartzScheduler.java
/**
 * <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);
    }
}
 
源代码19 项目: lams   文件: QuartzScheduler.java
private List<JobListener> buildJobListenerList()
    throws SchedulerException {
    List<JobListener> allListeners = new LinkedList<JobListener>();
    allListeners.addAll(getListenerManager().getJobListeners());
    allListeners.addAll(getInternalJobListeners());

    return allListeners;
}
 
源代码20 项目: lams   文件: QuartzScheduler.java
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;
}
 
源代码21 项目: AsuraFramework   文件: RemoteMBeanScheduler.java
/**
 * <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);
}
 
源代码22 项目: AsuraFramework   文件: RemoteMBeanScheduler.java
/**
 * <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);
}
 
源代码23 项目: AsuraFramework   文件: RemoteScheduler.java
/**
 * <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);
}
 
源代码24 项目: AsuraFramework   文件: RemoteScheduler.java
/**
 * <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);
}
 
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;
}
 
public void jobToBeExecuted(JobExecutionContext context) {

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

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

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

        Iterator itr = listeners.iterator();
        while(itr.hasNext()) {
            JobListener jl = (JobListener) itr.next();
            jl.jobExecutionVetoed(context);
        }
    }
 
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);
        }
    }
 
源代码29 项目: AsuraFramework   文件: QuartzScheduler.java
/**
 * <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);
    }
}
 
源代码30 项目: AsuraFramework   文件: QuartzScheduler.java
/**
 * <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);
    }
}
 
 类所在包
 同包方法