KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > poa_monitor > user_poa > FooServantActivatorImpl


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