01: package demo.poa_monitor.user_poa;
02:
03: import demo.poa_monitor.foox.*;
04: import org.omg.PortableServer.*;
05:
06: public class FooServantActivatorImpl extends _ServantActivatorLocalBase {
07: private org.omg.CORBA.Object forwardRef = null;
08: private FooImpl forwardServant = new FooImpl("0");
09: private org.omg.PortableServer.POA rootPOA = null;
10:
11: public FooServantActivatorImpl(org.omg.CORBA.ORB orb) {
12: try {
13: rootPOA = POAHelper.narrow(orb
14: .resolve_initial_references("RootPOA"));
15: } catch (Throwable e) {
16: e.printStackTrace();
17: }
18: }
19:
20: private void initForwardRef() {
21: if (Server.kind == 2) {
22: try {
23: System.out.println("[ creating forward reference ]");
24: forwardRef = rootPOA
25: .servant_to_reference(forwardServant);
26: } catch (Throwable e) {
27: e.printStackTrace();
28: }
29: }
30: }
31:
32: public void etherealize(byte[] oid, POA adapter, Servant servant,
33: boolean cleanup_in_progress, boolean remaining_activations) {
34: String oidStr = new String(oid);
35: System.out.println("[ etherialize servant for oid: " + oidStr
36: + " ]");
37: }
38:
39: public Servant incarnate(byte[] oid, POA adapter)
40: throws ForwardRequest {
41: if (forwardRef == null)
42: initForwardRef();
43:
44: String oidStr = new String(oid);
45: int oidInt = Integer.parseInt(oidStr);
46: if (oidInt >= 1000) {
47: if (Server.kind == 2 && (oidInt % 2) == 0) {
48: System.out
49: .println("[ trying to incarnate servant for oid: "
50: + oidStr + " ]");
51: System.out.println("[ forward request ]");
52: throw new ForwardRequest(forwardRef);
53:
54: } else {
55: System.out.println("[ incarnate servant for oid: "
56: + oidStr + " ]");
57: return new FooImpl(oidStr);
58: }
59: } else {
60: throw new org.omg.CORBA.OBJECT_NOT_EXIST();
61:
62: }
63: }
64: }
|