Commit 653c14aa authored by Dan Rossi's avatar Dan Rossi
Browse files

- #70 load osmf classes as runtime libraries for bwcheck except a few required...

- #70 load osmf classes as runtime libraries for bwcheck except a few required classes to be loaded first. the rsls are loaded from httpstreaming instead, but is required to be configured and loaded first in the config.
- cleanup rtmpcluster class and use builtin urlutil instead.
parent 7b6f83bb
......@@ -34,4 +34,64 @@
<target name="demo" >
<example player-swf="flowplayer.swf" main-swf="${plugin-binary-versioned}" />
</target>
<macrodef name="mxmlc.compile">
<attribute name="src" default="${src-as}" />
<attribute name="plugin-main-class" default="${plugin-main-class}" />
<attribute name="out" default="${plugin-binary}" />
<attribute name="libs" default="" />
<sequential>
<condition property="libs" value="" else="-include-libraries @{libs}">
<equals arg1="@{libs}" arg2="" />
</condition>
<condition property="pluginruntimelibs1" value="-runtime-shared-library-path+=${plugin-runtime-lib-swc1},library.swf" else="">
<isset property="plugin-runtime-lib-swc1" />
</condition>
<condition property="pluginruntimelibs2" value="-runtime-shared-library-path+=${plugin-runtime-lib-swc2},library.swf" else="">
<isset property="plugin-runtime-lib-swc2" />
</condition>
<condition property="pluginruntimelibs3" value="-runtime-shared-library-path+=${plugin-runtime-lib-swc3},library.swf" else="">
<isset property="plugin-runtime-lib-swc3" />
</condition>
<condition property="mxmlc-library-path" value="${library-path}" else="">
<isset property="library-path" />
</condition>
<condition property="mxmlc-define" value="-define=${compiler-define}" else="">
<isset property="compiler-define" />
</condition>
<condition property="mxmlc-defines" value="${compiler-defines}" else="">
<isset property="compiler-defines" />
</condition>
<condition property="mxmlc-sources" value="${extra-sources}" else="">
<isset property="extra-sources" />
</condition>
<echo message="compiling with ${mxmlc-library-path}" />
<echo message="compiling with ${mxmlc-define} ${mxmlc-defines}" />
<exec executable="${mxmlc_bin}" failonerror="true">
<arg line="-source-path @{src} ${mxmlc-library-path} ${mxmlc-sources}" />
<arg line="${mxmlc-define}" />
<arg line="${mxmlc-defines}" />
<arg line="${libs}" />
<arg line="-library-path ${flex-libs-path} ${mxmlc-library-path}" />
<arg line="-runtime-shared-library-path=${flowplayer_lib},library.swf" />
<arg line="${pluginruntimelibs1}" />
<arg line="${pluginruntimelibs2}" />
<arg line="${pluginruntimelibs3}" />
<arg line="-static-link-runtime-shared-libraries=false"/>
<arg line="-generate-frame-loader=false"/>
<arg line="-default-frame-rate=${framerate}" />
<arg line="-default-background-color=${bgcolor}" />
<arg line="-strict=true" />
<arg line="-keep-as3-metadata=Value,External" />
<!-- Load external osmf library from httpstreaming except NetClient -->
<arg line="-load-externs lib/externs.xml" />
<arg line="'@{src}/@{plugin-main-class}'" />
<arg line="-output '${build-dir}/@{out}'" />
<arg line="-incremental=false"/>
</exec>
</sequential>
</macrodef>
</project>
\ No newline at end of file
This diff is collapsed.
......@@ -10,260 +10,257 @@
package org.flowplayer.cluster
{
import flash.events.TimerEvent;
import flash.net.SharedObject;
import flash.utils.Timer;
import mx.utils.URLUtil;
import org.flowplayer.flow_internal;
import org.flowplayer.model.ClipEvent;
import org.flowplayer.model.PluginEventDispatcher;
import org.flowplayer.model.PluginEventType;
import org.flowplayer.model.PluginModel;
import org.flowplayer.model.PluginModelImpl;
import org.flowplayer.util.Log;
use namespace flow_internal;
public class RTMPCluster {
protected var _hosts:Array;
protected var _timer:Timer;
protected var _hostIndex:int = 0;
protected var _hostCount:int = 0;
protected var _connectCount:int = 0;
protected var _reConnectCount:int = 0;
protected var _connectTimeout:int = 2000;
protected var _loadBalanceServers:Boolean = false;
protected var _liveHosts:Array;
protected var _liveRandomServers:Array = [];
private var _startAfterConnect:Boolean;
protected var _failureExpiry:int = 0;
import flash.events.TimerEvent;
import flash.net.SharedObject;
import flash.utils.Timer;
//import mx.utils.URLUtil;
import org.flowplayer.flow_internal;
//import org.flowplayer.model.PluginModelImpl;
import org.flowplayer.util.Log;
import org.flowplayer.util.URLUtil;
use namespace flow_internal;
public class RTMPCluster {
protected var _hosts:Array;
protected var _timer:Timer;
protected var _hostIndex:int = 0;
//protected var _hostCount:int = 0;
protected var _connectCount:int = 0;
protected var _reConnectCount:int = 0;
protected var _connectTimeout:int = 2000;
//protected var _loadBalanceServers:Boolean = false;
protected var _liveHosts:Array;
//protected var _liveRandomServers:Array = [];
//private var _startAfterConnect:Boolean;
protected var _failureExpiry:int = 0;
protected var _reconnectFailureExpiry:int = 0;
private var _config:*;
private var _dispatcher:PluginModelImpl;
private var log:Log = new Log(this);
private var _reconnectListener:Function;
private var _failureListener:Function;
private var _currentHost:Object;
public function RTMPCluster(config:*)
{
_config = config;
// there can be several hosts, or we are just using one single netConnectionUrl
initHosts(_config.hosts, config.netConnectionUrl);
_connectCount = config.connectCount;
_connectTimeout = config.connectTimeout;
_failureExpiry = config.failureExpiry;
_currentHost = _hosts ? _hosts[0] : null;
}
private function initHosts(hosts:Array, fallback:String):void {
log.debug("initHosts()");
var myHosts:Array = [];
if (! hosts || hosts.length == 0) {
if (! fallback) {
throw new Error("A hosts array or a netConnectionUrl must be configured");
}
myHosts.push({ 'host': fallback});
} else {
for (var i:int = 0; i < hosts.length; i++) {
myHosts.push(hosts[i] is String ? { 'host': hosts[i] } : hosts[i]);
}
private var _config:*;
//private var _dispatcher:PluginModelImpl;
private var log:Log = new Log(this);
private var _reconnectListener:Function;
private var _failureListener:Function;
private var _currentHost:Object;
public function RTMPCluster(config:*)
{
_config = config;
// there can be several hosts, or we are just using one single netConnectionUrl
initHosts(_config.hosts, config.netConnectionUrl);
_connectCount = config.connectCount;
_connectTimeout = config.connectTimeout;
_failureExpiry = config.failureExpiry;
_currentHost = _hosts ? _hosts[0] : null;
}
_hosts = myHosts;
_liveHosts = _hosts;
log.debug("initHosts(), we have " + _liveHosts.length + " live hosts initially");
}
private function initHosts(hosts:Array, fallback:String):void {
log.debug("initHosts()");
var myHosts:Array = [];
if (! hosts || hosts.length == 0) {
if (! fallback) {
throw new Error("A hosts array or a netConnectionUrl must be configured");
}
myHosts.push({ 'host': fallback});
} else {
for (var i:int = 0; i < hosts.length; i++) {
myHosts.push(hosts[i] is String ? { 'host': hosts[i] } : hosts[i]);
}
}
_hosts = myHosts;
_liveHosts = _hosts;
log.debug("initHosts(), we have " + _liveHosts.length + " live hosts initially");
}
public function onReconnected(listener:Function):void {
_reconnectListener = listener;
}
public function onFailed(listener:Function):void {
_failureListener = listener;
}
public function onReconnected(listener:Function):void {
_reconnectListener = listener;
}
public function get currentHosts():Array
{
return _hosts.filter(_checkLiveHost);
}
public function onFailed(listener:Function):void {
_failureListener = listener;
}
public function get hosts():Array
{
return _hosts;
}
public function get currentHosts():Array
{
return _hosts.filter(_checkLiveHost);
}
public function get nextHost():String
{
if (hasMultipleHosts())
public function get hosts():Array
{
_liveHosts = currentHosts;
if (_liveHosts.length == 0) {
log.error("no live hosts available");
if (_failureListener != null) {
_failureListener();
return null;
return _hosts;
}
public function get nextHost():String
{
if (hasMultipleHosts())
{
_liveHosts = currentHosts;
if (_liveHosts.length == 0) {
log.error("no live hosts available");
if (_failureListener != null) {
_failureListener();
return null;
}
}
if (_config.loadBalance)
{
_hostIndex = getRandomIndex();
log.debug("Load balanced index " + _hostIndex);
}
if (_liveHosts.length > _hostIndex) {
log.debug("cluster has multiple hosts");
_currentHost = _liveHosts[_hostIndex];
return _currentHost["host"];
}
}
if (_config.loadBalance)
{
_hostIndex = getRandomIndex();
log.debug("Load balanced index " + _hostIndex);
log.error("no hosts available");
return null;
}
public function start():void
{
if (_timer && _timer.running) {
_timer.stop();
}
if (_liveHosts.length > _hostIndex) {
log.debug("cluster has multiple hosts");
_currentHost = _liveHosts[_hostIndex];
return _currentHost["host"];
_timer = new Timer(_connectTimeout, _liveHosts.length);
_timer.addEventListener(TimerEvent.TIMER , tryFallBack);
if (hasMultipleHosts()) {
log.debug("starting connection timeout timer, with a delay of " + _connectTimeout);
_timer.start();
}
}
log.error("no hosts available");
return null;
}
public function start():void
{
if (_timer && _timer.running) {
_timer.stop();
public function stop():void
{
if (_timer != null && _timer.running) _timer.stop();
}
public function hasMultipleHosts():Boolean
{
return _liveHosts.length > 0;
}
_timer = new Timer(_connectTimeout, _liveHosts.length);
_timer.addEventListener(TimerEvent.TIMER , tryFallBack);
if (hasMultipleHosts()) {
log.debug("starting connection timeout timer, with a delay of " + _connectTimeout);
_timer.start();
public function getRandomIndex():uint {
return Math.round(Math.random() * (_liveHosts.length - 1));
}
}
public function stop():void
{
if (_timer != null && _timer.running) _timer.stop();
}
public function hasMultipleHosts():Boolean
{
return _liveHosts.length > 0;
}
public function getRandomIndex():uint {
return Math.round(Math.random() * (_liveHosts.length - 1));
}
public function get liveServers():Array
{
return _liveHosts;
}
private function _checkLiveHost(element:*, index:int, arr:Array):Boolean
{
return _isLiveServer(element);
}
private function _getFailedServerSO(host:String):SharedObject
{
var domain:String = URLUtil.getServerName(host);
return SharedObject.getLocal(domain,"/");
}
public function setFailedServer(host:String):void
{
log.debug("Setting Failed Server: " + host);
var server:SharedObject = _getFailedServerSO(host);
server.data.failureTimestamp = new Date();
}
public function set connectCount(count:Number):void
{
_connectCount = count;
}
internal function hasMoreHosts():Boolean
{
if (_failureExpiry == 0)
_hostIndex++
else
_hostIndex = 0;
_liveHosts = currentHosts;
if (_hostIndex >= _liveHosts.length)
public function get liveServers():Array
{
//
_reConnectCount++;
if (_reConnectCount < _connectCount)
{
log.debug("Restarting Connection Attempts");
_hostIndex = 0;
//#427 when reconnecting to the max reconnect count, clear the failure expiry and reset the live hosts to enable to try again ?
_reconnectFailureExpiry = 0;
_liveHosts = currentHosts;
return _liveHosts;
}
}
} else {
//#427 set the normal failure expiry during retries.
_reconnectFailureExpiry = _failureExpiry;
private function _checkLiveHost(element:*, index:int, arr:Array):Boolean
{
return _isLiveServer(element);
}
log.debug("Host Index: " + _hostIndex + " LiveServers: " + _liveHosts.length);
return (_hostIndex <= _liveHosts.length && _liveHosts[_hostIndex]);
}
private function _isLiveServer(element:*):Boolean
{
var host:String = element.host;
var server:SharedObject = _getFailedServerSO(host);
// Server is failed, determine if the failure expiry interval has been reached and clear it
if (server.data.failureTimestamp)
private function _getFailedServerSO(host:String):SharedObject
{
var date:Date = new Date();
var domain:String = URLUtil.baseUrl(host);
return SharedObject.getLocal(domain,"/");
}
// Determine the failure offset
var offset:int = date.getTime() - server.data.failureTimestamp.getTime();
public function setFailedServer(host:String):void
{
log.debug("Setting Failed Server: " + host);
var server:SharedObject = _getFailedServerSO(host);
server.data.failureTimestamp = new Date();
}
log.debug("Failed Server Remaining Expiry: " + offset + " Start Time: " + server.data.failureTimestamp.getTime() + " Current Time: " + date.getTime());
public function set connectCount(count:Number):void
{
_connectCount = count;
}
internal function hasMoreHosts():Boolean
{
if (_failureExpiry == 0)
_hostIndex++
else
_hostIndex = 0;
_liveHosts = currentHosts;
// Failure offset has reached the failureExpiry setting, clear it from the list to allow a connection
//#427 failure expiry was not being reset to honour connect retry.
if (offset >= _reconnectFailureExpiry && _reConnectCount < _connectCount)
if (_hostIndex >= _liveHosts.length)
{
log.debug("Clearing Failure Period " + _config.failureExpiry);
server.clear();
return true;
//
_reConnectCount++;
if (_reConnectCount < _connectCount)
{
log.debug("Restarting Connection Attempts");
_hostIndex = 0;
//#427 when reconnecting to the max reconnect count, clear the failure expiry and reset the live hosts to enable to try again ?
_reconnectFailureExpiry = 0;
_liveHosts = currentHosts;
}
} else {
//#427 set the normal failure expiry during retries.
_reconnectFailureExpiry = _failureExpiry;
}
return false;
log.debug("Host Index: " + _hostIndex + " LiveServers: " + _liveHosts.length);
return (_hostIndex <= _liveHosts.length && _liveHosts[_hostIndex]);
}
return true;
}
protected function tryFallBack(e:TimerEvent):void
{
// Check if there is more hosts to attempt reconnection to
if (hasMoreHosts())
private function _isLiveServer(element:*):Boolean
{
log.debug("invoking reconnect listener");
if (_reconnectListener != null) {
_reconnectListener();
var host:String = element.host;
var server:SharedObject = _getFailedServerSO(host);
// Server is failed, determine if the failure expiry interval has been reached and clear it
if (server.data.failureTimestamp)
{
var date:Date = new Date();
// Determine the failure offset
var offset:int = date.getTime() - server.data.failureTimestamp.getTime();
log.debug("Failed Server Remaining Expiry: " + offset + " Start Time: " + server.data.failureTimestamp.getTime() + " Current Time: " + date.getTime());
// Failure offset has reached the failureExpiry setting, clear it from the list to allow a connection
//#427 failure expiry was not being reset to honour connect retry.
if (offset >= _reconnectFailureExpiry && _reConnectCount < _connectCount)
{
log.debug("Clearing Failure Period " + _config.failureExpiry);
server.clear();
return true;
}
return false;
}
return true;
}
} else {
// we have reached the end of the hosts list stop reconnection attempts and send a failed event
stop();
if (_failureListener != null) {
_failureListener();
protected function tryFallBack(e:TimerEvent):void
{
// Check if there is more hosts to attempt reconnection to
if (hasMoreHosts())
{
log.debug("invoking reconnect listener");
if (_reconnectListener != null) {
_reconnectListener();
}
} else {
// we have reached the end of the hosts list stop reconnection attempts and send a failed event
stop();
if (_failureListener != null) {
_failureListener();
}
}
}
}
public function get currentHost():String {
return _currentHost["host"];
}
public function get currentHost():String {
return _currentHost["host"];
}
public function get currentHostIndex():int {
return _hosts.indexOf(_currentHost);
}
public function get currentHostIndex():int {
return _hosts.indexOf(_currentHost);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment