2312321

public abstract class BaseActivity implements Activity, BeanNameAware
{
    private String beanName;
    private ErrorHandler errorHandler;
    private List output;
    /**
     * Activity.execute的缺省实现,由处理器(Processor)进行调用,触发Activity单元的执行
     *
     * @param context - process context for this workflow
     * @return resulting process context
     * @throws ActivityException 执行中的异常
     */
    public ProcessContext execute(ProcessContext context)
        throws ActivityException
    {
        ProcessContext result;
        result = perform(context);//执行子类业务逻辑
        yield(result); //触发种子生长
        return result;
    }
   
    /**
     * 由继承的业务Activity子类实现其业务逻辑
     * @param context 业务Activity执行中所需要的“上下文”对象,该对象包含“种子(Seed)”属性和流程相关属性
     * @return 业务Activity执行后的结果“上下文”对象
     */
    protected abstract ProcessContext perform(ProcessContext context);
    private void yield(ProcessContext context)
    {
        context.filter(output);
    }
public class BaseEngine implements Engine, BeanNameAware
{
    private static final int DEFAULT_POOL_SIZE = 3;
   
    private String beanName;
   
    private List targetTypes = new ArrayList();
   
    private BlockingQueue queue;
   
    private Processor processor;
   
    private int poolSize = DEFAULT_POOL_SIZE;
   
    private ExecutorService executor;
   
    /**
     * 初始化引擎,初始化工作队列和执行线程
     */
    public void init()
    {
        executor = Executors.newFixedThreadPool(poolSize);
    }
   
    /**
     * 运转引擎
     */
    public void run()
    {
        startTasks();
    }
   
    /*
     * 创建并启动执行器线程(共poolSize个执行器)
     */
    private void startTasks()
    {
        for (int i = 0; i < poolSize; i++)
        {
            Runnable exe = processor.createExecutor(queue);
            addTask(exe);
        }
    }
   
    private void addTask(Runnable exe)
    {
        try
        {
            executor.execute(exe);
        }
        catch (RejectedExecutionException re)
        {
            AEnvAdapter.LOGGER_WARN.warn("RejectedExecutionException be throwed!",
                    re);
        }
    }

你可能感兴趣的:(工作,workflow)