|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.red5.server.adapter.AbstractScopeAdapter
org.red5.server.adapter.StatefulScopeWrappingAdapter
org.red5.server.adapter.MultiThreadedApplicationAdapter
public class MultiThreadedApplicationAdapter
ApplicationAdapter class serves as a base class for your Red5 applications.
It provides methods to work with SharedObjects and streams, as well as
connections and scheduling services.
ApplicationAdapter is an application level IScope. To handle streaming
processes in your application you should implement
IStreamAwareScopeHandler interface and implement handling methods.
Application adapter provides you with useful event handlers that can be used to intercept streams,
authorize users, etc. Also, all methods added in subclasses can be called from client side with NetConnection.call
method. Unlike to Flash Media server which requires you to keep methods on Client object at server side, Red5
offers much more convenient way to add methods for remote invocation to your applications.
EXAMPLE:
public List
// Implementation goes here, say, use Red5 object to obtain scope and all it's streams
}
This method added to ApplicationAdapter sublass can be called from client side with the following code:
var nc:NetConnection = new NetConnection();
nc.connect(...);
nc.call("getLiveStreams", resultHandlerObj);
If you want to build a server-side framework this is a place to start and wrap it around ApplicationAdapter subclass.
| Field Summary | |
|---|---|
protected static org.slf4j.Logger |
log
Logger object |
protected ISchedulingService |
schedulingService
Scheduling service. |
| Fields inherited from class org.red5.server.adapter.StatefulScopeWrappingAdapter |
|---|
scope |
| Fields inherited from interface org.red5.server.api.so.ISharedObjectService |
|---|
BEAN_NAME |
| Fields inherited from interface org.red5.server.api.stream.IBroadcastStreamService |
|---|
BROADCAST_STREAM_SERVICE |
| Fields inherited from interface org.red5.server.api.stream.IOnDemandStreamService |
|---|
BEAN_NAME |
| Fields inherited from interface org.red5.server.api.stream.ISubscriberStreamService |
|---|
BEAN_NAME |
| Fields inherited from interface org.red5.server.api.scheduling.ISchedulingService |
|---|
BEAN_NAME |
| Fields inherited from interface org.red5.server.api.stream.IStreamSecurityService |
|---|
BEAN_NAME |
| Fields inherited from interface org.red5.server.api.so.ISharedObjectSecurityService |
|---|
BEAN_NAME |
| Constructor Summary | |
|---|---|
MultiThreadedApplicationAdapter()
|
|
| Method Summary | |
|---|---|
void |
addListener(IApplication listener)
Register listener that will get notified about application events. |
String |
addScheduledJob(int interval,
IScheduledJob job)
Wrapper around ISchedulingService, adds a scheduled job to be run periodically. |
String |
addScheduledJobAfterDelay(int interval,
IScheduledJob job,
int delay)
Adds a scheduled job which starts after the specified delay period and fires periodically. |
String |
addScheduledOnceJob(Date date,
IScheduledJob job)
Adds a scheduled job that's gonna be executed once on given date. |
String |
addScheduledOnceJob(long timeDelta,
IScheduledJob job)
Adds a scheduled job that's gonna be executed once. |
boolean |
appConnect(IConnection conn,
Object[] params)
Handler method. |
void |
appDisconnect(IConnection conn)
Handler method. |
boolean |
appJoin(IClient client,
IScope app)
|
void |
appLeave(IClient client,
IScope app)
Handler method. |
boolean |
appStart(IScope app)
Called once on scope (that is, application or application room) start. |
void |
appStop(IScope app)
Handler method. |
void |
cancelGhostConnectionsCleanup()
Cancel ghost connections cleanup period |
boolean |
clearSharedObjects(IScope scope,
String name)
Deletes persistent shared objects specified by name and clears all properties from active shared objects (persistent and nonpersistent). |
boolean |
connect(IConnection conn,
IScope scope,
Object[] params)
Returns connection result for given scope and parameters. |
boolean |
createSharedObject(IScope scope,
String name,
boolean persistent)
Creates a new shared object for given scope. |
void |
disconnect(IConnection conn,
IScope scope)
Returns disconnection result for given scope and parameters. |
void |
FCPublish(String streamName)
Notification method that is sent by FME just before publishing starts. |
void |
FCUnpublish()
Notification method that is sent by FME when publishing of a stream ends. |
IBroadcastStream |
getBroadcastStream(IScope scope,
String name)
Get a broadcast stream by name |
List<String> |
getBroadcastStreamNames(IScope scope)
Returns list of stream names broadcasted in |
long |
getClientTTL()
Client time to live is max allowed connection ping return time in seconds |
int |
getGhostConnsCleanupPeriod()
Return period of ghost connections cleanup task call |
Set<IApplication> |
getListeners()
Return handlers that get notified about application events. |
IOnDemandStream |
getOnDemandStream(IScope scope,
String name)
Returns VOD stream with given name from specified scope. |
List<String> |
getScheduledJobNames()
Retuns list of scheduled job names |
ISharedObject |
getSharedObject(IScope scope,
String name)
Returns shared object from given scope by name. |
ISharedObject |
getSharedObject(IScope scope,
String name,
boolean persistent)
Returns shared object from given scope by name. |
Set<String> |
getSharedObjectNames(IScope scope)
Returns available SharedObject names as List |
Set<ISharedObjectSecurity> |
getSharedObjectSecurity()
Get handlers that protect shared objects. |
double |
getStreamLength(String name)
Returns stream length. |
Set<IStreamPlaybackSecurity> |
getStreamPlaybackSecurity()
Get handlers that protect stream plaback. |
Set<IStreamPublishSecurity> |
getStreamPublishSecurity()
Get handlers that protect stream publishing. |
ISubscriberStream |
getSubscriberStream(IScope scope,
String name)
Returns subscriber stream with given name from specified scope. |
boolean |
hasBroadcastStream(IScope scope,
String name)
Does the scope have a broadcast stream registered with a given name |
boolean |
hasOnDemandStream(IScope scope,
String name)
Check whether scope has VOD stream with given name or not |
boolean |
hasSharedObject(IScope scope,
String name)
Checks whether there's a SO with given scope and name |
boolean |
join(IClient client,
IScope scope)
Adds client to scope. |
protected void |
killGhostConnections()
Cleans up ghost connections |
void |
leave(IClient client,
IScope scope)
Disconnects client from scope. |
void |
measureBandwidth()
Try to measure bandwidth of current connection. |
void |
measureBandwidth(IConnection conn)
Try to measure bandwidth of given connection. |
void |
registerSharedObjectSecurity(ISharedObjectSecurity handler)
Add handler that protects shared objects. |
void |
registerStreamPlaybackSecurity(IStreamPlaybackSecurity handler)
Add handler that protects stream playback. |
void |
registerStreamPublishSecurity(IStreamPublishSecurity handler)
Add handler that protects stream publishing. |
protected boolean |
rejectClient()
Reject the currently connecting client without a special error message. |
protected boolean |
rejectClient(Object reason)
Reject the currently connecting client with an error message. |
void |
removeListener(IApplication listener)
Unregister handler that will not get notified about application events any longer. |
void |
removeScheduledJob(String name)
Removes scheduled job from scheduling service list |
boolean |
roomConnect(IConnection conn,
Object[] params)
Handler method. |
void |
roomDisconnect(IConnection conn)
Handler method. |
boolean |
roomJoin(IClient client,
IScope room)
|
void |
roomLeave(IClient client,
IScope room)
Handler method. |
boolean |
roomStart(IScope room)
Handler method. |
void |
roomStop(IScope room)
Handler method. |
void |
scheduleGhostConnectionsCleanup()
Schedules new ghost connections cleanup using current cleanup period |
void |
setClientTTL(int clientTTL)
Client time to live is max allowed connection ping return time in seconds |
void |
setGhostConnsCleanupPeriod(int ghostConnsCleanupPeriod)
Set new ghost connections cleanup period |
boolean |
start(IScope scope)
Starts scope. |
void |
stop(IScope scope)
Stops scope handling (that is, stops application if given scope is app level scope and stops room handling if given scope has lower scope level). |
void |
streamBroadcastClose(IBroadcastStream stream)
Notified when a broadcaster closes. |
void |
streamBroadcastStart(IBroadcastStream stream)
Notified when a broadcaster starts. |
void |
streamPlaylistItemPlay(IPlaylistSubscriberStream stream,
IPlayItem item,
boolean isLive)
Notified when a playlist item plays. |
void |
streamPlaylistItemStop(IPlaylistSubscriberStream stream,
IPlayItem item)
Notified when a playlist item stops. |
void |
streamPlaylistVODItemPause(IPlaylistSubscriberStream stream,
IPlayItem item,
int position)
Notified when a playlist vod item pauses. |
void |
streamPlaylistVODItemResume(IPlaylistSubscriberStream stream,
IPlayItem item,
int position)
Notified when a playlist vod item resumes. |
void |
streamPlaylistVODItemSeek(IPlaylistSubscriberStream stream,
IPlayItem item,
int position)
Notified when a playlist vod item seeks. |
void |
streamPublishStart(IBroadcastStream stream)
A broadcast stream starts being published. |
void |
streamRecordStart(IBroadcastStream stream)
A broadcast stream starts being recorded. |
void |
streamSubscriberClose(ISubscriberStream stream)
Notified when a subscriber closes. |
void |
streamSubscriberStart(ISubscriberStream stream)
Notified when a subscriber starts. |
void |
unregisterSharedObjectSecurity(ISharedObjectSecurity handler)
Remove handler that protects shared objects. |
void |
unregisterStreamPlaybackSecurity(IStreamPlaybackSecurity handler)
Remove handler that protects stream playback. |
void |
unregisterStreamPublishSecurity(IStreamPublishSecurity handler)
Remove handler that protects stream publishing. |
| Methods inherited from class org.red5.server.adapter.StatefulScopeWrappingAdapter |
|---|
createChildScope, getAttribute, getAttribute, getAttributeNames, getAttributes, getChildScope, getChildScopeNames, getClients, getConnectionsIter, getContext, getDepth, getName, getParent, getPath, getResource, getResources, getScope, hasAttribute, hasChildScope, hasParent, lookupConnections, removeAttribute, removeAttributes, setAttribute, setAttributes, setAttributes, setScope |
| Methods inherited from class org.red5.server.adapter.AbstractScopeAdapter |
|---|
addChildScope, handleEvent, removeChildScope, serviceCall, setCanCallService, setCanConnect, setCanStart, setJoin |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.red5.server.api.IScopeHandler |
|---|
addChildScope, removeChildScope, serviceCall |
| Methods inherited from interface org.red5.server.api.event.IEventHandler |
|---|
handleEvent |
| Field Detail |
|---|
protected static org.slf4j.Logger log
protected ISchedulingService schedulingService
| Constructor Detail |
|---|
public MultiThreadedApplicationAdapter()
| Method Detail |
|---|
public void addListener(IApplication listener)
IApplication.appStart(IScope))
will be ignored for listeners.
listener - object to registerpublic void removeListener(IApplication listener)
listener - object to unregisterpublic Set<IApplication> getListeners()
public void registerStreamPublishSecurity(IStreamPublishSecurity handler)
registerStreamPublishSecurity in interface IStreamSecurityServicehandler - Handler to add.public void unregisterStreamPublishSecurity(IStreamPublishSecurity handler)
unregisterStreamPublishSecurity in interface IStreamSecurityServicehandler - Handler to remove.public Set<IStreamPublishSecurity> getStreamPublishSecurity()
getStreamPublishSecurity in interface IStreamSecurityServicepublic void registerStreamPlaybackSecurity(IStreamPlaybackSecurity handler)
registerStreamPlaybackSecurity in interface IStreamSecurityServicehandler - Handler to add.public void unregisterStreamPlaybackSecurity(IStreamPlaybackSecurity handler)
unregisterStreamPlaybackSecurity in interface IStreamSecurityServicehandler - Handler to remove.public Set<IStreamPlaybackSecurity> getStreamPlaybackSecurity()
getStreamPlaybackSecurity in interface IStreamSecurityServicepublic void registerSharedObjectSecurity(ISharedObjectSecurity handler)
registerSharedObjectSecurity in interface ISharedObjectSecurityServicehandler - Handler to add.public void unregisterSharedObjectSecurity(ISharedObjectSecurity handler)
unregisterSharedObjectSecurity in interface ISharedObjectSecurityServicehandler - Handler to remove.public Set<ISharedObjectSecurity> getSharedObjectSecurity()
getSharedObjectSecurity in interface ISharedObjectSecurityService
protected boolean rejectClient()
throws ClientRejectedException
ClientRejectedException exception.
ClientRejectedException - Thrown when client connection must be rejected by application logic
protected boolean rejectClient(Object reason)
throws ClientRejectedException
reason - Additional error message to return to client-side Flex/Flash application
ClientRejectedException - Thrown when client connection must be rejected by application logic
public boolean connect(IConnection conn,
IScope scope,
Object[] params)
appConnect(IConnection, Object[]) or
roomConnect(IConnection, Object[]) in your
application to make it act the way you want.
connect in interface IScopeHandlerconnect in class AbstractScopeAdapterconn - Connection objectscope - Scopeparams - List of params passed to connection handler
true if connect is successful, false
otherwisepublic boolean start(IScope scope)
start in interface IScopeHandlerstart in class AbstractScopeAdapterscope - Scope object
true if scope can be started, false
otherwise. See AbstractScopeAdapter.start(IScope) for
details.
public void disconnect(IConnection conn,
IScope scope)
disconnect in interface IScopeHandlerdisconnect in class AbstractScopeAdapterconn - Connection objectscope - Scopepublic void stop(IScope scope)
appStop(IScope) or
roomStop(IScope) handlers respectively.
stop in interface IScopeHandlerstop in class AbstractScopeAdapterscope - Scope to stop
public boolean join(IClient client,
IScope scope)
appJoin(IClient, IScope) or
roomJoin(IClient, IScope) handlers
respectively.
join in interface IScopeHandlerjoin in class AbstractScopeAdapterclient - Client objectscope - Scope object
true to allow, false to deny
connection
public void leave(IClient client,
IScope scope)
appLeave(IClient, IScope) or
roomLeave(IClient, IScope) handlers
respectively.
leave in interface IScopeHandlerleave in class AbstractScopeAdapterclient - Client objectscope - Scope objectpublic boolean appStart(IScope app)
appStart(IScope) or
roomStart(IScope)} in your application to
make it act the way you want.
appStart in interface ApplicationMBeanapp - Application scope object
true if scope can be started, false
otherwisepublic void appStop(IScope app)
appStop in interface ApplicationMBeanapp - Scope objectpublic boolean roomStart(IScope room)
roomStart in interface ApplicationMBeanroom - Room scope
public void roomStop(IScope room)
roomStop in interface ApplicationMBeanroom - Room scope.
public boolean appConnect(IConnection conn,
Object[] params)
NetConnection.connect method.
EXAMPLE:
In this simple example we pass user's skin of choice identifier from
client to th server.
Client-side:
NetConnection.connect("rtmp://localhost/killerred5app", "silver");
Server-side:
if (params.length > 0) System.out.println("Theme selected: " + params[0]);
appConnect in interface ApplicationMBeanconn - Connection objectparams - List of parameters after connection URL passed to
NetConnection.connect method.
public boolean roomConnect(IConnection conn,
Object[] params)
NetConnection.connect method.
See appConnect(IConnection, Object[]) for code
example.
roomConnect in interface ApplicationMBeanconn - Connection objectparams - List of params passed to room scope
public void appDisconnect(IConnection conn)
appDisconnect in interface ApplicationMBeanconn - Disconnected connection objectpublic void roomDisconnect(IConnection conn)
roomDisconnect in interface ApplicationMBeanconn - Disconnected connection object
public boolean appJoin(IClient client,
IScope app)
appJoin in interface ApplicationMBean
public void appLeave(IClient client,
IScope app)
appLeave in interface ApplicationMBeanclient - Client object that leftapp - Application scope
public boolean roomJoin(IClient client,
IScope room)
roomJoin in interface ApplicationMBean
public void roomLeave(IClient client,
IScope room)
roomLeave in interface ApplicationMBeanclient - Disconnected client objectroom - Room scopepublic void measureBandwidth()
public void measureBandwidth(IConnection conn)
conn - the connection to measure the bandwidth for
public boolean createSharedObject(IScope scope,
String name,
boolean persistent)
SharedObject.getRemote().
SharedObjects can be persistent and transient. Persistent RSO are
statuful, i.e. store their data between sessions. If you need to store
some data on server while clients go back and forth use persistent SO
(just use true ), otherwise perfer usage of transient for
extra performance.
createSharedObject in interface ISharedObjectServicescope - Scope that shared object belongs toname - Name of SharedObjectpersistent - Whether SharedObject instance should be persistent or not
true if SO was created, false otherwise
public ISharedObject getSharedObject(IScope scope,
String name)
getSharedObject in interface ISharedObjectServicescope - Scope that shared object belongs toname - Name of SharedObject
public ISharedObject getSharedObject(IScope scope,
String name,
boolean persistent)
getSharedObject in interface ISharedObjectServicescope - Scope that shared object belongs toname - Name of SharedObjectpersistent - Whether SharedObject instance should be persistent or not
public Set<String> getSharedObjectNames(IScope scope)
getSharedObjectNames in interface ISharedObjectServicescope - Scope that SO belong to
public boolean hasSharedObject(IScope scope,
String name)
hasSharedObject in interface ISharedObjectServicescope - Scope that SO belong toname - Name of SharedObject
true if the shared object exists, otherwise
false
public boolean hasBroadcastStream(IScope scope,
String name)
hasBroadcastStream in interface IBroadcastStreamServicescope - the scope to check for the streamname - name of the broadcast
public IBroadcastStream getBroadcastStream(IScope scope,
String name)
getBroadcastStream in interface IBroadcastStreamServicescope - the scope to return the stream fromname - the name of the broadcast
public List<String> getBroadcastStreamNames(IScope scope)
scope. Broadcast stream name is somewhat different from server stream name. Server stream name is just an ID assigned by Red5 to every created stream. Broadcast stream name is the name that is being used to subscribe to the stream at client side, that is, in
NetStream.play call.
getBroadcastStreamNames in interface IBroadcastStreamServicescope - Scope to retrieve broadcasted stream names
public boolean hasOnDemandStream(IScope scope,
String name)
hasOnDemandStream in interface IOnDemandStreamServicescope - Scopename - VOD stream name
true if scope has VOD stream with given name,
false otherwise.
public IOnDemandStream getOnDemandStream(IScope scope,
String name)
getOnDemandStream in interface IOnDemandStreamServicescope - Scope objectname - VOD stream name
IOnDemandStream for
details.
public ISubscriberStream getSubscriberStream(IScope scope,
String name)
getSubscriberStream in interface ISubscriberStreamServicescope - Scopename - Stream name
public String addScheduledJob(int interval,
IScheduledJob job)
addScheduledJob in interface ISchedulingServiceinterval - Time inverval to run the scheduled jobjob - Scheduled job object
public String addScheduledOnceJob(long timeDelta,
IScheduledJob job)
addScheduledOnceJob in interface ISchedulingServicetimeDelta - Time offset in milliseconds from the current date when given
job should be runjob - Scheduled job object
public String addScheduledOnceJob(