def __init__(self, local_address, ns_address, server_type, db_file): """Initialize the client.""" orb.Peer.__init__(self, local_address, ns_address, server_type) self.peer_list = PeerList(self) self.distributed_lock = DistributedLock(self, self.peer_list) self.drwlock = DistributedReadWriteLock(self.distributed_lock) self.db = database.Database(db_file) self.dispatched_calls = { "display_peers": self.peer_list.display_peers, "acquire": self.distributed_lock.acquire, "release": self.distributed_lock.release, "request_token": self.distributed_lock.request_token, "obtain_token": self.distributed_lock.obtain_token, "display_status": self.distributed_lock.display_status } orb.Peer.start(self) self.peer_list.initialize() self.distributed_lock.initialize()
""" Simple Database Server Driver Team 3 Jack Andersen """ # Server consists of a database component and web interface component from Server import database, web_interface # Database adapter db_instance = database.Database('simple.db') def method_handler(parameters): """ Adapt HTTP request into database RPC :param parameters: JSON-format dict with "method" selecting action and additional parameters :return: JSON-format result """ mname = parameters["method"] if not hasattr(db_instance, mname): return {"result", "invalid_method"} method = getattr(db_instance, mname) return method({k: v for k, v in parameters.items() if k != "method"}) # Serve HTTP RPC web_instance = web_interface.WebInterface(8080, method_handler) web_instance.serve_forever()