Javaの場合,SampleServerInterceptorLoaderオブジェクトは,POALifeCycleInterceptorクラスのロードとオブジェクトの実体化に責任があります。このクラスは,vbroker.orb.dynamicLibsによって動的にBorland Enterprise Server VisiBroker ORBにリンクされます。SampleServerLoader クラスにはinit()メソッドがあり,このメソッドは初期化時にBorland Enterprise Server VisiBroker ORBによって起動されます。その唯一の目的は,POALifeCycleInterceptorオブジェクトを生成して,InterceptorManagerに登録することによって,POALifeCycleInterceptorオブジェクトをインストールすることです。
import java.util.*;
import com.inprise.vbroker.orb.*;
import com.inprise.vbroker.interceptor.*;
import com.inprise.vbroker.PortableServerExt.*;
public class SampleServerLoader implements ServiceLoader {
public void init(org.omg.CORBA.ORB orb){
try {
InterceptorManagerControl control =
InterceptorManagerControlHelper.narrow(
orb.resolve_initial_references
("VisiBrokerInterceptorControl"));
//Install a POA interceptor
POALifeCycleInterceptorManager poa_manager =
(POALifeCycleInterceptorManager)control.get_manager
("POALifeCycle");
poa_manager.add(new SamplePOALifeCycleInterceptor());
}catch(Exception e){
e.printStackTrace();
throw new org.omg.CORBA.INITIALIZE(e.toString());
}
System.out.println("============>SampleServerLoader:
Interceptors loaded");
}
public void init_complete(org.omg.CORBA.ORB orb){
}
public void shutdown(org.omg.CORBA.ORB orb){
}
}
SamplePOALifeCycleInterceptorオブジェクトは,POAが生成されるたびに,またはPOAがデストラクトされるたびに起動されます。client_serverの例では二つのPOAがあるので,このインタセプタは2回起動されます。1回目は,rootPOA生成時,2回目はmyPOA生成時です。myPOAの生成時だけ,SampleServerInterceptorをインストールします。
import com.inprise.vbroker.interceptor.*;
import com.inprise.vbroker.PortableServerExt.*;
import com.inprise.vbroker.IOP.*;
public class SamplePOALifeCycleInterceptor implements
POALifeCycleInterceptor {
public void create(org.omg.PortableServer.POA poa,
org.omg.CORBA.PolicyListHolder policies_holder,
IORValueHolder iorTemplate,
InterceptorManagerControl control){
if(poa.the_name().equals("bank_agent_poa")){
//Add the Request-level interceptor
SampleServerInterceptor interceptor =
new SampleServerInterceptor("MyServerInterceptor");
//Get the IORCreation interceptor manager
ServerRequestInterceptorManager manager =
(ServerRequestInterceptorManager)control.get_manager
("ServerRequest");
//Add the interceptor
manager.add(interceptor);
System.out.println("========>In POA " + poa.the_name() +
",1 ServerRequest interceptor installed");
}else
System.out.println("========>In POA " + poa.the_name() +
". Nothing to do.");
}
public void destroy(org.omg.PortableServer.POA poa){
//To be a trace!
System.out.println("========>SamplePOALifeCycleInterceptor
destroy");
}
}
SampleServerInterceptorオブジェクトは,リクエストを受信するたびに,またはサーバが応答するたびに起動されます。
import com.inprise.vbroker.interceptor.*;
import com.inprise.vbroker.IOP.*;
import com.inprise.vbroker.CORBA.portable.*;
public class SampleServerInterceptor implements ServerRequestInterceptor {
private String _id;
public SampleServerInterceptor(String id){
_id =id;
}
public void preinvoke(org.omg.CORBA.Object target,
String operation,
ServiceContext [ ] service_contexts,
InputStream payload,
Closure closure){
//Put the _id of this ServerRequestInterceptor into the
// closure object
closure.object =new String(_id);
System.out.println("========>SampleServerInterceptor id "+
closure.object + " preinvoke => " + operation);
}
public void postinvoke_premarshal(org.omg.CORBA.Object target,
ServiceContextListHolder service_contexts_holder,
org.omg.CORBA.Environment env,
Closure closure){
System.out.println("========>SampleServerInterceptor id "+
closure.object + " postinvoke_premarshal");
}
public void postinvoke_postmarshal(org.omg.CORBA.Object target,
OutputStream payload,
Closure closure){
System.out.println("========>SampleServerInterceptor id "+
closure.object + " postinvoke_postmarshal");
}
public void exception_occurred(org.omg.CORBA.Object target,
org.omg.CORBA.Environment env,
Closure closure){
System.out.println("============>SampleServerInterceptor id "+
closure.object +" exception_occurred");
}
}
SampleClientInterceptorは,リクエストを生成するたびに,またはクライアントが応答を受信するたびに起動されます。
ローダはBindInterceptorオブジェクトのロードに責任があります。SampleClientInterceptorLoaderクラスには,bind()メソッドとbind_succeeded()メソッドがあります。これらのメソッドは,オブジェクトのバインド時にBorland Enterprise Server VisiBroker ORBによって起動されます。バインドが成功すると,bind_succeeded()メソッドがORBによって起動され,BindInterceptorオブジェクトを生成し,それをInterceptorManagerに登録することによって,BindInterceptorオブジェクトがインストールされます。
import com.inprise.vbroker.interceptor.*;
import com.inprise.vbroker.IOP.*;
import com.inprise.vbroker.CORBA.portable.*;
public class SampleClientInterceptor implements ClientRequestInterceptor {
private String _id;
public SampleClientInterceptor(String id){
_id =id;
}
public void preinvoke_premarshal(org.omg.CORBA.Object target,
String operation,
ServiceContextListHolder service_contexts_holder,
Closure closure){
// Put the _id of this ClientRequestInterceptor into the
// closure object
closure.object =new String(_id);
System.out.println("============>SampleClientInterceptor id "+
closure.object +
"preinvoke_premarshal =>"+operation);
}
public void preinvoke_postmarshal(org.omg.CORBA.Object target,
OutputStream payload,
Closure closure){
System.out.println("============>SampleClientInterceptor id "+
closure.object +"preinvoke_postmarshal");
}
public void postinvoke(org.omg.CORBA.Object target,
ServiceContext [ ] service_contexts,
InputStream payload,
org.omg.CORBA.Environment env,
Closure closure){
System.out.println("============>SampleClientInterceptor id "+
closure.object +"postinvoke");
}
public void exception_occurred(org.omg.CORBA.Object target,
org.omg.CORBA.Environment env,
Closure closure){
System.out.println("============>SampleClientInterceptor id "+
closure.object +"exception_occurred");
}
}
Javaの場合,ローダはBindInterceptorオブジェクトのロードに責任があります。このクラスは,vbroker.orb.dynamicLibsによって動的にBorland Enterprise Server VisiBroker ORBにリンクされます。SampleClientInterceptorLoaderクラスには,bind()メソッドとbind_succeeded()メソッドがあります。これらのメソッドは,オブジェクトのバインド時にORBによって起動されます。バインドが成功すると,bind_succeeded()メソッドがORBによって起動され,BindInterceptorオブジェクトを生成し,それをInterceptorManagerに登録することによって,BindInterceptorオブジェクトがインストールされます。
import java.util.*;
import com.inprise.vbroker.orb.*;
import com.inprise.vbroker.interceptor.*;
import com.inprise.vbroker.PortableServerExt.*;
public class SampleClientLoader implements ServiceLoader {
public void init(org.omg.CORBA.ORB orb){
try {
InterceptorManagerControl control =
InterceptorManagerControlHelper.narrow(
orb.resolve_initial_references("VisiBrokerInterceptorControl"));
BindInterceptorManager bind_manager =
(BindInterceptorManager)control.get_manager("Bind");
bind_manager.add(new SampleBindInterceptor());
}catch(Exception e){
e.printStackTrace();
throw new org.omg.CORBA.INITIALIZE(e.toString());
}
System.out.println("Bind Interceptors loaded");
}
public void init_complete(org.omg.CORBA.ORB orb){
}
public void shutdown(org.omg.CORBA.ORB orb){
}
}
SampleBindInterceptorは,オブジェクトにバインドしようとするクライアントによって起動されます。ORB初期化後のクライアント側の最初の手順は,AccountManagerオブジェクトにバインドすることです。このバインドによってSampleBindInterceptorを起動し,バインドが成功すると,SampleClientInterceptorがインストールされます。
import com.inprise.vbroker.interceptor.*;
import com.inprise.vbroker.IOP.*;
public class SampleBindInterceptor implements BindInterceptor {
public IORValue bind(IORValue ior,org.omg.CORBA.Object target,
boolean rebind,Closure closure){
//To be a trace!
System.out.println("============>SampleBindInterceptor bind");
return null;
}
public IORValue bind_failed(IORValue ior,org.omg.CORBA.Object target,
Closure closure){
//To be a trace!
System.out.println("============>SampleBindInterceptor
bind_failed");
return null;
}
public void bind_succeeded(IORValue ior,org.omg.CORBA.Object target,
int Index,InterceptorManagerControl control,
Closure closure){
//To be a trace!
System.out.println("============>SampleBindInterceptor
bind_succeeded");
//Create the Client Request interceptor:
SampleClientInterceptor interceptor =
new SampleClientInterceptor("MyClientInterceptor");
//Get the manager
ClientRequestInterceptorManager manager =
(ClientRequestInterceptorManager)control.
get_manager("ClientRequest");
//Add CRQ to the list:
manager.add(interceptor);
}
public void exception_occurred(IORValue ior,org.omg.CORBA.Object
target,
org.omg.CORBA.Environment env,
Closure closure){
//To be a trace!
System.out.println("============>SampleBindInterceptor
exception_occurred");
}
}