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; char* url = "simhandle://localhost:9999"; int tid; sidl_rmi_ServerInfo si = NULL; echo = sidlx_rmi_SimpleOrb__create(&ex);SIDL_CHECK(ex); sidlx_rmi_SimpleOrb_init( echo, url, 1, &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, init must be called. init takes two arguments: a URL and a set of flags. In ``Simple Protocol'' the URL is simply a method of communicating what port the server should listen to for connections. The port given may be a single port, or a range of ports. The rest of the URL is simply a formality. The flags variable is treated as a boolean that turns on verbosity if TRUE. Additional flags could be added in the future for more special features.
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.