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

📄 scriptmanagerejb.java

📁 CRM源码This file describes some issues that should be implemented in future and how it should be imple
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 2006-2007 Queplix Corp. * * Licensed under the Queplix Public License, Version 1.1.1 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.queplix.com/solutions/commercial-open-source/queplix-public-license/ * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */package com.queplix.core.modules.services.ejb;import com.queplix.core.error.GenericSystemException;import com.queplix.core.modules.eql.error.EQLException;import com.queplix.core.modules.services.Action;import com.queplix.core.modules.services.jxb.Script;import com.queplix.core.modules.services.jxb.Task;import com.queplix.core.modules.services.jxb.types.DelayunitSType;import com.queplix.core.modules.services.jxb.types.StatusSType;import com.queplix.core.modules.services.utils.ServicesPropertyFactory;import com.queplix.core.utils.DateHelper;import com.queplix.core.utils.cache.Cache;import com.queplix.core.utils.ejb.AbstractSessionEJB;import java.io.Serializable;import java.util.ArrayList;import java.util.Collection;import java.util.Iterator;/** * Script manager session EJB. * @author [ALB] Baranov Andrey * @version $Revision: 1.4 $ $Date: 2005/12/05 08:59:59 $ */public class ScriptManagerEJB    extends AbstractSessionEJB {    // ----------------------------------------------------- public methods    /** Initializes bean. */    public void ejbCreate() {        INFO( "ScriptManager EJB created - " + hashCode() );    }    /**     * Gets the script by its ID.     * @param script_id script id     * @return Script object     */    public Script getScript( int script_id ) {        if( getLogger().isDebugEnabled() ) {            DEBUG( "Try to get Script" +                   ". Id: " + script_id + "." );        }        // Try to find out in cache.        Integer key = new Integer( script_id );        Cache cache = ServicesPropertyFactory.getInstance().getScriptCache();        Script script = null;        if( !cache.containsKey( key ) ) {            // Load Script from database.            script = ServicesPropertyFactory.getInstance().getScriptDAO().loadScriptVO( script_id );            // Store in cache.            updateCache( script );        } else {            // Found in cache!            if( getLogger().isDebugEnabled() ) {                DEBUG( "Script #" + script_id + " found in cache." );            }            script = ( Script ) cache.get( key );        }        return script;    }    /**     * Gets the script by its name.     * @param scriptName script name     * @return Script object     */    public Script getScript( String scriptName ) {        if( getLogger().isDebugEnabled() ) {            DEBUG( "Try to get Script" +                   ". Name: " + scriptName + "." );        }        // Load Script from database.        Script script = ServicesPropertyFactory.getInstance().getScriptDAO().loadScriptVO( scriptName );        // Store in cache.        updateCache( script );        return script;    }    /**     * Gets the task by its ID.     * @param task_id task id     * @return Task object     */    public Task getTask( long task_id ) {        if( getLogger().isDebugEnabled() ) {            DEBUG( "Try to get Task" +                   ". Id: " + task_id + "." );        }        // Try to find out in cache.        Long key = new Long( task_id );        Cache cache = ServicesPropertyFactory.getInstance().getTaskCache();        Task task = null;        if( !cache.containsKey( key ) ) {            // Load Task from database.            task = ServicesPropertyFactory.getInstance().getTaskDAO().loadTaskVO( task_id );            // Store in cache.            updateCache( task );        } else {            // Found in cache!            if( getLogger().isDebugEnabled() ) {                DEBUG( "Task #" + task_id + " found in cache." );            }            task = ( Task ) cache.get( key );        }        return task;    }    /**     * Gets the task by its name.     * @param taskName task name     * @return Task object     */    public Task getTask( String taskName ) {        if( getLogger().isDebugEnabled() ) {            DEBUG( "Try to get Task" +                   ". Name: " + taskName + "." );        }        // Load Task from database.        Task task = ServicesPropertyFactory.getInstance().getTaskDAO().loadTaskVO( taskName );        // Store in cache.        updateCache( task );        return task;    }    /**     * Get collection of Task value objects     * @return collection of Task objects     */    public Collection getTasks() {        Collection tasks;        long time = System.currentTimeMillis();        DEBUG( "Try to get All tasks" );        Cache cache = ServicesPropertyFactory.getInstance().getTaskCache();        if( cache.isOpen() ) {            // Load entities.            tasks = ServicesPropertyFactory.getInstance().getTaskDAO().loadAllTaskVO();            synchronized( cache ) {                // Clear cache.                cache.clear();                // Store tasks in cache.                if( tasks != null ) {                    for( Iterator it = tasks.iterator(); it.hasNext(); ) {                        Task task = ( Task ) it.next();                        cache.put( task.getId(), task );                    }                }                // Close cache.                cache.close();            }        } else {            // Take entire cache.            tasks = cache.values();        }        if( getLogger().isDebugEnabled() ) {            DEBUG( "Get All tasks - ok. Time (ms): " + ( System.currentTimeMillis() - time ) );        }        return tasks;    }    /**     * Updates cache with new VO.     * @param script Script VO     */    public void updateCache( Script script ) {        Integer key = script.getId();        if( getLogger().isDebugEnabled() ) {            DEBUG( "Try to update Script cache" +                   ". Id: " + key + "." );        }        Cache cache = ServicesPropertyFactory.getInstance().getScriptCache();        synchronized( cache ) {            boolean isOpen = cache.open();            cache.put( key, script );            if( !isOpen ) {                cache.close();            }        }    }    /**     * Updates cache with new VO.     * @param task Task VO     */    public void updateCache( Task task ) {        Long key = task.getId();        if( getLogger().isDebugEnabled() ) {            DEBUG( "Try to update Task cache" +                   ". Id: " + key + "." );        }        Cache cache = ServicesPropertyFactory.getInstance().getTaskCache();        synchronized( cache ) {            boolean isOpen = cache.open();            cache.put( key, task );            if( !isOpen ) {                cache.close();            }        }    }    /**     * Flushes key <code>script_id</code> from Script cache.     * @param script_id script id     */    public void flushScriptCache( int script_id ) {        Integer key = new Integer( script_id );        if( getLogger().isDebugEnabled() ) {            DEBUG( "Try to flush Script cache" +                   ". Id: " + key + "." );        }        Cache cache = ServicesPropertyFactory.getInstance().getScriptCache();        // Open cache and don't close it!        cache.open();        cache.remove( key );    }    /**     * Flushes key <code>task_id</code> from Task cache.     * @param task_id task id     */    public void flushTaskCache( long task_id ) {        Long key = new Long( task_id );        if( getLogger().isDebugEnabled() ) {            DEBUG( "Try to flush Task cache" +                   ". Id: " + key + "." );        }        Cache cache = ServicesPropertyFactory.getInstance().getTaskCache();        // Open cache and don't close it!        cache.open();        cache.remove( key );    }    /**     * Get tasks with flag "auto start"     * @return Collection of Task objects or null     */    public Collection getAutostartedTasks() {        DEBUG( "Try to get autostarted tasks" );        Collection tasks = getTasks();        if( tasks == null || tasks.size() == 0 ) {            return null;        }        Collection ret = new ArrayList();        for( Iterator it = tasks.iterator(); it.hasNext(); ) {            Task task = ( Task ) it.next();            if( task.getAutoStart().booleanValue() ) {                ret.add( task );            }        }        // Ok.        if( getLogger().isInfoEnabled() ) {            INFO( "Got [" + ret.size() + "] autostarted tasks..." );        }        return ret;    }    /**     * Get running tasks     * @return Collection of Task objects or null     */    public Collection getRunTasks() {        DEBUG( "Try to get running tasks" );        Collection tasks = getTasks();        if( tasks == null || tasks.size() == 0 ) {            return null;        }        Collection ret = new ArrayList();        for( Iterator it = tasks.iterator(); it.hasNext(); ) {            Task task = ( Task ) it.next();            int status = task.getStatus().getType();            if( status == StatusSType.RUN_TYPE ||                status == StatusSType.WAITED_TYPE ) {                ret.add( task );            }        }        // Ok.        if( getLogger().isInfoEnabled() ) {            INFO( "Got [" + ret.size() + "] running tasks..." );        }        return ret;    }    /**     * Get matured (ready to run) tasks     * @return Collection of Task objects or null     */    public Collection getMaturedTasks() {        DEBUG( "Try to get matured tasks" );        Collection tasks = getTasks();

⌨️ 快捷键说明

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