Module Service

This module defines classes encapsulating service descriptions. A service defines how an established client request should be handled. When a connection is accepted (usually by a listener, see the Listener module), the service bound to the given Listener is requested the create an instance of itself (using the startInstance() method, see below), which will handle the connection and takes care about proxying traffic between the client and the server.

Services are uniquely identified by their name, this name is then used as a reference to bind services to listeners. This name resolution is done through the mapping named "services" below. As a new service instance is created, it's name is registered in this hash.

The abstract interface a Service object is required to support is defined in AbstractService, customized service classes can be derived from this base class.

Imported modules

Class AbstractService

This is an abstract class defining the interface Zorp uses, and as such it doesn't really do anything other than raising NotImplementedError exceptions in its methods. You should either derive a descendant from AbstractService, or use Service instead.

Attributes

Table 4-95. Attributes for class AbstractService

name The name of the service
instance_idthe session serviced by the service

Constructor __init__

Initialize an AbstractService or a derived class instance.

Synopsis

__init__ ( self,  name )

Description

Sets attributes based on arguments, and registers this Service to the "services" hash so that Listeners may resolve service names to service instances.

Arguments

Table 4-96. Arguments for AbstractService.__init__()

self this instance
nameThe name of the service

Exceptions

  • ServiceException

Method __str__

Function to represent this object as a string

Synopsis

__str__ ( self )

Description

This function is called by the Python core when this object is used as-, or casted to a string. It simply returns the service name.

Arguments

Table 4-97. Arguments for AbstractService.__str__()

selfthis instance

Method startInstance

Function to start an instance of this service.

Synopsis

startInstance ( self,  session )

Description

Abstract method to be implemented in derived classes. Should start an instance of the given service. A service instance takes care of the client connection, connects to the server and supervises the traffic going in either direction.

Tasks of a service instance are implemented by classes derived from Proxy.

This method unconditionally raises a NotImplementedError exception to indicate that it must be overridden by descendant classes like Service.

Arguments

Table 4-98. Arguments for AbstractService.startInstance()

self this instance
sessionstart service within this session

Exceptions

  • NotImplementedError

Method stopInstance

Function called when an instance of this service is ended

Synopsis

stopInstance ( self,  session )

Description

This function is called by Session.__del__ and indicates that a given session (instance) of this service is ended.

Arguments

Table 4-99. Arguments for AbstractService.stopInstance()

selfthis instance
sessionending session

Exceptions

  • NotImplementedError

Class Service

This service class uses the standard Zorp provided Proxy class to implement the tasks required by a Service instance.

Attributes

Table 4-100. Attributes for class Service

chainer The chainer class used for the service
proxy_class The proxy class used for the service
auth Authentication handling class (None if no authentication)

Constructor __init__

Initializes a Service instance.

Synopsis

__init__ (
        self,
        name,
        chainer,
        proxy_class,
        auth=None,
        max_instances=0,
        )

Description

This function takes its arguments, and initializes appropriate attributes in self.

Arguments

Table 4-101. Arguments for Service.__init__()

self this instance
name Name of this service (used in access control)
chainer The chainer class used for the service

proxy_class-- The proxy class used for the service

Table 4-102. Arguments for Service.__init__()

auth Authentication handling class (None if no authentication)

Method startInstance

Start a service instance.

Synopsis

startInstance ( self,  session )

Description

Called by the Listener to create an instance of this service.

Arguments

Table 4-103. Arguments for Service.startInstance()

self this instance
sessionThe session object

Exceptions

  • LimitException

Method stopInstance

Synopsis

stopInstance ( self,  session )