Next Previous Up Top Contents Index

2.1 A CORBA-based Hello World

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 onop:hello that actually returns the desired string.

1. Create a file calledhello-world-server.lisp.
2. Enter the following code intohello-world-server.lisp:
(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 "Harlequin Common Lisp 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))))

3. Addhello-world-server to the defsystem by adding one line of code to thedefsys.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) "shared" "hello-world-server" "hello-world-client" ))

:rules ((:in-order-to :compile "all (:requires (:load :previous)))))

Developing Component Software with CORBA - 22 Jan 1999

Next Previous Up Top Contents Index

Generated with Harlequin WebMaker