<< Prev | - Up - | Next >> |
An example application is where the service is a shared registry. A client can connect to the registry server and add or lookup an entry. The registry is simply a dictionary.
db-server.oz
The registry server is compiled as follows:
ozc -x db-server.oz -o db-server.exe
and can be started with the command line:
db-server.exe --ticketfile
file
Initially, it has an empty registry.
functor
import
Server at 'server.ozf'
Application
define
class Registry
feat db
meth init {Dictionary.new self.db} end
meth put(Key Val) {Dictionary.put self.db Key Val} end
meth get(Key Val) {Dictionary.get self.db Key Val} end
meth condGet(Key Default Val)
{Dictionary.condGet self.db Key Default Val}
end
end
DB = {New Registry init}
Args = {Application.getCmdArgs
record(
ticketfile(single char:&t type:string optional:false))}
{Server.start DB Args.ticketfile}
end
db-client.oz
The client loads the pickled ticket from the given URL and uses it to obtain from the server the forwarding procedure. The client can be compiled as follows:
ozc -x db-client.oz -o db-client.exe
and can be invoked in one of two ways:
db-client.exe --url=
URL--get=
KEYURL
db-client.exe --url=--put=
KEYVAL
The first form retrieves a entry from the registry and displays it on standard output. The second form stores an entry in the registry.
functor
import
Application Connection System Pickle
define
Args = {Application.getCmdArgs
record(
url(single type:string optional:false)
get(single type:atom)
put(single type:atom))}
DB = {Connection.take {Pickle.load Args.url}}
if {HasFeature Args get} then
{System.showInfo {DB get(Args.get $)}}
elseif {HasFeature Args put} then
case Args.1 of [Value] then
{DB put(Args.put Value)}
else
{System.showError 'Missing value argument'}
{Application.exit 1}
end
else
{System.showError 'One of --get or --put is required'}
{Application.exit 1}
end
{Application.exit 0}
end
<< Prev | - Up - | Next >> |