2.1.5 Implementing the server

Implementing the server is also easy. We create a file
hello-world-server.lisp .

In the server the main function is less interesting because it is concerned with the administrative details of writing out a stringified form of the object reference into the shared file and initializing the server. The actual core of the application implementation is:

(defclass world-implementation (HelloWorld:world-servant) ())
(corba:define-method op:hello ((self world-implementation))
  (declare (ignore self))
  "Hello World!")

This subclasses a special generated class on the server side called a servant , and then implements a method on op:hello that actually returns the desired string.

  1. Create a file called hello-world-server.lisp.
  2. Enter the following code into hello-world-server.lisp :
  3. (in-package "CL-USER") (defclass world-implementation (HelloWorld:world-servant) ())
    (corba:define-method op:hello ((self world-implementation))
      (declare (ignore self))
      "Hello World!")
    (defun server-startup ()
      (let* ((orb (op:orb_init nil "LispWorks ORB"))
             (poa (op:resolve_initial_references orb "RootPOA"))
             (impl (make-instance 'world-implementation))
             (world (op:narrow 'HelloWorld:world
                               (op:servant_to_reference poa impl))))
        (object-to-file orb world)
        (let ((manager (op:the_poamanager poa)))
          (op:activate manager))))
  4. Add hello-world-server to the defsystem by adding one line of code to the defsys.lisp file, which should then look like this:
(in-package "CL-USER") (require "corba-orb")
(defsystem hello-world-corba-object ()
  :members (
            ("hello-world" :type :idl-file)
:rules ((:in-order-to :compile "all
         (:requires (:load :previous)))))

Developing Component Software with CORBA - 24 Feb 2006