`
semi_sleep
  • 浏览: 99410 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

20090220-20090221 (Red5 Study 1)

阅读更多

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?

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics