gk::service

Locate and connect to specific facilities offered by other processes

Synopsis

gk::service provider providerName -type type -handler handler ?-registry registry? ?-name name?
gk::service subscriber subscriberName -type type ?-name name? ?-registry registry ?-host host? ?-socket socket?

Description

The gk::service command provides an interface to both providing and using services. A service collects a well-defined set of functions that can be hosted on one process and accessed from another. Service requests may be either synchronous or asynchronous.

Providing a Service

The "gk::service provider" command is used to create a new service provider. This creates a new Tcl command named "providerName", which is used to refer to the service provider. Details of this command are below. The mandatory "type" parameter is used to identify the set of requests available; all service providers of the same type should share the same set of requests. The "handler" parameter specifies a Tcl procedure which will respond to requests from subscribers to the service; this is detailed below. The optional "registry" parameter indicates that the service is to be published in the specified registry; otherwise the default registry is used. Finally, the "name" parameter specifies the name under which the service should be published; if omitted, the type is also used as the name.

The Tcl command called "providerName" is used to refer to the service. It has the following two variants:

providerName retract
providerName ?request? ?-async? request args...
The "retract" command specifies that the service is no longer available, and should be withdrawn from the registry it is published in. The second form allows the local process to make requests of the provider, without creating a separate subscriber. Because the request is local, it is inherently handled synchronously; however the -async parameter remains for syntax compatibility with the service subscriber command.

The procedure that handles requests for the service provider must accept certain parameters. The first parameter is always the name of the service provider (i.e. providerName). The second parameter is the name of the request to be made. The valid requests are dependent on the type of the provider, however all providers must handle a request named "requests" by returning the list of possible requests. Finally, other parameters (e.g. args) may be required depending on the particular request.

Subscribing to a Service

gk::service subscriber subscriberName -type type ?-name name? ?-registry registry ?-host host? ?-socket socket? The "gk::service subscriber" command provides a mechanism to locate and then subscribe to a service offered by a provider. This creates a new Tcl command called "subscriberName" which is used to access the service; this is detailed shortly. The mandatory "type" parameter is used to specify the type of service to connect to. The remaining options are used to help narrow down which of possibly many services of the given type to connect to. The "name" parameter specifies that the service should have the given name. The "registry" parameter specifies what registry to search for the service in; normally this is the default registry. The "host" parameter specifies that the service provider should reside on the given host. Finally, the "socket" parameter specifies that the service provider exists on the other end of the given socket. If no matching service provider is found, an error is returned.

The Tcl command called "subscriberName" is used to refer to the service. It has the following two variants:

subscriberName unsubscribe
subscriberName ?request? ?-async? request args...
The "unsubscribe" command indicates the caller no longer needs the service; the connection is removed and the Tcl command "subscriberName" is destroyed. The second form makes requests of the provider. By default these are synchronous requests, but this can be overridden with the "-async" flag. The "request" parameter specifies the name of the requests, with any additional parameters needed by the request following.

GroupKit Reference Manual. Last updated April 24, 1998 by Mark Roseman.