WebSphere Application Server Network Deployment for i5/OS, Version 6.1   
             オペレーティング・システム: i5/OS

             目次と検索結果のパーソナライズ化

Java Message Service メッセージを送信するタスクの開発

スケジューラー API および WASScheduler MBean API は、 TaskInfo インターフェースの各種インプリメンテーションをサポートしています。 これらのインプリメンテーションはそれぞれ特定のタイプの作業のスケジューリングに使用することができます。 このトピックでは、Java Message Service (JMS) メッセージをキューまたはトピックに送信するタスクの作成方法について 説明します。

このタスクについて

Java Message Service (JMS) メッセージをキューまたはトピックに送信するタスクを作成するには、以下のステップを実行します。

プロシージャー

  1. Scheduler.createTaskInfo() ファクトリー・メソッドを使用して、MessageTaskInfo インターフェースの インスタンスを作成します。 JavaServer Pages (JSP) ファイル、サーブレット、または EJB コンテナーを使用して、 以下のコード例のようにインスタンスを作成します。
    //lookup the scheduler to be used
    Scheduler scheduler = (Scheduler)new InitialContext.lookup("java:comp/env/Scheduler");
    
    MessageTaskInfo taskInfo = (MessageTaskInfo) scheduler.createTaskInfo(MessageTaskInfo.class);
    
    wsadmin ツールを使用して、以下の JACL スクリプト例のようにインスタンスを作成することもできます。
    # Sample create a task using MessageTaskInfo task type
    # Call this mbean with the following parameters:
    #    <scheduler jndiName>     = JNDI name of the scheduler resource, 
    #                               for example scheduler/myScheduler
    #    <JNDI name of the QCF>   = The global JNDI name of the Queue Connection Factory.
    #    <JNDI name of the Queue> = The global JNDI name of the Queue destination
    
    set jndiName [lindex $argv 0]
    set jndiName_QCF [lindex $argv 1]
    set jndiName_Q [lindex $argv 2]
    
    # Map the JNDI name to the mbean name.  The mbean name is formed by replacing the / in the jndi name
    # with . and prepending Scheduler_
    regsub -all {/} $jndiName "." jndiNameset mbeanName Scheduler_$jndiName
    
    puts "Looking-up Scheduler MBean $mbeanName"
    set sched [$AdminControl queryNames WebSphere:*,type=WASScheduler,name=$mbeanName]
    puts $sched
    
    # Get the ObjectName format of the Scheduler MBean
    set schedO [$AdminControl makeObjectName $sched]
    
    # Create a MessageTaskInfo object using invoke_jmx
    puts "Creating MessageTaskInfo"
    set params [java::new {java.lang.Object[]} 1]
    $params set 0 [java::field com.ibm.websphere.scheduler.MessageTaskInfo class]
    
    set sigs [java::new {java.lang.String[]} 1]
    $sigs set 0 java.lang.Class
    
    set ti [$AdminControl invoke_jmx $schedO createTaskInfo $params $sigs]
    set mti [java::cast com.ibm.websphere.scheduler.MessageTaskInfo  $ti]
    puts "Created the MessageTaskInfo object: $mti"
    
    注: MessageTaskInfo オブジェクトを 作成しても、タスクはパーシスタント・ストアに追加されません。 その代わり、必要なデータのプレースホルダーが作成されます。 タスクが パーシスタント・ストアに追加されるのは、スケジューラーに対して create() メソッドが 呼び出された後になります (トピックスケジューラーへのタスクのサブミットを 参照)。
  2. MessageTaskInfo オブジェクトのパラメーターを設定します。 TaskInfo インターフェースには タスクの実行を制御するための set() メソッドが各種用意されており、いつタスクを実行し、開始時にどのような処理を行うかなどを 設定できます。

    TaskInfo インターフェースでは、動作に関する追加設定を指定することも できます (API 資料を参照)。 JavaServer Pages (JSP) ファイル、サーブレット、または EJB コンテナーを使用して、 以下のコード例のようにインスタンスを作成します。

    //create a date object which represents 30 seconds from now
    java.util.Date startDate = new java.util.Date(System.currentTimeMillis()+30000);
    
    
    //now set the start time and the JNDI names for the queue connection factory and the queue
    taskInfo.setConnectionFactoryJndiName("jms/MyQueueConnectionFactory");
    taskInfo.setDestination("jms/MyQueue");
    taskInfo.setStartTime(startDate);
    wsadmin ツールを使用して、以下の JACL スクリプト例のようにインスタンスを作成することもできます。
    # Setup the task 
    puts "Setting up the task..."
    # Set the startTime if you want the task to run at a specific time, for example:
    $mti setStartTime [java::new {java.util.Date long} [java::call System currentTimeMillis]]
    
    # Set the StartTimeInterval so the task runs in 30 seconds from now
    $mti setStartTimeInterval 30seconds
    
    # Set the global JNDI name of the QCF & Queue to send the message to.
    $mti setConnectionFactoryJndiName $jndiName_QCF
    $mti setDestinationJndiName $jndiName_Q
    
    # Set the message
    $mti setMessageData "Test Message"
    
    # Do not purge the task when it's complete
    $mti setAutoPurge false
    
    # Set the name of the task.  This can be any string value.
    $mti setName Created_by_MBean
    
    # If the task needs to run with specific authorization you can set the tasks Authentication Alias
    # Authentication aliases are created using the Admin Console.
    # $mti setAuthenticationAlias {myRealm/myAlias}
    
    puts "Task setup completed."
    

結果

MessageTaskInfo オブジェクトが作成されて、JMS メッセージを送信するタスクに関連するデータがすべて格納されます。

次の作業

スケジューラーにタスクの作成を サブミットします (トピックスケジューラーへの タスクのサブミットを参照)。



関連概念
スケジューラーを使用したタスク管理メソッド
関連タスク
Session Bean を呼び出すタスクの開発
スケジューラー通知の受信
スケジューラーの管理
関連資料
スケジューラー・インターフェース
タスク・トピック    

ご利用条件 | フィードバック

最終更新: Jan 21, 2008 8:28:52 PM EST
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.nd.iseries.doc/info/iseriesnd/scheduler/tasks/tsch_schedulemtask.html