KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > core > dist > corba > CORBADistd


1 /*
2   Renaud Pawlak, pawlak@cnam.fr, CEDRIC Laboratory, Paris, France.
3   Lionel Seinturier, Lionel.Seinturier@lip6.fr, LIP6, Paris, France.
4
5   JAC-Core is free software. You can redistribute it and/or modify it
6   under the terms of the GNU Library General Public License as
7   published by the Free Software Foundation.
8   
9   JAC-Core is distributed in the hope that it will be useful, but
10   WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13   This work uses the Javassist system - Copyright (c) 1999-2000
14   Shigeru Chiba, University of Tsukuba, Japan. All Rights Reserved. */

15
16 package org.objectweb.jac.core.dist.corba;
17
18 import org.objectweb.jac.core.dist.Distd;
19
20 import org.omg.CORBA.ORB JavaDoc;
21 import org.omg.CosNaming.NameComponent JavaDoc;
22 import org.omg.CosNaming.NamingContext JavaDoc;
23 import org.omg.CosNaming.NamingContextHelper JavaDoc;
24 import org.omg.PortableServer.POA JavaDoc;
25 import org.omg.PortableServer.POAHelper JavaDoc;
26 import org.omg.PortableServer.POAManager JavaDoc;
27
28
29 /**
30  * CORBADistd is a jac daemon that support the IIOP communication protocol.
31  *
32  * Daemons hold containers (only one for the moment) which themselves hold
33  * remote objects.
34  *
35  * @author <a HREF="http://cedric.cnam.fr/~pawlak/index-english.html">Renaud Pawlak</a>
36  * @author <a HREF="http://www-src.lip6.fr/homepages/Lionel.Seinturier/index-eng.html">Lionel Seinturier</a>
37  */

38  
39 public class CORBADistd extends Distd {
40
41    /** The CORBA ORB. */
42    protected ORB JavaDoc orb;
43    
44    /** The CORBA root POA. */
45    protected POA JavaDoc poa;
46    
47    /** The CORBA root POA manager. */
48    POAManager JavaDoc manager;
49
50    /** The root naming context of the COSNaming. */
51    protected NamingContext JavaDoc nc;
52
53    
54    /**
55     * This method initializes the CORBA environment.
56     */

57    
58    public void init() {
59    
60       orb = ORB.init( new String JavaDoc[]{}, null );
61       
62       try {
63          poa = POAHelper.narrow( orb.resolve_initial_references("RootPOA") );
64          manager = poa.the_POAManager();
65          nc =
66         NamingContextHelper.narrow(
67            orb.resolve_initial_references("NameService")
68         );
69       }
70       catch( Exception JavaDoc e ) { e.printStackTrace(); }
71    }
72    
73    
74    /**
75     * This method creates a new container.
76     *
77     * @param name the identifier of the container
78     */

79    
80    public void newContainer( String JavaDoc name ) {
81
82       registerContainer( new CORBARemoteContainer(verbose), name );
83    }
84   
85
86    /**
87     * The string used to identify the type of objects registered
88     * in the COS Naming.
89     */

90    
91    final static protected String JavaDoc cosNamingEntryType = "jac daemon";
92    
93    
94    /**
95     * This method register a container in the CORBA COSNaming.
96     *
97     * @param container the container
98     * @param name the identifier of the container
99     */

100    
101    protected void registerContainer( CORBARemoteContainer container, String JavaDoc name ) {
102
103       try {
104       
105          /**
106       * Create the CORBA tie object that acts as a delegator
107       * for the container.
108       */

109          
110      CORBARemoteContainerInterfPOATie containerTie =
111         new CORBARemoteContainerInterfPOATie(container);
112      
113      
114          /** Register the container in the CORBA COSNaming */
115          
116      nc.bind(
117         new NameComponent JavaDoc[]{new NameComponent JavaDoc(name,cosNamingEntryType)},
118         poa.servant_to_reference(containerTie)
119      );
120      
121          System.out.println(
122         "--- org.objectweb.jac.dist.corba.CORBADistd: new container " + name + " ---"
123      );
124      
125       }
126       catch( Exception JavaDoc e ) { e.printStackTrace(); }
127    }
128   
129
130    /**
131     * This method creates a new container and instantiates a given class.
132     *
133     * @param name the identifier of the container
134     * @param className the name of the class to instantiate
135     */

136    
137    public void newContainer( String JavaDoc name, String JavaDoc className ) {
138    
139       registerContainer( new CORBARemoteContainer(className,verbose), name );
140    }
141    
142
143    /**
144     * This method enters the event loop of
145     * the underlying communication protocol.
146     */

147
148    public void run() {
149      
150       System.out.println( "--- org.objectweb.jac.dist.corba.CORBADistd is running ---" );
151       
152       try { manager.activate(); }
153       catch( Exception JavaDoc e ) { e.printStackTrace(); }
154       
155       orb.run();
156    }
157
158
159    /**
160     * The is the main constructor.
161     *
162     * @param args command line arguments
163     */

164    
165    public CORBADistd( String JavaDoc[] args ) { super(args); }
166    
167    public static void main( String JavaDoc[] args ) { new CORBADistd(args); }
168    
169 }
170
Popular Tags