这个模块安装在一个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) <this.maxEdgeConnections)
{
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文件的模块列表的最后添加下面的模块。
<Module>
<Name>ModuleLoadBalancerEdgeLimitConnections</Name>
<Description>Limit connects to an edge</Description>
<Class>com.wowza.wms.plugin.collection.module.ModuleLoadBalancerEdgeLimitConnections</Class>
</Module>
将下面的属性参数添加到属性列表中(在模块列表的下面)
<Property>
<Name>maxEdgeConnections</Name>
<Value>200</Value>
</Property>
Wowza Streaming Engine 4是功能强大、API接口丰富的流媒体Server产品,采用它作为流媒体服务器产品的案例很多,直播、在线教育、IPTV都有它的用武之地。
京ICP备09015132号-996 | 网络文化经营许可证京网文[2017]4225-497号 | 违法和不良信息举报电话:4006561155
© Copyright 2000-2023 北京哲想软件有限公司版权所有 | 地址:北京市海淀区西三环北路50号豪柏大厦C2座11层1105室