付録A オブジェクトストア実装

A.1. ObjectStore

本項では、様々なJBoss Transaction Service オブジェクトストア実装について触れており、新規実装の作成方法やアプリケーションで利用方法を説明しています。
JBoss Transaction Service には、基本的なオブジェクトストアの様々種類の実装が含まれています。各実装は、特定の目的用に最適化されています。実装はすべてObjectStore インターフェースから来ており、JBoss Trasaction Service が使用するオブジェクトストア実装に必要最小限の操作を定義しています。com.arjuna.ats.arjuna.objectstore.objectStoreType プロパティを例A.1「オブジェクトストアの種類」にて説明している種類の1つに設定することで、デフォルトのオブジェクトストア実装をランタイム時にオーバーライドすることができます。

例A.1 オブジェクトストアの種類

	/*
	* This is the base class from which all object store types are derived.
	* Note that because object store instances are stateless, to improve
	* efficiency we try to only create one instance of each type per process.
	* Therefore, the create and destroy methods are used instead of new
	* and delete. If an object store is accessed via create it *must* be
	* deleted using destroy. Of course it is still possible to make use of
	* new and delete directly and to create instances on the stack.
	*/
	
	public class ObjectStore
	{
	public static final int OS_COMMITTED;
	public static final int OS_COMMITTED_HIDDEN;
	public static final int OS_HIDDEN;
	public static final int OS_INVISIBLE;
	public static final int OS_ORIGINAL;
	public static final int OS_SHADOW;
	public static final int OS_UNCOMMITTED;
	public static final int OS_UNCOMMITTED_HIDDEN;
	public static final int OS_UNKNOWN;
	public ObjectStore (ClassName type);
	public ObjectStore (ClassName type, String osRoot);
	public ObjectStore (String osRoot);
	public synchronized boolean allObjUids (String s, InputObjectState buff)
	throws ObjectStoreException;
	public synchronized boolean allObjUids (String s, InputObjectState buff,
	int m) throws ObjectStoreException;
	
	public synchronized boolean allTypes (InputObjectState buff)
	throws ObjectStoreException;
	public synchronized int currentState(Uid u, String tn)
	throws ObjectStoreException;
	public synchronized boolean commit_state (Uid u, String tn)
	throws ObjectStoreException;
	public synchronized boolean hide_state (Uid u, String tn)
	throws ObjectStoreException;
	public synchronized boolean reveal_state (Uid u, String tn)
	throws ObjectStoreException;
	public synchronized InputObjectState read_committed (Uid u, String tn)
	throws ObjectStoreException;
	public synchronized InputObjectState read_uncommitted (Uid u, String tn)
	throws ObjectStoreException;
	public synchronized boolean remove_committed (Uid u, String tn)
	throws ObjectStoreException;
	public synchronized boolean remove_uncommitted (Uid u, String tn)
	throws ObjectStoreException;
	public synchronized boolean write_committed (Uid u, String tn,
	OutputObjectState buff)
	throws ObjectStoreException;
	public synchronized boolean write_uncommitted (Uid u, String tn,
	OutputObjectState buff)
	throws ObjectStoreException;
	public static void printState (PrintStream strm, int res);
	};
デフォルトのストアタイプを利用せずにオブジェクトストア実装を作成する場合をのぞき、オブジェクトストア実装と直接やりとりを行う必要はありません。ストアは全て、ObjectStateクラスのインスタンスを操作します。このObjectState クラスはオブジェクトのtype()操作とUid から取得したタイプを利用し命名されています。このストア内にあるオブジェクトステートは通常、OS_COMMITTEDOS_UNCOMMITTEDのように全く違った種類のステート2つのうち1つとなっています。オブジェクトステートは、OS_COMMITTEDのステートから開始しますが、atomic アクションの制御のもと変更されると、OS_UNCOMMITTED のステートにある、2番目の新規オブジェクトのステートを書き込むことができます。このアクションがコミットされると、元のオブジェクトステートがこの2番目のオブジェクトステートで置き換えられ、OS_COMMITTEDになります。このアクションが中断されると、2番目の状態は破棄されます。このリリースで提供されている実装はすべて、シャドーコピーを使い、これらのステート移行を処理します。しかし、別の方法でこれらのステートを実装することも可能です。クラッシュリカバリシステムの制御のもと、オブジェクトステートが隠されアクセスできなくなります。
allTypes および allObjUids メソッドにより、ストアの内容を参照することができます。allTypes メソッドが、ストア内にある全オブジェクトの全タイプ名を含むInputObjectState を返します。このメソッドは null 名で終了します。また、allObjUids メソッドは、特定の種類の全オブジェクトに含まれるUid すべてで構成されるInputObjectStateを返し、特別なUid.nullUid() タイプにより終了されます。