Once you have a BOS up and running, you are free to export your local object to remote servers. (And, depending on your BOS, remote clients may be able to create and access objects on your BOS.) Exporting an object basically means that remote Babel processes can access the object. In implementation, this means that the object is accessible through the sidl.rmi.InstanceRegistry. The InstanceRegistry maps objectIDs to objects, and vice-versa. This is what allows a remote client to get a handle to your object with nothing more than a URL.
There are 3 ways to for an object to end up in the InstanceRegistry. The first, and easiest, is simply to pass a local object by-reference as an argument in a remote call. The last example in 15.3.3 works if a BOS is running.
/* THIS WORKS IF A BOS IS RUNNING */ foo_Bar fb = foo_Bar__createRemote("simhandle://pc1:9999", &_ex); foo_Baz fz = foo_Baz__create(&_ex); //Local object foo_Bar_setBaz(fb, fz, &_ex); //BOS is running, OK!
Another possibility is simply to call _getURL() on the local object when a BOS is running. This will add the object to the InstanceRegistry, so theoretically a remote client could access it. Although realistically the remote client would have to get the URL somehow.
The third possibility is to add it to the InstanceRegistry your self. The InstanceRegistry class:
class InstanceRegistry { static string registerInstance( in sidl.BaseClass instance ); static string registerInstance[ByString]( in sidl.BaseClass instance, in string instanceID); static sidl.BaseClass getInstance[ByString]( in string instanceID ); static string getInstance[ByClass]( in sidl.BaseClass instance ); static sidl.BaseClass removeInstance[ByString]( in string instanceID ); static string removeInstance[ByClass]( in sidl.BaseClass instance ); }
calling registerInstance by itself results in the same thing as calling _getURL on the object, it puts the object in the registry, and returns a unique objectID. However, by calling registerInstance[ByString], the user can supply their own objectID. This is useful for WebServices and bootstrapping. It is possible to explicitly publish and object with a special name. In fact, the InstanceRegistry allows aliasing, the same object can be in the registry multiple times under the same name.
However, there is one issue with using registerInstance[ByString]. What is there is already an object in the registry with that name? There are two possible cases, if the object under that name is the same object you are trying to register, the call is idempotent, it does nothing. However, if a different object in the registry already has that name, the InstanceRegistry registers the new object under a similar, but unique name. Usually a combination of the instanceID passed in by the user and a unique integer. This is usually the correct thing to do, but if the user really wants the object under the original name, they must call removeInstance[ByString] on the object that currently has that name, and re-register the new object.
NOTE: The InstanceRegistry does not addRef objects when they are inserted into it. You must not destroy an object you wish to be accessible remotely. This means that if you create an object, insert it into the instanceRegistry, and then deleteRef it, it will be destroyed. You must keep a reference to it until you wish to remove it from the InstanceRegistry. (The InstanceRegistry does, however, addRef an objects that are gotten from it. If you call getInstance[ByString], you will get a reference to that object and are free to deleteRef it.)