20090220-20090221 (Red5 Study 1)

本文详细介绍了Red5服务器的核心组件及工作原理,包括IScope、ApplicationAdapter、IConnection等关键对象的功能与交互方式。探讨了资源访问、客户端连接管理、数据同步及持久化的实现机制。

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

IScope: A statefull object shared between a group of clients connected to the same context path. Scopes are arranged in hierarchical way, so its possible for a scope to have a parent and children scopes.If a client connects to a scope then they are also connected to its parent scope. The scope object is used to access resources, shared object, streams, etc. That is, scope are general option for grouping things in application. The following are all names for scopes: application, room, place, lobby.


ApplicationAdapter: The app* methods are called for the main application, the room* methods are called for
rooms (i.e. instances) of the application. (subsequentail call will only trigger connect, not join, so join is bigger)
Assuming you connect to rtmp://server/app/room1/room2
First connection:
1. app (-> appConnect)
2. room1 (-> roomConnect)
3. room2 (-> roomConnect)
After first connection:
1. app (-> appJoin)
2. room1 (-> roomJoin)
3. room2 (-> roomJoin)
matrix start/stop connect/disconnection join/leave
app ...  ...   ...
room ...  ...   ...
For start/connection/join, return true if success, false otherwise.
rejectClient methods can be called to reject a currently connecting client, different between start/connection/join return false?


IConnection: Each connection has an associated client and scope.
Current connection is retrieved through: 1. Red5.getConnectionLocal(); 2. when "public XXX xxx(IConnection conn, ...)" is called by client.


Client call server's methods: (methods inside application adapter is automatically callable from client?) Register an object (can be any type) as a handler using the following 2 ways:
1.<bean id="sample.service" class="com.fancycode.red5.HandlerSample" singleton="true" />
Note that "service" is a keyword, client codes only need to refer to "sample". This will apply to all scope.
2.Iscope(IServiceHandlerProvider).registerServiceHandler("sample", handler), note that this will override the spring config for chosen scope, and should  consider putting it in either appStart/roomStart to choose correct scope.


Server call client's methods: if IConnection is IServiceCapableConnection, use the invoke method, pass a IPendingServiceCallback if you need a method call result.


ISharedObject:
Create/retrieve: use ApplicationAdapter.createSharedObject/getSharedObject. Create it in appStart/Connect or roomStart/Connect.
Data synchronization: use ISharedObject.setAttribute to update data, use ISharedObject.beginUpdate/endUpdate to issue a batch update, use ISharedObject.addSharedObjectListener(ISharedObjectListener) to get informed by update.
Method call: use ISharedObject.registerServiceHandler or <bean id="sampleSO.one.two.soservice" class="com.fancycode.red5.MySharedObjectHandler" /> ("soservice" is keyword, and the shared object will be created in all scope?) to register a service, use ISharedObject.sendMessage to invoke service.


Persistence:
IPersistable: Basically these objects have a type, a path, a name (all strings) and know how to serialize and deserialize themselves.
IPersistenceStore: Used to save and load IPersistable to somewhere. For FilePersistence implementation, a file is created in "webapps/<app>/persistence/<type>/<path>/<name>.red5", e.g. for a shared object "theSO" in the connection to "rtmp://server/myApp/room1" a file at
"webapps/myApp/persistence/SharedObject/room1/theSO.red5" would be created.
To make a object persitable, either put it in IScope through IAttributeStore's method, because IScope implements IPersistable, it will be load/save by server automatically, or find the global IPersistenceStore used by the server, using IScope.getStore(), to load/save object manually.


Scheduling: includes ISchedulingService and IScheduledJob, as ApplicationAdapter already implements ISchedulingService, all you have to do is just implement IScheduledJob, add it to ApplicationAdapter and store the job id somewhere (in a IScope maybe) so that you can manage it from ApplicationAdapter later.


Stream file name:
IStreamFilenameGenerator: implement this class to decide the file path to save in server, use <bean id="streamFilenameGenerator" class="..." /> (use IStreamFilenameGenerator.BEAN_NAME as bean id).
Flash client: the NetStream.play/publish method accept a file name, which will be used to resolve to actual path in server.

 

 


Compare ApplicationAdapter with Servlet?


ApplicationAdapter/IConnection/IXXXHandler design pattern?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值