Babel Object servers are easy to start up. All of the servers currently implemented and under development are thread based, so they can run easily in the background of any normal client program. Furthermore, they all implement 2 simple interfaces, 1 for user use and 1 for internal Babel RMI use. 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
The init and run methods come from the sidl.rmi.BaseServer interface:
interface BaseServer { void init(in string url, in int flags); long run(); }
This is the simple interface for starting up any BOS. Notice that before a server is run, init must be called. init takes two protocol specific arguments: a URL and a set of flags. The form of both the URL and the flags is entirely protocol dependent, so I cannot document their use here except in the case of ``Simple Protocol.'' In ``Simple Protocol'' the URL is simply a method of communicating what port the server should listen to for connections. The rest of the URL is simply a formality. The flags variable is treated as a boolean that turns on verbosity if TRUE. Other servers may have more flags that could be set for special features.
run returns a long. This return argument is meant to hold the thread id if the server is threaded. The user may wish to join on the thread in order to keep the server from exiting prematurely.
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.
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.