KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > bidir > ServerImpl


1 package demo.bidir;
2
3 import org.omg.CosNaming.*;
4 import org.omg.PortableServer.*;
5 import org.omg.BiDirPolicy.*;
6 import org.omg.CORBA.*;
7
8 import java.util.Properties JavaDoc;
9 /**
10  * ServerImpl.java
11  *
12  *
13  * Created: Mon Sep 3 19:28:34 2001
14  *
15  * @author Nicolas Noffke
16  * @version $Id: ServerImpl.java,v 1.2 2003/12/01 12:36:00 simon.mcqueen Exp $
17  */

18
19 public class ServerImpl
20     extends ServerPOA
21 {
22     private ClientCallback ccb = null;
23
24     public ServerImpl()
25     {
26     }
27
28     public void register_callback( ClientCallback ccb )
29     {
30         this.ccb = ccb;
31     }
32     
33     public void callback_hello( String JavaDoc message )
34     {
35         System.out.println( "Server object received hello message >" +
36                             message +
37                             '<');
38         
39         ccb.hello( message );
40     }
41
42     public static void main( String JavaDoc[] args )
43         throws Exception JavaDoc
44     {
45         Properties JavaDoc props = new Properties JavaDoc();
46         props.put( "org.omg.PortableInterceptor.ORBInitializerClass.bidir_init",
47                    "org.jacorb.orb.giop.BiDirConnectionInitializer" );
48
49         org.omg.CORBA.ORB JavaDoc orb = org.omg.CORBA.ORB.init( args, props );
50
51         Any any = orb.create_any();
52         BidirectionalPolicyValueHelper.insert( any, BOTH.value );
53
54         POA root_poa = (POA) orb.resolve_initial_references( "RootPOA" );
55
56         Policy[] policies = new Policy[4];
57         policies[0] =
58             root_poa.create_lifespan_policy(LifespanPolicyValue.TRANSIENT);
59
60         policies[1] =
61             root_poa.create_id_assignment_policy(IdAssignmentPolicyValue.SYSTEM_ID);
62
63         policies[2] =
64             root_poa.create_implicit_activation_policy( ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION );
65
66         policies[3] = orb.create_policy( BIDIRECTIONAL_POLICY_TYPE.value,
67                                          any );
68         
69         POA bidir_poa = root_poa.create_POA( "BiDirPOA",
70                                              root_poa.the_POAManager(),
71                                              policies );
72         bidir_poa.the_POAManager().activate();
73
74         org.omg.CORBA.Object JavaDoc o =
75             bidir_poa.servant_to_reference( new ServerImpl() );
76
77         NamingContextExt nc =
78             NamingContextExtHelper.narrow(
79                 orb.resolve_initial_references( "NameService" ));
80         
81         NameComponent[] n = nc.to_name( "bidir.example" );
82
83         nc.bind( n, o );
84
85         orb.run();
86     }
87 }// ServerImpl
88

89
Popular Tags