work in progress: talk package for generic data communication tasks
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2925 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
9a6d66dfea
commit
3baf1fabb5
3 changed files with 87 additions and 32 deletions
47
agent/talk/base.py
Normal file
47
agent/talk/base.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
#
|
||||
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
"""
|
||||
Handling asynchronous communication tasks - common and base classes.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
||||
from zope.interface import implements
|
||||
|
||||
from cybertools.agent.talk.interfaces import ISession, IInteraction
|
||||
|
||||
|
||||
class Session(object):
|
||||
|
||||
implements(ISession)
|
||||
|
||||
def __init__(self, manager):
|
||||
self.manager = manager
|
||||
self.interactions = {}
|
||||
|
||||
|
||||
class Interaction(object):
|
||||
|
||||
implements(IInteraction)
|
||||
|
||||
finished = False
|
||||
|
||||
def __init__(self, session):
|
||||
self.session = session
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
#
|
||||
|
||||
"""
|
||||
Handling asynchronous and possibly asymmetric communication tasks.
|
||||
Handling asynchronous and possibly asymmetric communication tasks via HTTP.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
@ -30,8 +30,38 @@ from zope.interface import implements
|
|||
from cybertools.agent.base.agent import Master
|
||||
from cybertools.agent.components import servers, clients
|
||||
from cybertools.agent.system.http import listener
|
||||
from cybertools.agent.talk.base import Session, Interaction
|
||||
from cybertools.agent.talk.interfaces import IServer, IClient
|
||||
from cybertools.agent.talk.interfaces import ISession, IInteraction
|
||||
|
||||
|
||||
# server implementation
|
||||
|
||||
class HttpServer(object):
|
||||
|
||||
implements(IServer)
|
||||
|
||||
def __init__(self, agent):
|
||||
self.agent = agent
|
||||
self.port = agent.config.talk.server.http.port
|
||||
self.subscribers = {}
|
||||
self.sessions = {}
|
||||
self.site = Site(RootResource())
|
||||
|
||||
def setup(self):
|
||||
print 'Setting up HTTP handler for port %i.' % self.port
|
||||
listener.listenTCP(self.port, self.site)
|
||||
|
||||
def subscribe(self, subscriber, aspect):
|
||||
pass
|
||||
|
||||
def unsubscribe(self, subscriber, aspect):
|
||||
pass
|
||||
|
||||
def send(self, session, data, interaction=None):
|
||||
# respond to open poll request or put in queue
|
||||
return defer.Deferred() # Interaction
|
||||
|
||||
servers.register(HttpServer, Master, name='http')
|
||||
|
||||
|
||||
class RootResource(Resource):
|
||||
|
@ -46,33 +76,11 @@ class CommandHandler(Resource):
|
|||
self.command = path
|
||||
|
||||
def render(self, request):
|
||||
#
|
||||
return '{"message": "OK"}'
|
||||
|
||||
|
||||
class HttpServer(object):
|
||||
|
||||
implements(IServer)
|
||||
|
||||
def __init__(self, agent):
|
||||
self.agent = agent
|
||||
self.port = agent.config.talk.server.http.port
|
||||
self.subscribers = {}
|
||||
|
||||
def setup(self):
|
||||
print 'Setting up HTTP handler for port %i.' % self.port
|
||||
listener.listenTCP(self.port, Site(RootResource()))
|
||||
|
||||
def subscribe(self, subscriber, aspect):
|
||||
pass
|
||||
|
||||
def unsubscribe(self, subscriber, aspect):
|
||||
pass
|
||||
|
||||
def send(self, client, data, interaction=None):
|
||||
return defer.Deferred() # Interaction
|
||||
|
||||
servers.register(HttpServer, Master, name='http')
|
||||
|
||||
# client implementation
|
||||
|
||||
class HttpClient(object):
|
||||
|
||||
|
@ -81,10 +89,10 @@ class HttpClient(object):
|
|||
def __init__(self, agent):
|
||||
self.agent = agent
|
||||
|
||||
def logon(self, subscriber, url):
|
||||
def connect(self, subscriber, url, credentials=None):
|
||||
return defer.Deferred() # Session
|
||||
|
||||
def logoff(self, session):
|
||||
def disconnect(self, session):
|
||||
pass
|
||||
|
||||
def send(self, session, data, interaction=None):
|
||||
|
|
|
@ -57,7 +57,7 @@ class IClient(Interface):
|
|||
sent data to or receive data from the server.
|
||||
"""
|
||||
|
||||
def logon(subscriber, url, credentials=None):
|
||||
def connect(subscriber, url, credentials=None):
|
||||
""" Connect to a server using the URL given, optionally logging in
|
||||
with the credentials given.
|
||||
|
||||
|
@ -67,7 +67,7 @@ class IClient(Interface):
|
|||
this may then be used sending data to the server.
|
||||
"""
|
||||
|
||||
def logoff(session):
|
||||
def disconnect(session):
|
||||
""" Close the connection for the session given.
|
||||
"""
|
||||
|
||||
|
@ -97,8 +97,8 @@ class ISession(Interface):
|
|||
a remote client connection within a server.
|
||||
"""
|
||||
|
||||
issuer = Attribute("""The issuer of the session, i.e. the server or
|
||||
client object, respectively.""")
|
||||
manager = Attribute("""The server or client object, respectively, that
|
||||
created the session.""")
|
||||
|
||||
state = Attribute("""A string specifying the current state of the session:
|
||||
'logon': The remote client is trying to connect/log in,
|
||||
|
|
Loading…
Add table
Reference in a new issue