Babel RMI casting works the same as normal Babel casting, the user calls casts an object to a new type, and gets a new reference back of the object of the new type. In normal Babel, the new reference points to the same IOR object as the old reference. This is because all Babel objects are internally represented as the type they were created as, so casting is simply a matter of checking if the internal Babel type extends the target type or not.
Babel RMI objects are more complex, a cast may result in a new stub. If _connect() is called on a remote object, the object can be connected as a super type of its actual type, such as an interface. If this object is later cast to a more derived type, a new local object stub must be created. These two stubs must be deleteRef'd individually.
Here is an example where foo_Quux extends foo_Bar. The first is what the user should do, the second is an error.
foo_Bar fb = foo_Bar__connect("simhandle://pc1:9999/quux1234", &_ex); foo_Quux fz = foo_Quux__cast(fb); foo_Bar_deleteRef(fb); foo_Quux_deleteRef(fz); //object is destroyed
Do not do this:
foo_Bar fb = foo_Bar__connect("simhandle://pc1:9999/quux1234", &_ex); foo_Quux fz = foo_Quux__cast(fb); foo_Bar_deleteRef(fb); foo_Quux_deleteRef(fb); //ERROR!!!