Changeset View
Changeset View
Standalone View
Standalone View
support/aphlict/client/src/AphlictMaster.as
| Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | final public class AphlictMaster extends Aphlict { | ||||
| */ | */ | ||||
| private function purgeClients(event:TimerEvent):void { | private function purgeClients(event:TimerEvent):void { | ||||
| for (var client:String in this.clients) { | for (var client:String in this.clients) { | ||||
| var checkin:Number = this.clients[client]; | var checkin:Number = this.clients[client]; | ||||
| if (new Date().getTime() - checkin > AphlictMaster.PURGE_INTERVAL) { | if (new Date().getTime() - checkin > AphlictMaster.PURGE_INTERVAL) { | ||||
| this.log('Purging client: ' + client); | this.log('Purging client: ' + client); | ||||
| delete this.clients[client]; | delete this.clients[client]; | ||||
| this.log('Removing client subscriptions: ' + client); | |||||
| this.unsubscribeAll(client); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Clients will regularly "ping" the master to let us know that they are | * Clients will regularly "ping" the master to let us know that they are | ||||
| * still alive. We will "pong" them back to let the client know that the | * still alive. We will "pong" them back to let the client know that the | ||||
| * master is still alive. | * master is still alive. | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | public function subscribe(client:String, phids:Array):void { | ||||
| this.subscriptions[phid][client] = true; | this.subscriptions[phid][client] = true; | ||||
| } | } | ||||
| if (newPHIDs.length) { | if (newPHIDs.length) { | ||||
| this.sendSubscribeCommand(newPHIDs); | this.sendSubscribeCommand(newPHIDs); | ||||
| } | } | ||||
| } | } | ||||
| private function getSubscriptions(client:String):Array { | |||||
| var subscriptions = new Array(); | |||||
| for (var phid:String in this.subscriptions) { | |||||
| var clients = this.subscriptions[phid]; | |||||
| if (clients[client]) { | |||||
| subscriptions.push(phid); | |||||
| } | |||||
| } | |||||
| return subscriptions; | |||||
| } | |||||
| public function unsubscribeAll(client:String):void { | |||||
| this.unsubscribe(client, this.getSubscriptions(client)); | |||||
| } | |||||
| public function unsubscribe(client:String, phids:Array):void { | public function unsubscribe(client:String, phids:Array):void { | ||||
| var oldPHIDs = new Array(); | var oldPHIDs = new Array(); | ||||
| for (var phid:String in phids) { | for (var i:String in phids) { | ||||
| var phid = phids[i]; | |||||
| if (!this.subscriptions[phid]) { | if (!this.subscriptions[phid]) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| delete this.subscriptions[phid][client]; | delete this.subscriptions[phid][client]; | ||||
| var empty = true; | var empty = true; | ||||
| for (var key:String in this.subscriptions[phid]) { | for (var key:String in this.subscriptions[phid]) { | ||||
| ▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines | |||||