⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmsscheduledjobinfo.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     *
     * @return an instance of the configured job class, or null if an error occured
     */
    public synchronized I_CmsScheduledJob getJobInstance() {

        if (m_jobInstance != null) {

            if (LOG.isDebugEnabled()) {
                LOG.debug(Messages.get().getBundle().key(
                    Messages.LOG_REUSING_INSTANCE_1,
                    m_jobInstance.getClass().getName()));
            }

            // job instance already initialized
            return m_jobInstance;
        }

        I_CmsScheduledJob job = null;

        try {
            // create an instance of the OpenCms job class
            job = (I_CmsScheduledJob)Class.forName(getClassName()).newInstance();
        } catch (ClassNotFoundException e) {
            LOG.error(Messages.get().getBundle().key(Messages.LOG_CLASS_NOT_FOUND_1, getClassName()), e);
        } catch (IllegalAccessException e) {
            LOG.error(Messages.get().getBundle().key(Messages.LOG_ILLEGAL_ACCESS_0), e);
        } catch (InstantiationException e) {
            LOG.error(Messages.get().getBundle().key(Messages.LOG_INSTANCE_GENERATION_0), e);
        } catch (ClassCastException e) {
            LOG.error(Messages.get().getBundle().key(Messages.LOG_BAD_INTERFACE_0), e);
        }

        if (m_reuseInstance) {
            // job instance must be re-used
            m_jobInstance = job;
        }

        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.get().getBundle().key(Messages.LOG_JOB_CREATED_1, getClassName()));
        }

        return job;
    }

    /**
     * Returns the job name.<p>
     *
     * @return the job name
     */
    public String getJobName() {

        return m_jobName;
    }

    /**
     * Returns the parameters.<p>
     *
     * @return the parameters
     */
    public SortedMap getParameters() {

        return m_parameters;
    }

    /**
     * Finalizes (freezes) the configuration of this scheduler job entry.<p>
     * 
     * After this job entry has been frozen, any attempt to change the 
     * configuration of this entry with one of the "set..." methods
     * will lead to a <code>RuntimeException</code>.<p> 
     * 
     * @see org.opencms.configuration.I_CmsConfigurationParameterHandler#initConfiguration()
     */
    public void initConfiguration() {

        // simple default configuration does not need to be initialized
        if (LOG.isDebugEnabled()) {
            LOG.debug(org.opencms.configuration.Messages.get().getBundle().key(
                org.opencms.configuration.Messages.LOG_INIT_CONFIGURATION_1,
                this));
        }
        setFrozen(true);
    }

    /**
     * Returns <code>true</code> if this job is currently active in the scheduler.<p>
     *
     * @return <code>true</code> if this job is currently active in the scheduler
     */
    public boolean isActive() {

        return m_active;
    }

    /**
     * Returns true if the job instance class is reused for this job.<p>
     *
     * @return true if the job instance class is reused for this job
     */
    public boolean isReuseInstance() {

        return m_reuseInstance;
    }

    /**
     * Sets the active state of this job.<p>
     *
     * @param active the active state to set
     */
    public void setActive(boolean active) {

        checkFrozen();
        m_active = active;
    }

    /**
     * Sets the name of the class to schedule.<p>
     * 
     * @param className the class name to set
     */
    public void setClassName(String className) {

        checkFrozen();
        if (!CmsStringUtil.isValidJavaClassName(className)) {
            throw new CmsIllegalArgumentException(
                Messages.get().container(Messages.ERR_BAD_JOB_CLASS_NAME_1, className));
        }
        Class jobClass;
        try {
            jobClass = Class.forName(className);
        } catch (ClassNotFoundException e) {
            throw new CmsIllegalArgumentException(Messages.get().container(
                Messages.ERR_JOB_CLASS_NOT_FOUND_1,
                className));
        }
        if (!I_CmsScheduledJob.class.isAssignableFrom(jobClass)) {
            throw new CmsIllegalArgumentException(Messages.get().container(
                Messages.ERR_JOB_CLASS_BAD_INTERFACE_2,
                className,
                I_CmsScheduledJob.class.getName()));
        }

        m_className = className;
        if (getJobName() == null) {
            // initialize job name with class name as default
            setJobName(className);
        }
    }

    /**
     * Sets the context information for the user executing the job.<p>
     *
     * This will also "freeze" the context information that is set.<p>
     *
     * @param contextInfo the context information for the user executing the job
     * 
     * @see CmsContextInfo#freeze()
     */
    public void setContextInfo(CmsContextInfo contextInfo) {

        checkFrozen();
        if (contextInfo == null) {
            throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_BAD_CONTEXT_INFO_0));
        }
        m_context = contextInfo;
    }

    /**
     * Sets the cron expression for this job entry.<p>
     * 
     * @param cronExpression the cron expression to set
     */
    public void setCronExpression(String cronExpression) {

        checkFrozen();

        try {
            // check if the cron expression is valid
            new CronTrigger().setCronExpression(cronExpression);
        } catch (Exception e) {
            throw new CmsIllegalArgumentException(Messages.get().container(
                Messages.ERR_BAD_CRON_EXPRESSION_2,
                getJobName(),
                cronExpression));
        }

        m_cronExpression = cronExpression;
    }

    /**
     * Sets the job name.<p>
     *
     * @param jobName the job name to set
     */
    public void setJobName(String jobName) {

        checkFrozen();
        if (CmsStringUtil.isEmpty(jobName) || !jobName.trim().equals(jobName)) {
            throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_BAD_JOB_NAME_1, jobName));

        }
        m_jobName = jobName;
    }

    /**
     * Sets the job parameters.<p>
     *
     * @param parameters the parameters to set
     */
    public void setParameters(SortedMap parameters) {

        checkFrozen();
        if (parameters == null) {
            throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_BAD_JOB_PARAMS_0));
        }
        // make sure the parameters are a sorted map
        m_parameters = new TreeMap(parameters);
    }

    /**
     * Controls if the job instance class is reused for this job,
     * of if a new instance is generated every time the job is run.<p>
     * 
     * @param reuseInstance must be true if the job instance class is to be reused
     */
    public void setReuseInstance(boolean reuseInstance) {

        checkFrozen();
        m_reuseInstance = reuseInstance;
    }

    /**
     * Checks if this job info configuration is frozen.<p>
     * 
     * @throws CmsRuntimeException in case the configuration is already frozen
     */
    protected void checkFrozen() throws CmsRuntimeException {

        if (m_frozen) {
            throw new CmsRuntimeException(Messages.get().container(Messages.ERR_JOB_INFO_FROZEN_1, getJobName()));
        }
    }

    /**
     * Returns the Quartz trigger used for scheduling this job.<p>
     *
     * This is an internal operation that should only by performed by the 
     * <code>{@link CmsScheduleManager}</code>, never by using this API directly.<p>
     * 
     * @return the Quartz trigger used for scheduling this job
     */
    protected Trigger getTrigger() {

        return m_trigger;
    }

    /**
     * Sets the "frozen" state of this job.<p>
     *
     * This is an internal operation to be used only by the <code>{@link CmsScheduleManager}</code>.<p>
     *
     * @param frozen the "frozen" state to set
     */
    protected synchronized void setFrozen(boolean frozen) {

        if (frozen && !m_frozen) {
            // "freeze" the job configuration
            m_parameters = Collections.unmodifiableSortedMap(m_parameters);
            m_context.freeze();
            m_frozen = true;
        } else if (!frozen && m_frozen) {
            // "unfreeze" the job configuration
            m_parameters = new TreeMap(m_parameters);
            m_frozen = false;
        }
    }

    /**
     * Sets the is used for scheduling this job.<p>
     *
     * This is an internal operation that should only by performed by the 
     * <code>{@link CmsScheduleManager}</code>, never by using this API directly.<p>
     * 
     * @param id the id to set
     */
    protected void setId(String id) {

        checkFrozen();
        m_id = id;
    }

    /**
     * Sets the Quartz trigger used for scheduling this job.<p>
     *
     * This is an internal operation that should only by performed by the 
     * <code>{@link CmsScheduleManager}</code>, never by using this API directly.<p>
     * 
     * @param trigger the Quartz trigger to set
     */
    protected void setTrigger(Trigger trigger) {

        checkFrozen();
        m_trigger = trigger;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -