2013-04-30 06:49:56 +01:00
|
|
|
|
|
|
|
# Copyright 2013 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
|
|
|
|
import abc
|
|
|
|
|
|
|
|
|
|
|
|
class Listener(object):
|
|
|
|
|
|
|
|
__metaclass__ = abc.ABCMeta
|
|
|
|
|
2013-05-06 20:54:12 +02:00
|
|
|
def __init__(self, driver, target):
|
|
|
|
self.driver = driver
|
2013-04-30 06:49:56 +01:00
|
|
|
self.target = target
|
|
|
|
|
|
|
|
@abc.abstractmethod
|
|
|
|
def poll(self):
|
2013-05-13 07:46:34 +01:00
|
|
|
# returns (ctxt, message)
|
2013-04-30 06:49:56 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
@abc.abstractmethod
|
2013-05-13 07:46:34 +01:00
|
|
|
def done(self, ctxt, message):
|
2013-04-30 06:49:56 +01:00
|
|
|
# so the transport can ack the message
|
|
|
|
pass
|
|
|
|
|
2013-05-11 13:19:59 +01:00
|
|
|
@abc.abstractmethod
|
2013-05-13 07:46:34 +01:00
|
|
|
def reply(self, ctxt, reply=None, failure=None):
|
2013-05-11 13:19:59 +01:00
|
|
|
pass
|
|
|
|
|
2013-04-30 06:49:56 +01:00
|
|
|
|
|
|
|
class BaseDriver(object):
|
|
|
|
|
|
|
|
__metaclass__ = abc.ABCMeta
|
|
|
|
|
|
|
|
def __init__(self, conf, url=None, default_exchange=None):
|
|
|
|
self.conf = conf
|
|
|
|
self._url = url
|
2013-05-11 16:22:37 +01:00
|
|
|
self._default_exchange = default_exchange
|
2013-04-30 06:49:56 +01:00
|
|
|
|
|
|
|
@abc.abstractmethod
|
2013-05-13 07:46:34 +01:00
|
|
|
def send(self, target, ctxt, message, wait_for_reply=None, timeout=None):
|
2013-04-30 06:49:56 +01:00
|
|
|
"""Send a message to the given target."""
|
|
|
|
return None
|
|
|
|
|
|
|
|
@abc.abstractmethod
|
2013-05-06 15:29:37 -04:00
|
|
|
def listen(self, target):
|
2013-04-30 06:49:56 +01:00
|
|
|
"""Construct a Listener for the given target."""
|
|
|
|
return None
|