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

📄 jobmanager.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        job.set("statusId", "SERVICE_CRASHED");                        job.set("cancelDateTime", now);                        toStore.add(job);                    }                }            }            if (toStore.size() > 0) {                try {                    delegator.storeAll(toStore);                } catch (GenericEntityException e) {                    Debug.logError(e, module);                }                if (Debug.infoOn()) Debug.logInfo("-- " + toStore.size() + " jobs re-scheduled", module);            }        } else {            if (Debug.infoOn()) Debug.logInfo("No crashed jobs to re-schedule", module);        }    }    /**     * Schedule a job to start at a specific time with specific recurrence info     *@param serviceName The name of the service to invoke     *@param context The context for the service     *@param startTime The time in milliseconds the service should run     *@param frequency The frequency of the recurrence (HOURLY,DAILY,MONTHLY,etc)     *@param interval The interval of the frequency recurrence     *@param count The number of times to repeat     */    public void schedule(String serviceName, Map context, long startTime, int frequency, int interval, int count) throws JobManagerException {        schedule(serviceName, context, startTime, frequency, interval, count, 0);    }    /**     * Schedule a job to start at a specific time with specific recurrence info     *@param serviceName The name of the service to invoke     *@param context The context for the service     *@param startTime The time in milliseconds the service should run     *@param frequency The frequency of the recurrence (HOURLY,DAILY,MONTHLY,etc)     *@param interval The interval of the frequency recurrence     *@param endTime The time in milliseconds the service should expire     */    public void schedule(String serviceName, Map context, long startTime, int frequency, int interval, long endTime) throws JobManagerException {        schedule(serviceName, context, startTime, frequency, interval, -1, endTime);    }    /**     * Schedule a job to start at a specific time with specific recurrence info     *@param serviceName The name of the service to invoke     *@param context The context for the service     *@param startTime The time in milliseconds the service should run     *@param frequency The frequency of the recurrence (HOURLY,DAILY,MONTHLY,etc)     *@param interval The interval of the frequency recurrence     *@param count The number of times to repeat     *@param endTime The time in milliseconds the service should expire     */    public void schedule(String serviceName, Map context, long startTime, int frequency, int interval, int count, long endTime) throws JobManagerException {        schedule(null, serviceName, context, startTime, frequency, interval, count, endTime);    }    /**     * Schedule a job to start at a specific time with specific recurrence info     *@param poolName The name of the pool to run the service from     *@param serviceName The name of the service to invoke     *@param context The context for the service     *@param startTime The time in milliseconds the service should run     *@param frequency The frequency of the recurrence (HOURLY,DAILY,MONTHLY,etc)     *@param interval The interval of the frequency recurrence     *@param count The number of times to repeat     *@param endTime The time in milliseconds the service should expire     */    public void schedule(String poolName, String serviceName, Map context, long startTime, int frequency, int interval, int count, long endTime) throws JobManagerException {        schedule(null, serviceName, context, startTime, frequency, interval, count, endTime, -1);    }    /**     * Schedule a job to start at a specific time with specific recurrence info     *@param poolName The name of the pool to run the service from     *@param serviceName The name of the service to invoke     *@param context The context for the service     *@param startTime The time in milliseconds the service should run     *@param frequency The frequency of the recurrence (HOURLY,DAILY,MONTHLY,etc)     *@param interval The interval of the frequency recurrence     *@param count The number of times to repeat     *@param endTime The time in milliseconds the service should expire     *@param maxRetry The max number of retries on failure (-1 for no max)     */    public void schedule(String poolName, String serviceName, Map context, long startTime, int frequency, int interval, int count, long endTime, int maxRetry) throws JobManagerException {        if (delegator == null) {            Debug.logWarning("No delegator referenced; cannot schedule job.", module);            return;        }        // persist the context        String dataId = null;        try {            dataId = delegator.getNextSeqId("RuntimeData").toString();            GenericValue runtimeData = delegator.makeValue("RuntimeData", UtilMisc.toMap("runtimeDataId", dataId));            runtimeData.set("runtimeInfo", XmlSerializer.serialize(context));            delegator.create(runtimeData);        } catch (GenericEntityException ee) {            throw new JobManagerException(ee.getMessage(), ee);        } catch (SerializeException se) {            throw new JobManagerException(se.getMessage(), se);        } catch (IOException ioe) {            throw new JobManagerException(ioe.getMessage(), ioe);        }        // schedule the job        schedule(poolName, serviceName, dataId, startTime, frequency, interval, count, endTime, maxRetry);    }    /**     * Schedule a job to start at a specific time with specific recurrence info     *@param poolName The name of the pool to run the service from     *@param serviceName The name of the service to invoke     *@param dataId The persisted context (RuntimeData.runtimeDataId)     *@param startTime The time in milliseconds the service should run     */    public void schedule(String poolName, String serviceName, String dataId, long startTime) throws JobManagerException {        schedule(poolName, serviceName, dataId, startTime, -1, 0, 1, 0, -1);    }    /**     * Schedule a job to start at a specific time with specific recurrence info     *@param poolName The name of the pool to run the service from     *@param serviceName The name of the service to invoke     *@param dataId The persisted context (RuntimeData.runtimeDataId)     *@param startTime The time in milliseconds the service should run     *@param frequency The frequency of the recurrence (HOURLY,DAILY,MONTHLY,etc)     *@param interval The interval of the frequency recurrence     *@param count The number of times to repeat     *@param endTime The time in milliseconds the service should expire     *@param maxRetry The max number of retries on failure (-1 for no max)     */    public void schedule(String poolName, String serviceName, String dataId, long startTime, int frequency, int interval, int count, long endTime, int maxRetry) throws JobManagerException {        if (delegator == null) {            Debug.logWarning("No delegator referenced; cannot schedule job.", module);            return;        }        // create the recurrence        String infoId = null;        if (frequency > -1 && count != 0) {            try {                RecurrenceInfo info = RecurrenceInfo.makeInfo(delegator, startTime, frequency, interval, count);                infoId = info.primaryKey();            } catch (RecurrenceInfoException e) {                throw new JobManagerException(e.getMessage(), e);            }        }        // set the persisted fields        String jobName = new String(new Long((new Date().getTime())).toString());        String jobId = delegator.getNextSeqId("JobSandbox").toString();        Map jFields = UtilMisc.toMap("jobId", jobId, "jobName", jobName, "runTime", new java.sql.Timestamp(startTime),                "serviceName", serviceName, "recurrenceInfoId", infoId, "runtimeDataId", dataId);        // set the pool ID        if (poolName != null && poolName.length() > 0) {            jFields.put("poolId", poolName);        } else {            jFields.put("poolId", ServiceConfigUtil.getSendPool());        }        // set the loader name        jFields.put("loaderName", dispatcherName);        // set the max retry        jFields.put("maxRetry", new Long(maxRetry));        // create the value and store        GenericValue jobV = null;        try {            jobV = delegator.makeValue("JobSandbox", jFields);            delegator.create(jobV);        } catch (GenericEntityException e) {            throw new JobManagerException(e.getMessage(), e);        }    }    /**     * Kill a JobInvoker Thread.     * @param threadName Name of the JobInvoker Thread to kill.     */    public void killThread(String threadName) {        jp.killThread(threadName);    }    /**     * Get a List of each threads current state.     * @return List containing a Map of each thread's state.     */    public List processList() {        return jp.getPoolState();    }    /** Close out the scheduler thread. */    public void finalize() {        if (jp != null) {            jp.stop();            jp = null;            Debug.logInfo("JobManager: Stopped Scheduler Thread.", module);        }    }    /** gets the recurrence info object for a job. */    public static RecurrenceInfo getRecurrenceInfo(GenericValue job) {        try {            if (job != null && !UtilValidate.isEmpty(job.getString("recurrenceInfoId"))) {                if (job.get("cancelDateTime") != null) {                    // cancel has been flagged, no more recurrence                    return null;                }                GenericValue ri = job.getRelatedOne("RecurrenceInfo");                if (ri != null) {                    return new RecurrenceInfo(ri);                } else {                    return null;                }            } else {                return null;            }        } catch (GenericEntityException e) {            e.printStackTrace();            Debug.logError(e, "Problem getting RecurrenceInfo entity from JobSandbox", module);        } catch (RecurrenceInfoException re) {            re.printStackTrace();            Debug.logError(re, "Problem creating RecurrenceInfo instance: " + re.getMessage(), module);        }        return null;    }}

⌨️ 快捷键说明

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