Home
ORBacus - Dr. Michael Ebner
Contents
1. exception M IPackage E Raised under certain circumstances public String S int arg ea throws M IPackage Note that jid1 automatically inserts the fully qualified Java name for the exception E in this case M IPackage E These are the contents of IPackage E java Java package M IPackage IDL M I E 1 0 This comment describes exception E x final public class E extends org omg CORBA UserException public E Now you can use javadoc to extract the comments from the generated Java files and pro duce nicely formatted HTML documentation For additional information please refer to the javadoc documentation ORBacus 41 The ORBacus Code Generators 42 ORBacus ORB and BOA CHAPTER 4 Initializati 4 1 ORB Initialization 4 1 1 Initializing the C ORB In C the ORB is initialized with CORBA_ORB_init For example C int main int argc char argv char CORBA_ORB_var orb CORBA_ORB_init argc argv The CORBA_ORB_init call interprets arguments starting with ORB All of these argu ments passed through the argc and argv parameters are automatically removed from the argument list 4 1 2 Initializing the Java ORB for Applications A Java application can initialize the ORB in the following manner Java import org omg CORBA public static void main String args
2. 43 nce bind a2Name a2 44 45 NameComponent a3Name new NameComponent 1 46 a3Name 0 new NameComponent 47 a3Name 0 id a3 48 a3Name 0 kind 49 nc bind a3Name a3 50 51 NameComponent bName new NameComponent 2 52 bName 0 new NameComponent 53 bName 0 id ncl 54 bName 0 kind 55 bName 1 new NameComponent 56 bName 1 id b 57 bName 1 kind 58 nce bind bName b 59 60 NameComponent cName new NameComponent 3 61 cName 0 new NameComponent 62 cName 0 id ncl 63 cName 0 kind 64 cName 1 new NameComponent 65 cName 1 id nc2 66 cName 1 kind 67 cName 2 new NameComponent 68 cName 2 id c 69 cName 2 kind 70 nce bind cName c 71 72 boa impl_is_ready null 73 3 3 8 Several sample objects are created that will later be bound to our Naming Service These objects implement an interface called Named In this example the details of this interface are not important Named might even be an interface without any operations defined in it 160 ORBacus The Naming Service 10 70 72 NOD G8 WN HE MND AA WwWNH HB RoR RR HOW GQ Www HF DS amp Create and bind some new contexts and bind the sample objects to these contexts Each binding name consists of several name components NameComponent that are similar to the path components of a file located somewhere in a file
3. Client Server A Client Server B Figure 9 3 Blocking Client Server back g from B to A does not succeed because A blocks while waiting for a reply for f from B In contrast if the reactive concurrency model for the client and the server is used A can dispatch incoming requests while waiting for B s reply for This is shown in Fig ure 9 4 f r Fa dispatch g e dispatch z lt at hat Client Server Client Server Figure 9 4 Reactive Client Server The reactive concurrency models are also very fast There is no overhead for thread cre ation or context switching Only an additional call to an operation like select is needed before operations such as send recv or accept can be used by the ORB ORBacus 121 Concurrency Models 9 3 Multi Threaded Concurrency Models 9 3 1 Threaded Clients and Servers A threaded client uses two separate threads for each connection to a server one for send ing requests and another for receiving replies In contrast to a blocking server this model has the advantage that oneway requests can be sent in the background i e without blocking the user thread execution The separate receiver thread allows messages to be received and buffered for later retrieval by the user thread with DII operations such as get_response Or poll_response Like a threaded client a threaded server uses separa
4. MND AA WH FP RoR OW ORS io 8 9 10 MN A aA PWN HP bie RY Bo 12 Dawe wd bP C class I_impl virtual public I_skel public virtual char op char amp os char amp ios Wrong ios is not freed ios abc Wrong os def Wrong return ghi Wrong Forgot to free the inout string parameter ios Wrong Strings must be duplicated Here is the correct version C class I_impl virtual public I_skel public virtual char op char amp os char amp ios CORBA_string_free ios ios CORBA_string_dup abc os CORBA_string_dup def return CORBA_string dup ghi Now ios is freed All String values are now duplicated Here is an example showing how to use string out inout or return values on the calling side if CORBA_string_free is used C I_ptr i Get a reference to an I somehow char out char inOut CORBA_string_dup This is my inout arg char result ORBacus 111 C Mapping Notes 10 HI 12 LQ i2Z MANDAP WH HP 8 4 2 result i gt op out inOut CORBA_string_free out CORBA_string_free inOut CORBA_string_free result The parameters are defined A value must be assigned to the inout parameter Of course values to in parameters must also be assigned but our example does not have any in parameters op is called All out and inout parameters as well as the r
5. T C sa 3 class ShutdownObject_impl public virtual ShutdownObject_skel 4 5 CORBA_BOA_var boa_ 6 7 public 8 9 Shut downObject_impl CORBA_BOA_ptr boa 10 boa_ CORBA_BOA _duplicate boa wi 12 13 14 virtual void deactivate 15 16 boa_ gt deactivate_impl CORBA_ImplementationDef _nil 17 18 ORBacus 57 ORB and BOA Initialization AN DAP WN HE RoR kK ORS Ao 13 10 12 BOM DAN DA GAB WN HR by RY A servant class for ShutdownOb ject is defined For more information on how to imple ment servant classes see Chapter 5 A BOA is needed to call deactivate_impl The constructor initializes the BOA member deactivate calls deactivate_imp1 on the BOA Here s the main code for this example C int main int argc char argv char CORBA_ORB_var orb CORBA_ORB_init argc argv CORBA_BOA_var boa orb gt BOA_init argc argv ShutdownObject_var shutdownObj new ShutdownObject_impl boa boa gt impl_is_ready CORBA_ImplementationDef _nil return 0 ORB and BOA initialization The shutdown object is created The impl_is_ready main event loop is entered This call only returns if deactivate is called The server was deactivated so main can now return The client can use the deactivate call as shown below Lf Cr int main int argc char argv char CORBA_ORB_var orb CORBA_ORB_init argc argv
6. ShutdownObject_var shutdownObj Get a reference somehow try shutdownObj gt deactivate 58 ORBacus Applets 12 T3 14 3 16 L7 18 4 5 4 5 1 4 5 2 catch const CORBA_COMM_FAILURE amp ex return 0 Initialize the ORB Get a reference to the server s shutdown object somehow for example by reading in a stringified object reference see Stringified Object References on page 85 Call deactivate on the shutdown object COMM_FAILURE exceptions must be ignored since the server may shut down immediately without any chance for a proper reply mes sage to be delivered back to the client Therefore the client will usually get a COMM_FAILURE exception at this point Applets Adding ORBacus Applets to Web Pages Like any other applet ORBACUS applets can be added to HTML pages with the APPLET tag lt APPLET CODE Client class ARCHIVE 0B jar WIDTH 500 HEIGHT 300 gt lt APPLET gt It is necessary to tell the Web browser where to find the ORBACUs Java classes This is best done with the ARCHIVE attribute as shown above An alternative is to use the CODEBASE attribute and to extract the OB jar archive in the directory defined by CODEBASE For more information please consult your Java Development Kit documenta tion Defining ORB and BOA Options for an Applet The PARAM tag is used in HTML to define parameters for an a
7. class MyEventHandler public OBEventHandler public MyEventHandler virtual MyEventHandler virtual void handleEvent CORBA_ULong virtual void handleStop J MyEventHandler MyEventHandler OBReactor Reactor OBReactor instance Reactor gt registerHandler this OBEventRead 0 MyEventHandler MyEventHandler OBReactor Reactor OBReactor instance Reactor gt unregisterHandler this void MyEventHandler handleEvent OBMask mask assert mask OBEventRead char c Ccin read amp c 1 Handle character input here 134 ORBacus Using Timers 36 37 38 39 40 14 18 20 24 26 25 37 40 10 4 void MyEventHandler handleStop The header file for the reactor is included This file also contains the definition of OBEventHandler An event handler MyEventHandler is defined which has a constructor a destructor a handleEvent and a handleStop operation The constructor registers the event handler with the Reactor singleton Only read events are requested The destructor unregisters the event handler with the Reactor singleton The ORBACUS Reactor calls the handleEvent function each time a read event from stan dard input is pending handleStop is not used by this event handler Using Timers Often an application may wish to perform tasks on a regular timed basis The reactor pro
8. 30 ORBacus Options for jidl 3 5 output dir DIR Write generated files to directory DIR dll import DEF Put DEF in front of every symbol that needs an explicit DLL import statement Options for jidl h he lp v version e cpp NAMI d debug DNAME DNAME DEF UNAME IDIR no skeletons locality constrained all tie pa These options are the same as for the id1 command no comments The default behavior of jid1 is to add any comments from the IDL file starting with to the generated Java files Specify this option if you don t want these comments added to your Java files package PKG Specifies a package name for the generated Java classes Each class will be generated rel ative to this package prefix package PRE PKG Specifies a package name for a particular prefix Each class with this prefix will be gener ated relative to the specified package auto package 1 Prefix refers to the value of the pragma prefix statement in an IDL file For example the statement pragma prefix ooc comdefines ooc com as the prefix The prefix is included in the Interface Repository identifiers for all types defined in the IDL file ORBacus 31 The ORBacus Code Generators 3 6 3 7 Derives the package names for generated Java classes from the IDL prefixes The prefix ooc com for example results in the
9. 9 3 3 9 3 4 The thread per client model is still efficient Like with the threaded concurrency model no threads need to be created except when new connections are accepted Thread per Request Server If the thread per request server concurrency model is chosen the ORB creates a new thread for each request This is shown in Figure 9 7 For simplicity there are no separate l 0 p g0 __ ph p a a at Client A Thread per Request Client B Server Figure 9 7 Thread per Request Server arrows for dispatch and thread creation in the diagram With the thread per request model requests are never delayed When they come in a new thread is created and the request is executed in the user code using this thread On return the thread is destroyed Besides using a reactive client together with a reactive server the thread per request server in combination with a threaded client is the only other model that allows nested method calls with an unlimited nesting level The thread pool model also allows nested method calls but the nesting level is limited by the number of threads in the pool The thread per request concurrency model is inefficient The main problem results from the overhead involved in creating new threads namely one for each request Thread Pool Server The thread pool model uses threads from a pool to carry out requests
10. The handle for this Transport The handle may only be used to determine whether the Trans port object is ready to send or to receive data e g with select on Unix based operating systems All other uses e g calls to read write close are strictly non compliant A handle value of 1 indicates that the protocol plug in does not support selectable Trans ports fragmentation readonly attribute unsigned long fragmentation The Transport s maximum packet size The send and receive operations must not be used to send packets larger than this size within a single call A value of 0 means that there is no upper limit for the packet size Operations close void close Closes the Transport send and receive must not be called after close has been called 198 ORBacus Interface OCI Transport shutdown void shutdown Shuts down the Transport After calling shutdown all calls to the send and receive opera tions result in an appropriate CORBA COMM_FAILURE exception being raised receive void receive in Buffer buf in boolean block Receives a buffer s contents Parameters buf The buffer to fill block If set to TRUE the operation blocks until the buffer is full If set to FALSE the oper ation fills as much of the buffer as possible without blocking receive_detect boolean receive_detect in Buffer buf in boolean block Similar to receive but it signals a connectio
11. add_profile void add_profile in ObjectKey key inout IOR ior Adds a new profile that matches this Acceptor to an IOR Parameters key The object key to use for the new profile ior The IOR is_local ObjectKey is_local in IOR ior Checks whether an IOR is for a local object taking only profiles into account matching this Acceptor Parameters ior The IOR to check for Returns If the IOR is for a local object the object key for that local object or an empty object key otherwise get_info AcceptorInfo get_info Returns the information object associated with the Acceptor Returns 210 ORBacus Interface OCI Acceptor The Acceptor information object ORBacus 211 Open Communications Interface Reference B 10 Interface OCI AcceptorInfo interface AcceptorInfo Information on an OCI Acceptor object Objects of this type must be narrowed to an Acceptor information object for a concrete protocol implementation for example to OCI IIOP Accep torInfo in case the plug in implements IIOP See Also Acceptor Attributes tag readonly attribute Profileld tag The profile id tag Operations add_accept_cb void add_accept_cb in AcceptCB cb Add a callback that is called whenever a new connection is accepted If the callback has already been registered this method has no effect Parameters ch The callback to add remove_accept_cb void remove_accept_cb in AcceptCB
12. Java org omg CORBA ORB orb Get a reference to the ORB somehow com ooc CORBA ORB orb connect impl MyName In both examples the servant imp1 is connected to the object adapter using the name MyName The cast to com ooc CORBA ORB is necessary because the Java overloading of connect in support of named servants is an ORBACUS specific extension and is not available in org omg CORBA ORB The name assigned to a servant must be unique among all servants in a server In case the name is already in use the INV_IDENT exception is raised 72 ORBacus Factory Objects 5 5 SM DAN DAB WNHPHR Ky Factory Objects It is quite common to use the Factory 10 design pattern in CORBA applications In short a factory object provides access to one or more additional objects In CORBA applica tions a factory object can represent a focal point for clients In other words the object ref erence of the factory object can be published in a well known location and clients know that they only need to obtain this object reference in order to gain access to other objects in the system thereby minimizing the number of object references that need to be published The Factory pattern can be applied in a wide variety of situations including the following e Security A client is required to provide security information before the factory object will allow the client to have access to another object e Load balancing
13. The factory object manages a pool of objects often representing some limited resource and assigns them to clients based on some utilization algorithm e Polymorphism A factory object enables the use of polymorphism by returning object references to different implementations depending on the criteria specified by a client These are only a few examples of the potential applications of the Factory pattern The examples listed above can also be used in any combination depending on the require ments of the system being designed A simple application of the Factory pattern in which a new object is created for each cli ent is illustrated below The implementation uses the following interface definitions IDL interface Product void destroy interface Factory Product createProduct The Product interface is defined The dest roy operation allows a client to destroy the object when it is no longer needed The Factory interface is defined The createProduct operation returns the object ref erence of a new Product ORBacus 73 CORBA Objects 5 5 1 AND GAA WH NH HK RoR RR HOW QW amp NSF DS amp 16 MN A aA PWN PE RoR ROR U N R O amp Factory Objects using C First we ll implement the Product interface C class Product_impl public virtual Product_skel CORBA_ORB_ var orb_ public void Product_impl CORBA_ORB_ptr orb orb_ CORBA_ORB _dupli
14. vides an API for the integration of timed tasks into an ORBACUS application In order to have a timed task a class must be created that inherits from the class OBTimer The class OBTimer provides a pure virtual method notify that is called when the timer expires For the timer to be notified it must first be enabled To do this the activate method is called This method takes two parameters A timeval and a boolean flag The boolean flag indicates whether the timeval is a relative or absolute true indicates a relative value The timeval contains two members tv_sec and tv_usec Note that the timer is only as accu rate as the underlying operating system so microsecond accuracy is not necessarily offered The act ivate method causes the timer to be notified once If a recurring timer is desired the activate method should be invoked before the not ify method is completed The stop method is provided to cancel the next notification include lt OB Timer h gt class CustomTimer public OBTimer ORBacus 135 The Reactor IA 4 void register 5 t 6 struct timeval tv 7 tv tv_sec 10 8 tv tv_usec 0 9 LI 10 Call notify method in 10 seconds 11 Nis activate tv true LS 14 TS 16 public a CustomTimer 18 19 register 20 21 22 virtual void notify 23 24 cout lt lt Notify called lt lt endl 25 register 26 27 FF 1 The file OB Timer h must be included to
15. 10000 org omg CORBA ORB orb org omg CORBA ORB init args null Obtain the system properties Define ORBACUS properties Initialize the ORB Java virtual machines typically allow you to define system properties on the command line For example using Sun s JVM you can do the following java Dooc boa port 5000 MyServer You can also use the java util Properties object that is passed to the org omg CORBA ORB init and org omg CORBA ORB BOA_init methods to provide ORBACUS property definitions Java java util Properties props new java util Properties props put ooc boa numeric true org omg CORBA ORB orb org omg CORBA ORB init args props org omg CORBA BOA boa orb BOA_init args props Create a java util Properties object to hold our properties Define ORBACUS properties Initialize the ORB and BOA using the java util Properties object Precedence of Properties Given that properties can be defined in several ways it s important to establish the order of precedence used by ORBACUS when collecting and processing the property definitions The order of precedence is listed below from lowest to highest Properties defined at a higher precedence override the same properties defined at a lower precedence e Configuration file e User supplied properties Java only e System properties Java only ORBacus 51 ORB and BOA Initialization 4 3 7 e Command line options
16. Initial Services 7 8 9 10 11 12 Pe 14 15 16 17 18 19 20 21 22 23 DAN DA AAW NH HE KN NO NO e ka e a a E a wWNHRE BDH AN DA O A N e D O obj orb resolve_initial_references NameService catch org omg CORBA ORBPackage InvalidName ex An error occured service is not available if obj null The object reference is invalid ctx org omg CosNaming NamingContextHelper narrow obj if ctx null This object does not implement a NamingContext And here s the C version C CORBA_Object_var obj CosNaming_NamingContext_var ctx try obj orb gt resolve_initial_references NameService catch CORBA_InvalidName amp An error occured service is not available if CORBA object_is_nil obj The object reference is invalid ctx CosNaming_NamingContext narrow ctx if CORBA object_is_nil ctx This object does not implement NamingContext ORBacus 91 Locating Objects 5 12 Try to resolve the name of a particular service If a service of the specified name is not 1L9 2 6 5 2 3 Aa UNAK known to the ORB an InvalidName exception is thrown The service type was known Now the object reference has to be narrowed to the particular service type If this fails the service is not available ORBACUS allows you to define your own initial services as described in the next secti
17. ORBacus 151 ORBacus Basic Services 13 1 1 13 1 2 Starting the Service To start the C version of the Naming Service type the following nameserv i OAport 10000 gt nameserv ref The Java version can be started like this java com ooc CosNaming Server i OAport 10000 gt nameserv ref Notice that we have specified a unique port number for the service in order to ensure that the object reference of the service remains valid across executions of the service see Lifetime of Object References on page 83 The i argument causes the service to dump its IOR to standard output which we have redirected to the file nameserv ref Connecting to the Service Chapter 6 describes different strategies for locating objects and these strategies can also be used to locate services For example it s possible to read the stringified IOR from the file nameserv ref convert it to an object using string_to_object and then narrow this object reference to the CosNaming NamingContext interface A more common way is to use resolve_initial_references as shown in Resolving an Initial Service on page 90 The references for the initial services can be defined using the ORBservice option Here s a Unix example which uses Bourne shell command substitution command to obtain an IOR from a file java MyClient ORBservice NameService cat nameserv ref On non Unix operating systems however it can be inc
18. ORBacus 43 ORB and BOA Initialization 4 1 3 4 2 4 2 1 4 2 2 ORB orb ORB init args new java util Properties The ORB init call interprets arguments starting with ORB Unlike the C version these arguments are not removed see Filtering Command line Options on page 49 for more information Initializing the Java ORB for Applets A different overloading of ORB init is provided for use by applets Java import org omg CORBA public void init ORB orb ORB init this new java util Properties See Applets on page 59 for more information on using ORBACUS in an applet BOA Initialization Initializing the C BOA In C the BOA is initialized with CORBA_ORB BOA_init For example Lf Crk int main int argc char argv char CORBA_ORB_var orb CORBA_ORB_init argc argv CORBA_BOA_var boa orb gt BOA_init argc argv BOA_init removes all arguments starting with OA passed through the argc and argv parameters Initializing the Java BOA In Java the BOA initialization looks like this Java import org omg CORBA 44 ORBacus Configuring the ORB and BOA 4 3 4 3 1 public static void main String args ORB orb ORB init args new java util Properties BOA boa orb BOA_init args new java util Properties Configuring the ORB and BOA ORBACUS applications can tailor the beh
19. ShortProperty anyShort catch ReadOnlyProperty ex An error occurred catch ConflictingProperty ex An error occurred catch UnsupportedProperty ex An error occurred catch UnsupportedTypeCode ex An error occurred catch InvalidPropertyName ex An error occurred PropertiesHolder ph new PropertiesHolder PropertiesIteratorHolder ih new PropertiesIteratorHolder set get_all_properties 0 ph ih PropertyHolder h new PropertyHolder while ih value next_one h The next property is now stored in h value ih value destroy Get a Property Service reference and check for errors The PropertySetFactory object is used to create a PropertySet instance Each property consists of a name and a value in the form of a CORBA Any Three properties are defined The first has the name LongProperty and stores a long value The second one is called IntProperty and stores an int The remaining property ORBacus 167 ORBacus Basic Services 61 69 71 13 4 13 4 1 represents a short value If for some reason a property cannot be created an exception is thrown Now we try to get a list of all the properties that were previously defined With get_all_properties the PropertySet returns its properties As we have set the how_many parameter to 0 we have to use the PropertiesIterator for each item Usu a
20. This policy can be used to specify communication timeouts Attributes value readonly attribute unsigned long value If an object has a Timeout Policy set and no response to a request is available after value milliseconds a CORBA NO_RESOURCE exception is raised ORBacus 191 ORBacus Policy Reference 192 ORBacus sexs Open Communications Interface Reference B 1 Module OCI The Open Communications Interface OCI The definitions in this module provide a uniform inter face to network protocols This allows for easy plug in of new protocols or other communication mechanisms into ORBs that implement the OCI Furthermore protocol implementations need only to be written once and can then be reused with all OCI compliant ORBs For more information please see the OCI documentation Aliases BufferSeq typedef sequence lt Buffer gt BufferSeq Alias for a sequence of buffers IOR typedef IOP IOR IOR Alias for an IOR ProfileId typedef IOP ProfileId Profileld ORBacus 193 Open Communications Interface Reference Alias for a profile id ProfileIdSeq typedef sequence lt ProfilelId gt ProfileldSeq Alias for a sequence of profile ids ObjectKey typedef sequence lt octet gt ObjectKey Alias for an object key which is a sequence of octets Handle typedef long Handle Alias for a system specific handle type CloseCBSeq typedef sequence lt CloseCB gt CloseCBSeq A
21. add_initial_reference NameService obj Get a reference to the naming service for example by reading a stringified object refer ence and converting it with st ring_to_object or by using get_inet_object or by any other means Add the reference to the ORB s list of initial references In Java it s necessary to cast the ORB to com ooc CORBA ORB since add_initial_reference is an ORBACUS spe cific extension and thus is not supported with org omg CORBA ORB ORBacus 93 Locating Objects 94 ORBacus CHAPTER 7 Reference Counting 7 1 7 2 What is Reference Counting Reference counting is a commonly used technique to manage CORBA servant and proxy objects In general a reference count is an integer value associated with an object The counter is initialized to 1 and will be incremented and decremented during the life of the object When the counter reaches zero the object is destroyed Unlike some distributed object technologies most notably Microsoft s Distributed Com ponent Object Model DCOM CORBA reference counting mechanisms typically are not distributed In other words the reference count of a proxy is independent of the reference count of its corresponding servant Therefore if the reference count of a proxy reaches zero the proxy object is destroyed but the servant is unaffected Similarly the reference counts of any proxy objects for a servant are not affected when that servant s ref
22. class Hello_impl public Hello_skel public virtual void hello SH DAN DA GAB WH HE Ky 3 Since our implementation class derives from the skeleton class Hello_skel we must include the file Hello_skel h 5 Here we define Hello_imp1 as a class derived from Hello_skel 9 Our implementation class must implement all operations from the IDL interface In this case this is just the operation hello The implementation for He110_imp1 looks as follows C include lt OB CORBA h gt include lt Hello_impl h gt void Hello_impl hello cout lt lt Hello World lt lt endl SuMY AND GAB UNAK Ky 3 We must include OB CORBA h which contains definitions for the standard CORBA classes as well as for other useful things 4 We must also include the Hello_imp1 class definition contained in the header file Hello_impl h ORBacus 17 Getting Started AN DA ASP WH HE OIN NOE NO Ee e R e Aa A a ania why FP ODwH DAN DoS WHE OD 1 11 13 The hello function simply prints Hello World on standard output Save the class definition of Hello_imp1 in the file Hello_imp1 h and the implementa tion of Hello_imp1 in the file Hello_impl cpp Now we need to write the server s main program which looks like this C include lt OB CORBA h gt include lt Hello_impl h gt include lt fstream h gt int main int argc char argv char CORBA_ORB_
23. interface I interface A I op out I oref inout I ioref An interface I is defined An interface A is defined having an operation op which returns an I and has an I in and inout parameter This implementation of the op operation is wrong TI OFE class A_ impl virtual public A_skel I_var myref public A_imp1 myref Initialize myref somehow virtual I_ptr op I_ptr amp oref I_ptr amp ioref Wrong ioref is not released ioref myref Wrong oref myref Ditto return myref Ditto hi Forgot to free the inout object reference parameter ioref Wrong Object references must be duplicated ORBacus 113 C Mapping Notes MN A aA PWN HE NO SwoM ANDAR WHE DOD amp BES 16 18 MN A AB WN HE Keo S ORS amp A l D This version is correct C class A_impl virtual public A_skel I_var myref public A_imp1 myref Initialize myref somehow virtual I_ptr op I_ptr amp oref I_ptr amp ioref CORBA_release ioref ioref I _duplicate myref oref I _duplicate myref return I _duplicate myref Now ioref is released All object references are now duplicated The first example on how to use object reference out inout or return values on the call ing side uses explicit calls to CORBA_release C A_ ptr a Get a reference to an A som
24. return any results and there is no guarantee that a oneway request was properly executed by a server 2 select is used for synchronous I O multiplexing For more information see the select Unix manual page 118 ORBacus Single Threaded Concurrency Models 9 2 2 connect rn T L l accept l C lt q dispatch connect r l a dispatch q a disconnect R ye R wg close Client A Server Client B Figure 9 1 Blocking Server is allowed to block on a single connection nor for any thread creation or context switches Reactive Clients and Servers Reactive servers use calls to operations like select in order to simultaneously accept incoming connection requests to receive requests from multiple clients and to send back replies This means that a reactive server can handle more than one client at a time This is shown in Figure 9 2 Reactive servers are the most common server types for single threaded client server applications Reactive clients also use operations like select to avoid blocking This means that while a request to a server is sent or a reply from that server is received the client can simulta neously send buffered requests to other servers or receive and buffer replies This is very useful for oneway operations or the Dynamic Invocation Interface DII operation send_deferred in combination with get_response o
25. so that threads have to be created only once and can then be reused for other requests Figure 9 8 shows an 124 ORBacus Performance Comparisons 9 4 9 4 1 Client Thread Pool Server Figure 9 8 Thread Pool Server example with one client and a thread pool server with three threads in the pool Sender and receiver threads are not shown The first three operation calls f g and h can be car ried out immediately since there are three threads in the pool However the fourth request iis delayed until at least one of the other requests returns Since there is no time consuming thread creation the thread pool concurrency model per forms better than the thread per request model The thread pool is a good trade off if on the one hand frequent thread creation and destruction result in unacceptable performance but on the other hand delaying the execution of concurrent method calls is also not desired Performance Comparisons Sample Application In order to measure the performance overhead introduced by a given concurrency model it is important to keep all other overhead not directly related to the concurrency model minimal Therefore the sample application for performance measurements only consists of a single interface with a single operation with no parameters and return values IDL interface I void f ORBacus 125 Concurrency Models 9 4 2 This ensures
26. virtual public X_skel Y_var y public void setY Y_ptr y y_ Y _duplicate y class Y_impl public Y_skel X_var X_ public void setX X_ptr x x_ X _duplicate x void f X_var x new X_impl Y_var y new Y_impl x gt setY y y gt setX x A servant class X_imp1 is defined which has a y_var data member that can be set with setY Ditto but a servant class y_imp1 with a data member X_var is defined The function f creates new X and Y servants It stores the reference of the x servant in the Y servant and vice versa 100 ORBacus Reference Counting in C MN DA GAP WN PE RoR HR HOH mM WD MHF DS Here the X_imp1 has a reference to the Y_imp1 and the y_imp1 has a reference to the X_imp1 what is known as a cyclic object dependency This means that when returns even though x and y get destroyed the objects they are referring to are not destroyed since the reference count never becomes zero Why Let s take a deeper look into what happens in the example program X_var x new X_impl The initial reference count of the X_imp1 after the newis 1 Y_var y new Y_impl Same as above the initial reference count of the y_imp is 1 x gt setY y After sety the reference count of the Y_imp1 is 2 y gt setX x After set xX the reference count of the X_imp1 is 2 return x and y get destroyed and therefore call CORBA_r
27. 226 ORBacus Interface OCI I1OP ConFactoryInfo B 21 Interface OCI IOP ConFactoryInfo interface ConFactoryInfo inherits from OCI ConFactoryInfo Information on an IIOP OCI Connector Factory object See Also ConFactory ConFactoryInfo ORBacus 227 Open Communications Interface Reference 228 ORBacus APPENDIX C Royalty Free Public License Agreement ORBACcUus for C and Java can be freely used for non commercial purposes as detailed in the license agreement below All commercial use is subject to a different license agree ment For information on commercial licenses please see the pricing information on our Web site or contact support ooc com ROYALTY FREE PUBLIC LICENSE AGREEMENT FOR ORBACUS SOFTWARE IMPORTANT READ CAREFULLY This Object Oriented Concepts Inc Royalty Free Public License Agreement for ORBacus Software License is a legal agreement between you the Lic ensee either an individual or a single entity and Object Oriented Concepts Inc for non commer cially using copying distributing and modifying the Software and any work derived from the Software as defined hereinbelow Any commercial use is subject to a different license By using modifying or distributing the Software or any work derived from the Software Licensee indicates acceptance of this License and agrees to be bound by all its terms and conditions for using copying distributing or modifying the Softw
28. BAD_PARAM An invalid parameter was passed NO_MEMORY Failure to allocate dynamic memory IMP_LIMIT Implementation limit was violated COMM_FAILURE Communication failure INV_OBJREF Invalid object reference NO_PERMISSION The attempted operation was not permitted H TERNAL Internal error in ORB MARSHAL Error marshalling a parameter or result H ITIALIZE Failure when initializing ORB NO_IMP LEMENT Operation implementation unavailable Table 14 1 Standard CORBA System Exceptions ORBacus 177 Exceptions and Error Messages UNKNOW Unknown exception type BAD_TYPECODE Bad typecode BAD_OPERATION Invalid operation NO_RESOURCES Insufficient resources for a request NO_RESPONSE Response to a request is not yet available PERSIST_STORE Persistent storage failure BAD_INV_ORDER Routine invocation out of order TRANSIENT Transient failure request can be reissued FREE_MEM Cannot free memory INV_IDENT Invalid identifier syntax INV_FLAG Invalid flag was specified INTF_REPOS Error accessing interface repository BAD_CONTEXT Error processing context object OBJ_ADAPTER Failure detected by object adapter DATA_CONVERSION Error in data conversion OBJECT_NOT_EXIST Non existent object references should be discarded INV_POLICY Invalid Policy Table 14 1 Standard CO
29. For example a property defined using a command line option overrides the same property defined in a configuration file Advanced Property Usage If you need explicit control of the properties from within your application you may also elect to use ORBACUS specific classes to create and retrieve property definitions In Java this class is com ooc CORBA Properties and in C the class is OBProperties These classes are used internally by ORBACUS but you can also use them in your applications Java package com ooc CORBA class Properties public static Properties init String args public static Properties instance public String getProperty String key public void setProperty String key String value public String getKeys String prefix public String getKeys C class OBProperties public static OBProperties init int amp argc char argv static OBProperties instance typedef OBStrSeq KeySeq void setProperty const char key const char value const char getProperty const char key KeySeq getKeys const char prefix KeySeq getKeys 1 The Properties class is probably more useful for C applications since Java applications can use system properties to achieve the same effect ORBacus Configuring the ORB and BOA Oo DN DAP UNAK GQ Aa UNAK In the discussion below these classes are referred to generically as the Properties class To use a
30. IOR of the server to standard output EERE Creating Properties A property handled by the CORBA Property Service consists of two components namely the property s name and its value The name is simply a CORBA string and the associated value is represented by a CORBA Any IDL typedef string PropertyName struct Property PropertyName property_name any property_value New properties are created using a factory object implementing the PropertySet inter face A new property is created using the def ine_property operation IDL void define_property in PropertyName in any property_value raises InvalidPropertyName ConflictingProperty UnsupportedTypeCode UnsupportedProperty ReadOnlyProperty As a property consists of a name value pair both the name and the value are the parame ters to this operation ORBacus 163 ORBacus Basic Services 13 3 3 Querying for Properties As soon as a property is defined the Propert ySet can be queried for the property s value with the get_property_value operation IDL any get_property_value in PropertyName property_name raises PropertyNotFound InvalidPropertyName For a particular property name this call either returns the Any associated with this name or throws an exception if a property with the name does not exist You can not only query for a particular property value but also for a list of all the proper ties defined within a PropertyS
31. Lic ensee may copy and distribute works derived from the Software throughout the world provided that Licensee distributes an unmodified easily readable copy of this License with such works derived from the Software and provided further that such distribution does not constitute a commercial use Licensee must cause any work derived from the Software that Licensee distributes to be licensed as a whole and at no charge to all third parties under the terms of this License Any work derived from the Software must be accompanied by the complete corresponding machine readable source code of such work derived from the Software delivered on a medium customarily used for software interchange The source code for the work derived from the Software means the preferred form of the work derived from the Software for making modifications to it For an execut able work derived from the Software complete source code means all of the source code for all modules of the work derived from the Software all associated interface definition files and all scripts used to control compilation and installation of all or any part of the work derived from the Software However the source code delivered need not include anything that is normally distrib uted in either source code or binary object code form with major components including but not limited to compilers linkers and kernels of the operating system on which the executable work derived from the Software runs
32. Obtaining Object References 81 Lifetime of Object References 83 Hostname 84 Port Number 84 Object Key 84 Stringified Object References 85 Using a File 85 Using a URL 87 Using Applet Parameters 88 Connecting to Named Objects 88 Using the tiop Notation 89 Using get_inet_object 89 Initial Services 90 Resolving an Initial Service 90 Providing IORs of Initial Services 92 Reference Counting 95 What is Reference Counting 95 Reference Counting in Java 95 Reference Counting inC 96 Marshalling Issues 96 ORBacus CHAPTER 8 CHAPTER 9 Releasing Proxies and Servants 98 Global Object References 99 Cyclic Object Dependencies 100 C Mapping Notes 105 Reserved Names 105 Mapping of Modules 105 Extensions 106 Extensions to the String Type 106 Extensions to _var Types 106 Extensions to Sequence Types 107 C Mapping Tips amp Tricks 108 CORBA Strings 108 Object References 112 Concurrency Models 117 Introduction 117 What is a Concurrency Model 117 Why different Concurrency Models 117 ORBacus Concurrency Models Overview 118 Single Threaded Concurrency Models 118 Blocking Clients and Servers 118 Reactive Clients and Servers 119 Multi Threaded Concurrency Models 122 Threaded Clients and Servers 122 Thread per Client Server 123 Thread per Request Server 124 Thread Pool Server 124 Performance Comparisons 125 Sample Application 125 Regular Method Invocations 126 Nested Method Invocations 127 Selecting Concurren
33. Properties class correctly you must be aware of the initialization steps taken by the ORB and BOA objects The Properties class is a Singleton class in that only one instance of the class is allowed The ORB initializes the Properties object during its own initialization However if you need to use the Properties class before the ORB has been initialized e g if you need to define an ORB property then you will need to initial ize the Properties class manually Defining ORB Properties The code below demonstrates a situation where an application needs to define a property prior to initializing the ORB First we ll show the example in C C include lt OB CORBA h gt include lt OB Properties h gt OBProperties properties OBProperties init argc argv properties gt setProperty ooc orb conc_model reactive CORBA_ORB_var orb CORBA_ORB_init argc argv Include the necessary header files The call to OBProperties init creates the OBProperties object and initializes it with the contents of a configuration file if necessary Set the ORB concurrency model using a property Initialize the ORB The code looks very similar in Java Java com ooc CORBA Properties properties com ooc CORBA Properties init args properties setProperty ooc orb conc_model threaded org omg CORBA ORB orb org omg CORBA ORB init args null Creates the com ooc CORBA Propertie
34. Sequence Types All unbounded non array sequences for example unbounded string struct and object ref erence sequences have an additional insert append and remove member function For a sequence s and a value v the s insert v and s append v behave as follows s length s length 1 Somehow shift sequence contents one to the right s 0 v s length s length 1 s s length 1 v respectively Please note that ORBACUS s sequence implementation does not really shift the contents of the sequence It is rather implemented as a double ended queue like the Standard Tem plate Library s dequeue and therefore needs no value shifting That is the insert function is as efficient as the append function ORBacus 107 C Mapping Notes 8 4 8 4 1 Aa UNAK Ky WW hb Ky C Mapping Tips amp Tricks Unfortunately the official CORBA IDL to C mapping is a little complicated The traps amp pitfalls justify devoting a section of the ORBACUS manual to how to avoid the most common mistakes Note that compared to the IDL to C mapping the IDL to Java mapping is nice clean and easy to understand so it s not really necessary to have a Java Mapping Tips amp Tricks The official mapping specification 3 is completely sufficient CORBA Strings When using CORBA strings always remember the following rules CORBA Specific String Functions Use the CORBA specific str
35. The Event Channel 169 Event Suppliers and Consumers 170 Event Channel Policies 171 A Simple Example 171 Exceptions and Error Messages 177 CORBA System Exceptions 177 Non Compliant Application Asserts 180 ORBacus Policy Reference 185 Module SSL 185 Interface SSL ConnectPolicy 186 Module OB 187 ORBacus APPENDIX B APPENDIX C Interface OB ProtocolPolicy 188 Interface OB ConnectionReusePolicy 189 Interface OB ReconnectPolicy 190 Interface OB TimeoutPolicy 191 Open Communications Interface Reference 193 Module OCI Interface OCI Interface OCI Interface OCI Interface OCI Interface OCI Interface OCI Interface OCI Interface OCI Interface OCI Interface OCI Interface OCI Interface OCI Interface OCI Interface OCI Interface OCI Buffer Transport 198 TransportInfo 202 CloseCB 204 Connector ConnectorInfo 207 ConnectCB 208 Acceptor AcceptorInfo 212 AcceptCB 213 ConFactory 214 ConFactoryInfo 217 ConFactoryRegistry 218 AccRegistry 220 Current 193 196 205 209 222 Module OCI JOP 223 Interface OCI IIOP TransportInfo 224 Interface OCI IIOP ConnectorInfo 225 Interface OCI IIOP AcceptorInfo 226 Interface OCI IIOP ConFactoryInfo 227 Royalty Free Public License Agreement 229 References 235 ORBacus 10 ORBacus CHAPTER 1 Introduction L l What is ORBacus ORBACUS is an Object Request Broker ORB that is compliant with
36. To do so send a message to ma jordomo ooc com not ob ooc com with 12 ORBacus Getting Help subscribe ob in the body not in the Subject field of your message To unsubscribe use unsubscribe ob in the body of your message To send a message to the list mail to ob ooc com not ma jordomo ooc com An archive of the ORBACUS mailing list can be found at http www ooc com ob mailing list html ORBacus 13 Introduction 14 ORBacus CHAPTER 2 Getting Started 2 1 The Hello World Application The example described in this chapter is founded on a well known application A Hello World program presented here in a special client server version Many books on programming start with this tiny demo program In introductory C books you ll probably find the following piece of code in the very first chapter C include lt iostream h gt int main int char char cout lt lt Hello World lt lt endl return 0 Or in introductory Java books Java public class Greeter public static void main String args ORBacus 15 Getting Started 2 2 2 3 Da ws WN HP System out printin Hello World These applications simply print Hello World to standard output and that is exactly what this chapter is about Printing Hello World with a CORBA based client server applica tion In other words we will dev
37. a CannotProceed exception ex printStackTrace return 1 catch InvalidName ex System err printin Got an InvalidName exception ex printStackTrace return 1 I catch AlreadyBound ex System err printin Got an AlreadyBound exception ex printStackTrace return 1 Catch exceptions Don t ever forget to do this It can be useful to call printStackTrace on the exception object in order to get detailed information about the program flow caus ing the exception Now you should have a look at the complete example as it is provided in the folder demo naming as a part of the ORBACUS distribution The Property Service The CORBA Property Service is another important CORBA service With it you can annotate an object with extra attributes called properties that were not defined by the 1 Note that the Property Service has nothing to do with the properties used for configuration pur poses as described in Properties on page 45 162 ORBacus The Property Service 13 3 1 13 3 2 object s IDL interface Properties can represent any value because they make use of the powerful CORBA Any data type Command line Options The ORBACUs Property Service supports the following command line options h z 2 Rgp Display the command line options supported by the server Sat Display the version of the server version 7 Te Print the interoperable object reference
38. blocking pull call IDL interface PullSupplier any pull raises Disconnected any try_pull out boolean has_event raises Disconnected void disconnect_pull_supplier Event Channel Policies The untyped event channel implementation included in the ORB ACUS distribution features a simple event queue policy Events are buffered in the form of a FIFO stack i e a certain number of events are stored and in case of a buffer overflow the oldest events are dis carded A Simple Example In the Event Service example that comes with ORBACUS two supplier and two consumer clients demonstrate how to use an untyped event channel to propagate information The pieces of information transferred by this example are strings containing the current date and time After starting the Event Service server you can start these clients in any order The demo applications obtain the initial Event Service reference as already demonstrated i e by calling resolve_initial_references When started each supplier will pro vide information about the current date and time and each client displays the event data in its console window This is the push supplier s main loop Java while consumer_ null ORBacus 171 ORBacus Basic Services DAN DA bh 20 27 DawP WN PH java util Date date new java util Date String s PushSupplier says date toString Any any orb_ create_any
39. comments starting with from the IDL file to the generated Java files so that javadoc can be used to generate documentation as long as the comments are in a format compatible with javadoc Here is an example showing how to include documentation in an IDL interface description file Let s assume we have an interface I in a module M IDL module M This is a comment related to interface I author Uwe Seimet version 1 0 F F F F N interface I This comment describes exception E x exception E E ORBacus 39 The ORBacus Code Generators The description for operation S param arg A dummy argument exception E Raised under certain circumstances return A dummy string if string S in long arg raises E he When running jid1 on this file the comments will automatically be added to the gener ated Java files M I java and M IPackage E java For I java the generated code looks as follows Java package M IDL M 1I 1 0 This is a comment related to interface I author Uwe Seimet version 1 0 F x public interface I extends org omg CORBA Object IDL M 1 S 1 0 The description for operation S param arg A dummy argument 40 ORBacus Using javadoc return A dummy string
40. extract_string System out printin s catch MARSHAL ex Ignore unknown event data Thread yield try Thread sleep 1000 catch InterruptedException ex 174 ORBacus The Event Service 16 24 26 34 A CORBA Any is prepared for later use Using pull the consumer polls the event channel for new events The event channel acts as a pull supplier in this case The pu11 operation blocks until a new event is available The consumer expects a string wrapped in a CORBA Any The string value is extracted and displayed If an exception is raised the Any contained some other data type which is simply ignored After sleeping for one second the event channel is polled for the next event In all of these examples the event channel acts either as a consumer if the clients are sup pliers or a supplier if the clients are consumers of events Actually each client is not directly connected to the event channel but to a proxy that receives or sends events on behalf of the channel For more information on the Event Service and for the complete definitions of the IDL interfaces please refer to the official Event Service specification ORBacus 175 ORBacus Basic Services 176 ORBacus oaea Exceptions and Error Messages 14 1 CORBA System Exceptions The CORBA specification defines the standard system exceptions shown in Table 14 1 UNKNOWN Unknown exception type
41. for CORBA_ULong i 0 i lt acceptors gt length i OCI_AcceptorInfo_var info acceptors i gt get_info OCI_IIOP_AcceptoriInfo_var iiopInfo OCI_IIOP_AcceptoriInfo _narrow info if CORBA_is_nil iiopInfo CORBA_String_var host iiopInfo gt host CORBA_UShort port iiopInfo gt port cout lt lt host lt lt host lt lt endl cout lt lt port lt lt port lt lt endl The Acceptor Registry is requested from the object adapter From the Acceptor Registry the list of registered acceptors is requested The for loop iterates over all acceptors The info object for the acceptor is requested and narrowed to an IIOP acceptor info object The if block is only entered in case the info object really belongs to an IIOP plug in ORBacus 141 The Open Communications Interface 14 18 DAN DAA WH HE ONO TA ka ho Ea EI ia Thao ja ka EO o DAN Das w o a O O 16 18 F9 11 4 3 The hostname and port number are requested from the IIOP acceptor info object and printed on standard output The Java version is basically equivalent to the C code and looks as follows Java com ooc OCI AccRegistry registry com ooc CORBA BOA boa get_acc_registry com ooc OCI Acceptor acceptors registry get_acceptors for int i 0 i lt acceptors length i com ooc OCI AcceptorInfo info acceptors i get_info com ooc OCI IIOP AcceptoriInfo iiopIn
42. gt gt s CORBA_Object_var obj orb gt string_to_object s B_var b B _narrow obj The stringified object reference is read string_to_object creates an object reference from the string Since the return value of string_to_object is of type CORBA_Object_ptr B _narrow must be used to get a B_ptr which is assigned to a self managed B_var in this example Java org omg CORBA ORB orb Get a reference to the ORB somehow java io BufferedReader in new java io BufferedReader new FileReader object ref String ref in readLine org omg CORBA Object obj orb string_to_object ref B b BHelper narrow obj The stringified object reference is read 86 ORBacus Stringified Object References 6 3 2 MANA GAP WN HP RR RHR HOH Daw WHE DD amp 17 16 17 string_to_object creates an object reference from the string Use BHelper narrow to narrow the return value of string_to_object toB Using a URL It is sometimes inconvenient or impossible for clients to have access to the same filesys tem as the server in order to read a stringified object reference from a file A more flexible method is to publish the reference in a file that is accessible by clients as a URL Your cli ents can then use HTTP or FTP to obtain the contents of the file freeing them from any local filesystem requirements This strategy only requires that your clients know the appropriate URL and
43. is abc s is abcx s is abcxy s is abcxyz s is abcxyz12345 Extensions to _var Types All _var types have the following additional member functions e in This function converts the _var type to a type suitable for in parameters e inout This function converts the _var type to a type suitable for inout parameters 106 ORBacus Extensions 8 3 3 e out This function converts the _var type to a type suitable for out parameters As a side effect this function ensures that the value held by the _var is released or freed by either calling CORBA_st ring_free in case of a string CORBA_release in case of an object reference or delete in case of types like sequences variable length structs etc e _retn This function converts the _var type to a type suitable for function return values The _retn function also removes the value that is held by the _var type without destroying it i e without calling delete CORBA_string_free or CORBA_release on its value For example consider a function f that returns its three in string arguments as a single string char f const char sl const char s2 const char s3 CORBA_String_var s sl s s2 Sut S33 return s _retn Please note that these functions are not covered by the CORBA 2 0 version of the IDL to C mapping but it is likely that they will become a part of the standard for the next major mapping revision Extensions to
44. is a Reactor In reactive mode see Reactive Clients and Servers on page 119 ORBACUS uses a so called Reactor for event dispatching 6 Simply speaking the Reactor is an instance in ORBACUS a singleton where special objects so called event handlers can regis ter if they are interested in specific events These events can be network events such as an event signaling that data are ready to be read from a network connection Again this chapter only applies to ORBACUS when used with reactive concurrency mod els If you use ORBACUS with any other concurrency model for example blocking or any of the multi threaded models the following examples are not applicable Also since ORBACUS for Java currently doesn t support the reactive model at all the following only applies to ORBACUs for C Available Reactors Currently there are three Reactors supported by ORBACUS e The standard select Reactor which relies on the Berkeley Sockets select function e A special Reactor for use with the X11 Window System This Reactor handles X11 events which for example can trigger X11 callbacks and CORBA network events simultaneously ORBacus 131 The Reactor 10 2 1 ND G8 WN FE 8 9 10 LL LZ T3 14 La 16 17 18 19 20 21 22 23 24 e A special Reactor for use with Microsoft Windows 95 or Windows NT This Reactor handles Windows messages and CORBA network events simultaneously Th
45. is especially suited for use in applets Note This example will only be shown in Java because of its built in support for URLs but the strategy can also be used in C Java import java io import java net String location http www mywebserver object ref org omg CORBA ORB orb Get a reference to the ORB somehow URL url new URL location URLConnection conn url openConnection BufferedReader in new BufferedReader new InputStreamReader conn getInputStream String ref in readLine in close org omg CORBA Object object orb string_to_object ref B b BHelper narrow object location is the URL of the file containing the stringified object reference Read the string from the URL connection Convert the string to an object reference Narrow the reference to a B object ORBacus 87 Locating Objects 6 3 3 6 4 GQ Aa UNAK Using Applet Parameters In addition to using the URL method described in the previous section an applet can also use an applet parameter to obtain a stringified object reference The following HTML illustrates this concept lt APPLET CODE Client class ARCHIVE 0B jar WIDTH 500 HEIGHT 300 gt lt PARAM NAME ref VALUE IOR 000012031 gt lt APPLET gt The stringified object reference is inserted directly into the HTML file and passed to the applet as a parameter The applet can retrieve this parameter and
46. must be used with the names of all super classes as arguments If you are using ORBACUS on multiple platforms where some support RTTI and others don t it might be best to always use OB Narrow_impl h since __narrow_imp1 will automatically use dynamic_cast lt gt on those platforms where it is available Getting a Servant using Java This example demonstrates how to cast an object reference to the servant class in Java Java public class I_impl extends _IImplBase public void foo I ref try I_impl impl I_imp1 ref The implementation for ref is local catch ClassCastException ex The implementation for ref is not local Servant class I_imp1 is defined ORBacus 79 CORBA Objects 7 The method foo takes an object reference ref to an I object as a parameter 11 An attempt is made to cast ref to I_imp1 If this cast succeeded then the servant is local i e the servant is in the same address space as the program 16 If the cast failed then ClassCast Exception will be thrown indicating that the servant is not in the same address space as the program In other words the reference ref is really the proxy for a remote object therefore you cannot obtain a reference to the servant 80 ORBacus CHAPTER 6 Locating Objects 6 1 Oo MND ABP LUNAK Obtaining Object References Using CORBA an object can obtain a reference to another object in a mul
47. of the Y_imp1 to X _nil Assign ment to a _var object reference causes CORBA_release to be called on its contents So now the reference count of the X_imp1 is 1 return x and y are destroyed and therefore call CORBA_release on their contents That means that the reference count of the X_imp1 becomes zero resulting in X_imp1 being destroyed This of course also eliminates X_imp1 s y_ data member causing 102 ORBacus Reference Counting in C CORBA_release to be called on the Y_imp1 So the Y_imp1 s reference count also becomes zero and the y_imp1 is also destroyed ORBacus 103 Reference Counting 104 ORBacus C Mapping Notes CHAPTER 8 ORBACUS implements the IDL to C mapping as described in 2 The standard IDL to C mapping is not a topic of this manual Please refer to 2 for the exact specifications 8 1 Reserved Names All names starting with OB _OB_ or _ob_ are reserved by ORBACUS for internal use and must not be used as identifiers 8 2 Mapping of Modules Generally IDL modules are mapped to C namespaces However since most C com pilers currently do not support namespaces the IDL to C mapping defines two alterna tives The first one maps modules to C classes implying that nested classes are needed for interfaces or other modules defined within a module The second alternative is to map modules to name prefixes e g the name of an interface I in a module M is mapped to M_
48. orb BOA_init args null Initialize the ORB The ORB will initialize the Properties object Obtain the Properties instance Set the BOA concurrency model using a property and initialize the BOA 54 ORBacus Configuring the ORB and BOA WO MONA GPW NH HE GQ Ww UNAK Application specific Properties Another situation where the Properties class can be useful is if you d like to obtain application specific properties from the ORBACUS configuration file Suppose your con figuration file looks as follows ORBacus configuration file ooc orb conc_model threaded Application specific settings acme widget_count 20 The following C example demonstrates how to access your application specific proper ties C include lt OB CORBA h gt include lt OB Properties h gt CORBA_ORB_var orb CORBA_ORB_init argc argv OBProperties properties OBProperties instance j const char value properties gt getProperty acme widget_count Include the necessary header files The ORB must be initialized so that the configuration file is processed Obtain the OBProperties instance and then retrieve the value of the property And in Java Java org omg CORBA ORB orb org omg CORBA ORB init args null com ooc CORBA Properties properties com ooc CORBA Properties instance String value properties getProperty acme widget_count The ORB must be initialized so that th
49. problem FECES void f I_impl impl Wrong Upon return from f imp1 is destroyed without the proper call to CORBA_release Global Object References You should never have global _var type object references because you can never tell exactly when and in which order they will be destroyed For example it is possible that a _var reference could be destroyed after the ORB was destroyed Here s an example Ivar impl Don t do this int main int argc char argv char CORBA_ORB_var orb CORBA_ORB_init argc argv impl new I_impl return 0 A global object reference _var type is created The ORB is initialized The I_var object reference is initialized with a new servant Upon return the ORB is destroyed since orb is destroyed causing CORBA_release to be called for the ORB However imp1 is still alive and therefore the servant is not ORBacus 99 Reference Counting 7 3 4 MAN Da P WN HE MOOS N NN e a Aoh he e HHH HK At wWwNHHE DH AND GAP WHE ODO LOLS Lo 25 destroyed meaning that there is still a servant but no ORB anymore This will most likely result in a crash The ORB must be the last object to be destroyed In addition to the technical justification for avoiding global object references it is generally a bad programming style to have glo bal object references Cyclic Object Dependencies Consider the following code class X_impl
50. reference to an object of A Here is our implementation C class A_impl public virtual A_skel class B_impl public virtual B_skel A_var a CORBA_ORB_var orb _ public void B_impl CORBA_ORB_ptr orb orb_ CORBA_ORB _duplicate orb a_ new A_impl orb_ gt connect a_ virtual A_ ptr getA return A _duplicate a_ ORBacus 97 Reference Counting 25 14 19 21 24 7 3 2 Servant class A_imp1 is defined Servant class B_imp1 is defined The B_imp1 constructor saves a reference to the ORB instantiates A_imp1 and connects it to the object adapter It is not strictly necessary to invoke connect because the object will be connected automatically when the object s reference is returned to a client Upon entry to getA the reference count of a_ is 2 the initial value is 1 upon construction and is incremented to 2 when connected To maintain this value getA duplicates a_ which increments the reference count to 3 The marshalling code that returns the reference will decrement the reference count back to 2 For more information on using object references as in inout out and return values see Object References on page 112 Releasing Proxies and Servants The reference count of a servant is incremented by 1 when the servant is implicitly or explicitly connected to the object adapter see Connecting Servants using C on page 71 Ther
51. remoteAddr 0 lt lt lt lt remoteAddr 1 lt lt lt lt remoteAddr 2 lt lt lt lt remoteAddr 3 lt lt lt lt remotePort lt lt endl The OCI current object is requested and narrow d to the correct OCI Current type The info object for the transport is requested and narrow d to an IIOP transport info object The remainder of the example code is only executed if this was really an IIOP transport info object The address and the port of the client calling this operation are obtained and printed on standard output The Java version looks as follows org omg CORBA Object baseCurrent orb resolve_initial_references OCICurrent comod OCI Current current com ooc OCI CurrentHelper narrow baseCurrent com ooc OCI TransportInfo info current get_oci_transport_info com ooc OCI IIOP TransportInfo iiopInfo com ooc OCI IIOP TransportInfoHelper narrow baselInfo if iiopInfo null int remoteAddr Converter addr iiopInfo remote_addr int remotePort Converter port iiopInfo remote_port System out printin Call from ORBacus 143 The Open Communications Interface 16 17 18 19 20 LALO 12 13 1519 11 4 4 AN DAA WH HE RRR RH RH RH HR NOD G WNHE DO O 18 remoteAddr remoteAddr remoteAddr remoteAddr 0 1 2 ai remotePort This code is equivalent to the C version Agai
52. reused with all OCI compliant ORBs For more information please see the OCI documentation Aliases BufferSeq typedef sequence lt Buffer gt BufferSeq Alias for a sequence of buffers IOR typedef IOP IOR IOR Alias for an IOR ProfileId typedef IOP ProfileId Profileld Alias for a profile id ProfileIdSeq typedef sequence lt ProfileId gt ProfileIdSeq Alias for a sequence of profile ids ObjectKey typedef sequence lt octet gt ObjectKey Alias for an object key which is a sequence of octets 4 Page 7 Sec 1 7 37 at Ln Col JREG fie Ez ovr eA Figure 3 2 Documentation generated with the IDL to RTF translator see reference Adds a See also note since since text Comment related to the availability of new features version version The interface s version number 38 ORBacus Using javadoc 3 15 Like javadoc hidl and rid1 use the first sentence in the documentation comment as the summary sentence This sentence ends at the first period that is followed by a blank tab or line terminator or at the first ridl understands most basic HTML tags and will produce an equivalent format in the generated RTF files The following HTML tags are supported lt B gt lt BR gt lt CODE gt lt EM gt lt HR gt lt P gt lt U gt lt UL gt Using javadoc If not explicitly suppressed with the no comments option the ORBACUus IDL to Java translator jid1 adds
53. that any additional overhead for parameter marshalling or request dispatch ing is minimal All tests have been performed with ORBACUS for C version 3 1 1 on a Linux 2 0 35 based machine libe 5 4 33 PII 400 MHz 128 MB memory egcs 1 0 3a C compiler with optimization compiled with 02 DNDEBUG shared libraries and no debug code Regular Method Invocations The first test scenario is a server that is used by a single client Table 9 1 shows the time Blocking Reactive Threaded Blocking 0 20 ms 0 25 ms 0 28 ms Reactive 0 25 ms 0 29 ms 0 33 ms Threaded 0 26 ms 0 31 ms 0 37 ms Thread per Client 0 25 ms 0 30 ms 0 36 ms Thread per Request 0 63 ms 0 68 ms 0 71 ms Thread Pool 0 31 ms 0 39 ms 0 42 ms Table 9 1 Regular Method Invocations needed for a single call to f In this and all following tables the different columns corre spond to the client side concurrency models and the different rows to the server side con currency models The clear winners are the blocking concurrency models which are fastest Second fastest are the reactive concurrency models followed by the different threaded concurrency mod els Note that Table 9 1 shows the performance results for a thread safe version of ORBACUS In case no threads are used at all i e if no multi threaded concurrency model is chosen and if multiple threads are not used in application code then it s also possible to use a
54. the ORB to print its version to standard output ORBlicense Causes the ORB to print its license to standard output Table 4 2 Additional Command line Options Filtering Command line Options In C all command line options recognized by ORBACUS are automatically removed from the argv array after initializing the ORB and BOA In Java command line options are not automatically removed by ORBACUS If you would like to have ORBACUS specific options removed from the argument list you will need to do so using two additional methods The example below demonstrates how to remove the ORB and BOA options in Java Java org omg CORBA ORB orb org omg CORBA ORB init args null org omg CORBA BOA boa orb BOA_init args null String noOrbArgs com ooc CORBA ORB orb filter_options args String noBoaArgs com ooc CORBA BOA boa filter_options noOrbArgs Initialize the ORB and BOA Remove the ORB options i e options starting with ORB from args The array noOrbArgs contains the filtered options ORBacus 49 ORB and BOA Initialization 5 6 Remove the BOA options i e options starting with 0A By passing noOrbArgs to this 4 3 4 4 3 5 method we ensure that both ORB and BOA options have been removed Note that the casts for the ORB and BOA are necessary because filter_options is an ORBACUS specific operation which only exists in the ORB and BOA classes residing in the com
55. the nil object reference acceptor_info readonly attribute AcceptorInfo acceptor_info The AcceptorInfo object for the Acceptor that created the Transport object that this Transport Info object belongs to If the Transport for this TransportInfo was not created by an Acceptor this attribute is set to the nil object reference Operations add_close_cb void add_close_cb in CloseCB cb Add a callback that is called before a connection is closed If the callback has already been reg istered this method has no effect ORBacus Interface OCI TransportInfo Parameters cb The callback to add remove_close_cb void remove_close_cbh in CloseCB cb Remove a close callback If the callback was not registered this method has no effect Parameters ch The callback to remove ORBacus 203 Open Communications Interface Reference B 5 Interface OCI CloseCB interface CloseCB An interface for a close callback object See Also TransportInfo Operations close_cb void close_cb in TransportInfo transport_info Called before a connection is closed Parameters transport_info The TransportInfo for the new closeion 204 ORBacus Interface OCI Connector B 6 Interface OCI Connector interface Connector An interface for Connector objects A Connector is used by CORBA clients to initiate a connection to a server It also provides operations for the management of IOR profiles See A
56. the primary advantages of using CORBA If something is defined in CORBA IDL 24 ORBacus Summary 2 5 2 6 the programming language used for the implementation is irrelevant CORBA applica tions can talk with each other regardless of the language they are written in Summary At this point you might be inclined to think that this is the most complicated method of printing a string that you have ever encountered in your career as a programmer At first glance a CORBA based approach may indeed seem complicated On the other hand think of the benefits this kind of approach has to offer You can start the server and client applications on different machines with exactly the same results Concerning the commu nication between the client and the server you don t have to worry about platform specific methods or protocols at all provided there is a CORBA ORB available for the platform and programming language of your choice If possible get some hands on experience and start the server on one machine the client on another As you will see CORBA based applications run interchangeably in both local and network environments One last point to note you likely wont be using CORBA to develop systems as simple as our Hello World example The more complex your applications become and today s applications are complex the more you will learn to appreciate having a high level abstraction of your applications key interfaces
57. threaded concurrency models describe how an ORB behaves while a request is sent or received in a single threaded environment For example one model is to simply let the ORB block on sending and receiving messages Another model is to let the ORB do some work while sending and receiving messages for example to receive user input through a keyboard or a GUI or to simply transfer buffered messages Multi threaded concurrency models describe how the ORB makes use of multiple threads for example to send and receive messages in the background Multi threaded concur rency models also describe how several threads can be active in the user code and the strategy the ORB employs to create these threads Why different Concurrency Models There is no one size fits all approach with respect to concurrency models Each concur rency model provides a unique set of properties each having advantages and disadvan ORBacus 117 Concurrency Models 9 1 3 9 2 9 2 1 tages For example applications using callbacks must have a concurrency model that allows nested method invocations to avoid deadlocks Other applications must be opti mized for speed in which case a concurrency model with the least overhead will be cho sen Some ORBs are highly specialized providing only the most frequently used concurrency models for a specific domain ORBACUS takes a different approach by supporting several concurrency models ORBacus Concur
58. usually imp1_is_ready would have to be called in main However this is not possible since imp1_is_ready blocks which makes it impossible for the mixed client server program to invoke operations on the server after the call to impl_is_ready To solve this problem ORBACUS provides the operation init_servers Here s how init_servers is called in Java Java org omg CORBA BOA boa Get the BOA somehow com ooc CORBA BOA boa init_servers 1 The argument to imp1_is_ready is currently unused by ORBACUS therefore the dummy argument null Java or CORBA_ImplementationDef _nil C is used 56 ORBacus Server Event Loop This is similar to impl_is_ready except that init_servers does not block Note that the cast for the BOA is necessary because init_servers is an ORBACUS specific oper ation which only exists in com ooc CORBA BOA and not in org omg CORBA BOA The C version look similar Fi GEE CORBA_BOA_var boa Get the BOA somehow boa gt init_servers 4 4 2 Deactivating the Server A server can be deactivated with a call to BOA deactivate_imp1l This causes BOA impl_is_ready to return For example consider a server which can be shut down by a client by calling a deactivate operation on one of the server s objects First the IDL code IDL interface ShutdownObject void deactivate On the server side ShutdownObject can be implemented like this
59. works fine for C but in Java this causes a problem because there are no unsigned types in Java The Java mapping simply maps unsigned types to signed types Consider for example the IP address 126 127 128 129 In Java the OCI will return this as 126 127 128 127 because 128 and 129 if bit wise mapped to the Java byte type are 128 and 127 To avoid this problem we will use a helper class which converts port numbers and IP addresses to Java int types This helper class looks as follows Java final class Converter static int port short s if s lt 0 return Oxffff int s 1 else return int s static int addr byte bArray int iArray new int 4 for int i 0Oj i lt 4 itt if bArray i lt 0 iArray i Oxff int bArray i 1 else iArray i int bArray i 140 ORBacus OCI for the Application Programmer 11 4 2 AND AAS WH HE ORR HH HHH HHH SH DAN DAR WHE DOD O return iArray hi Converts short port numbers to int Converts byte IP addresses to int The converter class is used throughout the examples in the sections below Getting Hostnames and Port Numbers The following code fragments show how it is possible to find out on what hostnames and port numbers a server is listening First the C version C OCI_AccRegistry_var registry boa gt get_acc_registry OCI_AcceptorSeq_var acceptors registry gt get_acceptors
60. 0 ORBacus Non Compliant Application Asserts Application used wrong memory allocation function If this message appears an incorrect memory allocation function has been used A com mon mistake that leads to this error is to use malloc strdup and free or the new and delete operator instead of CORBA_string_alloc and CORBA_string_dup and CORBA_string_free for string memory management Memory that was already deallocated was deallocated again This message indicates multiple memory deallocations For example if CORBA_string_free is called twice on the same string this message will be displayed Object was deleted without an object reference count of zero This message appears if an object was deleted by calling delete on its object reference Never use the delete operator for that Use CORBA_release instead Object was already deleted object reference count was already zero This message appears if the number of release operations on an object reference is higher than the number of _duplicate operations Sequence length was greater than maximum sequence length This message indicates that the application tried to set the length of a bounded sequence to a value greater than its maximum length Index for sequence operator or remove function was out of range This message appears if the argument to the sequence member functions operator or remove exceeds the sequence length Null pointer was used to initialize T_v
61. 4 and javadoc style keywords are supported The section Documenting IDL Files on page 36 provides more information irserv is the Interface Repository Server Together with irfeed a program that feeds the Interface Repository with IDL code and irgen the Interface Repository C Code Generator it is possible to generate C code directly from the contents of an Interface Repository See The IDL to C Translator and the Interface Repository on page 35 for an example Options for idl h help Show a short help message v version Show the ORBACUS version number e cpp NAME Use NAME as the preprocessor program d debug Print diagnostic messages This option is for ORBACUS internal debugging purposes only DNAME Defines NAME as 1 This option is directly passed to the preprocessor DNAME DEF Defines NAME as DEF This option is directly passed to the preprocessor UNAME Removes any definition for NAME This option is directly passed to the preprocessor IDIR Adds DIR to the include file search path This option is directly passed to the preprocessor no skeletons Don t generate skeleton classes no type codes ORBacus 29 The ORBacus Code Generators Don t generate type codes and insertion and extraction functions for the Any type Use of this option will cause the translator to generate more compact code locality constrained Generate l
62. 8 ORBacus Interface OCI Acceptor B 9 Interface OCI Acceptor interface Acceptor An interface for an Acceptor object which is used by CORBA servers to accept client connection requests It also provides operations for the management of IOR profiles See Also AccRegistry Transport Attributes tag readonly attribute Profileld tag The profile id tag handle readonly attribute Handle handle The handle for this Acceptor Like with the handle for Transports the handle may only be used with operations like select A handle value of 1 indicates that the protocol plug in does not support selectable Transports Operations close void close Closes the Transport accept or listen must not be called after close has been called shutdown void shutdown j Shuts down the Transport After calling shutdown calls to accept or listen result in an appropriate CORBA COMM_FAILURE exception being raised listen void listen ORBacus 209 Open Communications Interface Reference Sets the acceptor up to listen for incoming connections Until this method is called on the accep tor new connection requests should result in a connection request failure accept Transport accept Used by CORBA servers to accept client connection requests It returns a Transport object which can be used for sending and receiving octet streams to and from the client Returns The new Transport object
63. BILITY FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS THE ENTIRE RISK AS TO THE USE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH LICENSEE SHOULD THE SOFTWARE PROVE DEFECTIVE LICENSEE ASSUMES THE COST OF ALL NECESSARY SERVICING REPAIR OR CORRECTION NO LIABILITY FOR GENERAL SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES IN NO EVENT WILL OBJECT ORIENTED CONCEPTS INC OR ANY OTHER PARTY WHO MAY COPY DISTRIBUTE OR MODIFY THE SOFTWARE AS PERMITTED HEREIN BE LIABLE FOR ANY GENERAL SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES WHATSOEVER INCLUDING WITHOUT LIMITATION DAMAGES FOR LOSS OF BUSI NESS PROFITS BUSINESS INTERRUPTION INACCURATE INFORMATION LOSS OF INFORMATION OR ANY OTHER PECUNIARY LOSS ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE EVEN IF OBJECT ORIENTED CONCEPTS INC OR SUCH OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES U S GOVERNMENT RESTRICTED RIGHTS The Software is provided with RESTRICTED RIGHTS Use duplication or disclosure by the Gov ernment is subject to restrictions as set forth in subparagraph c 1 11 of The Rights in Technical Data and Computer Software clause at DFARS 252 227 7013 or subparagraphs c 1 and 2 of the Commercial Computer Software Restricted Rights 48 C F R paragraph 52 227 19 as applicable Manufacturer is Object Oriented Concepts Inc 44 Manning Road Billerica MA 01821 TERMINATION Any violation or any attempt to violate
64. ER 4 CHAPTER 5 The IDL to C Translator and the Interface Repository 35 Include Statements 35 Documenting IDL Files 36 Using javadoc 39 ORB and BOA Initialization 43 ORB Initialization 43 Initializing the C ORB 43 Initializing the Java ORB for Applications 43 Initializing the Java ORB for Applets 44 BOA Initialization 44 Initializing the C BOA 44 Initializing the Java BOA 44 Configuring the ORB and BOA 45 Properties 45 Command line Options 48 Filtering Command line Options 49 Using a Configuration File 50 Defining Properties in Java 50 Precedence of Properties 51 Advanced Property Usage 52 Server Event Loop 56 Mixed Client Server Applications 56 Deactivating the Server 57 Applets 59 Adding ORBacus Applets to Web Pages 59 Defining ORB and BOA Options for an Applet 59 Defining the ORB Class Parameters 60 Security Issues 60 CORBA Objects 61 Overview 61 Implementing Servants 62 Implementing Servants using Inheritance 63 Implementing Servants using Delegation 65 Creating Servants 69 ORBacus CHAPTER 6 CHAPTER 7 Creating Servants using C 69 Creating Servants using Java 70 Connecting Servants 71 Connecting Servants using C 71 Connecting Servants using Java 71 Named Servants 72 Factory Objects 73 Factory Objects using C 74 Factory Objects using Java 75 Caveats 76 Getting a Servant from a Reference 77 Getting a Servant using C 77 Getting a Servant using Java 79 Locating Objects 81
65. I ORBACUS uses the name prefix mapping alternative for the following reasons e As mentioned earlier C namespaces are not widely available yet ORBACUS was designed to be portable among a variety of C compilers Therefore using namespaces was not possible 1 Who wants to use such ugly names anyway ORBacus 105 C Mapping Notes 8 3 8 3 1 8 3 2 Da ws WN PH e Although nested classes are available with most C compilers this mapping alternative has the disadvantage that modules cannot be reopened since classes cannot be reopened That is it is not possible to define in one IDL file one part of a module and in another IDL file another part of the same module Extensions ORBACUS provides several extensions to the standard IDL to C mapping If you are concerned about source code compatibility with CORBA compliant ORBs from other vendors you should not use these extensions However if you plan to use your source code exclusively with ORBACUS these extensions will reduce programming overhead Extensions to the String Type The ORBACUS CORBA_St ring_var type provides the operat or for appending to the string The argument to operator can be of type const char char and unsigned char as well as short unsigned short int unsigned int long and unsigned long For example CORBA_String_var s s abc ay Big ee Aa ai zl 12345 nn HD YW s is empty s
66. IDL file four C files are generated For example idl MyFile idl produces the following files yFile h Header file containing MyFile idl s translated data types and interface stubs yFile cpp Source file containing MyFile id1 s translated data types and interface stubs yFile_skel h Header file containing skeletons for MyFile idl s interfaces yFile_skel cpp Source file containing skeletons for MyFile idl s interfaces jid1 translates IDL files into Java files For every construct in the IDL file that maps to a Java class or interface a separate class file is generated Directories are automatically cre ated for those IDL constructs that map to a Java package e g a module jidl can also add comments from the IDL file starting with to the generated Java files This allows you to use the javadoc tool to produce documentation from the gener ated Java files See Using javadoc on page 39 for additional information hidl creates HTML files from IDL files An HTML file is generated for each module and interface defined in an IDL file Comments in the IDL file are preserved and javadoc style keywords are supported The section Documenting IDL Files on page 36 provides more information ridl creates Rich Text Format RTF files from IDL files An RTF file is generated for each module and interface defined in an IDL file Comments in the IDL file are preserved 28 ORBacus Options for idl 3
67. Info Information on an IIOP OCI Transport object See Also Transport TransportInfo Attributes addr readonly attribute InetAddr addr The local 32 bit IP address port readonly attribute unsigned short port The local port remote_addr readonly attribute InetAddr remote_addr The remote 32 bit IP address remote_port readonly attribute unsigned short remote_port The remote port 224 ORBacus Interface OCI IIOP ConnectorInfo B 19 Interface OCI IIOP ConnectorInfo interface ConnectorInfo inherits from OCI ConnectorInfo Information on an HOP OCI Connector object See Also Connector ConnectorInfo Attributes remote_addr readonly attribute InetAddr remote_addr The remote 32 bit IP address to which this connector connects remote_port readonly attribute unsigned short remote_port The remote port to which this connector connects ORBacus 225 Open Communications Interface Reference B 20 Interface OCI IIOP AcceptorInfo interface AcceptorInfo inherits from OCI AcceptorInfo Information on an IIOP OCI Acceptor object See Also Acceptor AcceptorInfo Attributes host readonly attribute string host Hostname used for creation of IIOP object references addr readonly attribute InetAddr addr The local 32 bit IP address on which this acceptor accepts port readonly attribute unsigned short port The local port on which this acceptor accepts
68. Naming Service instance 34 Finally the BOA is initialized Binding In the next step some sample bindings are created and bound to the Naming Service 1 Java 2 3 Named a new Named_impl 4 Named al new Named_impl 5 Named a2 new Named_impl 6 Named a3 new Named_impl 7 Named b new Named_impl 8 Named c new Named_impl 9 10 try 11 12 NameComponent nclName new NameComponent 1 13 nclName 0 new NameComponent 14 nclName 0 id ncl 15 nclName 0 kind 16 NamingContext ncl nc bind_new_context nclName 17 18 NameComponent nc2Name new NameComponent 2 19 nc2Name 0 new NameComponent 20 nc2Name 0 id ncl 21 nc2Name 0 kind 22 nc2Name 1 new NameComponent 23 nc2Name 1 id nc2 24 nc2Name 1 kind 25 NamingContext nc2 nc bind_new_context nc2Name 26 27 NameComponent aName new NameComponent 1 28 aName 0 new NameComponent 29 aName 0 id a 30 aName 0 kind 31 nc bind aName a 32 ORBacus 159 ORBacus Basic Services 33 NameComponent alName new NameComponent 1 34 alName 0 new NameComponent 35 alName 0 id al 36 alName 0 kind 37 nc bind alName al 38 39 NameComponent a2Name new NameComponent 1 40 a2Name 0 new NameComponent 41 a2Name 0 id a2 42 a2Name 0 kind
69. ORBA PolicyList policies Creates a new Connector for a given IOR satisfing a list of policies Like create all connec tion specific data is taken from an IOR profile that matches this Connector factory and if more than one profile matches then which of these profiles is used is implementation specific 214 ORBacus Interface OCI ConFactory Parameters ior The IOR from which the profile and connection data are extracted policies The policies that must be satisfied Returns The new Connector A nil object reference is returned if the IOR does not contain a profile which matches this Connector factory or if the policies cannot be satisfied consider_with_policies boolean consider_with_policies in IOR ior in CORBA PolicyList policies Determines whether this Connector factory can create a Connector for a given IOR and a given list of policies Parameters ior The IOR to consider policies The policies that must be satisfied Returns TRUE if a Connector can be created for the IOR and the policies can be satisfied FALSE oth erwise equivalent boolean equivalent in IOR iorl in IOR ior2 Checks whether two IORs are equivalent taking only profiles into account matching this Con nector factory Parameters ior1 The first IOR to check for equivalence ior2 The second IOR to check for equivalence Returns TRUE if the IORs are equivalent FALSE otherwise hash unsigned long hash in IOR
70. ORBacus For C and Java Version 3 1 1 Copyright c 1998 Object Oriented Concepts Inc All Rights Reserved Object Oriented Concepts ORBacus and JThreads C are trademarks or regis tered trademarks of Object Oriented Concepts Inc OMG CORBA and Object Request Broker are trademarks or registered trade marks of the Object Management Group Java is a trademark of Sun Microsystems Inc Netscape is a registered trademark of Netscape Communications Corporation Other names products and services may be the trademarks or registered trademarks of their respective holders ORBacus CHAPTER 1 CHAPTER 2 CHAPTER 3 Introduction Il What is ORBacus 11 How is it licensed 12 About this Document 12 Getting Help 12 Getting Started 15 The Hello World Application 15 The IDL Code 16 Implementing the Example inC 16 Implementing the Server 17 Implementing the Client 19 Compiling and Linking 20 Running the Application 21 Implementing the Example in Java 21 Implementing the Server 21 Implementing the Client 23 Compiling 24 Running the Application 24 Summary 25 Where to go from here 25 The ORBacus Code Generators 27 Overview 27 Synopsis 27 Description 28 Options for idl 29 Options for jidl 31 Options for hid 32 Options for rid 32 Options for irserv 33 Options for irfeed 34 Options for irdel 34 Options for irgen 34 ORBacus CHAPT
71. RBA System Exceptions 178 ORBacus CORBA System Exceptions Table 14 2 shows the minor codes for the COMM_FAILURE exception and Table 14 3 the Table 14 2 Minor Exception Codes for COMM_FAILURE OBMinorRecv recv failed OBMinorSend send failed OBMinorRecvzZero recv returned zero OBMinorSendZero send returned zero OBMinorSocket socket failed OBMinorSetsockopt setsockopt failed OBMinorGet sockopt getsockopt failed OBMinorBind bind failed OBMinorListen bind failed OBMinorConnect connect failed OBMinorAccept accept failed OBMinorSelect select failed OBMinorGethostname gethostname failed OBMinorGethostbyname gethostbyname OBMinorWSAStartup WSAStartup failed OBMinorWSACleanup WSACleanup failed OBMinorNoGIOP Not a GIOP message OBMinorUnknownMessage Unknown GIOP message OBMinorWrongMessage Wrong GIOP message OBMinorCloseConnection Got a close connection message OBMinorMessageError Got a message error message minor codes for the INTF_REPOS exception No other minor codes are currently defined by ORBACUS ORBacus 179 Exceptions and Error Messages OBMinorNoIntfRepos Interface repository is not available OBMinorIdExists Repository id already exists OBMinorNameExists Name already exists OBMinorRepositoryDestroy destroy invoked on Reposito
72. Windows h gt include lt OB CORBA h gt include lt OB Windows h gt int WINAPI WinMain HINSTANCE hInstance HINSTANCE hPrevinstance LPSTR lpszArgs int nWinMode OBWindowsInit hInstance int dummy 0 CORBA_ORB_var orb CORBA_ORB_init dummy 0 CORBA_BOA_var boa orb gt BOA_init dummy 0 More application code boa gt impl_is_ready return 0 Include header files Define the WinMain function Use the Windows application instance to initialize the Windows Reactor Initialize ORB and BOA as usual Enter the CORBA event loop which now also dispatches Windows events The standard Windows event loop may also be called which will then also dispatch CORBA events ORBacus 133 The Reactor 10 3 MANDA GASP WHE Wwwwwwnhs vb NY NHN NHN NHN NHHRHHHH HHH HH At wWwNHHE DH AN DA aS WHERE DH DAN DAP WwWNHE DO o Writing a Custom Event Handler ORBACUS in reactive mode includes support for customized event handlers This means that while your application is running it can react to events like keyboard events In order to implement your own ORBACUS event handler you must derive a class from OBEventHandler and overload the handleEvent and handleStop member functions The constructor of the derived class must ensure that objects of this class are registered with the Reactor This is an example for an event handler that listens to keyboard events include lt OB Reactor h gt
73. a 12 13 public void op_i 14 15 16 3 The servant class I_imp1_tie is defined to implement the TOperations interface 5 15 I_impl_tie must implement all of 1 s operations including inherited operations Figure 5 3 illustrates the relationship between the classes generated by the IDL to Java translator and the servant implementation classes I _ITmpIBase I_impl _IImp Base_tie EPEE IOperations I_impl_tie Figure 5 3 Class Hierarchy for Inheritance and Delegation Implementation in Java ORBacus Creating Servants 5 3 5 3 1 Creating Servants Servants are created the same way in both C and Java once your servant class is writ ten you simply instantiate a servant with new Creating Servants using C Here is how to create servants using C C I_var impl new I_impl I_var anotherImpl new I_impl Two servants impl and anotherImpl are created with new In case the servant class was written using the delegation approach an object of the class implementing I s operations must be passed to the servant s constructor C I_impl_tie impl new I_impl_tie I_var tie new I_skel_tie lt I_impl_tie gt impl CORBA_TRUE A new I_impl_tie is created with new An instance of I_skel_tie parameterized with I_imp1_tie is created taking impl asa parameter All operation calls to tie will
74. a good example of how to create properties and query for their values The code below is based on excerpts of this test suite which is located in the directory property test We will concentrate on an example in Java here As with the previous examples the Java code is very similar to what is necessary in C The example demonstrates how to create prop erties and how to get a list of all the properties defined within a PropertySet Java org omg CORBA Object obj null try obj orb resolve_initial_references PropertyService catch org omg CORBA ORBPackage InvalidName ex An error occurred Property Service is not available if obj null The object reference is invalid PropertySetFactory factory PropertySetFactoryHelper narrow obj if factory null This object does not implement the Property Service PropertySet set factory create_propertyset Any anyLong orb create_any Any AnyInt orb create_any Any anyShort orb create_any j anyLong insert_long 12345L anyInt insert_int 6789 anyShort insert_short 0 try 166 ORBacus The Property Service 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 a 58 59 60 61 62 63 64 65 66 67 68 69 70 71 25 21732 34 59 set define_property LongProperty anyLong set define_property IntProperty anyInt set define_property
75. a pointer to a servant class C include lt OB Narrow_impl h gt class I_impl virtual public I_skel OB_MAKE_NARROW_IMPL I_imp1 OB_MAKE_NARROW_IMPL_1 I_impl I_skel void foo I_ptr ref I_impl p I_impl _narrow_impl ref if p The implementation for ref is local else The implementation for ref is not local The file lt OB Narrow_imp1 h gt must be included for the definitions of the OB_MAKE_NARROW_IMPL macros A servant class for I is defined with OB_MAKE_NARROW_IMPL as shown The only other difference is that now I_impl _narrow_imp1 must be used instead of dynamic_cast lt gt The macro OB_MAKE_NARROW_IMPL_1 can only be used if the servant class has exactly one super class the skeleton class If the servant class has two or more super classes use the macro OB_MAKE_NARROW_IMPL_n where n is the number of super classes For exam ple 1 RunTime Type Identification 78 ORBacus Getting a Servant from a Reference SMH DAN DA GAB UNAK Ky 10 5 6 2 MN A ab WN PE hi oR Bow 12 LS 14 195 16 17 18 C class C_impl virtual public C_skel virtual public A_impl virtual public B_impl OB_MAKE_NARROW_IMPL C_imp1 OB_MAKE_NARROW_IMPL_3 C_impl C_skel A impl B_imp1 C_imp1 is derived from three classes C_skel A_imp1l and B_imp1 Now OB_MAKE_NARROW_IMPL_3
76. a reference to a Hello object A simple Java cast doesn t work here since it is possible that the client has to ask the server whether the object is really of type Hello Finally the hello operation is invoked causing the server to print Hello World on standard output Compiling To compile the implementation classes and the classes generated by the ORBACus IDL to Java translator use javac or the Java compiler of your choice javac java hello java Ensure that your CLASSPATH environment variable includes the ORBACUS Java classes i e the OB jar file If you are using the Unix Bourne shell or a compatible shell you can do this with the following commands CLASSPATH your_orbacus_directory lib OB jar CLASSPATH export CLASSPATH Replace your_orbacus_directory with the name of the directory where ORBACUS is installed If you are running ORBACUS on a Windows based system you can use the following command within the Windows command interpreter set CLASSPATH your_orbacus_directory lib OB jar SCLASSPATHS 66 99 66 99 Note that for Windows you must use and not as the delimiter Running the Application The Hello World Java server is started with java hello Server And the client with java hello Client Again make sure that your CLASSPATH environment variable includes the OB jar file You might also want to use a C server together with a Java client or vice versa This is one of
77. ame n raise NotFound AlreadyBound CannotProceed InvalidName bind registers a new object with the Naming Service whereas a new context is registered with bind_context For each operation an object reference and a Name are expected as parameters If no exception was thrown the bind operation was successful New naming context objects are created with new_context or bind_new_context Use the unbind operation to delete a particular binding IDL void unbind in Name n raises NotFound CannotProceed InvalidName Name Resolution Besides registering objects an equally important task of the Naming Service is name reso lution A name is passed to the resolve operation and an object reference is returned if the name exists IDL Object resolve in Name n raises NotFound CannotProceed InvalidName The resolve operation is only useful when a particular name is known in advance Sometimes it is necessary to ask for a list of all bindings registered with a particular nam ing context The list operation returns a list of bindings 156 ORBacus The Naming Service 13 2 5 13 2 6 IDL typedef sequence lt Binding gt BindingList void list in unsigned long how_many out BindingList bl out BindingIterator bi If the number of bindings is especially large the BindingIterator interface is provided so that you don t have to query for all available bindings at once Simply get a certain number of bin
78. and BOA on page 45 for more information on the OAport option Object Key Each object created by a server is assigned a unique key that is included in object refer ences published for the object Furthermore the order in which your server creates its objects affects the keys assigned to those objects To ensure that your objects always have the same keys ORBACUS allows you to specify a unique name to be used as the key for an object See Named Servants on page 72 for more information 84 ORBacus Stringified Object References 6 3 6 3 1 ND GQ WN FE Stringified Object References The CORBA specification defines two operations on the ORB interface for converting object references to and from strings IDL module CORBA interface ORB string object_to_string in Object obj Object string_to_object in string ref Using stringified object references is the simplest way of bootstrapping your first object reference In short the server must create a stringified object reference for an object and make the string available to clients A client obtains the string and converts it back into an object reference and can then invoke on the object The examples discussed in the sections below are based on the IDL definitions presented at the beginning of this chapter Using a File One way to publish a stringified object reference is for the server to create the string using ob ject_to_
79. antage of the user code not hav ing to take care of any kind of thread synchronization This means that the user code can be written as if for a single threaded system but without losing the advantage of the ORB optimizing its operation by using multiple threads internally The threaded concurrency model is still fast No calls to operations like select are required Time consuming thread creation is only necessary when a new client is connect ing but not for each request However thread context switching makes this approach slower than the blocking concurrency model at least on a single processor computer Thread per Client Server The thread per client server concurrency model is very similar to the threaded server con currency model except that the ORB allows one active thread per client in the user code This is shown in Figure 9 6 A s call to and B s call to g are carried out simultaneously g0 h Ye 2 Client A Thread per Client Client B Server Figure 9 6 Thread per Client Server each in its own thread However if A tries to call another operation h for example by sending requests from different threads in a multi threaded client or by using the DII oper ation send_deferred in a single threaded client as long as f has not finished yet the execution of h is delayed until f returns ORBacus 123 Concurrency Models
80. any insert_string s try consumer_ push any catch Disconnected ex Supplier was disconnected from event channel Thread yield try Thread sleep 1000 catch InterruptedException ex The current date and time is inserted into the Any The event data in this example date and time are pushed to the event channel From the push supplier s view the event channel is just a consumer implementing the PushConsumer interface After sleeping for one second the steps above are repeated The example s pull supplier works similarly to the push supplier except that the event channel explicitly polls the supplier for new events This is done by either pull or try_pull The pull supplier doesn t see anything from the event channel but an object implementing the Pull Consumer interface The following example shows the basic lay out of a pull supplier Java public Any pull ORB orb ORB init 172 ORBacus The Event Service 10 11 12 23 14 15 16 17 18 19 20 21 22 23 MN DA AA WNP i So o 11 12 13 14 I9 java util Date date new java util Date String s PullSupplier says date toString Any any orb create_any any insert_string s return any public Any try_pull BooleanHolder has_event has_event value true return pull Date and time are inserted into the Any In this example new
81. any of the terms and conditions of this License will automat ically terminate Licensee s rights under this License Licensee further agrees upon such termination to cease any and all using copying distributing and modifying of the Software and any work derived from the Software and further to destroy any and all of Licensee s copies of the Software and any work derived from the Software However parties who have received copies of the Software or copies of any work derived from the Software or rights from Licensee under this License will not have their licenses terminated so long as such parties remain in full compliance with this License LICENSE SCOPE AND MODIFICATION This License sets forth the entire agreement between Licensee and Object Oriented Concepts Inc and supersedes all prior agreements and understandings between the parties relating to the subject ORBacus 233 Royalty Free Public License Agreement matter hereof None of the terms of this License may be waived or modified except as expressly agreed in writing by both Licensee and Object Oriented Concepts Inc SEVERABILITY Should any provision of this License be declared void or unenforceable the validity of the remain ing provisions shall not be affected thereby GOVERNING LAWS This License is governed by the laws of the State of Massachusetts U S A and shall be interpreted in accordance with and governed by the laws thereof Licensee hereby wai
82. ar type This message indicates an attempt to initialize a _var type with a null pointer operator gt was used on null pointer or nil object reference This message indicates an attempt to use operat or gt on an uninitialized _var type ORBacus 181 Exceptions and Error Messages Aa UNAK Aa UNAK Application tried to dereference a null pointer Some CORBA _var types have built in conversion operators to a C reference type i e some _var types for type T have a conversion operator to T amp This message appears if an application uses this conversion operator on an uninitialized _var type Null pointer was passed as string parameter or return value According to the IDL to C mapping specification no null pointers may be passed as string parameters or return values This message appears if an application tries to do so Self assignment caused a dangling pointer This message appears if the content of a _var type is assigned to itself For example the following code will lead to this error message Somehow get a pointer to a variable struct AVariableStruct_var var AVariableStruct ptr var var ptr This will result in a dangling pointer because var will free its own content on assignment Replacement of Any content by its own value caused a dangling pointer This message appears if there is an attempt to replace the content of an Any by its own value For example char s CORBA_str
83. are and works derived from the Software No rights are granted to the Software except as expressly set forth herein Nothing other than this License grants Licensee permission to use copy distribute or modify the Software or any work derived from the Software Licensee may not use copy distribute or modify the Software or any work derived from the Software except as expressly provided under this License If Licensee does not accept the terms and conditions of this License do not use copy distribute or modify the Soft ware ORBacus 229 Royalty Free Public License Agreement In consideration for Licensee s forbearance of commercial use of the Software Object Oriented Concepts Inc grants Licensee non exclusive royalty free rights as expressly provided herein DEFINITIONS The Software is the ORBacus software including but not limited to the ORBacus Libraries and Class Files the ORBacus IDL to C and IDL to Java translators associated media and printed materials and any included on line documentation A work derived from the Software is any derivative work as defined in 17 U S C 101 which is derived from the Software for example code generated by the ORBacus IDL to C or IDL to Java translators a program which is linked with or otherwise incorporates the ORBacus Libraries or Class Files or a translation improvement enhancement extension or other modification of the Soft ware To u
84. ate objDelegate com ooc CORBA Delegate objImpl _get_delegate com ooc OCI ConnectorInfo info objDelegate get_oci_connector_info com ooc OCI IIOP ConnectorInfo iiopInfo com ooc OCI IIOP ConnectorInfoHelper narrow info if iiopInfo null int remoteAddr Converter addr iiopInfo remote_addr int remotePort Converter port iiopInfo remote_port System out printin Will connect to remoteAddr 0O remoteAddr 1 remoteAddr 2 remoteAddr 3 remotePort We need to retrieve the ORBACUS specific Delegate object so that we can get the con nector info Get the OCI connector info and narrow to an IIOP connector info The if block is only entered if this really was an IIOP connector info The address and port are obtained and displayed on standard output ORBacus 145 The Open Communications Interface 146 ORBacus CHAPTER 12 Using Policies 12 1 Overview The ORB and its services may allow the application developer to configure the semantics of its operations This configuration is accomplished in a structured manner through inter faces derived from the interface CORBA Policy For instance the ORBACUS SSL plug in 13 allows the configuration of the cipher suites used for peer communications through the interface SSL CipherSuitePolicy The configuration of these policy objects is accomplished at three levels e ORB Level These policies
85. ation that is contributed by an event source An event channel ORBacus 169 ORBacus Basic Services 13 4 5 instance accepts this information and distributes it to a list of objects that previously have connected to the channel and are listening for events The Event Service specification defines two distinct kinds of event channels untyped and typed Whereas an untyped event channel forwards every event to each of the registered clients in the form of a CORBA Any a typed event channel works more selectively by supporting strongly typed events which allow for data filtering We will only discuss the untyped event channel here For information on typed event channels and more details on the Event Service in general please refer to the official Event Service specification 4 Event Suppliers and Consumers Applications participating in generating and accepting events are called suppliers and con sumers respectively To be more precise there are two kinds of suppliers namely push suppliers and pull suppliers The situation is similar with event consumers in that there are push consumers and pull consumers What s the difference between pushing events and pulling events Let s have a look at the consumer side first There are consumers that have to be immediately informed when any new events become available on the event channel These consumers usually act as push consumers They implement the PushConsumer interface which en
86. ava translator includes methods for accessing and changing the implementation object Java public class _IImplBase_tie extends _IImplBase public IOperations _delegate public void _delegate IOperations delegate The tie class for interface I is defined This method returns the current delegate i e implementation object This method changes the delegate object 70 ORBacus Connecting Servants 5 4 5 4 1 Ww UNAK 5 4 2 Aa Ww hb Connecting Servants Servants must be connected to the object adapter in order to receive requests from clients Usually this is done automatically whenever an object reference to a servant is passed to a client as a parameter or return value Servants are also connected implicitly when used in calls to operations like object_to_string However it is also possible to connect a ser vant explicitly Connecting Servants using C The following code shows how to explicitly connect a servant C CORBA_ORB_var orb Get a reference to the ORB somehow I_var impl new I_impl orb gt connect impl To connect a servant we need the ORB A new servant imp is created The new servant is connected to the object adapter A servant can also be disconnected from the object adapter This is done with the disconnect call C orb gt disconnect impl The servant imp1 is disconnected from the object adapte
87. avior of the ORB and BOA objects using a col lection of properties These properties can be defined in a number ways e using a configuration file e using system properties Java e using command line options e programmatically at run time Properties The ORBACUS configuration properties are described in the sections below Unless other wise noted every property can be used in both C and Java applications ORB Properties ooc orb add_iiop_connector Value true false Determines whether the ORB should register an IIOP connector during initialization The default value is true ooc orb conc_model Value blocking reactive threaded Selects the client side concurrency model The reactive concurrency model is not currently available in ORBACUS for Java The default value is blocking for both C and Java applications See Chapter 9 for more information on concurrency models 1 Note that these properties have nothing to do with the Property Service as described in The Property Service on page 162 ORBacus 45 ORB and BOA Initialization ooc orb id Value id Specifies the identifier of the ORB to be used by the application The only valid identifier is OB_ORB ooc orb trace_level Value level gt 0 Defines the output level for diagnostic messages printed by ORBACUS A level of 1 pro duces information about connection events The default level is 0 which produces no out put ooc service
88. captured in CORBA IDL Where to go from here To understand the remaining chapters of this manual you must have read the CORBA specifications in 2 and 3 You will not be able to understand the chapters that follow without a good knowledge of CORBA in general CORBA IDL and the IDL to C and IDL to Java mappings 1 Note that after the startup of the server program you have to copy the stringified object refer ence i e the file Hello ref to the machine where the client program is to be run ORBacus 25 Getting Started 26 ORBacus The ORBacus Code CHAPTER 3 3 1 Overview ORBACUS includes the following code generators and Interface Repository tools idl The ORBAcus IDL to C Translator jidl The ORBACUS IDL to Java Translator hidl The ORBAcus IDL to HTML Translator ridl The ORBAcus IDL to RTF Translator irserv The ORBACUs Interface Repository Server irfeed The ORBACUs Interface Repository Feeder irdel The ORBACUS Interface Repository Deleter irgen The ORBACUs Interface Repository C Code Generator 3 2 Synopsis idl options idl files jidl options idl files hidl options idl files ORBacus 27 The ORBacus Code Generators 3 3 ridl options idl files irserv options idl files irfeed options idl files irdel options scoped name irgen name base Description idl is the ORBACus IDL to C translator It translates IDL files into C files For each
89. cate orb virtual void destroy orb_ gt disconnect this Servant class Product_imp1 is defined as an implementation of the P roduct interface The constructor takes an ORB parameter and saves it for later use The destroy operation disconnects the object from the object adapter A side effect of disconnecting the object is that the object adapter no longer holds a reference to the ser vant If there are no other references to this servant in the server then the servant will be destroyed See Releasing Proxies and Servants on page 98 for more information Next we ll implement the factory C class Factory_impl public virtual Factory_skel CORBA_ORB_var orb_ public void Factory_impl CORBA_ORB_ptr orb orb_ CORBA_ORB _duplicate orb virtual Product_ptr createProduct 74 ORBacus Factory Objects 14 19 16 17 18 5 5 2 MN A AA WN HP RoR RH HOW GQ is whMRE DS amp 23 Product_ptr result new Product_impl orb_ orb_ gt connect result return result Servant class Factory_imp1 is defined as an implementation of the Factory interface The constructor takes an ORB parameter and saves it for later use The createProduct operation instantiates a new Product servant connects it to the object adapter and returns an object reference to the client Use of the connect operation is optional an object will be connected automatica
90. cb Remove an accept callback If the callback was not registered this method has no effect Parameters ch The callback to remove 212 ORBacus Interface OCI AcceptCB B 11 Interface OCI AcceptCB interface AcceptCB An interface for an accept callback object See Also AcceptorInfo Operations accept_cb void accept_cb in TransportInfo transport_info Called after a new connection has been accepted If the application wishes to reject the connec tion CORBA NO_PERMISSION may be raised Parameters transport_info The TransportInfo for the new connection ORBacus 213 Open Communications Interface Reference B 12 Interface OCI ConFactory interface ConFactory A factory for Connector objects See Also Connector ConFactoryRegistry Attributes tag readonly attribute Profileld tag The profile id tag Operations create Connector create in IOR ior Creates a new Connector for a given IOR All connection specific data is taken from an IOR profile that matches this Connector factory If more than one profile matches then which of these profiles is used is implementation specific Parameters ior The IOR from which the profile and connection data are extracted Returns The new Connector A nil object reference is returned if the IOR does not contain a profile which matches this Connector factory create_with_policies Connector create_with_policies in IOR ior in C
91. client does not need to include He1lo_imp1 h Only the gen erated file Hello h is needed Like the server s implementation of main the client s main starts with the initialization of the ORB It s not necessary to initialize the BOA because the BOA is only needed by server applications The stringified object reference written by the server is read and converted to a CORBA_Ob ject object reference The _narrow operation generates a Hello object reference from the CORBA_Ob ject object reference Finally the hello operation on the he11o object reference is invoked causing the server to print Hello World Save this into the file Client cpp Compiling and Linking Both the client and the server must be linked with the compiled Hello cpp which usu ally has the name Hello o under Unix and Hello obj under Windows The compiled Hello_skel cpp and Hello_imp1 cpp are only needed by the server Compiling and linking is to a large degree compiler and platform dependent Many com pilers require unique options to generate correct code To build ORBACUS programs you must at least link with the ORBACUS library 1ib0B a Unix or ob 1ib Windows Additional libraries are required on some systems such aslibsocket aand libnsl a for Solaris or wsock32 1ib for Windows The ORBACUsS distribution comes with various README files for different platforms which give hints on the options needed for compiling and the libraries nece
92. contains interfaces to gather information on the IIOP OCI plug in Interface Index AccRegistry A registry for Acceptors AcceptCB An interface for an accept callback object Acceptor An interface for an Acceptor object which is used by CORBA servers to accept chent connection requests Acceptorinfo Information on an OCI Acceptor object Buffer An interface for a buffer CloseCB An interface for a close callback object ConFactory A factory for Connector objects ConFactoryInfo gt a Document Done ES Ve AA 7 Figure 3 1 Documentation generated with the IDL to HTML translator Adds a member description to the member list of a struct union enum or exception type param parameter name description Adds a parameter description to the parameter list of an operation return description Adds descriptive text for the return value of an operation ORBacus 37 The ORBacus Code Generators Microsoft Word ociref olx F Elle Edt View Insert Format Tools Table Window Help l8 x OSE SRY e2 Ov o T BERes rule Dp Reyes i x Module OCI Normal Times New Roman 14 B The Open Communications Interface OCD The definitions in this module provide a uniform interface to network protocols This allows for easy plug in of new protocols or other communication mechanisms into ORBs that implement the OCI Furthermore protocol implementations need only to be written once and can then be
93. convert it to an object reference as shown below Java org omg CORBA ORB orb Get a reference to the ORB somehow String ref getParameter ref org omg CORBA Object object orb string_to_object ref B b BHelper narrow object Obtain the applet parameter ref Convert the string to an object reference Narrow the object reference to a B object The presence of the stringified object reference in the HTML file could present a mainte nance problem One solution is for the server to write the entire HTML file thereby ensur ing that the object reference is always up to date You can find an example of this approach in the demo hel1o subdirectory See Applets on page 59 for more information on using ORBACUS in applets Connecting to Named Objects In some applications it may be necessary for the client to have no resource dependencies e g files URLs etc in order to bootstrap an object reference In this case you can use the ORBACUS specific iiop notation for IORs or the ORB operation get_inet_object The only prerequisites are that the object must have been assigned a name by the server see Named Servants on page 72 and the client must be able to determine the hostname and port number of the server and the name of the desired object The services included with ORBACUS all use named objects that can be accessed using get_inet_object The names for these objects can be found in Obj
94. cy Models 128 6 ORBacus CHAPTER 10 CHAPTER 11 CHAPTER 12 The Reactor 131 What is a Reactor 131 Available Reactors 131 The X11 Reactor 132 The Windows Reactor 133 Writing a Custom Event Handler 134 Using Timers 135 The Open Communications Interface 137 What is the Open Communications Interface 137 Interface Summary 137 Buffer 137 Transport 138 Acceptor and Connector 138 Connector Factory 138 The Registries 138 The Info Objects 138 Class Diagram 139 OCI Reference 139 OCI for the Application Programmer 140 A Converter Class for Java 140 Getting Hostnames and Port Numbers 141 Finding out a Client s IP Address 142 Finding out a Server s IP Address 144 Using Policies 147 Overview 147 Supported Policies 148 Examples 148 Connection Reuse Policy at ORB Level 149 Connection Reuse Policy at Object Level 150 ORBacus CHAPTER 13 CHAPTER 14 APPENDIX A ORBacus Basic Services 151 Configuring and Using a Basic Service 151 Starting the Service 152 Connecting to the Service 152 Object Names for the Basic Services 153 The Naming Service 154 Properties 154 Command line Options 154 Creating Bindings 155 Name Resolution 156 Persistence 157 A Simple Example 157 The Property Service 162 Command line Options 163 Creating Properties 163 Querying for Properties 164 Deleting Properties 165 A Simple Example 166 The Event Service 168 Properties 168 Command line Options 169 Diagnostics 169
95. de the ORBAcus IDL to C transla tor idi will not create code for included IDL files The translator will insert the appropri ORBacus 35 The ORBacus Code Generators 3 14 ate include statements in the generated header files instead Please note that there are several restrictions on where to place the include statements in your IDL files for this feature to work properly e include may only appear at the beginning of your IDL files All include statements must be placed before the rest of your IDL code e Type definitions such as interface or struct definitions may not be split among several IDL files In other words no include statement may appear within such definitions If you don t want these restrictions to be applied you can use the translator option a11 with idl With this option the IDL to C translator treats code from included files as if the code appeared in your IDL file at the position where it is included This means that the compiler will not place include statements in the automatically generated header files regardless of whether the code comes directly from your IDL file or from files included by your IDL file Note that when generating code from an Interface Repository using irgen the translator behaves identically to id1 with the a11 option In other words the irgen command will not place include statements in the generated files but rather generates code for all IDL definitions in t
96. dings specified with how_many and get the rest if any using the BindingIterator IDL interface BindingIterator boolean next_one out Binding b boolean next_n in unsigned long how_many out BindingList bl void destroy Make sure that you destroy the iterator object when it is no longer needed Persistence The ORBACUS Naming Service can optionally be used in a persistent mode in which all bindings managed by the service are saved in a file If you do not run the service in its per sistent mode all of the bindings will be lost when the service terminates It is also important to note that when using the service in its persistent mode you should always start the service on the same port see Configuring the ORB and BOA on page 45 for more information A Simple Example ORBACUS includes simple C and Java examples that demonstrate how to use the CORBA Naming Service These examples are located in the folder naming demo We will concentrate on the Java example but the C example works similarly The example expects a Naming Service server to be already running and that the server s initial refer ence can be resolved by the ORB Because of its volume we have split the code into sev eral parts for the discussion below ORBacus 157 ORBacus Basic Services MANDA OA PWN HE Wwwwnhs NS NHN NHN NHN NHN NHPRPHHH HHH HHH G N H DH AND ABR WBNHRE DH DAN DAB WHE DD amp 34 12 20 Initial
97. e default Reactor is the select Reactor If one of the other Reactors is to be used it must be initialized explicitly The X11 Reactor An application that wants to use the X11 Reactor simply has to call the function OBX11Init before the ORB is initialized with CORBA_ORB_init For example include lt X11 Intrinsic h gt include lt OB CORBA h gt include lt OB X11 h gt int main int argc char argv char XtAppContext appContext Widget topLevel XtAppInitialize amp appContext MyApplication 04 0 amp argce argv 0 0 0 OBX11Init appContext CORBA_ORB_var orb CORBA_ORB_init argc argv CORBA_BOA_var boa orb gt BOA_init argc argv More application code boa gt impl_is_ready return 0 Include header files Define the main function Initialize X11 application Use the X11 application context to initialize the X11 Reactor 132 ORBacus Available Reactors 18 19 23 10 2 2 MN A GOW WN PE Oe KREn R KR kRkh RahkKRhAkK SoH AND T e Wo D 21 10 12 14 18 Initialize ORB and BOA as usual Enter the CORBA event loop This loop will now also dispatch X11 events Alternatively the standard X11 event loop may be called which will then also dispatch CORBA events The Windows Reactor For the Windows Reactor the function OBWindowsInit must be called also before the ORB is initialized For example include lt
98. e It is much more nat ural to think of an object in terms of its name which is a core feature of the CORBA Nam ing Service In the Naming Service objects are registered with a unique name which can later be used to resolve its associated object reference 13 2 1 Properties The ORBACUus Naming Service supports the following properties ooc naming database FILE Enables persistence for the server All of the bindings cre ated by the server will be saved to the specified file If you are starting the server for the first time using this database you must also use the s command line option ooc naming timeout MINS Specifies the timeout in minutes after which a persistent server automatically compacts its database The default tim eout is five minutes 13 2 2 Command line Options The ORBACUus Naming Service supports the following command line options peip Display the command line options supported by the server ORBacus The Naming Service 13 2 3 v Display the version of the server version i Print the interoperable object reference IOR of the server to standard 1Or output S Use this option only when starting a persistent server using a new database start d FILE Equivalent to the coc naming database property database FILE q gJ property t MINS Equivalent to the ooc naming timeout property timeout MINS q J U property Creating Bindings Object re
99. e classes in order to provide concrete implementations for a specific protocol ORBACUS also pro vides concrete classes for the interfaces Buffer Connector Factory Registry and Acceptor Registry Instances of Connector Factory Registry and Acceptor Registry are provided by the ORB and Object Adapter respectively Concrete implementations of the Connector Factory must be registered with the ORB s Connector Factory Registry and concrete implementations of the Acceptor must be registered with the Acceptor Registry OCI Reference This chapter does not contain a complete reference of the OCI It only explains OCI basics and in the remainder of this chapter how it is used from the application programmer s ORBacus 139 The Open Communications Interface 11 4 11 4 1 1 2 3 4 DANDY pis 12 13 14 19 16 I7 18 19 20 Zl point of view for the most common tasks For more information on how to use the OCI to write your own protocol plug ins and for a complete reference please refer to Appendix B OCI for the Application Programmer The following information only applies to the standard ORB ACUS IOP plug in For other plug ins like the ORBACUS SSL plug in please refer to the plug in s documentation A Converter Class for Java As you will see in the following examples the OCI info objects return port numbers as IDL unsigned short values and IP addresses as an array of 4 IDL unsigned octet values This
100. e configuration file is processed Obtain the Properties instance and then retrieve the value of the property Finally it is important to remember the precedence rules for ORBACUS properties Specif ically command line options will always override any existing property definitions including those you set within your application ORBacus 55 ORB and BOA Initialization 4 4 4 4 1 Server Event Loop A server s event loop is entered by calling BOA imp1_is_ready For example in 1 Java Java org omg CORBA BOA boa Get the BOA somehow boa impl_is_ready null And in C C CORBA_BOA_var boa Get the BOA somehow boa gt impl_is_ready CORBA_ImplementationDef _nil impl_is_ready only returns if e The blocking concurrency model see Chapter 9 has been chosen for the server and the client disconnects e deactivate_imp is called see Deactivating the Server on page 57 Mixed Client Server Applications In case the reactive or one of the threaded concurrency models has been chosen see Chap ter 9 it is possible to service requests without calling imp1_is_ready This is especially useful in mixed client server applications For example consider a mixed client server program that wants to invoke operations on a server in the program s main function but still wants to be able to receive callbacks from this server In order to receive these callback requests
101. e shows the difference between _var type assignments from strings and from object references C class X_impl virtual public X_skel ORBacus 115 C Mapping Notes 14 15 16 CORBA_String_var sl_ CORBA_String_var s2_ Y_var yl_ Y_var y2_ public void init const char sl const char s2 Y_ptr yl Y_ptr y2 sl_ sl s2_ CORBA_string_dup s2 yl Wrong y2_ Y _duplicate y2 yl_ OK CORBA_String_var automatically duplicates const char Explicit duplication is also OK as the CORBA_St ring_var consumes the duplicated string returned from CORBA_string_dup which returns a string of type char This is wrong Y_var consumes the value of type y_ptr Therefore y _duplicate must be used This is correct now since Y _duplicate was used The reason for this behavior is that there is no such thing as a constant object reference for in parameters Therefore it is not possible for the object reference _var type to distin guish between assignments from regular object references and in object references 116 ORBacus CHAPTER 9 Concurrency Models 9 1 9 1 1 9 1 2 Introduction What is a Concurrency Model A concurrency model describes how an Object Request Broker ORB handles communi cation and request execution There are two main categories of concurrency models sin gle threaded concurrency models and multi threaded concurrency models Single
102. eaded And for BOA conc_model ConcModelBlocking ConcModelReactive 128 ORBacus Selecting Concurrency Models ConcModelThreaded ConcModelThreadPerClient ConcModelThreadPerRequest ConcModelThreadPool In Java the example looks like this Java org omg CORBA ORB orb Get a reference to the ORB somehow org omg CORBA BOA boa Get a reference to the BOA somehow com ooc CORBA ORB orb conc_model com ooc CORBA ORB ConcModel ConcModelThreaded com ooc CORBA BOA boa conc_model com ooc CORBA BOA ConcModel ConcModelThreadPerRequest The casts to com ooc CORBA ORB and com ooc CORBA BOA are necessary because the conc_model operations are ORBACUS specific and are not available in the classes org omg CORBA ORB and org omg CORBA BOA respectively In case the thread pool concurrency model has been selected it s also necessary to specify the number of threads in the thread pool This can be done with the operation BOA conc_model_thread_pool C CORBA_BOA_var boa Get a reference to the BOA somehow boa gt conc_model_thread_pool 10 This allocates 10 threads for the thread pool Here is the same example in Java Java org omg CORBA BOA boa Get a reference to the BOA somehow com ooc CORBA BOA boa conc_model_thread_pool 10 ORBacus 129 Concurrency Models 130 ORBacus CHAPTER 10 The Reactor 10 1 10 2 What
103. ect Names for the Basic Services on page 153 88 ORBacus Connecting to Named Objects 6 4 1 6 4 2 Aa UNAK Using the iiop Notation The standard string representation of an object reference is completely opaque and can be quite long making it difficult to use ORBACUS also supports a non standard but more human friendly string representation of an object reference that uses URL notation iiop hostname port object name This notation is only suitable for referring to named objects but it can be used anywhere a normal stringified object reference is expected Using get_inet_object The ORB operation get_inet_ob ject is defined as follows IDL module CORBA interface ORB Object get_inet_object in string host in unsigned short port in string name Here s an example of using get_inet_object in C C CORBA_ORB_var orb Get a reference to the ORB somehow CORBA_Object_var obj orb gt get_inet_object host port MyName B_var b B _narrow obj get_inet_object is called with the hostname the port number and the object name which in this case is MyName As with string_to_ob ject the reference returned by get_inet_ob ject must be nar rowed to a B reference Here is an identical implementation in Java Java org omg CORBA ORB orb Get a reference to the ORB somehow org omg CORBA Object obj ORBacus 89 Locating Ob
104. eers If this policy is false then each object will have a new communications channel to its peer The default for this policy is true OB ProtocolPolicy This policy is used to force the selection of a particular protocol If this policy is set then the protocol with the identified tag will be used if possible If it is not possible to use this protocol a CORBA NO_RESOURCES exception will be raised OB ReconnectPolicy If an object possesses this policy and the value flag of this policy is t rue then upon a communications failure a reconnection will automatically be attempted If this reconnec tion attempt fails a CORBA COMM_FAILURE exception is raised OB TimeoutPolicy If an object has this policy and no response is available for a request after value millisec onds a CORBA NO_RESPONSE exception is raised Examples The following examples demonstrate how to set OB Connect ionReusePolicy at both the ORB level and the object level in C and Java Setting a policy at the ORB level means that the ORB will honor this policy for all newly created objects Existing objects 148 ORBacus Examples 12 3 1 SH AN DAB WH HE 10 maintain their current set of policies Setting a policy at the object level overrides any ORB level policies applied to that object Setting the connection reuse policy to false at the ORB level means that the ORB will create a new connection from the client to the se
105. efaultTypedEvent Channel YP R TypedEventChannel vice Property CosPropertyService n DefaultPropertySetDefFactory Service PropertySetDefFactory Interface x a DefaultRepository CORBA Repository Repository Table 13 1 Primary Object Names and Interface Types a The Interface Repository is nota CORBA Service and therefore not described in this chapter However the object name of the Interface Repository is shown here for completeness The examples below illustrate how to connect to the Naming Service using get_inet_object Here s the C version C CORBA_ORB_var orb Get a reference to the ORB somehow CORBA_Object_var obj orb gt get_inet_object myhost 10000 DefaultNamingContext CosNaming_NamingContext_var ctx CosNaming_NamingContext _narrow obj ORBacus 153 ORBacus Basic Services And in Java Java org omg CORBA ORB orb Get a reference to the ORB somehow org omg CORBA Object obj com ooc CORBA ORB orb get_inet_object myhost 10000 DefaultNamingContext org omg CosNaming NamingContext ctx org omg CosNaming NamingContextHelper narrow ob For these examples to work the Naming Service must have been started on the host myhost using the port number 10000 13 2 The Naming Service A CORBA object is often represented by an object reference in the form of a stringified IOR a lengthy string that is difficult to read and cumbersome to us
106. efore you must disconnect a servant from the object adapter prior to releasing it with CORBA_release in order to ensure that its reference count reaches zero See Factory Objects using C on page 74 for an example that properly manages the reference count of a servant It is important to remember to never use delete to destroy proxies or servants Use only CORBA_release For example the following code calling delete on a proxy obtained with string_to_object is wrong const char s Obtain a stringified reference somehow CORBA_Object_ptr p orb gt string_to_object s delete p Wrong This line is wrong Instead of delete CORBA_release must be used This is the correct version const char s Obtain a stringified reference somehow CORBA_Object_ptr p orb gt string_to_object s CORBA_release p OK CORBA_release is used You should use self managed types whenever possible 98 ORBacus Reference Counting in C Daw WN HE 7 3 3 Oo DN DAA WH HB const char s Obtain a stringified reference somehow CORBA_Object_var p orb gt string_to_object s No CORBA_release is necessary since the _var will automatically call CORBA_release upon destruction You should also avoid allocating servants on the stack If you do so the servant will be destroyed if the stack unwinds without any calls to CORBA_release The following code demonstrates the
107. ehow I pti Out I_ptr inOut Get a reference to an I somehow I_ptr result result a gt op out inOut CORBA_release out CORBA_release inOut CORBA_release result The parameters are defined A value must be assigned to the inout parameter 114 ORBacus C Mapping Tips amp Tricks 10 22 MN A GaP WN HP WO MND AP UNAK op is called All out and inout parameters as well as the return value must be released The second example uses self managed I_var types C A_ptr a Get a reference to an A somehow I_var out I_var inOut Get a reference to an I somehow I_var result result i gt op out ios I_var is used instead of I_ptr After the call to op no explicit calls to CORBA_release are necessary since the I_var type destroys its contents automatically We recommend that you use method two with the self managed types since this method is much less error prone Differences between String_var and Object Reference _var Types There is a slight but important difference between St ring_var and object reference _var types regarding their initialization or assignment from in parameters Consider the following IDL code IDL interface Y interface X void init in string sl in string s2 in Y yl in Y y2 Here the init function is used to initialize an X with two strings and two Y object refer ences The following cod
108. elease on their contents so the refer ence count of the X_imp1 and the y_imp1 is 1 This means that after the return of the X_imp1 and the Y_imp1 will live forever This problem can be solved by adding a releaseInternal function to at least one of the two interface implementations For example class X_impl public X_skel Y_var y public void setY Y_ptr y y_ Y _duplicate y class Y_impl public Y_skel Implements interface Y X_var X_ public 1 Of course you are free to choose whatever name you like ORBacus 101 Reference Counting LS 16 Le 18 9 20 21 22 23 24 25 26 27 L0 18 26 void setX X_ptr x x_ X _duplicate x void releaseInternal x_ X _nil void f X_var x new X_impl Y_var y new Y_impl x gt setY y y gt setX x y gt releaseInternal Same as before The releaseInternal operation has been added releaseInternal is called before f returns Now both the X_imp1 and the Y_imp1 get destroyed at the return of f X_var x new X_impl The initial reference count of the X_imp1 after the newis 1 Y_var y new Y_impl Same as above the initial reference count of the y_imp is 1 x gt setY y After sety the reference count of the Y_imp1 is 2 y gt setX x After set xX the reference count of the X_imp1 is 2 y gt releaseInternal The releaseInternal function sets the x_ value
109. elop a client program that invokes a hello operation on an object in a server program The server responds by printing Hello World on its stan dard output The IDL Code How do we write a CORBA based Hello World application The first step is to create a file containing our IDL definitions Since our sample application isn t a complicated one the IDL code needed for this example is simple IDL interface Hello void hello An interface with the name He11o is defined An IDL interface is conceptually equivalent to a pure abstract class in C or to an interface in Java The only operation defined is hello which neither takes any parameters nor returns any value Implementing the Example in C The next step is to translate the IDL code to C using the IDL to C translator Save the IDL code shown above to a file called He11o0 id1 Now translate the code to C using the following command idl Hello idl This command will create the files Hello h Hello cpp Hello_skel h and Hello_skel cpp 16 ORBacus Implementing the Example in C 2 3 1 Implementing the Server To implement the server we need to define an implementation class for the He11o inter face To do this we create a class Hel1lo_imp1 that is derived from the skeleton class Hello_skel defined in the file Hello_skel h The definition for Hello_imp1 looks like this C include lt Hello_skel h gt
110. erence count reaches zero and the servant is subsequently destroyed Reference Counting in Java ORBACUS for Java does not need to use reference counting because the standard Java gar bage collector performs this activity automatically However there is one issue that should be mentioned regarding garbage collection of servant objects In Java the garbage collector does not reclaim an object until there are no more references to that object held by the program When you use the ORB s connect method to connect ORBacus 95 Reference Counting a servant to the object adapter the ORB will keep a reference to your servant Therefore in order for your servant to be eligible for garbage collection you must eliminate all refer ences to the servant in your server code and you must use the ORB s disconnect method to ensure that the ORB no longer holds a reference to the servant Although use of connect is optional because the ORB will automatically connect objects when neces sary use of disconnect is always required 7 3 Reference Counting in C ORBACUuS for C implements servants and proxies as reference counted objects The reference counting semantics used by ORBACUs for C are outlined in Table 7 1 new Servant_impl Reference count of new servant is initialized to 1 ORB string_to_object Reference count of proxy is initialized to 1 ORB get_inet_object Like string_to_object reference count of proxy is init
111. es A_impl and B_impl C class A_impl virtual public A_skel public virtual void op_a class B_impl virtual public B_skel public virtual void op_b class I_impl virtual public I_skel virtual public A_impl 1 These naming rules are not mandatory they are just a recommendation ORBacus 63 CORBA Objects LT 18 Lg 20 21 Oo MN DOP WH HE virtual public B_impl public virtual void op_i The servant class A_imp1 is defined inheriting from the skeleton class A_skel If op_a had any parameters these parameters would be mapped according to the standard IDL to C mapping rules 2 This is the servant class for B_imp1 The servant class for I_imp1 is not only derived from I_skel but also from the servant classes A_impl and B_impl Note that virtual public inheritance must be used The only situation in which the keyword virtual is not necessary is for an interface I which does not inherit from any other interface and from which no other interface inherits This means that the implemen tation class I_imp1 only inherits from the skeleton class I_ske1 and no implementation class inherits from I_imp1 It is not strictly necessary to have an implementation class for every interface For exam ple it is sufficient to only have the class I_imp1 as long as I_imp1 implements all inter face operations including the operations of the base interfaces C c
112. es it is not desirable to use an inheritance based approach for implementing an interface This is especially true if the use of inheritance would result in an implementa tion being incompatible with existing legacy code Therefore another alternative is avail able for implementing servants which does not use inheritance A special class known as a tie class can be used to delegate the implementation of an interface to another class ORBacus 65 CORBA Objects Delegation using C The ORBAcus IDL to C translator can automatically generate a tie class for an inter face in the form of a template class A tie template class is derived from the corresponding skeleton class and has the same name as the skeleton with the suffix _t ie appended For the interface I from the C example above the template I_ske1_tie is generated and must be instantiated with a class that implements all operations of I By convention the name of this class should be the name of the interface with __impl_tie appended In contrast to the inheritance based approach it is not necessary that the class implement ing I s operations i e I_impl_tie be derived from any skeleton class Instead an instance of I_skel_tie delegates all operation calls to I_imp1_tie as shown in Figure 5 2 I skel T I_skel_tie T gates to I_impl_tie Figure 5 2 Class Hierarchy for Inheritance and Delegati
113. et The get_all_properties operation serves this purpose IDL void get_all_properties in unsigned long how_many out Properties nproperties out PropertiesIterator rest This operation works similar to the 1ist call offered by the Naming Service In both cases the maximum number of items to be returned at once is specified An iterator imple menting the PropertiesIterator interface gives access to the remaining items if any IDL interface PropertiesIterator void reset boolean next_one out Property aproperty boolean next_n in unsigned long how_many out Properties nproperties void destroy If you are only interested in a list of property names you can get this list by calling get_all_property_names IDL void get_all_property_names in unsigned long how_many out PropertyNames property_names out PropertyNamesIterator rest As with get_all_properties a list of names as well as an iterator is returned This iter ator implements the PropertyNamesIterator interface 164 ORBacus The Property Service 13 3 4 IDL interface PropertyNamesIterator void reset boolean next_one out PropertyName property_name boolean next_n in unsigned long how_many out PropertyNames property_names void destroy The iterators should always be destroyed when they are no longer needed Sometimes it is useful to know of how many properties a PropertySet consi
114. eturn value must be freed Here is the same example but with self managed CORBA_String_var types instead of explicitly calls to CORBA_st ring_free C I_ptr i Get a reference to an I somehow CORBA_String_var out CORBA_String_var inOut CORBA_string_dup This is my inout arg CORBA_String_var result result i gt op out ios CORBA_String_var is used instead of char After the call to op no explicit calls to CORBA_string_free are necessary since the CORBA_String_var type destroys its contents automatically Since method two in this example is much less error prone you should always use the self managed type CORBA_String_var in such a case Object References If you use CORBA object references i e ptr and _var types for specific interfaces keep the following in mind Object References as Parameters and Return Values If a function returning an object reference via an out or inout parameter or as a return value is called the callee must duplicate and the caller must release the reference As described above an object reference to an object of type I i e an object with the inter 112 ORBacus C Mapping Tips amp Tricks Oo DN DAB WH HB MND AAP WwW HH ORR HH HHH HHH SH AN DAR WwW NE DOD amp 15 16 18 face I is duplicated with I _duplicate and released with CORBA_release This is quite similar to strings as parameters and return values For example IDL
115. event data can be provided at any time so try_pu11 always sets has_event to true in order to signal that an event is available It then returns the actual event data After examining the most important aspects of the event suppliers code we are now going to analyze the consumers code The push consumer with its push operation is shown first Java public void push Any any try String s any extract_string System out printin s catch MARSHAL ex Ignore unknown event data ORBacus 173 ORBacus Basic Services 6 14 The push consumer s push operation is called with the event wrapped in a CORBA Any In this code fragment it is assumed that the Any contains a string with date and time infor mation In case the Any contains another data type a MARSHAL exception is thrown This exception can be ignored here because other events aren t of interest After extracting the string it is displayed in the console window MN A GAP WN HE Ww Ww WH HS HS NH NH NH NH WB NH NH HP HHH HHH HH ORF DMH AND ANB WHR DH DAN DAS WHE DTD amp 33 34 35 In contrast to the push consumer the pull consumer has to actively query the event chan nel for new events This is how the pull consumer loop looks Java while supplier_ null Any any null try any supplier_ pull catch Disconnected ex Supplier was diconnected from event channel try String s any
116. ferences registered with the Naming Service are maintained in a hierarchical structure similar to a filesystem A file in a filesystem is analogous to an object binding in the Naming Service The equivalent for a folder in a filesystem is a naming context in Naming Service terms The pieces of information stored in a Naming Service are called bindings A binding consists of an object s name and its type as defined in the CosNaming module IDL typedef string Istring struct NameComponent Istring id Istring kind typedef sequence lt NameComponent gt Name enum BindingType nobject ncontext struct Binding Name binding_name BindingType binding_type ORBacus 155 ORBacus Basic Services 13 2 4 J As you can see each name consists of one or more components like a file is fully speci fied by its path in a filesystem Each name component consists of two strings id and kind which could be likened to a file s name and its extension Generally the filesystem analogy works very well when describing the Naming Service structures A new Naming Service entry i e a binding is created with the following operations IDL void bind in Name n in Object obj raises NotFound CannotProceed InvalidName AlreadyBound void bind_context in Name n in NamingContext nc raises notFound CannotProceed InvalidName NamingContext new_context NamingContext bind_new_context in N
117. fo com ooc OCI IIOP AcceptorInfoHelper narrow info if iiopInfo null String host iiopInfo host short port Converter port iiopInfo port System out printin host host System out printlin port port The acceptor registry is requested from the BOA Since the standard BOA org omg CORBA BOA does not provide a method for this there must be a cast to com ooc CORBA BOA This is equivalent to the C version The converter class is used to get a port number in int format Like in the C version the hostname and port number are printed on standard output Finding out a Client s IP Address To find out the IP address of a client within a server method the following code can be used in a servant class method implementation C CORBA_Object_var baseCurrent 142 ORBacus OCI for the Application Programmer MBNA Os 11 12 LS 14 15 16 17 18 19 20 11 F3 19 MN A ate a HE HR RR ROW QS whNMRE DS amp orb gt resolve_initial_references OCICurrent OCI_Current_var current OCI_Current _narrow baseCurrent OCI_TransportInfo_var info current gt get_oci_transport_info OCI_IIOP_TransportInfo_var iiopInfo OCI_IIOP_TransportInfo _narrow info if CORBA_is_nil iiopInfo OCI_IIOP_InetAddr remoteAddr iiopInfo gt remote_addr CORBA_UShort remotePort iiopInfo gt remote_port cout lt lt Call from lt lt
118. hat is you must either import this package or as shown in our exam ple you must use org omg CORBA explicitly 22 ORBacus Implementing the Example in Java 14 16 30 32 An instance of Hello_imp1 is created This instance is released automatically when it is not used anymore The object reference is stringified and written to a file Finally the server enters its event loop to receive incoming requests 2 4 2 Implementing the Client Save this to a file with the name Client java 1 Java 2 3 package hello 4 5 public class Client 6 7 public static void main String args 8 9 org omg CORBA ORB orb 10 org omg CORBA ORB init args new java util Properties 1d 12 String ref null 13 try 14 15 String refFile Hello ref 16 java io BufferedReader in Lee new java io BufferedReader new FileReader refFile 18 ref in readLine 19 20 catch java io IOException ex 21 22 System err printin Can t read from 23 ex getMessage 24 System exit 1 25 26 org omg CORBA Object obj orb string_to_object ref 27 28 Hello p HelloHelper narrow obj 29 30 p hello 31 32 9 10 The ORB is initialized BOA initialization is not necessary for clients ORBacus 23 Getting Started 12 26 28 30 2 4 3 2 4 4 The stringified object reference is read and converted to an object The object reference is narrowed to
119. he Interface Repository Documenting IDL Files With the ORBACUS IDL to HTML and IDL to RTF translators hidl and rid1 you can easily generate HTML and RIF files containing IDL interface descriptions The transla tors will generate a nicely formatted file for each IDL module and interface Figure 3 1 shows an HTML example and Figure 3 2 an RTF example The formatting syntax supported by hidl and rid1 is similar to that used by javadoc The following keywords are recognized author author Denotes the author of the interface exception exception name description Adds an exception description to the exception list of an operation member member name description 1 Preprocessor statements like define or ifdef may be placed before your include statements 36 ORBacus Documenting IDL Files IDL Documentation for OCI Netscape iof x File Edit View Go Communicator Help a Bookmarks Location file Cl ml cpp ob idl OCI html Module OCI The Open Communications Interface OCI The definitions in this module provide a uniform interface to network protocols This allows for easy plug in of new protocols or other communication mechanisms into ORBs that implement the OCI Furthermore protocol implementations need only to be written once and can then be reused with all OCI compliant ORBs For more information please see the OCI documentation Module Index IOP This module
120. he oldest event is discarded The default value is 10 168 ORBacus The Event Service 13 4 2 13 4 3 13 4 4 ooc event max_retries The maximum number of times to retry before giving up and disconnecting the proxy The default value is 10 Command line Options The ORBACUs Event Service supports the following command line options h heip Display the command line options supported by the server i Display the version of the server version ni Print the interoperable object reference IOR of the server to standard O output The C implementation of the Event Service supports both typed and untyped event channels therefore the following additional command line options are provided to allow you to select which kind of channel the server should create SE Run a typed event service typed service U Run an untyped event service This is the default behavior untyped service Diagnostics The C Event Service uses the ORBACUS OBMessageViewer class to generate diagnos tic messages You can activate these messages by setting the ooc orb trace_level property to 2 Note that you must have compiled the ORBACUs distribution with the OB_TRACE preprocessor macro defined in order to enable diagnostic messages This macro is defined by default The Event Channel The Event Service distributes data in the form of events The term event in this context refers to a piece of inform
121. hnson and John Vlissides Design Patterns Addi son Wesley 1994 CORBA Messaging OMG document 98 03 11 The Common Object Request Broker Architecture and Specification Revision 2 2 OMG document 98 02 33 ORBacus SSL User s Manual Object Oriented Concepts Inc 236 ORBacus
122. ialized to 1 ORB connect servant Reference count of servant is incremented by 1 since a reference to the servant is added to the object adapter ORB disconnect servant Reference count of servant is decremented by 1 since the object adapter s reference to the servant is removed _duplicate obj Reference count of servant or proxy is incremented by 1 CORBA_release obj Reference count of servant or proxy is decremented by 1 Table 7 1 C Reference Counting Semantics a b 7 3 1 The reference count is only incremented by 1 after the first implicit or explicit call to connect Subsequent calls to connect do not affect the reference count If the servant is already disconnected calling disconnect again does not change the reference count Marshalling Issues When a server returns the object reference of a servant to a client either as a return value or as an out or inout parameter the marshalling code automatically decrements the ser 96 ORBacus Reference Counting in C SMH DAN DAB WN PR MANA aA PWN HP OS HNHNHNHHKRHHH HHH HK AS w HR DH AND AP WHE OD vant s reference count by 1 Therefore you will need to use _duplicate if you wish to preserve the existing reference count of your servant as shown in the following example IDL interface A hi interface B A getA Interfaces A and B are defined The operation getA returns a
123. in by any recipient of any work derived from the Software RESTRICTIONS Licensee acknowledges that the Software is protected by copyright laws and international copyright treaties as well as other intellectual property laws and treaties The Software is licensed not sold All title and copyrights in and to the Software including but not limited to any images photographs databases animations video text and applets incorporated into the Software the accompanying printed materials and any copies of the Software are owned exclusively by Object Oriented Con cepts Inc Licensee may not sublicense assign or transfer this License the Software or any work derived from the Software except as permitted by this License If Licensee distributes any written or printed material at all with the Software or any work derived from the Software such material must include either a a written copy of this License or b a prominent written indication that the Software or work derived from the Software is covered by this License and also written instructions for printing and or displaying the copy of this License which is provided on the distribution medium If using copying distributing and or modifying the Software is restricted in certain countries for any reason Object Oriented Concepts Inc may in the future add an explicit geographical distribution limitation excluding those countries so that using copying distributing and or modify
124. in implementors The Connector Factory must then be registered with the ORB s Connector Factory Regis try and the Acceptor must be registered with the Object Adapter s Acceptor Registry The Info Objects Info objects provide information on Transports Acceptors and Connectors A Transport Info provides information on a Transport an Acceptor Info on an Acceptor and a Connec tor Info on a Connector To get information for a concrete protocol these info objects must be narrow d to an info object for this protocol for example in the case of an IIOP plug in a OCI TransportInfo must be narrow d to OCI IIOP TransportInfo 138 ORBacus OCI Reference 11 2 7 Class Diagram Figure 11 1 shows the classes and interfaces of the OCI except for the Buffer and Info O o _ 1 ORB OA 1 Connector Acceptor Factory Registr Registry gistry e Connector c nh A cal Factory onnector ransport cceptor creates gt creates gt 4 creates ee l Protocol Protocol Protocol eben Specific Specific Specific Connector F Connector Transport Acceptor actory 11 3 Figure 11 1 OCI Class Diagram interfaces ORBACUS provides abstract base classes for the interfaces Connector Factory Connector Transport and Acceptor The protocol plug in must inherit from thes
125. ing functions CORBA_string_alloc CORBA_string_free and CORBA_string_dup if you re dealing with CORBA strings Never use new delete malloc free strdup or similar functions For example the following code is incorrect char sl strdup Hello Wrong Allocate a string for 10 characters trailing 0 String_var s2 malloc 11 Wrong Error CORBA_string_dup must be used instead of st rdup No CORBA_string_alloc must be used This is the correct version char sl CORBA_string_dup Hello Allocate a string for 10 characters trailing 0 CORBA_String_var s2 CORBA_string_alloc 10 OK CORBA_string_dup is fine 1 Note that OOC did not invent this mapping We just had to implement it exactly as specified to be CORBA compliant 108 ORBacus C Mapping Tips amp Tricks OK Note that CORBA_st ring_alloc unlike malloc adds an additional character for the trailing 0 automatically This code is wrong too free s2 Wrong No Use CORBA_string_free And again the corrected version CORBA_string_free s1l This is OK Note that there is no need to free s2 explicitly since CORBA_String_var types release the string they manage automatically when the CORBA_St ring_var type is destroyed Initialization and Assignment from char and const char Initialization of a CORBA_String_var type or assignment to a CORBA_String_var type fr
126. ing is permit ted only in or among countries not thus excluded In such case this License incorporates the limita tion as if written in the body of this License LICENSE TO WORKS DERIVED FROM THE SOFTWARE Licensee hereby grants to Object Oriented Concepts Inc a non exclusive non transferable royalty free right to use copy distribute and modify with the right to sublicense at any tier any and all works derived from the Software that Licensee creates provided such works derived from the Soft ware are distributed to Object Oriented Concepts Inc by Licensee and further provided that if such works derived from the Software comprise either code generated by the ORBacus IDL to C or IDL to Java translators or a program which is linked with or otherwise incorporates the ORBacus Libraries or Class Files such works derived from the Software would constitute works derived from the Software independent of comprising code generated by the ORBacus IDL to C or IDL to Java translators or a program which is linked with or otherwise incorporates the ORBacus Libraries or Class Files for example a bug fix of the Software LIMITED WARRANTY NO WARRANTIES 232 ORBacus OBJECT ORIENTED CONCEPTS INC EXPRESSLY DISCLAIMS ANY WARRANTY FOR THE SOFTWARE THE SOFTWARE IS PROVIDED TO LICENSEE AS IS WITHOUT WAR RANTY OF ANY KIND EITHER EXPRESS OR IMPLIED INCLUDING WITHOUT LIMITA TION THE IMPLIED WARRANTIES OF MERCHANTA
127. ing_dup Hello world CORBA_Any any any lt lt s any lt lt s Inserting s into any twice will result in a dangling pointer because any will free its own value which is s on assignment Invalid union discriminator type used This message appears if the discriminator type argument to CORBA_ORB create_union_tc denotes a type invalid for union discriminators Valid types have a CORBA_TCKind that is one of CORBA_tk_short CORBA_tk_ushort CORBA_tk_long CORBA_tk_ulong CORBA_tk_char CORBA_tk_boolean or CORBA_tk_enum 182 ORBacus Non Compliant Application Asserts Union discriminator mismatch This message either indicates an attempt to set a union discriminator to an invalid value with the _d modifier function or the use of a wrong accessor function i e an accessor function that does not correspond to the type of the union s actual value Uninitialized union used If this message appears an unitialized union i e a union that was created with the default constructor and that was not set to any legal value was used Dynamic implementation object cannot be used as static implementation object This message appears if an attempt is made to use a DSI object implementation as a regu lar i e static implementation object ORBacus 183 Exceptions and Error Messages 184 ORBacus weenoxa ORBacus Policy Reference A l Module SSL Constants CONNECT_POLICY const CORBA Polic
128. ior in unsigned long maximum ORBacus 215 Open Communications Interface Reference Calculates a hash value for an IOR Parameters ior The IOR to calculate a hash value for maximum The maximum value of the hash value Returns The hash value get_info ConFactoryInfo get_info Returns the information object associated with the Connector factory Returns The Connnector factory information object 216 ORBacus Interface OCI ConFactoryInfo B 13 Interface OCI ConFactoryInfo interface ConFactoryInfo Information on an OCI ConFactory object See Also ConFactory Attributes tag readonly attribute Profileld tag The profile id tag Operations add_connect_cb void add_connect_cb in ConnectCB cb Add a callback that is called whenever a new connection is established If the callback has already been registered this method has no effect Parameters cb The callback to add remove_connect_cb void remove_connect_cbh in ConnectCB cb Remove a connect callback If the callback was not registered this method has no effect Parameters ch The callback to remove ORBacus 217 Open Communications Interface Reference B 14 Interface OCI ConFactoryRegistry interface ConFactoryRegistry A registry for Connector factories See Also Connector ConFactory Operations add_factory void add_factory in ConFactory factory Adds a Connector factory to the regist
129. ir DIR These options are the same as for the id1 command The argument to irgen is the pathname to use as the base name of the output filenames For example if the pathname you supply is output file then irgen will produce output file cpp output file h output file_skel cpp and output file_skel h Note that irgen will generate code for all of the type definitions contained in the Inter face Repository server The IDL to C Translator and the Interface Repository The ORBAcus IDL to C and IDL to Java translators internally use the Interface Repository for generating code That is these programs have their own private Interface Repository that is fed with the specified IDL files All code is generated from that private Interface Repository It is also possible to generate C code from a global Interface Repository First the com mand irserv must be used to start the Interface Repository Then the Interface Reposi tory must be fed with the IDL code using the command irfeed Finally the irgen command can be used to generate the C code For example irserv ior gt IntRep ref amp irfeed ORBrepository cat IntRep ref file idl irgen ORBrepository cat IntRep ref file The IDL to C translator id1 performs all these steps at once in a single process with a private Interface Repository Thus you only have to run a single command idl file idl Include Statements If you use the include statement in your IDL co
130. is the same example in Java Java org omg CORBA Any boolAny orb create_any boolAny insert_boolean false org omg CORBA Policy policies new org omg CORBA Policy 1 policies 0 orb create_policy com ooc OB CONNECTION_REUSE value boolAny org omg CORBA Object newObj obj _set_policy_overrides policies org omg CORBA SetOverrideType ADD_OVERRIDE This is equivalent to the C version 150 ORBacus ORBacus Basic Services CHAPTER 13 This chapter describes the standard services included with the ORBACUs distribution e The Naming Service e The Property Service e The Event Service These services are implemented compliant to 4 and available in C and Java versions Other services such as the Trading Service ORBACUsS Trader are not included in the standard ORBACUS distribution For more information on other services available from Object Oriented Concepts please see our Web site This chapter does not provide a complete description of the naming property and event services It only provides an overview suitable to get you started For more information please refer to the service specifications 13 1 Configuring and Using a Basic Service This section describes the steps necessary to start a service publish its IOR and connect to the service from a client We will use the Naming Service as an example but the steps outlined below are applicable to all of the services
131. ization The first code fragment deals with initializing the ORB and the BOA Java try ORB orb ORB init args new java util Properties catch SystemException ex The ORB initialization failed org omg CORBA Object obj null try obj orb resolve_initial_references NameService catch org omg CORBA ORBPackage InvalidName ex There is no Naming Service available if obj null Something is wrong with the Naming Service reference NamingContext nc NamingContextHelper narrow obj if nc null This is not a Naming Service reference at all BOA boa orb BOA_init args new java util Properties Usually the application is initialized in the main method In order to initialize the ORB its init operation is called In the next step we try to connect to the Naming Service by supplying NameService to resolve_initial_references If InvalidName is thrown there is no Naming Ser vice available because the ORB doesn t know anything about this service 158 ORBacus The Naming Service 22 32 If calling resolve_initial_references was successful the object reference is checked and narrowed in order to verify that it s a Naming Service instance If the narrow operation returns a null reference the object returned is not a Naming Service instance but something else This is considered to be an error because we explicitly asked for a
132. jects 6 5 1 DawP WN HB com ooc CORBA ORB orb get_inet_object host port MyName B b BHelper narrow obj The operation get_inet_ob ject is only defined in com coc CORBA ORB because it is ORBACUS specific therefore the cast is necessary Again we must narrow to the derived type B Initial Services The CORBA specification provides another standard way to bootstrap an object reference through the use of initial services which denote a set of unique services whose object ref erences if available can be obtained using the ORB operation resolve_initial_references which is defined as follows IDL module CORBA interface ORB typedef string ObjectId exception InvalidName Object resolve_initial_references in ObjectId identifier raises InvalidName Initial services are intended to have well known names and the OMG has standardized the names for some of the CORBAservices 4 For example the Naming Service has the name NameService and the Trading Service has the name TradingService Resolving an Initial Service An example in which the ORB is queried for a Naming Service object reference will dem onstrate how to use resolve_initial_references The example assumes that the ORB has already been initialized as usual First the Java version Java org omg CORBA Object obj null org omg CosNaming NamingContext ctx null try 90 ORBacus
133. k for equivalence ior2 The second IOR to check for equivalence Returns TRUE if the IORs are equivalent FALSE otherwise hash unsigned long hash in IOR ior in unsigned long maximum Calculates an hash value for an IOR This hash value is based on the return values of the hash operations of all registered Connector factories Parameters ior The IOR to calculate an hash value for maximum The maximum hash value that is allowed Returns The hash value ORBacus 219 Open Communications Interface Reference B I5 Interface OCI AccRegistry interface AccRegistry A registry for Acceptors See Also Acceptor Operations add_acceptor void add_acceptor in Acceptor Acceptor Adds an Acceptor to the registry Parameters Acceptor The Acceptor to add get_acceptors AcceptorSeq get_acceptors Returns a sequence of all registered Acceptors Returns A sequence of all registered Acceptors add_profiles void add_profiles in ObjectKey key inout IOR ior Adds new profiles to an IOR For each registered Acceptor a new profile is added by calling the Acceptor s add_profile operation Parameters key The object key to use for the new profiles ior The IOR is_local ObjectKey is_local in IOR ior ORBacus Interface OCI AccRegistry Checks whether an IOR is for a local object It calls the is_local operation of all registered Acceptors An IOR is considered local if at
134. l service and b distributing the Software on a CD ROM provided that the Software is reproduced entirely and verbatim on such CD ROM and provided further that all information on such CD ROM may be distributed in a manner which does not constitute a commercial use GRANT OF LICENSE LICENSE TO USE Licensee may use the Software 230 ORBacus LICENSE TO COPY AND DISTRIBUTE Licensee may copy and distribute literal i e verbatim copies of the Software as Licensee receives it throughout the world in any medium provided that Licensee distributes an unmodified easily readable copy of this License with the Software and pro vided further that such distribution does not constitute a commercial use LICENSE TO CREATE WORKS DERIVED FROM THE SOFTWARE Licensee may create works derived from the Software provided that any such work derived from the Software carries prominent notices stating both the manner in which Licensee has created a work derived from the Software for example notices stating that the work derived from the Software is linked with or oth erwise incorporates the ORBacus Libraries or Class Files or code generated by the ORBacus IDL to C or IDL to Java translators or notices stating that the work derived from the Software is an enhancement to the Software which Licensee has created and the date any such work derived from the Software was created LICENSE TO COPY AND DISTRIBUTE WORKS DERIVED FROM THE SOFTWARE
135. lass I_impl virtual public I_skel public virtual void op_a virtual void op_b virtual void op_i Now I_imp1 is only derived from I_ske1 but not from the other servant classes I_imp1 must implement all operations from the interface I as well as the operations of all interfaces from which T is derived Inheritance using Java Several files are generated by the ORBACus IDL to Java translator for an interface I including 64 ORBacus Implementing Servants MN A a PWN EP HR RR HOH Qs wNMRE OS W 16 e I java which defines a Java interface I containing public methods for the operations and attributes of I and e _TIImplBase java which is an abstract skeleton class that serves as the base class for servant classes In contrast to C Java s lack of multiple inheritance currently makes it impossible for a servant class to inherit operation implementations from other servant classes For our interface I it is therefore necessary to implement all operations in a single servant class I_imp1 regardless of whether those operations are defined in I or in an interface from which T is derived Java public class I_impl extends _IImplBase public void op_a public void op_b public void op_i The servant class I_imp1 is defined which implements op_i as well as the inherited operations op_a and op_b Implementing Servants using Delegation Sometim
136. least one of these calls returns a non empty object key Parameters ior The IOR to check for Returns If the IOR is for a local object the object key for that local object or an empty object key otherwise ORBacus 221 Open Communications Interface Reference B 16 Interface OCI Current interface Current inherits from CORBA Current Interface to access Transport and Acceptor information objects related to the current request Operations get_oci_transport_info TransportInfo get_oci_transport_info This method returns the Transport information object for the Transport used to invoke the cur rent request Returns The Transport information object get_oci_acceptor_info AcceptoriInfo get_oci_acceptor_info This method returns the Acceptor information object for the Acceptor which created the Trans port used to invoke the current request Returns The Acceptor information object 222 ORBacus Module OCI ILOP B 17 Module OCI IIOP This module contains interfaces to gather information on the IIOP OCI plug in Aliases InetAddr typedef octet InetAddr 4 Alias for an array of four octets This alias will be used for address information from the various information classes The address will always be in network byte order ORBacus 223 Open Communications Interface Reference B 18 Interface OCI IIOP Transportinfo interface TransportInfo inherits from OCI Transport
137. lias for a sequence of close callback objects ConnectCBSeq typedef sequence lt ConnectCB gt ConnectCBSeq Alias for a sequence of connect callback objects AcceptorSeq typedef sequence lt Acceptor gt AcceptorSeq Alias for a sequence of Acceptors AcceptCBSeq typedef sequence lt AcceptCB gt AcceptCBSeq Alias for a sequence of accept callback objects ConFactorySeq typedef sequence lt ConFactory gt ConFactorySeq 194 ORBacus Module OCI Alias for a sequence of Connector factories ORBacus 195 Open Communications Interface Reference B 2 Interface OCI Buffer interface Buffer An interface for a buffer A buffer can be viewed as an object holding an array of octets and a posi tion counter which determines how many octets have already been sent or received The IDL inter face definition for Buffer is incomplete and must be extended by the specific language mappings For example the C mapping defines the following additional functions e Octet data Returns a C pointer to the first element of the array of octets which repre sents the buffer s contents e Octet rest Similar to data this operation returns a C pointer but to the n th ele ment of the array of octets with n being the value of the position counter Attributes length readonly attribute unsigned long length The buffer length pos attribute unsigned long pos The position counter Note
138. lly if it has not already been connected at the time a reference to the object is transmitted to a client Users familiar with other CORBA implementations may think there is an error in the createProduct method because _duplicate is not being used However the code is correct See Chapter 7 for a complete discussion of reference counts Factory Objects using Java Here is our Java implementation of the Product interface Java public class Product_impl extends _ProductImplBase org omg CORBA ORB orb_ public Product_impl org omg CORBA ORB orb orb_ orb public void destroy orb_ disconnect this Servant class Product_imp1 is defined as an implementation of the Product interface The dest roy operation disconnects the object from the object adapter As long as no other references to the servant are held in the server the object will be eligible for garbage collection See Reference Counting in Java on page 95 for more information on garbage collection of servant objects ORBacus 75 CORBA Objects MAN DAA WH HE RRR RH RH RH HW ND GQ WNHE DO 1316 5 5 3 Here s our implementation of the factory Java public class Factory_impl extends _FactoryImplBase org omg CORBA ORB orb_ public Factory_impl org omg CORBA ORB orb orb_ orb public Product createProduct Product result new Product_impl orb_ orb_ connect result return resu
139. lly you provide a positive integer for how_many The iterator has fulfilled its duty and can now be destroyed The Event Service Sometimes applications have to exchange information without explicitly knowing about each other Often a server isn t even aware of the nature and number of clients that are interested in the data the server has to offer A special mechanism is required that provides decoupled data transfer between servers and clients This issue is addressed by the CORBA Event Service 4 Properties The ORBACus C Event Service supports the following properties ooc event response_timeout ps Specifies the initial amount of time in microsec onds that the service will wait for a response The default value is 100000 ooc event response_increment ps_ After each consecutive expiration of the response timeout the timeout value will be increased by the specified number of microseconds The default value is 100000 ooc event retry_timeout ps Specifies the initial amount of time in microsec onds that the service will wait before trying again after an error has occurred The default value is 500000 ooc event retry_increment ps After each consecutive expiration of the retry tim eout the timeout value will be increased by the specified number of microseconds The default value is 100000 ooc event max_events The maximum number of events in each event queue If this limit is reached and another event is received t
140. lso ConFactory Transport Attributes tag readonly attribute Profileld tag The profile id tag Operations connect Transport connect Used by CORBA clients to establish a connection to a CORBA server It returns a Transport object which can be used for sending and receiving octet streams to and from the server Returns The new Transport object is_usable ObjectKey is_usable in IOR ior Checks whether this Connector can be used for a specific IOR That is the IOR must contain at least one profile that matches this Connector Parameters ior The IOR to check for Returns The object key of the matching profile if the Connector can be used for the given IOR or an ORBacus 205 Open Communications Interface Reference empty object key otherwise is_usable_with_policies ObjectKey is_usable_with_policies in IOR ior in CORBA PolicyList policies Checks whether this Connector can be used for a specific IOR with a given set of polcies That is the IOR must contain at least one profile that matches this Connector and the Connector must also satisfy the provided list of policies for the given IOR Parameters ior The IOR to check for policies The policies that must be satisfied Returns The object key of the matching profile if the Connector can be used for the given IOR and policies or an empty object key otherwise get_info ConnectoriInfo get_info Returns the information object as
141. lt Servant class Factory_imp1 is defined as an implementation of the Factory interface The createProduct operation instantiates a new Product servant connects it to the object adapter and returns an object reference to the client Like in the C version the explicit call to connect is optional Caveats In these simple examples the factory objects do not maintain any references to the Product servants they create it is the responsibility of the client to ensure that it destroys a Product object when it is no longer needed This design has a significant potential for resource leaks in the server as it is quite possible that a client will not destroy its Product objects either because the programmer who wrote the client forgot to invoke dest roy or because the client program crashed before it had a chance to clean up You should keep these issues in mind when designing your own factory objects 1 Two possible strategies for handling this issue include time outs in which a servant that has not been used for some length of time is automatically released and expiration in which an object reference is only valid for a certain length of time after which a client must obtain a new refer ence The implementation of these solutions is beyond the scope of this manual 76 ORBacus Getting a Servant from a Reference 5 6 5 6 1 DAN DA AS WH HE RR RHR HH HHH WO MONA AA WHE DD amp 11 18 Getting a Ser
142. n the port number must be converted from short to int This is also equivalent to the C version Finding out a Server s IP Address To find out the server s IP address and port that an object will attempt to connect to the following code can be used C CORBA_Object_var obj Get an object reference somehow oCcI_ConnectorInfo_var info obj gt get_oci_connector_info OCI_IIOP_ConnectorInfo_var iiopInfo OCI_IIOP_ConnectorInfo _narrow info if CORBA_is_nil iiopInfo OCI_IIOP_InetAddr_var remoteAddr iiopInfo gt remoteAddr CORBA_UShort remotePort iiopInfo gt remote_port cout lt lt Will connect to lt lt remoteAddr 0 lt lt lt lt remoteAddr 2 lt lt lt lt remoteAddr 2 lt lt lt lt remoteAddr 3 lt lt lt lt remotePort lt lt endl Get the OCI connector info and narrow to an IIOP connector info The if block is only executed if this really was an IIOP connector info The address and port are obtained and displayed on standard output The Java version looks as follows Java 144 ORBacus OCI for the Application Programmer MANDA W 10 11 12 13 14 15 16 L 18 19 20 21 22 23 24 25 10 13 T9 17 24 org omg CORBA Object obj Get an object reference somehow org omg CORBA portable ObjectImpl objImpl org omg CORBA portable ObjectImpl obj com ooc CORBA Deleg
143. n loss by returning FALSE instead of raising CORBA COMM_FAILURE Parameters buf The buffer to fill block If set to TRUE the operation blocks until the buffer is full If set to FALSE the oper ation fills as much of the buffer as possible without blocking Returns FALSE if a connection loss is detected TRUE otherwise receive_timeout void receive_timeout in Buffer buf in unsigned long timeout Similar to receive but it is possible to specify a timeout On return the caller can test whether there was a timeout by checking if the buffer has been filled completely Parameters buf The buffer to fill ORBacus 199 Open Communications Interface Reference timeout The timeout value in milliseconds A zero timeout is equivalent to calling receive buf FALSE send void send in Buffer buf in boolean block Sends a buffer s contents Parameters buf The buffer to send block If set to TRUE the operation blocks until the buffer has completely been sent If set to FALSE the operation sends as much of the buffer s data as possible without blocking send_detect boolean send_detect in Buffer buf in boolean block Similar to send but it signals a connection loss by returning FALSE instead of raising CORBA COMM_FAILURE Parameters buf The buffer to fill block If set to TRUE the operation blocks until the entire buffer has been sent If set to FALSE the operation sends a
144. name Value ior Adds an initial service to the ORB s internal list This list is consulted when the applica tion invokes the ORB operation resolve_initial_references name is the key that is associated with a stringified IOR created using ob ject_to_string For example the property 0o0c service NameService adds NameService to the list of initial services See Stringified Object References on page 85 and Initial Services on page 90 for more information BOA Properties ooc boa add_iiop_acceptor Value true false Determines whether the BOA should register an IIOP acceptor during initialization The default value is true ooc boa conc_model Value blocking reactive threaded thread_per_client thread_per_request thread_pool Selects the server side concurrency model The reactive concurrency model is not available in ORBACUS for Java The default value is react ive for C applications and threaded for Java applications See Chapter 9 for more information on concurrency models If this property is set to 46 ORBacus Configuring the ORB and BOA thread_pool then the property ooc boa thread_pool determines how many threads are in the pool 00c boa disable_iiop_acceptor Value true false Determines whether the BOA should disable the HOP acceptor after registering it The default value is false ooc boa host Value hostname Explicitly defines the hostname to be used in object refe
145. ncy model namely the reactive con currency model Here the difference between single threaded and multi threaded concur rency models is very significant because there is a huge overhead for creating threads and thread context switches in the multi threaded concurrency models The maximum nesting level for the reactive concurrency model is usually much higher than for the thread per request and thread pool concurrency models The reason is that the maximum nesting level for thread per request and thread pool is determined by the maxi mum number of threads allowed per process whereas the reactive concurrency model is only limited by the maximum stack size per process Selecting Concurrency Models Concurrency models can be selected either by command line parameters see Chapter 4 or with the operations ORB conc_model and BOA conc_model The default concur rency models are shown in Table 9 4 Client Server Java Blocking Threaded C Blocking Reactive Table 9 4 Default Concurrency Models For example here is how to establish the concurrency models in C C CORBA_ORB_var orb Get a reference to the ORB somehow CORBA_BOA_var boa Get a reference to the BOA somehow orb gt conc_model CORBA_ORB ConcModel Threaded boa gt conc_model CORBA_BOA ConcModelThreadPerRequest Other possible parameters for ORB conc_model are ConcModelBlocking ConcModelReactive ConcModelThr
146. non thread safe version of ORBACUS Table 9 2 shows that such a version is much faster 126 ORBacus Performance Comparisons 9 4 3 Blocking Reactive Blocking 0 16 ms 0 20 ms Reactive 0 20 ms 0 23 ms Table 9 2 Non Thread Safe Version than a thread safe one because there is no additional overhead for any thread synchroniza tion Nested Method Invocations As already pointed out nested methods invocations are only possible with the following concurrency model combinations e reactive client reactive server e threaded client thread per request server e threaded client thread pool server Table 9 3 shows the performance results for a nesting level of 100 That is in the test Reactive Threaded Reactive 2 78 ms n a Thread per Request n a 3 39 ms Thread Pool n a 3 23 ms Table 9 3 Nested Method Invocations applications there are two mixed client servers each of them implementing the IDL code of the test application The first client server calls on the second and before f returns the second client server calls on the first client server then the first client server f on the second again and so on This is repeated until each client server called on the other cli ent server 50 times which corresponds to a total nesting level of 100 ORBacus 127 Concurrency Models 9 5 Again the clear winner is a single threaded concurre
147. o force the selection of a specific protocol Attributes value readonly attribute IOP ProfileId value Ifa ProtocolPolicy is set then the protocol with the identified tag will be used if possible If it is not possible to use this protocol a CORBA NO_RESOURCES exception will be raised 188 ORBacus Interface OB ConnectionReusePolicy A 5 Interface OB ConnectionReusePolicy interface ConnectionReusePolicy inherits from CORBA Policy The connection reuse policy This policy determines whether connections may be reused or are pri vate to specific objects Attributes value readonly attribute boolean value If an object has a Connect ionReusePolicy set with value set to FALSE then other objects will not be permitted to also use any connection made on behalf of this object ORBacus 189 ORBacus Policy Reference A 6 Interface OB ReconnectPolicy interface ReconnectPolicy inherits from CORBA Policy The reconnect policy This policy determines if an object will automatically try to reconnect to a server upon a communication failure Attributes value readonly attribute boolean value If an object has a Reconnect Policy set with value set to TRUE then upon a CORBA COMM_FAILURE a reconnection will automatically be attempted 190 ORBacus Interface OB TimeoutPolicy A 7 Interface OB TimeoutPolicy interface TimeoutPolicy inherits from CORBA Policy The timeout policy
148. o the actual object reference The operation object_to_string converts a CORBA object reference into its string representation Finally in order to react to incoming requests the server must enter its event loop This is done by calling impl_is_ready Since ORBACUS does not use the CORBA_ImplementationDef argument CORBA_ImplementationDef _nil can be used as a dummy argument Save this to a file with the name Server cpp Implementing the Client Writing the client requires less work than writing the server since the client in this exam ple only consists of the main function In several respects the client s main is similar to the server s main function C include lt OB CORBA h gt include lt Hello h gt include lt fstream h gt int main int argc char argv char CORBA_ORB_var orb CORBA_ORB_init argc argv const char refFile Hello ref ifstream in refFile char s 1000 in gt gt s CORBA_Object_var obj orb gt string_to_object s 1 If your application contains more than one object you do not need to save object references for all objects Usually you save the reference of one object which provides operations that can sub sequently return references to other objects ORBacus 19 Getting Started 19 20 21 22 4 11 13 17 19 21 2 3 3 Hello_var hello Hello _narrow obj hello gt hello In contrast to the server the
149. ocality constrained objects no virtual inheritance Don t use virtual C inheritance If you use this option you cannot use multiple interface inheritance in your IDL code and you also cannot use multiple C inheritance to imple ment your servant classes tie Generate tie classes for delegate based interface implementations Tie classes depend on the corresponding skeleton classes i e you must not use no skeletons in combina tion with t ie c suffix SUFFIX Use SUFFIX as the suffix for source files The default value is cpp h suffix SUFFIX Use SUFFIX as the suffix for header files The default value is h all Generate code for included files instead of inserting include statements See Include Statements on page 35 no relative When generating code idl assumes that the same I options that are used with idl are also going to be used with the C compiler Therefore id1 will try to make all include statements relative to the directories specified with 1 The option no relative suppresses this behavior in which case id1 will not make include state ments for included files relative to the paths specified with the I option header dir DIR This option can be used to make include statements for header files relative to a spe cific directory other header dir DIR This option works like header dir but it only applies to header files for included IDL files
150. om a char type value consumes that value That means that if the CORBA_String_var is destroyed the value from which the CORBA_String_var was initialized or that was assigned to the CORBA_String_var will also be destroyed Initialization of a CORBA_String_var type or assignment to a CORBA_String_var type from a const char type value duplicates that value This means that if the CORBA_String_var is destroyed the value from which the CORBA_String_var was initialized or that was assigned to the CORBA_St ring_var is not destroyed Note that for compatibility reasons with C the type of string literals in C is char not const char So the following code is wrong CORBA_String_var s Hello Wrong Error since Hello is char not const char The following code is OK CORBA_String_var sl CORBA_string_dup Hello CORBA_String_var s2 const char Hello OK s1 consumes the value returned by CORBA_st ring_dup ORBacus 109 C Mapping Notes GQ Aa UNAK OK s2 will implicitly duplicate Hello Initialization and Assignment from CORBA_String_var Initialization of a CORBA_String_var type or assignment to a CORBA_String_var type from another CORBA_String_var type value automatically duplicates that value This means that it is not necessary to use explicit calls to CORBA_string_dup The following examples are correct CORBA_String_var s1 CORBA_string_dup ABC CORBA_String_
151. om the skeleton class _AImplBase The servant class B_imp1 is defined which inherits from the skeleton class __BImp1Base B_imp1 s constructor creates anew A_imp1 servant getA returns an object reference to the A_imp1 servant A client written in C could use code like the following to get references to A C B_var b Get a B object reference somehow A_var a b gt getA Invoke getA to obtain an object reference for an A And in Java Java Bbe Get a B object reference somehow Aa b getA Invoke getA to obtain an object reference for an A In this example once your application has a reference to a B object it can obtain a refer ence to an A object using get A The question that arises however is How do I obtain a reference to a B object This chapter answers that question by describing a number of ways an application can bootstrap its first object reference Lifetime of Object References All of the strategies described in this chapter involve the publication of an object reference in some form A common source of problems for newcomers to CORBA is the lifetime and validity of object references Using IIOP an object reference can be thought of as encapsulating several pieces of information e hostname e port number e object key If any of these items were to change any published object references containing the old information would likely become invalid and their use might re
152. on However these are the recommended names for the services included with ORBACUS NameService PropertyService EventService Providing IORs of Initial Services When starting a program that makes use of an initial service the object references of the objects implementing these services have to be registered with the ORB ORBACUS sup ports the ORBservice command line option for adding an initial service ORBservice name IOR The ORBconfig option is an alternative method for defining a list of initial services and is often preferable when a number of services must be defined See Configuring the ORB and BOA on page 45 for more information on the ORBservice and ORBconfig options In addition to using command line parameters a program can also add to the list of initial services using the ORBACUS specific ORB operation add_initial_reference IDL module CORBA interface ORB void add_initial_reference in ObjectId identifier in Object obj hi For example in C C CORBA_ORB_var orb Get a reference to the ORB somehow CORBA_Object_var obj Get a name service reference somehow orb gt add_initial_reference NameService obj 92 ORBacus Initial Services mM WM a Or in Java Java org omg CORBA ORB orb Get a reference to the ORB somehow org omg CORBA Object obj Get a name service reference somehow com ooc CORBA ORB orb
153. on Implementation in C 1 Again you are free to choose whatever name you like This is just a recommendation I_impl 66 ORBacus Implementing Servants Oo DMN DAP UNAK MN A aA WN PE Here is our definition of I_impl_tie C class I_impl_tie public virtual void op_a virtual void op_b virtual void op_i I_impl_tie is defined which is not derived from any other class I_impl_tie must implement all of I s operations including inherited operations A servant class for I can then be defined using the I_ske1l_tie template C typedef I_skel_tie lt I_impl_tie gt I_impl The servant class I_imp1 is defined as a template instance of I_ske1l_tie parameter ized with I_impl_tie Delegation using Java The ORBAcus IDL to Java translator generates two additional files to support delegation based servant implementation for an interface I e Operations java an interface that defines public methods for all attributes and operations of I and e _IImplBase_tie java the tie class that inherits from _IImp1Base and delegates all requests to an instance of Operations To implement our servant class using delegation we need to write a class that implements the Operations interface Java public class I_impl_tie implements IOperations public void op_a ORBacus 67 CORBA Objects 9 public void op_b 10 1
154. onvenient to handle IORs on the command line therefore it s often easier to use the ORBconfig option java MyClient ORBconfig orb cfg The configuration file orb cfg could be written as follows ORB configuration file ooc service NameService iiop myhost 10000 DefaultNamingContext Notice that we are using the ORBACUS specific iiop notation for specifying the IOR of the Naming Service but we also could have pasted the contents of nameserv ref See Using the iiop Notation on page 89 for more information 152 ORBacus Configuring and Using a Basic Service The IOR contains the name of the host where the naming service was started myhost the port number that we specified when starting the service and the name assigned to the service s primary object DefaultNamingContext 13 1 3 Object Names for the Basic Services Each of the Basic Services has a named primary object which allows you to use the iiop notation or the ORB operation get_inet_object to obtain a reference to the service see Connecting to Named Objects on page 88 The name and interface type of each service s primary object is shown in Table 13 1 Object Name Interface Type Naming M DefaultNamingContext CosNaming NamingContext Service Event CosEventChannelAdmin 6 DefaultEventChannel Service EventChannel Typed COST dE tCh lAdmi os edEven anne nan Event Ser D
155. ooc CORBA package and not in the org omg CORBA package Using a Configuration File A convenient way to define a group of properties is to use a configuration file A sample configuration file is shown below Concurrency models ooc orb conc_model threaded ooc boa conc_model thread_pool ooc boa thread_pool 5 Initial services ooc service NameService iiop myhost 5000 DefaultNamingContext ooc service EventService iiop myhost 5001 DefaultEventChannel ooc service TradingService iiop myhost 5002 TradingService You can define the name of the configuration file using a command line option an envi ronment variable C or a system property Java e Command line option ORBconfig filename e Environment variable ORBACUS_CONF1G filename e Java system property ooc conf ig filename The file is read once when the ORB is initialized and is not read again for the lifetime of the application process Defining Properties in Java Java applications can use the standard Java mechanism for defining system properties because ORBACUS will also search the system properties during ORB and BOA initializa tion 1 ORBACUS for Java also accepts a URL specification as the filename 50 ORBacus Configuring the ORB and BOA GQ A UNAK GQ Aa UNAK For example Java java util Properties props System getProperties props put ooc orb conc_model threaded props put ooc boa port
156. operties The options and their equivalent property settings are shown in Table 4 1 Refer to Proper ties on page 45 for a description of the properties Option Property OAblocking ooc boa conc_model blocking OAdisable_iiop_acceptor ooc boa disable_iiop_acceptor true OAhost host ooc boa host host OAid id ooc boa id id OAnumeric ooc boa numeric true OAport port ooc boa port port OAreactive ooc boa conc_model reactive OAthreaded ooc boa conc_model threaded OAthread_per_client ooc boa conc_model thread_per_client OAthread_per_request ooc boa conc_model thread_per_request OAthread_pooln ooc boa conc_model thread_pool ooc boa thread_pool n ORBblocking ooc orb conc_model blocking ORBid id ooc orb id id ORBnaming ior ooc service NameService ior ORBreactive ooc orb conc_model reactive ORBrepository ior ooc service InterfaceRepository ior Table 4 1 Command line Options 48 ORBacus Configuring the ORB and BOA Option Property ORBservice name ior ooc service name ior ORBthreaded ooc orb conc_model threaded ORBtrace_level level ooc orb trace_level level 4 3 3 Table 4 1 Command line Options A few additional command line options are supported that do not have equivalent proper ties These options are described in Table 4 2 Option Description ORBversion Causes
157. override the system defaults The ORB has an initial reference ORBPolicyManager A PolicyManager has a set of operations through which the current set of overriding policies can be obtained and new policies can be applied e Thread Level A standard PolicyCurrent is defined with operations that allow the querying and retrieval of policies that affect the current thread These policies override the policies set at the ORB level e Object Level The object interface contains operations to retrieve and set policies for itself Policies applied at the object level override those applied at the thread level or the ORB level At present ORBACUS does not support thread level policies ORBacus 147 Using Policies 12 2 12 3 For more information on Policies the PolicyManager interface and the CORBA Object policy operations see 11 and 12 Supported Policies The following is a brief description of the policies that are currently supported For a detailed description please refer to Appendix A SSL ConnectPolicy This policy determines whether the ORB is permitted to establish an insecure communica tions channel between peers The default for this policy is t rue if the SSL plug in is not installed If the SSL plug in is installed the default is false For more information on this policy see 13 OB ConnectionReusePolicy This policy determines whether the ORB is permitted to reuse a communications channel between p
158. package com ooc output dir DIR Specifies a directory where jid1 will place the generated Java files Without this option the current directory is used clone Generates a clone method for struct union enum and exception types Options for hidl h help v version e cpp NAMI d debug DNAME DNAME DEF UNAME IDIR Loh These options are the same as for the id1 command no sort Don t sort symbols alphabetically output dir DIR Write HTML files to the directory DIR Options for ridl h help v version e cpp NAMI d debug DNAME DNAME DEF UNAME IDIR GI These options are the same as for the id1 command no sort 32 ORBacus Options for irserv 3 8 Don t sort symbols alphabetically output dir DIR Write RTF files to the directory DIR single file FILE Create a single rtf file called FILE with index Create index entries font NAME literal font NAME Use font NAME as the font for literals title font NAME Use font NAME as the font for the title heading font NAME Use font NAME as the font for headings font size SIZE Text body font size in points Fl literal font size SIZI Literal font size in points title font size SIZE Title font size in points P4 heading font size SIZI Heading font
159. plementation classes for the IDL interfaces defined below IDL interface A void op_a MBNA aA PWN HE RoR RR OW Now NARO interface B void op_b interface I A B 1 Because of these problems the OMG is currently defining a new object adapter the so called Portable Object Adapter POA Future versions of ORBACUS will implement the POA 62 ORBacus Implementing Servants 15 MANDA ASP WH HP RR HR RH HH Daw WHE DD amp void op_i An interface A is defined with the operation op_a An interface B is defined with the operation op_b Interface I is defined which is derived from A and B It also defines a new operation op_i Implementing Servants using Inheritance ORBACUus for C and ORBACUS for Java both support the use of inheritance for inter face implementation To implement an interface using inheritance you write a servant class that inherits from a skeleton class generated by the IDL translator By convention the name of the servant class should be the name of the interface with the suffix _imp1 e g for an interface 1 the implementation class is named T_imp1 Inheritance using C In C I_imp1 must inherit from the skeleton class I_ske1 that was generated by the IDL to C translator If I inherits from other interfaces for example from the interfaces A and B then I_imp1 must also inherit from the corresponding implementation class
160. pplet When initialized by an applet the ORB looks for the parameters ORBparams and BOAparams whose values should be command line options separated by spaces For example the HTML code below uses the ORBconfig option to specify the URL of the ORB configuration file lt APPLET CODE Client class ARCHIVE 0B jar WIDTH 500 HEIGHT 300 gt ORBacus 59 ORB and BOA Initialization 4 5 3 4 5 4 lt PARAM NAME ORBparams VALUE ORBconfig http www orb cfg gt lt APPLET gt Your applet can also define ORBACUS configuration properties using Java system proper ties or using the java util Properties object passed to org omg CORBA ORB init See Configuring the ORB and BOA on page 45 for more information Defining the ORB Class Parameters Some Web browsers have a built in ORB In order to use ORBACUS instead of this built in ORB you must set the following applet parameters lt APPLET CODE Client class ARCHIVE 0B jar WIDTH 500 HEIGHT 300 gt lt PARAM NAME o0rg omg CORBA ORBClass VALUE com ooc CORBA ORB gt lt PARAM NAME org omg CORBA ORBSingletonClass VALUE com ooc CORBA ORBSingleton gt lt APPLET gt Security Issues Web browsers generally place several security restrictions on applets that you need to be aware of when developing an applet using ORBACUS e Applets can only communicate with the host from which the applet was downloaded e A
161. pplets cannot accept connections from any host The first limitation forces you to run any CORBA server applications that your applet communicates with on your Web server host The second limitation prevents your applet from acting as a CORBA server which is often necessary when a client wishes to receive callbacks from a server These limitations are the most common causes of security exceptions in an applet You must ensure that any object references used by your applet refer to objects on the Web server host Furthermore you must not attempt to enable CORBA server functionality in your applet by initializing the BOA 1 For example Netscape v4 has a built in ORB 2 Netscape v4 also does not normally allow CORBA applets to be loaded from a local i e filesys tem HTML file causing a SecurityException when the applet attempts to connect to the CORBA server To workaround this problem CORBA applets must be downloaded from a Web server 60 ORBacus CHAPTER 5 CORBA Objects 5 1 Overview A CORBA object is an object with an interface defined in CORBA IDL CORBA objects have different representations in clients and servers e A server implements a CORBA object in a concrete programming language for example in C or Java This is done by writing an implementation class for the CORBA object and by instantiating this class The resulting object is called a servant e A client that wants to make use of a servan
162. r From now on requests from clients to this servant will cause an OBJECT_NOT_EXIST exception to be raised Connecting Servants using Java This is how Java servants are explicitly connected to the object adapter Java org omg CORBA ORB orb Get a reference to the ORB somehow I impl new I_impl orb connect impl To connect a servant we need the ORB A new servant imp is created ORBacus 71 CORBA Objects 5 4 3 N oh The new servant is connected to the object adapter A servant can also be disconnected from the object adapter This is done with the disconnect call Java orb disconnect impl The servant imp1 is disconnected from the object adapter From now on requests from clients to this servant will cause an OBJECT_NOT_EXIST exception to be raised Named Servants ORBACUS for C and ORBACUsS for Java support the notion of named servants in which a name is assigned to a servant when it is connected to the object adapter allowing a client to identify a servant by its name The ORB operation get_inet_object is used on the client side to resolve a named servant within a specific server see Connecting to Named Objects on page 88 For named servants a parameter for the servant s name must be provided to connect For example in C C CORBA_ORB_var orb Get a reference to the ORB somehow orb gt connect impl MyName And in Java
163. r poll_re sponse However the main advantage of a reactive client becomes apparent if it is used together with a reactive server in mixed client server applications A mixed client server applica ORBacus 119 Concurrency Models connect ia eos accept f lt t dispatch a p connect acceptly CSS m i l dispatch disconnect close a disconnect close i BE el Client A Server Client B Figure 9 2 Reactive Server tion is a program that is both a client and server at the same time Without the reactive concurrency model it is not possible to use nested method calls in single threaded applica tions which are absolutely necessary for most kinds of callbacks Consider two programs A and B both mixed client server applications First A tries to call a method f on B Before this method returns B calls back A by invoking method g This scenario is quite common and for example is used in the popular Model View Controller pattern 7 1 For more information on send_deferred get_response and poll_response see the chapter The Dynamic Invocation Interface in 2 120 ORBacus Single Threaded Concurrency Models For blocking client servers this scenario is shown in Figure 9 3 As you can see the call p l dispatch
164. ready been sent or received ORBacus 137 The Open Communications Interface 11 2 2 11 2 3 11 2 4 11 2 5 11 2 6 Transport The Transport interface allows the sending and receiving of octet streams in the form of Buffer objects There are blocking and non blocking send receive operations available as well as operations that handle time outs and detection of connection loss Acceptor and Connector Acceptors and Connectors are Factories 10 for Transport objects A Connector is used to connect clients to servers An Acceptor is used by a server to accept client connection requests Acceptors and Connectors also provide operations to manage protocol specific IOR pro files This includes operations for comparing profiles adding profiles to IORs or extract ing object keys from profiles Connector Factory A Connector Factory is used by clients to create Connectors No special Acceptor Factory is necessary since an Acceptor is created just once on server start up and then accepts incoming connection requests until it is destroyed on server shutdown Connectors how ever need to be created by clients whenever a new connection to a server has to be estab lished The Registries The ORB provides a Connector Factory Registry and the Object Adapter provides an Acceptor Registry These registries allow the plugging in of new protocols Transport Connector Connector Factory and Acceptor must be written by the plug
165. rences generated by the BOA The default value is the canonical hostname of the machine This property is especially useful if a host has more than one name Note that this property is ignored if ooc boa numeric is true ooc boa id Value id Specifies the identifier of the BOA to be used by the application The only valid identifier is OB_BOA ooc boa numeric Value true false If true the BOA will generate object references that contain an internet IP address in dotted dec imal notation instead of the canonical hostname The default value is false 0oc boa port Value 0 lt port lt 65535 Specifies the port number on which the server should listen for new connections If no port is specified one will be selected automatically by the BOA Use this property if you plan to publish an IOR e g in a file a naming service etc and you want that IOR to remain valid across executions of your server Without this property your server is likely to use a different port number each time the server is executed See Chapter 6 for more informa tion ORBacus 47 ORB and BOA Initialization 4 3 2 ooc boa thread_pool Value n gt 0 Determines the number of threads to reserve for servicing incoming requests The default value is 10 This property is only effective when the ooc boa conc_model property has the value thread_pool Command line Options There are equivalent command line options for many of the ORBACUS pr
166. rency Models Overview ORBACUS allows different concurrency models to be established for the client and server activities of an application The client side concurrency models are Blocking Reactive and Threaded The server side concurrency models are Blocking Reactive Threaded Thread per Client Thread per Request and Thread Pool Single Threaded Concurrency Models Blocking Clients and Servers The blocking concurrency model is the simplest one For the client blocking means that the ORB blocks while sending requests to or receiving replies from a server A special case are oneway requests which do not block the ORB If the ORB determines that sending the oneway request would cause blocking it puts the oneway request into a request buffer Whenever the client tries to send another request to the same server this buffer s contents are sent first Blocking servers block the ORB while receiving a request or sending a reply Addition ally since the ORB blocks on a connection after accepting it with a call like accept the ORB cannot accept any new connections Therefore a blocking server can only serve one client at a time This is shown in Figure 9 1 Because of its simplicity the blocking concurrency models are the fastest models avail able There is no overhead neither for calls to operations like select because the ORB 1 A oneway request is a request for which no reply is received Therefore a oneway request cannot
167. rver for each new proxy object instead of reusing existing ones Setting the connection reuse policy to false at the object level means that the client does not reuse connections to the server only for a particular proxy object If the connection reuse policy is set to true at some later point communications channels that were previously created with a connection reuse policy set to false will not be reused That is the connection reuse policy is sticky in the sense that the reuse policy that was in effect at the time that a communications channel is created stays with it Setting the reuse policy at the object level means that for a client the ORB will not reuse the commu nications channel that is associated with the proxy object Connection Reuse Policy at ORB Level Our first example shows how the connection reuse policy can be set at the ORB level First in C C CORBA_Any boolAny boolAny lt lt CORBA_Any from_boolean CORBA_FALSI CORBA_PolicyList policies policies length 1 policies 0 orb gt create_policy OB_CONNECTION_REUSE boolAny CORBA_Object_var pmObj orb gt resolve_initial_references ORBPolicyManager CORBA_PolicyManager_var pm CORBA _PolicyManager _narrow pmObj pm gt add_policy_overrides policies Fa Ea Create an any and insert the value CORBA_FALS Create a sequence containing one policy object Ask the ORB to create a connection reu
168. ry Parameters factory The Connector factory to add get_factory ConFactory get_factory in IOR ior Returns a suitable Connector factory for an IOR Parameters ior The IOR to for which a Connector factory is requested Returns The Connector factory A nil object reference is returned if no Connector factory is regis tered which is able to create a Connector for the given IOR get_factory_with_policies ConFactory get_factory_with_policies in IOR ior in CORBA PolicyList policies Returns a suitable Connector factory for an IOR The Connector factory returned must satisfy a list of policies Parameters ior The IOR for which a Connector factory is requested 218 ORBacus Interface OCI ConFactoryRegistry policies The list of policies which have to be satisfied Returns The Connector factory A nil object reference is returned if no Connector factory is regis tered which is able to create a Connector for the given IOR with the given list of policies get_factories ConFactorySeq get_factories Returns a sequence of all registered Connector factories Returns A sequence with all registered Connector factories equivalent boolean equivalent in IOR iorl in IOR ior2 Checks whether two IORs are equivalent It calls the equivalent operation of all registered Connector factories Two IORs are considered equivalent if all these calls return TRUE Parameters ior1 The first IOR to chec
169. ry object OBMinorPrimitiveDefDestroy destroy invoked on PrimitiveDef object OBMinorAttrExists Attribute is already defined in a base interface OBMinorOperExists Operation is already defined in a base interface OBMinorLookupAmbiguous Search name for lookup is ambiguous OBMinorAttrAmbiguous Attribute name collisions in base interfaces OBMinorOperAmbiguous Operation name collisions in base interfaces Table 14 3 Minor Exception Codes for INTF_REPOS 14 2 Non Compliant Application Asserts If the ORBACUS library was compiled without the preprocessor definition DNDEBUG defined ORBACUS tries to detect common programming mistakes that lead to non com pliant CORBA applications If such a mistake is found an error messages like this will appear Non compliant application error detected Application used wrong memory allocation function After detecting such an error the ORBACUS library dumps a core Unix only and prints the file and line number where the error was detected You can use the core dump in order to track down the problem with a debugger The following error messages can appear Application requested a feature that has not yet been implemented This is not an application error This error message appears if an application attempts to use a feature that has not yet been implemented in ORBACUS In this case the only thing that can be done is to wait for the next ORBACUS version that has this particular feature implemented 18
170. s much of the buffer s data as possible without blocking Returns FALSE if a connection loss is detected TRUE otherwise send_timeout void send_timeout in Buffer buf in unsigned long timeout Similar to send butit is possible to specify a timeout On return the caller can test whether there was a timeout by checking if the buffer has been sent completely Parameters buf The buffer to send timeout The timeout value in milliseconds A zero timeout is equivalent to calling send buf FALSE get_info 200 ORBacus Interface OCI Transport TransportiInfo get_info Returns the information object associated with the Transport Returns The Transport information object ORBacus 201 Open Communications Interface Reference B 4 Interface OCI TransportInfo interface TransportInfo Information on an OCI Transport object Objects of this type must be narrowed to a Transport information object for a concrete protocol implementation for example to OCI IIOP Trans port Info in case the plug in implements IIOP See Also Transport Attributes tag readonly attribute Profileld tag The profile id tag connector_info readonly attribute ConnectorInfo connector_info The ConnectorInfo object for the Connector that created the Transport object that this Trans portInfo object belongs to If the Transport for this TransportInfo was not created by a Connec tor this attribute is set to
171. s object and initializes it with the contents of a configuration file if necessary ORBacus 53 ORB and BOA Initialization Ky SMU DAN DAB UNAK N W Set the ORB concurrency model using a property Initialize the ORB Defining BOA Properties In a situation where you don t need access to the Properties object until after the ORB has been initialized you can simply do the following C include lt OB CORBA h gt include lt OB Properties h gt CORBA_ORB_var orb CORBA_ORB_init argc argv OBProperties properties OBProperties instance properties gt setProperty ooc boa conc_model reactive CORBA_BOA_var boa orb gt BOA_init argc argv Include the necessary header files Initialize the ORB The ORB will initialize the Properties object Obtain the OBProperties instance Set the BOA concurrency model using a property and initialize the BOA Note that in this example we are defining a BOA property prior to initializing the BOA Also note that the Properties object has already been initialized by the ORB so the application simply needs to obtain a pointer to the object using the instance method Here s the same example in Java Java org omg CORBA ORB orb org omg CORBA ORB init args null com ooc CORBA Properties properties com ooc CORBA Properties instance properties setProperty ooc boa conc_model threaded org omg CORBA BOA boa
172. se means to execute i e run the Software To copy means to create one or more copies as defined in 17 U S C 101 To distribute means to broadcast publish transfer post upload download or otherwise dissemi nate in any medium to any third party To modify means to create a work derived from the Software A commercial use is any copying distribution or modification of the Software or any work derived from the Software to any party where payment or other consideration is made in connection with such copying distribution or modification whether directly as in payment for a copy of the Software or indirectly including but not limited to payment for some good or service related to the Software or payment for some product or service that includes a copy of the Software without charge However the following actions which involve payment do not in and of themselves con stitute a commercial use a posting the Software on a public access information storage and retrieval service for which a fee is received for retrieving information such as an on line service provided that the fee is not content dependent Such fees which are not content dependent include but are not limited to fees which are based solely on the storage capacity required to store the information and fees which are based solely on the time required to transfer the information from to the public access informa tion storage and retrieva
173. se policy Pass the any that contains the value for this policy Obtain the ORB level policy manager object Add the policies to the ORB level policy manager And here is the same example in Java ORBacus 149 Using Policies Ky SH DAN DAB UNAK Ka l Ky 12 3 2 AND GAA WH NH HB wo DN DAB WwW NH HK Ky Ke Java org omg CORBA Any boolAny orb create_any boolAny insert_boolean false org omg CORBA Policy policies new org omg CORBA Policy 1 policies 0 orb create_policy com ooc OB CONNECTION_REUSE value boolAny org omg CORBA PolicyManager pm org omg CORBA PolicyManagerHelper narrow orb resolve_initial_references ORBPolicyManager pm add_policy_overrides policies This is equivalent to the C version Connection Reuse Policy at Object Level And now the same example but at the object level C first C CORBA_Any boolAny boolAny lt lt CORBA_Any from_boolean CORBA_FALSI CORBA_PolicyList policies 1 policies length 1 policies 0 orb gt create_policy OB_CONNECTION_REUSE boolAny CORBA_Object_var newObj obj gt _set_policy_overrides policies CORBA_ADD_OVERRIDES Gi This is the same as in the example for the ORB level Set these policies on the object by using the set_policy_overrides method This method returns a new object that has the set of policies applied And here
174. se see the pricing information on our Web site or contact support ooc com About this Document This manual is except for the Getting Started chapter no replacement for a good CORBA book This manual also does not contain the precise specifications of the CORBA standard which are freely available on line A good grasp of the CORBA speci fications in 2 and 3 is absolutely necessary to effectively use this manual In particular the chapters in 2 covering CORBA IDL and the IDL to C mapping should be studied thoroughly Do not expect any of the introductory CORBA books to provide a reference for the IDL to C mapping The books that are currently available only give an overview and are neither complete nor up to date There is no substitute for the official CORBA specifica tion as defined in 2 What this manual does contain however is information on how ORBACUS implements the CORBA standard A shortcoming of the current CORBA specification is that it leaves a high degree of freedom to the CORBA implementation For example the precise seman tics of a oneway call are not specified by the standard To make it easier to get started with ORBACUS this manual contains a Getting Started chapter explaining some ORBACUS basics with a very simple example Getting Help Should you need any assistance with ORBACUS do not hesitate to contact us at support ooc com You might also consider joining our ORBACUS mailing list
175. size in points Options for irserv h he Lp v version e cpp NAME d debug Use font NAME as the font for the text body ORBacus 33 The ORBacus Code Generators 3 9 3 10 3 1 DNAME DNAME DEF UNAME IDIR These options are the same as for the id1 command i LOL Print the stringified IOR of the Interface Repository on standard output The arguments to irserv are zero or more IDL files If no IDL files are specified on the command line the Interface Repository server can be populated dynamically using the irfeed command Options for irfeed h help v version e cpp NAME d debug DNAME DNAME DEF UNAME IDIR These options are the same as for the id1 command The arguments to irfeed are one or more IDL files Options for irdel b help v version These options are the same as for the id1 command The arguments to irdel are one or more scoped names A scoped name has the form X Y Z For example an interface I defined in a module M can be identified by the scoped name M P Options for irgen p Shelp v version no skeletons 34 ORBacus The IDL to C Translator and the Interface Repository 3 12 3 13 no type codes locality contrained no virtual inheritance tie c suffix SUFFIX h suffix SUFFIX header dir DIR other header dir DIR output d
176. sociated with the Connector Returns The Connector information object 206 ORBacus Interface OCI ConnectorInfo B 7 Interface OCI ConnectorInfo interface ConnectorInfo Information on a OCI Connector object Objects of this type must be narrowed to a Connector information object for a concrete protocol implementation for example to OCI LIOP Connec torInfo in case the plug in implements IIOP See Also Connector Attributes tag readonly attribute Profileld tag The profile id tag Operations add_connect_cb void add_connect_cb in ConnectCB cb Add a callback that is called whenever a new connection is established If the callback has already been registered this method has no effect Parameters cb The callback to add remove_connect_cb void remove_connect_cbh in ConnectCB cb Remove a connect callback If the callback was not registered this method has no effect Parameters cb The callback to remove ORBacus 207 Open Communications Interface Reference B 8 Interface OCI ConnectCB interface ConnectCB An interface for a connect callback object See Also ConnectorInfo Operations connect_cb void connect_cb in TransportInfo transport_info Called after a new connection has been established If the application wishes to reject the con nection CORBA NO_PERMISSION may be raised Parameters transport_info The TransportInfo for the new connection 20
177. ss Hello_impl extends _HelloImplBase public void hello System out printin Hello World The implementation class Hel1lo_imp1 must inherit from the generated class _HelloImplBase As with the C implementation the hello method simply prints Hello World on standard output Save this class to the file Hello_impl java ORBacus 21 Getting Started MANDA ASW NH HE Wwwwwwrns SNH NHNHNHNHNHNH NRHP HH HH HH HH Bo M H DH DAN DAN WHHE DH DAN Da WHE DD T en N We also have to write a class which holds the server s main method We call this class Server saved in the file Server java Java package hello public class Server public static void main String args org omg CORBA ORB orb org omg CORBA ORB init args new java util Properties org omg CORBA BOA boa orb BOA_init args new java util Properties Hello_impl p new Hello_impl try String ref orb object_to_string p String refFile Hello ref java io PrintWriter out new PrintWriter new java io FileOutputStream refFile out println ref out flush catch java io IOException ex System err println Can t write to ex getMessage System exit 1 boa impl_is_ready null The ORB and BOA must be initialized This is done using ORB init and ORB BOA_init Note that all standard CORBA definitions are in the package org omg CORBA T
178. ssary for linking Please consult these README files for details 1 Although CORBA s T _narrow for an interface T works similar to dynamic_cast lt T gt for a plain C class T dynamic_cast lt T gt must not be used for CORBA object refer ences 20 ORBacus Implementing the Example in Java 2 3 4 2 4 2 4 1 RB OwM DAN DG AWN HB ba RY Running the Application Our Hello World application consists of two parts the client program and the server program The first program to be started is the server because it must create the file Hello ref that the client needs in order to connect to the server As soon as the server is running you can start the client If all goes well the Hello World message will appear on the screen Implementing the Example in Java In order to implement this application in Java the interface specified in IDL is translated to Java classes similar to the way the C code was created The ORBACcUs IDL to Java translator jid1 is used like this jidl package hello Hello idl This command results in several Java source files on which the actual implementation will be based The generated files are Hello java HelloHelper java HelloHolder java StubForHello javaand _HelloImp1Base java all generated in a directory with the name hello Implementing the Server The server s Hello implementation class looks as follows Java package hello public cla
179. string and then write it to a well known file Subsequently the client can read the string from the file and use it as the argument to string_to_ob ject This method is shown in the following C and Java examples First we ll look at the relevant server code C CORBA_ORB_var orb Get a reference to the ORB somehow B_var impl new B_impl CORBA_String_var s orb gt object_to_string impl ofstream out object ref out lt lt s lt lt endl out close A servant for the interface B is created The object reference of the servant is stringified The stringified object reference is written to a file ORBacus 85 Locating Objects AND GOW WwW NH ND GQ WN HE In Java the server code looks like this Java org omg CORBA ORB orb Get a reference to the ORB somehow B impl new B_impl String ref orb object_to_string impl java io PrintWriter out new PrintWriter new java io FileOutputStream object ref out println ref out flush A servant for the interface B is created The object reference of the servant is stringified The stringified object reference is written to a file Now that the stringified object reference resides in a file our clients can read the file and convert the string to an object reference C CORBA_ORB_var orb Get a reference to the ORB somehow ifstream in object ref char s 1000 in
180. sts of This information is provided by get_number_of_properties IDL unsigned long get_number_of_properties Note that you have to be careful if you intend to use the return value of get_number_of_properties as the input value for the how_many parameter of get_all_properties in order to get a complete property list You always have to check the PropertiesIterator for properties that were not returned as part of the Properties sequence returned by get_all_properties otherwise you might miss a property that was defined by another process between your calls to get_number_of_properties and get_all_properties Deleting Properties If a property has become obsolete it can be deleted from the PropertySet with delete_property IDL void delete_property in PropertyName property_name raises PropertyNotFound InvalidProperty FixedProperty As you might have guessed by this operation s signature there are properties that cannot be deleted at all This kind of property is called a FixedProperty The Property Service defines several other special property types such as read only properties Please refer to the OMG s Property Service 4 specification for details ORBacus 165 ORBacus Basic Services 13 3 5 A Simple Example AN DA GAP WHE WwWwwwwnhs Sb Nv NHNH NHN NHN NHRH HHH HHH HH At wWwNHRE DH AN DA aS WHERE DH DAN DAP WHE DOD The Property Service test suite which is part of the ORBACUS distribution provides
181. sult in an INV_OBJREF ORBacus 83 Locating Objects 6 2 1 6 2 2 6 2 3 exception being raised The sections below discuss each of these components and describe the steps you can take to ensure that a published object reference remains valid Hostname By default the hostname in an object reference is the canonical hostname of the host on which the server is running Therefore running the server on a new host invalidates any previously published object references for the old host ORBACUS provides the OAhost option to allow you to override the hostname in any object references published by the server This option can be especially helpful when used in conjunction with the Domain Name System DNS in which the OAhost option spec ifies a hostname alias that is mapped by DNS to the canonical hostname See Configuring the ORB and BOA on page 45 for more information on the OAhost option Port Number Each time a server is executed the BOA selects a new port number on which to listen for incoming requests Since the port number is included in published object references sub sequent executions of the server could invalidate existing object references To overcome this problem ORBACUS provides the OAport option that causes the BOA to use the specified port number You will need to select an unused port number on your host and use that port number every time the server is started See Configuring the ORB
182. sures that the event channel actively forwards events to them using the push operation IDL interface PushConsumer void push in any data raises Disconnected void disconnect_push_consumer The push consumer has a more or less passive role only waiting for something to happen This is different than pull consumers which optionally implement the PullConsumer interface A pull consumer has a more active role and usually periodically polls the event channel for new events As these events may occur more frequently than they are polled for by the pull consumer some events might get lost The buffering policy implemented by the event channel determines whether events are buffered and what happens in case of an event queue overflow A client is typically implemented as a pull consumer when it is not concerned about the possibility of lost events e g if the client is only interested in the most recent events 170 ORBacus The Event Service 13 4 6 13 4 7 mW GW hb Like consumers suppliers can also use push or pull behavior Push suppliers are probably the more common type in which the supplier directly forwards data to the event channel and thus plays the active role in the link to the channel Pull suppliers on the other hand are polled by the event channel and supply an event in response if a new event is avail able Polling is done by the try_pu11 operation if it is to be non blocking or by the
183. system Objects are bound with the Naming Service s bind operation for contexts the corresponding operation bind_context is used In addition to the object s IOR both calls expect a unique bind ing name If a name already exists an Al readyBound exception is thrown There are also other exceptions you might encounter at this stage e g 11 legalName if an empty string was provided as part of a NameComponent Everything is prepared now so we can listen for requests by calling imp1_is_ready on the BOA Unbinding Some cleanup work should be done before exiting the program Every binding is properly unbound here Java nc unbind cName nc unbind bName nc unbind aName nce unbind nc2Name nce unbind nclName Exceptions The final code fragment deals with exception handling Java catch NotFound ex System err print Got a NotFound exception switch ex why value case NotFoundReason _missing_nod System err print missing node break case NotFoundReason _not_context System err print not context break ORBacus 161 ORBacus Basic Services LS 17 18 19 20 21 22 23 24 23 26 27 28 29 30 ot 32 33 34 39 36 37 38 39 40 41 42 3 42 13 3 case NotFoundReason _not_object System err print not object break System err printin ex printStackTrace return 1 catch CannotProceed ex System err printin Got
184. t implemented by a server creates an object that delegates all operation calls to the servant via the ORB Such an object is called a proxy When a client invokes a method on the local proxy object the ORB packs the input parameters and sends them to the server which in turn unpacks these parameters and invokes the actual method on the servant Output parameters and return values if any fol low the reverse path back to the client From the client s perspective the proxy acts just like the servant since it hides all the communication details within itself A servant must somehow be connected to the ORB so that the ORB can invoke a method on the servant when a request is received from a client This connection is handled by the object adapter as shown in Figure 5 1 ORBACUS comes with an object adapter called the Basic Object Adapter BOA Unfor tunately the specification for the BOA 2 is quite incomplete leaving a lot of freedom to ORBacus 61 CORBA Objects Client Server Servant Proxy bject Adapter ORB Figure 5 1 Servants Proxies and the Object Adapter ORB implementors Therefore all BOAs are in fact more or less vendor specific It is therefore necessary to have a chapter explaining how servants are implemented in ORB A CUS and how they are connected to the ORBACUS BOA implementation Implementing Servants In this chapter we will implement servant classes or im
185. te threads for receiving requests from clients and sending replies Additionally there is a separate thread dedicated to accepting incoming connection requests so that a threaded server can serve more than one client at a time ORBACUS s threaded server concurrency model allows only one active thread in the user code This means that even though many requests can be received simultaneously the execution of these requests is serialized This is shown in Figure 9 5 For simplicity the esd at Client A Threaded Server Client B Figure 9 5 Threaded Server dispatch arrows and the corresponding return arrows are omitted in this and all follow 1 Instead of directly using operations like select ORBACUS uses a Reactor to provide for flex ible integration with existing event loops and to allow the installation of user supplied event han dlers See Chapter 10 for more information 122 ORBacus Multi Threaded Concurrency Models 9 3 2 ing diagrams In the example the threaded server has two clients connected to it and thus two receiver threads sender threads not shown First A calls on the server If before f returns B tries to call another operation g this request is delayed until returns The same is true for A s call to h which must wait until g returns Allowing only one active thread in user code has the adv
186. that the buffer s length and the position counter don t depend on each other There are no restrictions on the values permitted for the counter This implies that it s even legal to set the counter to values beyond the buffer s length Operations advance void advance in unsigned long delta Increment the position counter Parameters delta The value to add to the position counter rest_length unsigned long rest_length 196 ORBacus Interface OCI Buffer Returns the rest length of the buffer The rest length is the length minus the position counter s value If the value of the position counter exceeds the buffer s length the return value is unde fined Returns The rest length is_full boolean is_full Checks if the buffer is full The buffer is considered full if its length is equal to the position counter s value Returns TRUE if the buffer is full FALSE otherwise ORBacus 197 Open Communications Interface Reference B 3 Interface OCI Transport interface Transport The interface for a Transport object which provides operations for sending and receiving octet streams In addition it is possible to register callbacks with the Transport object which are invoked whenever data can be sent or received without blocking See Also Connector Acceptor Attributes tag readonly attribute Profileld tag The profile id tag handle readonly attribute Handle handle
187. the Common Object Request Broker Architecture CORBA specification as defined in The Common Object Request Broker Architecture and Specification 2 and IDL Java Language Mapping 3 These are some of the highlights of the ORBACUS 3 1 release e Full CORBA IDL support e Complete CORBA IDL to C mapping e Complete CORBA IDL to Java mapping e Includes the Basic CORBA Services Naming Event and Property e Pluggable Protocols with IIOP as the default plug in e Single and Multi Threaded support with several concurrency models Blocking Reactive Threaded Thread per Client Thread per Request and Thread Pool e Nested method invocations even in the single threaded version e Support for timeouts e Seamless event loop integration with X11 and Windows e Full support for dynamic programming Dynamic Invocation Interface Dynamic Skeleton Interface Interface Repository and DynAny ORBacus 11 Introduction 1 2 1 3 1 4 e IDL to HTML and IDL to RTF translators for generating javadoc style documentation This version of ORBACUS has the following limitations e Only persistent i e manually launched servers are currently supported For platform availability please refer to the ORBACUS home page at http www ooc com ob How is it licensed ORBACUS is licensed as free for non commercial use See the license agreement in Appendix C for details For information on commercial licenses plea
188. then be delegated to imp1 In this example the lifetime of imp1 is coupled to the lifetime of the servant tie That is when tie is destroyed delete imp is called In case you don t want the lifetime of imp1 to be coupled to the lifetime of t ie for example because you want to create imp1 on the stack and not on the heap making it illegal to call delete on imp1 use the fol lowing code C I_impl_tie impl I_var tie new I_skel_tie lt I_impl_tie gt amp impl CORBA_FALSE A new I_imp1_tie is created this time on the stack not on the heap An instance of I_skel_tie is created The CORBA_FALSE parameter tells tie not to call delete on impl ORBacus 69 CORBA Objects 5 3 2 MND AP WwWNH HE RoR ORS amp Creating Servants using Java This example demonstrates how to create servants using Java Java I impl new I_impl I anotherImpl new I_impl Two servants impl and anotherImpl are created with new In case the servant class was written using the delegation approach an object implement ing the LOperations interface must be passed to the servant s constructor Java I_impl_tie impl new I_impl_tie _IImplBase_tie tie new _IImplBase_tie impl A new I_impl_tie is created An instance of _IImp1Base_tie is created taking imp1 as a parameter All operation calls to t ie will then be delegated to imp1 Every tie class generated by the IDL to J
189. titude of ways One of the most common ways is by receiving an object reference as the result of an oper ation as demonstrated by the following example IDL interface A interface B A getA An interface A is defined An interface B is defined with an operation returning an object reference to an A On the server side A and B can be implemented in C as follows C class A_impl virtual public A_skel ORBacus 81 Locating Objects MBN Das 10 del 12 I3 14 15 16 L 18 Lo 20 21 I2 15 17 20 MN A aA PWN HE RRR RR RH HW N DOG WNHE DO G class B_impl virtual public B_skel A_var a public void B_imp1 a_ new A_impl virtual A_ ptr getA return A _duplicate a_ hi The servant class A_imp1 is defined which inherits from the skeleton class A_skel The servant class B_imp1 is defined which inherits from the skeleton class B_skel B_imp1 s constructor creates anew A_imp1 servant getA returns an object reference to the A_imp1 servant In Java the interfaces can be implemented like this Java public class A_impl extends _AImplBase public class B_impl extends _BImplBase A a_j public B_impl a_ new A_impl A getA return a_ 82 ORBacus Lifetime of Object References 10 13 19 18 6 2 The servant class A_imp1 is defined which inherits fr
190. unless that component itself accompanies the executable code of the work derived from the Software Furthermore if the executable code or object code of the work derived from the Software may be copied from a designated place and if the source code of the work derived from the Software may be copied from the same place then the work derived from the Software shall be construed as accompanied by the complete corresponding machine readable source code of such work derived from the Software even though third parties are not compelled to copy the source code along with the executable code or object code If the work derived from the Software normally reads commands interactively when run Licensee must cause the work derived from the Software at each time it commences operation to print or dis play an announcement including an appropriate copyright notice and either a notice consisting of the verbatim warranty and liability provisions of this License or a notice that Licensee and not Object Oriented Concepts Inc provides a warranty Such notice must also state that users may distribute the Software and or the work derived from the Software only under the conditions of this License ORBacus 231 Royalty Free Public License Agreement and must further state how to view the copy of this License included with the work derived from the Software Licensee may not impose any further restrictions on the exercise of the rights granted here
191. use the timer classes 2 Aclass CustomTimer is defined that inherits from OBTimer 4 12 The private method register causes the timer to be notified every 10 seconds 17 20 The constructor calls the register method 22 26 The notify method is called every 10 seconds A string is displayed and the timer is re registered 136 ORBacus CHAPTER 11 The Open Communications Interface 11 1 11 2 11 2 1 What is the Open Communications Interface The Open Communications Interface OCI defines common interfaces for pluggable pro tocols It supports connection oriented reliable byte stream protocols That is protocols which allow the transmission of a continuous stream of bytes octets from the sender to the receiver TCP IP is one possible candidate for an OCI plug in Since ORBACUS uses GIOP such a plug in then implements the IIOP protocol Other candidates are SCCP Signaling Con nection Control Part part of SS 7 or SAAL Signaling ATM Adaptation Layer Non reliable or non connection oriented protocols can also be used if the protocol plug in itself takes care of reliability and connection management For example UDP IP can be used if the protocol plug in provides for packet ordering and packet repetition in case of a packet loss Interface Summary Buffer An interface for a buffer A buffer can be viewed as an object holding an array of octets and a position counter which determines how many octets have al
192. vant from a Reference In some situations it may be necessary to obtain the servant implementation object of an object reference typically because you need to invoke a method on the servant implemen tation object that is not available via its IDL interface In ORBACUS servant classes are derived from skeleton classes which are derived from proxy classes so called stub classes Therefore you can simply cast an object refer ence to its servant class Getting a Servant using C In C dynamic_cast lt gt can be used to obtain a pointer to the servant as shown below C class I_impl virtual public I_skel void foo I_ptr ref I_impl p dynamic_cast lt I_impl gt ref if p The implementation for ref is in the same process else The implementation for ref is not in the same process A servant class for an interface I is defined The operation foo takes an object reference ref to an object I as a parameter dynamic_cast lt gt is used on ref to get a pointer to an I_imp1l The call to dynamic_cast lt gt returns a pointer to the servant if the object referred to by ref was local or a null pointer otherwise ORBacus 77 CORBA Objects AND GOW WN HB SOSH HHH HHH HEH HK wrnySRFR Dw AN DA aS WHE OD I3 In case your compiler does not support RTTU you can use the OB_MAKE_NARROW_IMPL macros from the ORBACUS header file Narrow_imp1 h to obtain
193. var orb CORBA_ORB_init argc argv CORBA_BOA_var boa orb gt BOA_init argc argv Hello_var p new Hello_impl CORBA_String_var s orb gt object_to_string p const char refFile Hello ref ofstream out refFile out lt lt s lt lt endl out close boa gt impl_is_ready CORBA_ImplementationDef _nil Several header files are included Of these OB CORBA h provides the standard CORBA definitions and Hello_imp1 h contains the definition of the Hello_imp1 class The first thing a CORBA program has to do is to initialize the ORB and the BOA This is done by CORBA_ORB_init and BOA_init Both operations expect the parameters with which the program was started These parameters may or may not be used by the ORB and BOA depending on the CORBA implementation ORBACUS recognizes certain options that will be explained later 1 Object Request Broker 2 Basic Object Adapter 18 ORBacus Implementing the Example in C 14 16 20 22 2 3 2 MANDA a PW NH HP i So o 11 12 F3 14 15 16 17 18 An instance of Hello_imp1 is created Hello_var like all _var types is a smart pointer i e p will release the object created by new Hello_imp1 automatically when p goes out of scope The client must be able to access the implementation object This can be done by saving a stringified object reference to a file which can be read by the client and converted back t
194. var s2 sl CORBA_String_var s3 CORBA_string_dup s1 OK s2 will implicitly duplicate ABC Also OK explicit duplication Note that string elements of a structure elements of a string array and elements of a string sequence behave exactly like the CORBA_String_var type i e you can deliberately assign between these types or use one of these types to initialize any other of these types There is no need to call CORBA_string_dup explicitly Strings as Parameters and Return Values If a function is called returning a string value via an out or inout parameter or as a return value the callee must duplicate and the caller must release this value The duplication can be done using CORBA_string_dup and the release by either explicitly calling CORBA_string_free or by assigning the value to a CORBA_String_var For example IDL interface I string op out string os inout string ios An operation op is defined with an out string argument an inout string argument and a string return value The following implementation of I s op operation is wrong 1 In code generated by the ORBACUS IDL to C translator array and structure string elements are actually of type CORBA_St ring_var String sequence elements are not of type CORBA_St ring_var for technical reasons but the type used for string sequence elements behaves exactly like the CORBA_St ring_var type 110 ORBacus C Mapping Tips amp Tricks
195. ves any and all right to assert a defense based on jurisdiction and venue for any action stemming from this License brought in U S District Court for the District of Massachusetts Should Licensee have any questions concerning this License or if Licensee desires to contact Object Oriented Concepts Inc for any reason please contact Object Oriented Concepts Inc at Object Oriented Concepts Inc 44 Manning Road Billerica MA 01821 234 ORBacus References The ORBACUS Home Page http www ococ com ob Object Oriented Concepts Inc The Common Object Request Broker Architecture and Specification Revision 2 0 OMG Document 97 02 25 IDL Java Language Mapping OMG document 97 03 01 CORBAservices Common Object Services Specification OMG document 97 12 02 Marc Laukien and Robert Resendes Introduction to CORBA Distributed Objects C C Users Journal April 1998 D C Schmidt Reactor An Object Behavioral Pattern for Concurrent Event Demutltiplex ing and Event Handler Dispatching in Pattern Languages of Program Design Addison Wesley 1995 Frank Buschman Regine Meunier Hans Rohnert Peter Sommerlad and Michael Stal A System of Patterns John Wiley amp Sons Inc The JTHREADS C Home Page http www ooc com jtc Object Oriented Con cepts Inc JTHREADS C User s Manual Object Oriented Concepts Inc ORBacus 235 References 10 11 12 13 Erich Gamma Richard Helm Ralph Jo
196. yType CONNECT_POLICY 1 This policy type identifies the connection policy Enums ConnectPolicyType enum ConnectPolicyType ConnectSecure ConnectInsecure i This enumeration is used to specify whether connection attempts should be secure or insecure ORBacus 185 ORBacus Policy Reference A 2 Interface SSL ConnectPolicy interface ConnectPolicy inherits from CORBA Policy The connection policy This policy is used to specify whether secure or insecure connections are used Attributes value readonly attribute ConnectPolicyType value If an object has a Connect Policy set with value set to Connect Secure then only secure connections will be used for that object 186 ORBacus Module OB A 3 Module OB Constants PROTOCOL_POLICY const CORBA PolicyType PROTOCOL_POLICY 2 This policy type identifies the protocol policy CONNECTION_REUSE_POLICY const CORBA PolicyType CONNECTION_REUSE_POLICY 3 This policy type identifies the connection reuse policy RECONNECT_POLICY const CORBA PolicyType RECONNECT_POLICY 4 This policy type identifies the reconnect policy TIMEOUT_POLICY const CORBA PolicyType TIMEOUT_POLICY 5 This policy type identifies the timeout policy ORBacus 187 ORBacus Policy Reference A 4 Interface OB ProtocolPolicy interface ProtocolPolicy inherits from CORBA Policy The protocol policy This policy is used t
Download Pdf Manuals
Related Search
Related Contents
All. 5. 3 -Allegato B フレキシブルシステム・システム仕様書 VGN-CR231E/R v3 MVC Splitter User Manual カタログはこちら Samsung SPF-86P Εγχειρίδιο χρήσης User Manual for the JNF99FL system-board PDF Copyright © All rights reserved.
Failed to retrieve file