The other part of writing the server is to perform the initializations necessary for the server to ready itself for CORBA-based interactions with a client.
Some of this coding is similar to what we did on the client side. The first thing we do is initialize, and get a reference to, the Functional Developer ORB. This step is exactly the same as on the client side:
let orb = corba/orb-init(make(corba/<arg-list>),
"Functional Developer ORB")
Next, we can make an instance of the object (servant) class:
let impl = make(<world-implementation>);
To make this object instance accessible to clients using CORBA, it has to be visible in the CORBA world, not just in the Dylan server application that instantiated it. To do this we use an object adapter -- part of an ORB that deals with activating CORBA objects and connecting them to the outside world.
The Functional Developer ORB supports CORBA's portable object adapter (POA) standard. To start the business of activating our world object, we get a reference to the POA:
let poa = corba/orb/resolve-initial-references(orb, "RootPOA");
This is another call to a standard CORBA operation. The operation resolve_initial_references takes an ORB reference and a list of string names for CORBA services, and returns object references for them.
The name used in the call above is the Dylan translation of the pseudo-IDL name CORBA::ORB::resolve_initial_references. The call resolves the name "RootPOA", which is the standard name for the basic POA service, into an object reference.
The next step is to get the POA to create a reference for our world object instance that can be given to a client. There are several ways to get object references from a POA; this is one of them:
let world = portableserver/poa/servant-to-reference(poa, impl);
Next, we want to publish the reference where the client can find it. Recall that the client looks for the reference in c:\temp\hello.ior, expecting to find a string there to translate back into a reference with the ORB utility corba/orb/file-to-object. The ORB also offers the opposite operation, available in Dylan as corba/orb/object-to-file, Thus the next piece of code is:
corba/orb/object-to-file(orb, "c:\\temp\\hello.ior", world);
The corba/orb/object-to-file method could have been defined using the standard ORB operation corba/orb/object-to-string as follows, but corba/orb/object-to-file is provided by the Dylan ORB as a convenience.
define method corba/orb/object-to-file (orb :: corba/<orb>,
file :: <string>,
object :: corba/<object>)
with-open-file(stream = file, direction: #"output")
write(stream, corba/orb/object-to-string(orb, object));
end;
end method;
Next, we have to allow the POA manager managing this POA to start processing requests. (A POA manager is an object that allows us to control the operation of a POA.) We use these standard POA calls:
let manager = portableserver/poa/the-poamanager(poa); portableserver/poamanager/activate(manager);
Finally, on the servant side we need to set the ORB running to receive client requests:
corba/orb/run(orb);