Download Ciao Manual - The Ciao System

Transcript
598
The Ciao System
The third one is based on a name server for active modules. When an active module is
started, it communicates its address to the name server. When the client of the active module
wants to communicate with it, it asks the name server the active module address. This is all
done transparently to the user. The name server must be running when the active module is
started (and, of course, when the application using it is executed). The location of the name
server for an application must be specified in an application file named webbased_common.pl
(see Section 3.1 below).
The fourth one is also based on a name server, but the address of the name server is given
as a parameter to the active modules when started.
The rendezvous methods (or protocols) are encoded in two modules: a first one, called
...publish.pl, is used by the server to publish its info. The second one, called ...locate.pl,
is used by the client(s) to locate the server info. For efficiency, the client methods maintain a
cache of addresses, so that the server information only needs to be read from the file system the
first time the active module is accessed.
Active modules are compiled using the -a option of the Ciao compiler (this can also be done
from the interactive top-level shell using make_actmod/2). For example, issuing the following
command:
ciaoc -a ’actmods/filebased_publish’ simple_server
compiles the simple server example that comes with the distribution (in the actmods/example
directory). The simple_client_with_main example (in the same directory) can be compiled
as usual:
ciaoc simple_client_with_main
Note that the client uses the actmods package, specifies the rendezvous method by importing library(actmods(filebased_locate)), and explicitely imports the “remote” predicates
(implicit imports will not work ). Each module using the actmods package should only use one
of the rendezvous methods.
Now, if the server is running (e.g., simple_server & in Un*x or double-clicking on it in
Win32) when the client is executed it will connect with the server to access the predicate(s) that
it imports from it.
A simpler even client simple_client.pl can be loaded into the top level and its predicates
called as usual (and they will connect with the server if it is running).
112.1 Active modules as agents
It is rather easy to turn Ciao active modules into agents for some kind of applications. The
directory examples/agents contains a (hopefully) self-explanatory example.
112.2 Usage and interface (actmods_doc)
• Library usage:
:- use_package(actmods).
or
:- module(...,...,[actmods]).
• New declarations defined:
use_active_module/2.