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

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

例: 作業オブジェクトの作成

トピックに動的にサブスクライブする作業オブジェクトを作成することができます。 また、イベント・ソースへのアクセスを持つ任意のコンポーネントは、要求に応じてイベントを追加することができます。

以下に、トピックを動的にサブスクライブする作業オブジェクトの一例を示します。
class SampleWork implements Work
{
	boolean released;
	Topic targetTopic;
	EventSource es;
	TopicConnectionFactory tcf;

	public SampleWork(TopicConnectionFactory tcf, EventSource es, Topic targetTopic)
	{
		released = false;
		this.targetTopic = targetTopic;
		this.es = es;
		this.tcf = tcf;
	}

	synchronized boolean getReleased()
	{
		return released;
	}

	public void run()
	{
		try {
    		// setup our JMS stuff.
		TopicConnection tc = tcf.createConnection();
		TopicSession sess = tc.createSession(false, Session.AUTOACK);
			tc.start();

		MessageListener proxy = es.getEventTrigger(MessageListener.class, false);
		while(!getReleased())
			{
			// block for up to 5 seconds.
			Message msg = sess.receiveMessage(5000);
			if(msg != null)
				{
// fire an event when we get a message
proxy.onMessage(msg);
				}
			}
		tc.close();
		}
		catch (JMSException ex)
		{
			// handle the exception here
		throw ex;
		}
		finally
		{
			if (tc != null)
			{
				try {
		tc.close();
				}
				catch (JMSExceptin ex1) 
				{
	// handle exception
				}
			}
		}
	}

	// called when we want to stop the Work object.
	public synchronized void release()
	{
		released = true;
	}
}

この結果、イベント・ソースへのアクセス権を持つコンポーネントは、 イベントをオンデマンドで追加することができます。これにより、コンポーネントは、 各クライアント・サブスクライバーに自身のスレッドを与えるよりもスケーラブルな方法でトピックをサブスクライブすることができます。 上記の例は WebSphere トレーダーのサンプルで詳細に説明されています。 詳しくは、サンプル・ギャラリーを参照してください。




関連概念
サンプルへのアクセス
関連タスク
コードを並列に実行する作業オブジェクトの開発
参照トピック    

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

最終更新: 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/asyncbns/xmp/xasb_workobject.html