design and implementation of a rpc library in
play

Design and implementation of a RPC library in Audebert python - PowerPoint PPT Presentation

Design and implementa- tion of a RPC library in python Rmi Design and implementation of a RPC library in Audebert python Introduction Client Service Decorators Signatures Rmi Audebert More signatures Conclusion 2014-07-18 Rmi


  1. Design and implementa- tion of a RPC library in python Rémi Design and implementation of a RPC library in Audebert python Introduction Client Service Decorators Signatures Rémi Audebert More signatures Conclusion 2014-07-18 Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 1 / 32

  2. Design and implementa- tion of a RPC library in python Rémi Audebert Introduction Client Service Decorators Introduction Signatures More signatures Conclusion Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 2 / 32

  3. Remote procedure call Design and implementa- tion of a RPC library in RPC python Services with methods Rémi Audebert Clients Introduction Request from a client to a service Client Reply from a service to a client Service Decorators Signatures More signatures Conclusion Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 3 / 32

  4. Remote procedure call Design and implementa- tion of a RPC library in RPC python Services with methods Rémi Audebert Clients Introduction Request from a client to a service Client Reply from a service to a client Service Decorators Signatures RPC system: Cellaserv2 More signatures Conclusion Based on TCP/IP Centralized server Uses protocol buffers More information: https://code.evolutek.org/cellaserv2 Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 3 / 32

  5. Register + Request + Reply Design and implementa- tion of a RPC library in python Rémi Audebert Introduction Client Service Decorators Signatures More signatures Conclusion Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 4 / 32

  6. The requierements of this library Design and implementa- tion of a RPC library in python Technical Rémi Python3 Audebert No external libraries Introduction Handle Client and Service Client Service Usage Decorators Signatures More signatures Easy to use Conclusion Hard to misuse Fail gracefully Target users: mostly sleep deprived Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 5 / 32

  7. The rush friendly requirement Design and implementa- tion of a RPC library in python Rémi Audebert Introduction Client Service Decorators Signatures More signatures Conclusion Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 6 / 32

  8. Design and implementa- tion of a RPC library in python Rémi Audebert Introduction Client Service Decorators Client Signatures More signatures Conclusion Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 7 / 32

  9. CellaservProxy Design and implementa- tion of a RPC library in Code python from cellaserv.proxy import CellaservProxy Rémi Audebert client = CellaservProxy() Introduction Client Configuration Service CellaservProxy(host="example.org", port=4242) Decorators Signatures Environnment variables: CS_HOST , CS_PORT More signatures Configuration file: /etc/conf.d/cellaserv Conclusion Usage Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 8 / 32

  10. CellaservProxy Design and implementa- tion of a RPC library in Code python from cellaserv.proxy import CellaservProxy Rémi Audebert client = CellaservProxy() Introduction Client Configuration Service CellaservProxy(host="example.org", port=4242) Decorators Signatures Environnment variables: CS_HOST , CS_PORT More signatures Configuration file: /etc/conf.d/cellaserv Conclusion Usage now = client.time.date() Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 8 / 32

  11. Implementation Design and implementa- tion of a RPC library in python Usage Rémi Audebert client.time.date() Introduction Client cellaserv/proxy.py Service class CellaservProxy(cellaserv.client.SynClient): Decorators Signatures ... More signatures def __getattr__(self, service_name): Conclusion return ServiceProxy(self.conn, service_name) Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 9 / 32

  12. Implementation Design and implementa- tion of a RPC library in python Usage Rémi Audebert client.time.date() Introduction Client cellaserv/proxy.py Service class CellaservProxy(cellaserv.client.SynClient): Decorators Signatures ... More signatures def __getattr__(self, "time"): Conclusion return ServiceProxy(self.conn, "time") Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 10 / 32

  13. client.time.date() Design and implementa- tion of a RPC library in python Rémi Audebert Introduction Client Service Decorators Signatures More signatures Conclusion Figure 1: Execution Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 11 / 32

  14. Design and implementa- tion of a RPC library in python Rémi Audebert Introduction Client Service Decorators Service Signatures More signatures Conclusion Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 12 / 32

  15. Design and implementa- tion of a RPC library in python Rémi Audebert Introduction Client Service Decorators Decorators Signatures More signatures Conclusion Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 13 / 32

  16. Service ’s design Design and implementa- tion of a RPC library in python Simple usage Rémi import time Audebert from cellaserv.service import Service Introduction Client class Time(Service): Service Decorators @Service.action Signatures More signatures def date(self): Conclusion return time.time() Time().run() Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 14 / 32

  17. Python’s feature: decorators Design and implementa- tion of a RPC Simple usage library in python >>> def log_usage(f): Rémi Audebert ... def wrap(*args, **kwargs): ... print("{} called".format(f)) Introduction Client ... return f(*args, **kwargs) Service ... return wrap Decorators ... Signatures More signatures >>> my_len = log_usage(len) Conclusion >>> my_len([42]) <built-in function len> called 1 Note: this decorator should use @functools.wraps(f) . Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 15 / 32

  18. Service ’s design Design and implementa- tion of a RPC library in python Rémi Audebert Advanced usage Introduction class Date(Service): Client @Service.action("heure") Service @Service.action("time_" + get_timezone()) Decorators Signatures def time(self): More signatures return time.time() Conclusion Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 16 / 32

  19. Function decorator: caution Design and implementa- tion of a RPC library in python What is the difference between: Rémi Name of the method is name of the function Audebert @Service.action Introduction def action1(self): Client pass Service Decorators Signatures More signatures Name of the method is given by the user Conclusion @Service.action("action_name") def action2(self): pass Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 17 / 32

  20. Function decorator: caution Design and implementa- tion of a RPC library in python Rémi Audebert Name of the method is name of the function Introduction action1 = Service.action(action1) Client Service Decorators Name of the method is given by the user Signatures More signatures action2 = Service.action("action_name")(action2) Conclusion Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 18 / 32

  21. Python’s feature: decorators Design and class Service: implementa- tion of a RPC @staticmethod library in python def action(method_or_name): def _set_action(method, action): Rémi Audebert try : method._actions.append(action) Introduction except AttributeError: Client method._actions = [action] Service Decorators return method Signatures More signatures def _wrapper(method): Conclusion return _set_action(method, method_or_name) if callable(method_or_name): return _set_action(method_or_name, method_or_name.__name__) else : return _wrapper Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 19 / 32

  22. Design and implementa- tion of a RPC library in python Rémi Audebert Introduction Client Service Signatures Decorators Signatures More signatures Conclusion Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 20 / 32

  23. Dealing with TypeError Design and We want to emit a warning when the user send a request with implementa- tion of a RPC bad arguments. library in python Rémi Audebert Introduction Client Service Decorators Signatures More signatures Conclusion Rémi Audebert Design and implementation of a RPC library in python 2014-07-18 21 / 32

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend