这个模块安装在一个edge服务器上,当这台edge服务器到达负载极限时,它会停止向Load Balancer listener发送自己的状态信息。这样新的客户连接请求就不会重定向到这台edge服务器上。
这个edge服务器不会限制客户端对它的直接访问,只是不会再有重定向到它的连接请求。 注意: 这个模块是针对LoadBalancer 2.0版本的附加模块,这个服务器必须按照如何获得Wowza的动态负载均衡模块的介绍,被配置为Load Balancer Listener edge服务器。
packagecom.wowza.wms.plugin.collection.module;
//com.wowza.wms.plugin.collection.module.ModuleLoadBalancerEdgeLimitConnections
importcom.wowza.wms.amf.AMFDataList;
importcom.wowza.wms.application.IApplicationInstance;
importcom.wowza.wms.client.ConnectionCounter;
importcom.wowza.wms.client.IClient;
importcom.wowza.wms.httpstreamer.cupertinostreaming.httpstreamer.HTTPStreamerSessionCupertino;
importcom.wowza.wms.httpstreamer.sanjosestreaming.httpstreamer.HTTPStreamerSessionSanJose;
importcom.wowza.wms.httpstreamer.smoothstreaming.httpstreamer.HTTPStreamerSessionSmoothStreamer;
importcom.wowza.wms.logging.WMSLoggerIDs;
importcom.wowza.wms.module.ModuleBase;
importcom.wowza.wms.plugin.loadbalancer.LoadBalancerSender;
importcom.wowza.wms.plugin.loadbalancer.ServerListenerLoadBalancerSender;
importcom.wowza.wms.request.RequestFunction;
importcom.wowza.wms.rtp.model.RTPSession;
importcom.wowza.wms.server.Server;
publicclass ModuleLoadBalancerEdgeLimitConnections extends ModuleBase
{
static final public int MAXCONNECTIONS= 200;
private ConnectionCounter counter;
private int maxEdgeConnections =MAXCONNECTIONS;
private LoadBalancerSenderloadBalancerSender;
public voidonAppStart(IApplicationInstance appInstance)
{
this.counter =appInstance.getConnectionCounter();
this.maxEdgeConnections =appInstance.getProperties().getPropertyInt("maxEdgeConnections",maxEdgeConnections);
loadBalancerSender =(LoadBalancerSender)Server.getInstance().getProperties().get(ServerListenerLoadBalancerSender.PROP_LOADBALANCERSENDER);
getLogger().info("ModuleLoadBalancerEdgeLimitConnectionsmaxEdgeConnections: " + maxEdgeConnections);
}
public void changeLimitEdge(IClientclient, RequestFunction function,
AMFDataList params){
Integer newLimit =params.getInt(PARAM1);
this.maxEdgeConnections =newLimit;
getLogger().info("ModuleLoadBalancerEdgeLimitConnectionsNew Limit: " + newLimit);
}
private void addConnection() {
loadBalancerSender =(LoadBalancerSender)Server.getInstance().getProperties().get(ServerListenerLoadBalancerSender.PROP_LOADBALANCERSENDER);
if (loadBalancerSender ==null)
{
getLogger().info("ModuleLoadBalancerEdgeLimitConnectionsError (addConnection): Load Balancer Sender is not installed",WMSLoggerIDs.CAT_application, WMSLoggerIDs.EVT_comment);
return;
}
long count =counter.getCurrent();
if ((count+1) >this.maxEdgeConnections)
{
loadBalancerSender.pause();
getLogger().info("ModuleLoadBalancerEdgeLimitConnectionsPause", WMSLoggerIDs.CAT_application, WMSLoggerIDs.EVT_comment);
}
getLogger().info("ModuleLoadBalancerEdgeLimitConnectionsCount: " + count, WMSLoggerIDs.CAT_application, WMSLoggerIDs.EVT_comment);
}
private void removeConnection() {
loadBalancerSender =(LoadBalancerSender)Server.getInstance().getProperties().get(ServerListenerLoadBalancerSender.PROP_LOADBALANCERSENDER);
if (loadBalancerSender ==null)
{
getLogger().info("ModuleLoadBalancerEdgeLimitConnectionsError (removeConnection): Load Balancer Sender is not installed",WMSLoggerIDs.CAT_application, WMSLoggerIDs.EVT_comment);
return;
}
long count =counter.getCurrent();
if ((count-1)
{
loadBalancerSender.unpause();
getLogger().info("ModuleLoadBalancerEdgeLimitConnectionsUnPause", WMSLoggerIDs.CAT_application, WMSLoggerIDs.EVT_comment);
}
getLogger().info("ModuleLoadBalancerEdgeLimitConnectionsCount: " + count, WMSLoggerIDs.CAT_application, WMSLoggerIDs.EVT_comment);
}
public void onConnect(IClient client,RequestFunction function, AMFDataList params)
{
addConnection();
}
public void onDisconnect(IClientclient) {
removeConnection();
}
public voidonHTTPSmoothStreamingSessionCreate(HTTPStreamerSessionSmoothStreamer httpSmoothStreamingSession)
{
addConnection();
}
public voidonHTTPSmoothStreamingSessionDestroy(HTTPStreamerSessionSmoothStreamerhttpSmoothStreamingSession)
{
removeConnection();
}
public voidonHTTPCupertinoStreamingSessionCreate(HTTPStreamerSessionCupertinohttpCupertinoStreamingSession)
{
addConnection();
}
public voidonHTTPCupertinoStreamingSessionDestroy(HTTPStreamerSessionCupertinohttpCupertinoStreamingSession)
{
removeConnection();
}
public void onHTTPSanjoseStreamingSessionCreate(HTTPStreamerSessionSanJosehttpSanJoseStreamingSession)
{
addConnection();
}
public voidonHTTPSanjoseStreamingSessionDestroy(HTTPStreamerSessionSanJosehttpSanJoseStreamingSession)
{
removeConnection();
}
public voidonRTPSessionCreate(RTPSession rtpSession)
{
addConnection();
}
public voidonRTPSessionDestroy(RTPSession rtpSession)
{
removeConnection();
}
}
这个模块编译后的版本已经被包含在Wowza的可选自定义模块。下载并解压缩后,将/lib/wms-plugin-collection.jar拷贝到Wowza安装目录下的 /lib 文件夹下。然后重启Wowza。 在/conf/[app-name]/Application.xml文件的模块列表的最后添加下面的模块。
ModuleLoadBalancerEdgeLimitConnections
Limit connects to an edge
com.wowza.wms.plugin.collection.module.ModuleLoadBalancerEdgeLimitConnections
将下面的属性参数添加到属性列表中(在模块列表的下面)
maxEdgeConnections
200
Wowza Streaming Engine 4是业界功能强大、API接口丰富的流媒体Server产品,采用它作为流媒体服务器产品的案例很多,直播、在线教育、IPTV都有它的用武之地。
公司名称:北京哲想软件有限公司
北京哲想软件官方网站:www.cogitosoft.com
北京哲想软件微信公众平台账号:cogitosoftware
北京哲想软件微博:哲想软件
北京哲想软件邮箱:sales@cogitosoft.com
销售(俞先生)联系方式:+86(010)68421378
微信:18610247936 QQ:368531638