Ryu application API原文加翻译(一)

本文介绍了Ryu应用编程模型的基础概念,包括线程、事件和事件队列的工作原理。详细解释了如何创建Ryu应用、如何观察及生成事件,并讨论了在Ryu应用中使用上下文的注意事项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Ryu application API

Ryu application programming model  Ryu应用编程模型

Threads, events, and event queues     线程、事件和事件队列

Ryu applications are single-threaded entities which implement various functionalities in Ryu. Events are messages between them.Ryu应用时单线程实体它在Ryu中继承各种功能,事件是信息在他们两个之间。

Ryu applications send asynchronous events to each other.Besides that, there are some Ryu-internal event sources which are not Ryu applications. One of examples of such event sourcesis OpenFlow controller.While an event can currently contain arbitrary python objects,it's discouraged to pass complex objects (eg. unpickleable objects)between Ryu applications.Ryu应用互相发送异步消息事件,除此以外,那有一些RYu内部事件资源那不是Ryu应用。OpenFlow控制器就是事件资源之一。

Each Ryu application has a receive queue for events.The queue is FIFO and preserves the order of events.Each Ryu application has a thread for event processing.The thread keeps draining the receive queue by dequeueing an event and calling the appropritate event handler for the event type.Because the event handler is called in the context ofthe event processing thread, it should be careful when blocking.While an event handler is blocked, no further events forthe Ryu application will be processed. 每一个RYu应用有一个接收事件的队列。这个队列是FIFO(先进先出)和保护队列的有序性。每一个Ryu应用有一个线程对应事件进程。这个线程保持接收队列通过获取一个事件和调用适合的事件处理器根据事件类型。因为事件处理器在事件线程的上下文中被调用,当被阻塞时应该小心。当一个事件处理器被阻塞,下一步的事件将不会处理。

There are kinds of events which are used to implement synchronousinter-application calls between Ryu applications.While such requests uses the same machinary as ordinary events, their replies are put on a queue dedicated to the transaction to avoid deadlock. 有各种各样的事件他们经常被用来实现同步交互应用在Ryu应用之间调用。虽然这样的请求使用一些机器作为普通事件,他们的reply放在专用于事务的队列避免死锁

While threads and queues is currently implemented with eventlet/greenlet,a direct use of them in a Ryu application is strongly discouraged.虽然线程和队列普片的实现和eventet/greenlet,直接使用他们在Ryu应用中被强烈的禁止。

Contexts(上下文)

Contexts are ordinary python objects shared among Ryu applications.The use of contexts are discouraged for new code.上下文是普通的Python对象在众多Ryu应用中被共享。使用上下文获取新的代码被禁止。

Create a Ryu application(创建Ryu应用)

A Ryu application is a python module which defines a subclass of ryu.base.app_manager.RyuApp.If two or more such classes are defined in a module, the first one(by name order) will be picked by app_manager.Ryu application is singleton: only single instance of a given Ryuapplication is supported. 一个Ryu应用是一个Python组件,是ryu.base.app_manager.RyuApp的子类,如果两个或者更多这样的类被定义为一个组件,第一个(通过姓名排序)将被app_manager采用。Ryu应用是一个:仅支持某个应用程序的单个实例。

Observe events(观察事件)

A Ryu application can register itself to listen for specific events using ryu.controller.handler.set_ev_cls decorator.

一个Ryu应用可以注册自己来监听特定事件使用ryu.controller.handler.set_ev_cls装饰器

Generate events(产生事件)

A Ryu application can raise events by calling appropriate ryu.base.app_manager.RyuApp's methods like send_event or send_event_to_observers.一个Ryu应用可以产生事件通过调用合适的ryu.base.app_manager.RyuApp's 方法像send_event或者是send_event_to_observers.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值