The QAM Server executes remote method calls received from a QAMProxy.
The QAMServer consists of the following classes:
The QAMServer consists of the following Exceptions:
An example-usage of the QAMServer. The code shows how to register a function.
>>> from qam.qam_server import QAMServer
>>> qam_server = QAMServer(hostname="localhost",
... port=5672,
... username='guest',
... password='guest',
... vhost='/',
... server_id='qamserver')
...
>>> def adder_function(x, y):
... return x + y
...
>>> qam_server.register_function(adder_function, 'add')
...
... # it is also possible to register the adder_function as follows:
... # qam_server.register_function(adder_function)
... # the method-name for registering in this case is adder_function.__name__
...
>>> qam_server.serve()
An example-usage of the QAMServer. The code shows how to register class-instance.
>>> from qam.qam_server import QAMServer
>>> qam_server = QAMServer(hostname="localhost",
... port=5672,
... username='guest',
... password='guest',
... vhost='/',
... server_id='qamserver')
...
>>> class TestClass():
... def __init__(self):
... pass
... def adder_function(self,a,b):
... return a+b
...
>>> testclass = TestClass()
>>> qam_server.register_class(testclass,'testclass')
>>> qam_server.serve()
The role of the ExecuteMethodThread is calling defined methods and creating messages out of the results, which could be send. Messages are stored in the a queue (result_queue) for further processing.
Parameters: |
|
---|
Class-variables of ExecuteMethodThread:
The run-method takes messages, and processes them. Content of a message is a simple method call, or a method-call of a given instance. For calling the method, it is necessary, that the message is registered on the QAMServer. A method-call of a non-registered method or instance.method throws an exception. The result of the call is packed into a message and stored in a queue (result_queue).
Internal QAMServer Exception, which is thrown, if a non-registered method is being called.
The PublisherThread sends given messages from a queue back to the caller proxy.
Parameters: |
|
---|
Class-variables of PublisherThread:
The PublisherThread is being stopped (kill-signal is set to True)
Messages from the given queue (result_queue) are sent back to a specified amqp-queue.
The QAMServer class provides the basic functions for registering methods and class-instances which could be executed and called by the server. Further the QAMServer receives messages (remote-method-calls) from an amqp-queue and passes them to a thread, which executes the remote-method-calls.
Parameters: |
|
---|
Class-variables of QAMServer:
The consumer, the publisher and the amqp-connection are being closed. The serve-function terminates (kill-signal is set to True).
Class-instances which should be available for calling, are registered with this function. Each class-instance is being stored in a dictionary (instance_dict), where the key is the name given and the value is the instance itself. No methods for this instance are stored because they could be reached with the function getattr for any given class.
Parameters: |
|
---|
Methods that should be available on the server for calling, are registered with this function. Each method is being stored in a dictionary (method_dict), where the name of the method is the key, and the value is the method itself.
Parameters: |
|
---|
The serve-function fetches messages (method-calls) from the amqp-queue. Each message is being executed by the ExecuteMethodThread, who calls the function and returns the result.