Babel Object Servers are generally easy to start up, although each BOS may have a different construction interface. Here is an example of starting up the ``Simple Protocol''
sidlx_rmi_SimpleOrb echo = NULL; int tid; sidl_rmi_ServerInfo si = NULL; int port_number = 9999; echo = sidlx_rmi_SimpleOrb__create(&ex);SIDL_CHECK(ex); sidlx_rmi_SimpleOrb_requestPort( echo, port_number, &ex);SIDL_CHECK(ex); tid = sidlx_rmi_SimpleOrb_run( echo, &ex );SIDL_CHECK(ex); si = sidl_rmi_ServerInfo__cast(echo,&ex);SIDL_CHECK(ex); sidl_rmi_ServerRegistry_registerServer(si, &ex);SIDL_CHECK(ex); sidl_rmi_ServerInfo_deleteRef(si,&ex);SIDL_CHECK(ex); pthread_join(tid, NULL); //Optional PTHREAD join
Notice that before the server is run, requestPort must be called. There are actually two versions of requestPort: requestPort, and requestPort[InRange]. requestPort takes one argument, a TCP port number (integer). The port number is the TCP port that the BOS should listen to for connections. requestPort[InRange] takes two integers, which denote a range of ports the BOS may try. Because only one server can listen on any TCP port, if the port is already in use by another program, requestPort may fail. requestPort[InRange] gets around this by giving the BOS a range of ports to try. The BOS will try ports in this range until the whole range is exausted, or the BOS succeeds is getting a port.
run returns a long. This return argument is meant to hold the thread id of the thread waiting for connections. The user may wish to join on the thread in order to keep the ``Simple Protocol'' server from exiting prematurely. (We are now past the ``Simple Protocol'' specific portion of this section)
After calling run the server is running, but you won't be able to export any local objects until you register the server with the sidl.rmi.ServerRegistry. Every BOS must be registered with the ServerRegistry, and therefore every BOS must implement the sidl.rmi.ServerInfo interface. This interface is what allows the server to interact with the ServerRegistry.
class ServerRegistry { static void registerServer(in sidl.rmi.ServerInfo si); static string getServerURL(in string objID); static string isLocalObject(in string url); static array<sidl.io.Serializable,1> getExceptions(); }
The ServerRegistry is a singleton class that Babel RMI uses internally to interface with the BOS. It interfaces through the sidl.rmi.ServerInfo interface:
interface ServerInfo { string getServerURL(in string objID); string isLocalObject(in string url); array<sidl.io.Serializable,1> getExceptions(); }
Simply cast the BOS to a ServerInfo and register it with the ServerRegistry.
The user is never really meant to use the ServerInfo interface. In some cases a user may wish to call getExceptions() through the ServerRegistry. getExceptions() is an advanced function. Usually, if there is an exception is raised in the BOS by a remote call, the exception is returned back to the caller. However, in some cases this is not possible. In those cases the BOS logs the exceptions. Later, a user may use getExceptions to get the logged exceptions.
NOTE: Currently the ServerRegistry can only handle one ServerInfo. This means that Babel can effectively only support one BOS at a time for exporting local objects. (There are hairy ways around this) This is because there are a lot of issues that appear when a user can export objects with a number of different protocols that we have not dealt with. This may be researched further in the future.