KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > bidir > Client


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  * Client.java
11  *
12  *
13  * Created: Mon Sep 3 19:28:34 2001
14  *
15  * @author Nicolas Noffke
16  * @version $Id: Client.java,v 1.2 2003/12/01 12:36:00 simon.mcqueen Exp $
17  */

18
19 public class Client
20     extends ClientCallbackPOA
21 {
22     public Client ()
23     {
24     }
25     
26     public void hello( String JavaDoc message )
27     {
28         System.out.println( "Client callback object received hello message >" +
29                             message +
30                             '<');
31     }
32
33     public static void main( String JavaDoc[] args )
34         throws Exception JavaDoc
35     {
36         Properties JavaDoc props = new Properties JavaDoc();
37         props.put( "org.omg.PortableInterceptor.ORBInitializerClass.bidir_init",
38                    "org.jacorb.orb.giop.BiDirConnectionInitializer" );
39
40         org.omg.CORBA.ORB JavaDoc orb = org.omg.CORBA.ORB.init( args, props );
41
42         NamingContextExt nc =
43             NamingContextExtHelper.narrow(
44                 orb.resolve_initial_references( "NameService" ));
45         
46         org.omg.CORBA.Object JavaDoc o =
47             nc.resolve( nc.to_name( "bidir.example" ));
48
49         Server server = ServerHelper.narrow( o );
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         ClientCallback ccb = ClientCallbackHelper.narrow( bidir_poa.servant_to_reference( new Client() ));
75         
76         server.register_callback( ccb );
77         
78         server.callback_hello( "A test string" );
79     }
80 }// Client
81
Popular Tags