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

📄 scriptmanagerejb.java

📁 CRM源码This file describes some issues that should be implemented in future and how it should be imple
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if( tasks == null || tasks.size() == 0 ) {            return null;        }        long nowMillis = DateHelper.currentTimeMillis();        Collection ret = new ArrayList();        for( Iterator it = tasks.iterator(); it.hasNext(); ) {            Task task = ( Task ) it.next();            int status = task.getStatus().getType();            if( status == StatusSType.READY_TYPE ) {                Long nextStart = task.getNextStart();                if( nextStart != null && nextStart.longValue() < nowMillis ) {                    ret.add( task );                }            }        }        // Ok.        if( getLogger().isInfoEnabled() ) {            INFO( "Got [" + ret.size() + "] matured tasks..." );        }        return ret;    }    /**     * Perform action     * @param action given Action object     * @return Action result     */    public Serializable startAction( java.io.Serializable action ) {        if( ! ( action instanceof Action ) ) {            throw new IllegalStateException( "Only Action classes supported!" );        }        return( ( Action ) action ).perform();    }    // ----------------------------------------------------- task management    //    // Set task status to READY    //    public void readyTask( long task_id, boolean ignoreStatus )        throws EQLException {        long time = System.currentTimeMillis();        Task task = getTask( task_id );        if( task == null ) {            throw new NullPointerException( "Task #" + task_id + " not found" );        }        if( !ignoreStatus ) {            // Check task status            int task_status = task.getStatus().getType();            switch( task_status ) {            case StatusSType.READY_TYPE:            case StatusSType.RUN_TYPE:            case StatusSType.WAITED_TYPE:                throw new EQLException( "Task #" + task_id + " already run" );            }        }        // Set READY status        task.setStatus( StatusSType.READY );        // Set next start        long next_start = getNextStart( task );        task.setNextStart( new Long( next_start ) );        // Update Task VO.        update( task );        // Ok.        if( getLogger().isInfoEnabled() ) {            INFO( "Task ready (ID = " + task_id + ")." );            INFO( "Time (ms) - " + ( System.currentTimeMillis() - time ) );        }    }    //    // Set task status to RUN    //    public void runTask( long task_id, boolean ignoreStatus )        throws EQLException {        long time = System.currentTimeMillis();        Task task = getTask( task_id );        if( task == null ) {            throw new NullPointerException( "Task #" + task_id + " not found" );        }        if( !ignoreStatus ) {            // Check task status            int task_status = task.getStatus().getType();            switch( task_status ) {            case StatusSType.NEW_TYPE:            case StatusSType.COMPLETED_TYPE:            case StatusSType.INTERRUPTED_TYPE:                throw new EQLException( "Can't run task #" + task_id );            case StatusSType.RUN_TYPE:                throw new EQLException( "Task #" + task_id + " already run" );            }        }        // Set RUN status        task.setStatus( StatusSType.RUN );        // Update Task VO.        update( task );        // Ok.        if( getLogger().isInfoEnabled() ) {            INFO( "Task run (ID = " + task_id + ")." );            INFO( "Time (ms) - " + ( System.currentTimeMillis() - time ) );        }    }    //    // Set task status to WAITED    //    public long waitTask( long task_id, boolean ignoreStatus )        throws EQLException {        long time = System.currentTimeMillis();        long timeout = 0;        Task task = getTask( task_id );        if( task == null ) {            throw new NullPointerException( "Task #" + task_id + " not found" );        }        // Get previos start date.        long prev_start = getNextStart( task );        // Calculate next start date.        timeout = getTimeout( task );        long now = DateHelper.currentTimeMillis();        long next_start = prev_start;        if (next_start < now) {            next_start += timeout;        }        if( !ignoreStatus ) {            // Check task status            int task_status = task.getStatus().getType();            switch( task_status ) {            case StatusSType.NEW_TYPE:            case StatusSType.READY_TYPE:            case StatusSType.COMPLETED_TYPE:            case StatusSType.INTERRUPTED_TYPE:                throw new EQLException( "Can't wait task #" + task_id );            case StatusSType.WAITED_TYPE:                throw new EQLException( "Task #" + task_id + " already waited" );            }        }        // Set WAITED status        task.setStatus( StatusSType.WAITED );        // Set next start        task.setNextStart( new Long( next_start ) );        // Update Task VO.        update( task );        // Ok.        if( getLogger().isInfoEnabled() ) {            INFO( "Task waited (ID = " + task_id + ") for " + timeout + "(ms)." );            INFO( "Time (ms) - " + ( System.currentTimeMillis() - time ) );        }        return timeout;    }    //    // Set task status to COMPLETED    //    public void completeTask( long task_id, boolean ignoreStatus )        throws EQLException {        long time = System.currentTimeMillis();        Task task = getTask( task_id );        if( task == null ) {            throw new NullPointerException( "Task #" + task_id + " not found" );        }        if( !ignoreStatus ) {            // Check task status            int task_status = task.getStatus().getType();            switch( task_status ) {            case StatusSType.NEW_TYPE:            case StatusSType.READY_TYPE:            case StatusSType.COMPLETED_TYPE:            case StatusSType.INTERRUPTED_TYPE:                throw new EQLException( "Task #" + task_id + " already stopped" );            }        }        // Set COMPLETED status        task.setStatus( StatusSType.COMPLETED );        // Set next start to NULL        task.setNextStart( null );        // Update Task VO.        update( task );        // Ok.        if( getLogger().isInfoEnabled() ) {            INFO( "Task completed (ID = " + task_id + ")." );            INFO( "Time (ms) - " + ( System.currentTimeMillis() - time ) );        }    }    //    // Set task status to INTERRUPTED    //    public void interruptTask( long task_id, boolean ignoreStatus )        throws EQLException {        long time = System.currentTimeMillis();        Task task = getTask( task_id );        if( task == null ) {            throw new NullPointerException( "Task #" + task_id + " not found" );        }        if( !ignoreStatus ) {            // Check task status            int task_status = task.getStatus().getType();            switch( task_status ) {            case StatusSType.NEW_TYPE:            case StatusSType.COMPLETED_TYPE:            case StatusSType.INTERRUPTED_TYPE:                throw new EQLException( "Task #" + task_id + " already stopped" );            }        }        // Set INTERRUPTED status        task.setStatus( StatusSType.INTERRUPTED );        // Update Task VO.        update( task );        // Ok.        if( getLogger().isInfoEnabled() ) {            INFO( "Task interrupted (ID = " + task_id + ")." );            INFO( "Time (ms) - " + ( System.currentTimeMillis() - time ) );        }    }    //    // Reanimate task and set status to READY    //    public void reanimateTask( long task_id )        throws EQLException {        long time = System.currentTimeMillis();        Task task = getTask( task_id );        if( task == null ) {            throw new NullPointerException( "Task #" + task_id + " not found" );        }        // Set READY status        task.setStatus( StatusSType.READY );        // Set next start        long next_start = getNextStart( task );        task.setNextStart( new Long( next_start ) );        // Update Task VO.        update( task );        // Ok.        if( getLogger().isInfoEnabled() ) {            INFO( "Task renimated (ID = " + task_id + ")." );            INFO( "Time (ms) - " + ( System.currentTimeMillis() - time ) );        }    }    // ----------------------------------------------------- private methods    /**     * Updates Task VO     * @param task Task     */    private void update( Task task ) {        // Update database.        ServicesPropertyFactory.getInstance().getTaskDAO().updateTaskVO( task );        // Update cache.        updateCache( task );    }    /**     * Calculate task next start     * @param task Task VO     * @return millis     */    private long getNextStart( Task task ) {        long now = DateHelper.currentTimeMillis();        long next_start;        if( task.getFirstStart() != null ) {            next_start = task.getFirstStart().longValue();        } else {            next_start = now;        }        if( next_start < now ) {            // bring next start up            if( task.getDelayunit() != null ) {                long timout = getTimeout( task );                do {                    next_start += timout;                } while( next_start < now );            } else {                next_start = now;            }        }        return next_start;    }    /**     * Calculate timeout period for task     * @param task Task VO     * @return timeout in ms or 0     */    private long getTimeout( Task task ) {        if( task.getDelayunit() == null ) {            throw new NullPointerException( "Delay unit is NULL" );        }        if( task.getDelay() == null ) {            throw new NullPointerException( "Delay is NULL" );        }        int delay = task.getDelay().intValue();        int delayunit = task.getDelayunit().getType();        switch( delayunit ) {        case DelayunitSType.MIN_TYPE:            return 60 * 1000 * delay;        case DelayunitSType.HOUR_TYPE:            return 60 * 60 * 1000 * delay;        case DelayunitSType.DAY_TYPE:            return 24 * 60 * 60 * 1000 * delay;        case DelayunitSType.MONTH_TYPE:            return 30 * 24 * 60 * 60 * 1000 * delay;        default:            throw new GenericSystemException( "Unsupported task delayunit type: " + delayunit );        }    }} // end of class

⌨️ 快捷键说明

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