cybertools/agent/talk
helmutm 2a7acff23b work in progress: agent.talk - client connect basically working
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3293 fd906abe-77d9-0310-91a1-e0d9ade77398
2009-03-22 17:00:09 +00:00
..
__init__.py add 'talk' package providing a common communication framework 2008-10-17 20:46:28 +00:00
base.py work in progress: agent.talk - client connect basically working 2009-03-22 16:46:09 +00:00
http.py work in progress: agent.talk - client connect basically working 2009-03-22 17:00:09 +00:00
interfaces.py work in progress: agent.talk - client connect basically working 2009-03-22 15:58:40 +00:00
README.txt work in progress: agent.talk - client connect basically working 2009-03-22 15:46:13 +00:00

================================================
Agents for Job Execution and Communication Tasks
================================================

  ($Id$)

  >>> from cybertools.agent.tests import tester


Communication Handling
======================

Communication services are provided by handlers specified in the ``talk``
package.

Set up and start an agent with a server
---------------------------------------

  >>> config = '''
  ... controller(names=['core.sample'])
  ... scheduler(name='core')
  ... logger(name='default', standard=30)
  ... talk.server(names=['http'])
  ... talk.server.http(port=8081)
  ... talk.http(handler='testing')
  ... '''
  >>> from cybertools.agent.main import setup
  >>> master = setup(config)
  Starting agent application...
  Using controllers core.sample.
  Setting up HTTP handler for port 8081.

  >>> master.servers
  [<cybertools.agent.talk.http.HttpServer object...>]

We also provide a class to be used for creating subscribers, i.e. objects
that receive messages.

  >>> class Subscriber(object):
  ...     def __init__(self, name):
  ...         self.name = name
  ...     def onMessage(self, interaction, data):
  ...         print ('%s receiving: interaction=%s, data=%s' %
  ...                       (self.name, interaction, data))
  ...         tester.stop()

  >>> serverSub = Subscriber('server')
  >>> master.servers[0].subscribe(serverSub, 'testing')

Set up a client
---------------

In order to simplify the testing we do not set up a separate agent to
work with the client but handle the client directly.

  >>> from cybertools.agent.talk.http import HttpClient
  >>> client = HttpClient(master)

  >>> clientSub = Subscriber('client')

  >>> session = client.connect(clientSub, 'http://localhost:8081/')

Run the communication dialog
----------------------------

  >>> tester.run()
  client receiving: interaction=None, data={u'status': u'OK'}


Fin de Partie
=============

  >>> tester.stopThreads()