IBM FileNet P8, バージョン 5.2.1            

デーモン・ベースのワーク・パフォーマーの開発

デーモン・ベースのワーク・パフォーマーは、カスタム Java™ コードと Process Java API を使用して、ワークフロー・ステップに関連付けられているオペレーションを実行します。

次のコード・ベースのアプローチを使用して、カスタム・デーモン・ベースのワーク・パフォーマーを作成し、キューの照会、ワークの処理、およびワークフロー・ステップでの自動オペレーションの完了を行います。

  1. Content Platform Engine サーバーにログインし、VWSession を使用してワークフロー・システム・セッションを確立します。

    詳細については、SessionHelper ヘルパー・クラスを参照してください。

  2. 目的のワークフロー・システム・キューをポーリングして、オペレーションを検索し、オブジェクトを取得します。ポーリング間隔 (ミリ秒) を設定します。

    パフォーマンスを最適化するには、キューから取得するステップ・エレメントやワーク・オブジェクトをフィルター処理または索引付けします。(例えば、Content Platform Engine サーバーからのそれぞれのフェッチで取得するオブジェクトの最大数を設定して、フィルター処理します。)

  3. (オプション) ログ用の Logger オブジェクトを作成して、初期化します。(例えば、Process Designer を使用して指定し、ユーザーに対して表示できるコメントを統合するための Logger オブジェクトを作成できます。)

    詳細については、Logger ヘルパー・クラスを参照してください。

  4. エレメントまたはワーク・オブジェクトを処理します。この処理には、次のようなものが含まれます。
    • オブジェクトをロックする (例えば、VWWorkObject.doLock() を使用する)。
    • ワークフロー・データを更新する (例えば、データ・フィールド値の抽出、パラメーターの更新、またはコメントの設定を行う)。
    • ステップを完了する (例えば、ワークフロー・ユーザーがユーザー・インターフェースで「完了」「保存」 の順にクリックしたときの操作を指定する)。

      詳細については、ステップの完了を参照してください。

ワーク・パフォーマーのサンプル

次のワーク・パフォーマー・クラスのサンプルは、ワーク・キューの自動的なポーリング、ワーク・オブジェクトの取得、ワーク・オブジェクトの処理、ステップの完了、および再利用の各方法を示しています。詳細については、WorkPerformerSample を参照してください。

package samples.api;

import filenet.vw.api.*;

/**
* This sample class illustrates how to retrieve, modify, and complete a step
* using the VWWorkObject class.
*
* @since eProcess 4.1
* @see      SessionHelper
* @see      QueueHelper
* @see      Logger
*/
public class WorkPerformerSample extends Object implements Runnable
{
        // declare variables
        private Logger          m_logger = null;
        private VWQueue         m_vwQueue = null;
        private boolean         m_bDone = false;
    
    
    /**
     * Constructor - performs initialization
     *
     * @param vwSession a VWSession object.
     * @param logger Logger オブジェクトです。
     * @param queueName 表示するキューの名前です。
     * @since eProcess 4.1
     */
        public WorkPerformerSample(VWSession vwSession, Logger logger, String queueName)
        {
            int nCh = 0;
            
                try
                {
                    m_logger = logger;
                    
                    if (m_logger != null)
                    m_logger.logAndDisplay("¥n~ Starting WorkPerformerSample execution.");

            // ヘルパー・クラスを作成
            QueueHelper queueHelper = new QueueHelper(vwSession, logger);
            
            // get the requested queue
            m_vwQueue = queueHelper.getQueue(queueName);
            if (m_vwQueue != null)
            {
                // start the process thread
                Thread thread = new Thread(this, "WorkPerformerSample");
                thread.start();
                
                // wait for key press
                System.out.print("Hit Enter key to exit:");
                while (!m_bDone)
                {
                    try
                    {
                        nCh = System.in.read();
                        if (nCh < 0 || (char)nCh == '¥n')
                            m_bDone = true;
                    }
                    catch(java.io.IOException e)
                    {
                        m_bDone = true;
                    }
                }
                
                // スレッドの終了を待機
                System.out.print("Finishing processing - please wait.");
                while (thread.isAlive());
            }
            else
            {
                        if (m_logger != null)
                            m_logger.logAndDisplay("¥n  Unable to retrieve queue: " + queueName);
            }
                }
                catch(Exception ex)
                {
                if (m_logger != null)
                    m_logger.log(ex);
            else
                            ex.printStackTrace();
                }
                finally
                {
                if (m_logger != null)
                        m_logger.logAndDisplay("~ WorkPerformerSample execution complete.¥n");
                }
        }

    /**
     * Creates the Logger and SessionHelper objects, then
     * instantiates the outer class.
     *
     * @param args a String array contianing command line arguments
     * @since eProcess 4.1
     */
    public static void main(String args[])
        {
                String              outputFileName = null;
            Logger              logger = null;
            SessionHelper       sessionHelper = null;
            VWSession           vwSession = null;
            
            try
            {
                // ユーザーが十分な引数を入力したか?
            if (args.length < 4 || (args.length > 0 && args[0].compareTo("?") == 0))
                {
                            System.out.println("Usage:  WorkPerformerSample username password router_URL queueName [output_filename]");
                System.exit(1);
                }
            
                    // the file name (for output) is optional
                if (args.length > 4)
                            outputFileName = args[4];
                    else
                            outputFileName = new String("WorkPerformerSample.out");

                // ロガーを作成して初期化
                logger = new Logger(outputFileName);
                
                // create the session and log in
                sessionHelper = new SessionHelper(args[0], args[1], args[2], logger);
                vwSession = sessionHelper.logon();
                if (vwSession != null)
                {
                    // create the sample class
                        new WorkPerformerSample(vwSession, logger, args[3]);
                    }
            }
            catch (Exception ex)
            {
                if (logger != null)
                    logger.log(ex);
            else
                            ex.printStackTrace();
                            
                        System.exit(1);
        }
        finally
        {
                // logoff
                if (sessionHelper != null)
                    sessionHelper.logoff();
        }

        System.exit(0);
        }

    //--------------------------------------
    // Runnable methods
    //--------------------------------------
    
    /**
     * Starts the thread's execution
     * 
     * @since eProcess 4.1
     */
    public void run()
    {
        try
        {
            while (!m_bDone)
            {
                // search the queue
                processQueue(m_vwQueue);
                
                // let some time go by (30 seconds)
                if (!m_bDone)
                    Thread.sleep(30000);
            }
        }
        catch(InterruptedException ie)
        {
        }
        catch (Exception ex)
        {
                        if (m_logger != null)
                            m_logger.log(ex);
            else
                            ex.printStackTrace();
        }
    } 

    //--------------------------------------
        // private methods
    //--------------------------------------

    /**
     * Retrieves all work objects from the specified queue
     *
     * @param vwQueue a VWQueue object.
     * @since eProcess 4.1
     */
        private void processQueue(VWQueue vwQueue)
        {
            VWQueueQuery    qQuery = null;
            VWWorkObject    workObject = null;

                try
                {
                        // 各サーバーのフェッチ・トランザクションで取得するアイテムの最大数を設定。
                        // この場合、値を 25 に設定することで、デフォルト設定値 (50) よりも
			// 各フェッチで必要なメモリーが少なくて済みます。
                        vwQueue.setBufferSize(25);

                        // キュー照会オブジェクトの構成と、すべてのステップ・エレメントの照会
                        qQuery = vwQueue.createQuery(null, null, null, 0, null, null, VWFetchType.FETCH_TYPE_WORKOBJECT);
                        if (qQuery != null)
                        {
                            while (qQuery.hasNext())
                            {
                                // get the work object
                                workObject = (VWWorkObject)qQuery.next();
                    if (workObject != null)
                        processWork(workObject);
                            }
                        }
            }
                catch (Exception ex)
                {
                        if (m_logger != null)
                            m_logger.log(ex);
            else
                            ex.printStackTrace();
                }
    }

    /**
     * Processes the work object
     *
     * @param workObject the work object to process.
     * @since eProcess 4.1
     */
        private void processWork(VWWorkObject workObject)
        {
                try
                {
            // lock the record
            workObject.doLock(true);
                    
            // extract the data field values
            if (workObject.hasFieldName("AppID"))
            {
                Integer appID = (Integer)workObject.getFieldValue("AppID");
            }
                
            if (workObject.hasFieldName("Title"))
            {
                String title = (String)workObject.getFieldValue("Title");
            }

            // コメントを設定
            if (workObject.hasFieldName("F_Comment"))
            {
                workObject.setFieldValue("F_Comment", "Processed by WorkPerformer", true);
            }

            // complete the step
            if (m_logger != null)
                m_logger.log("Completing step: " + workObject.getStepName());
                
            workObject.doDispatch();
                }
                catch(Exception ex)
                {
                if (m_logger != null)
                    m_logger.log(ex);
            else
                            ex.printStackTrace();
                }
        }

}


最終更新日: 2015 年 10 月
building_daemon_wp.htm

© Copyright IBM Corp. 2015.