private void InvokeCallback(BWContext context) { // loop through all channels in a context for (int i = 0; i < 3; i++) { IList pendingList = context.pendingRequestArray[i] as IList; if (pendingList.Count > 0) { // loop through all pending requests in a channel foreach (TokenRequest request in pendingList) { IBWControllable bc = context.GetBWControllable(); while (bc != null) { BWContext c = _contextMap[bc] as BWContext; if (c == null) { // context has been unregistered, we should ignore // this callback break; } lock (c) { if (c.bwConfig != null && !ProcessNonblockingRequest(request, c)) { break; } } TokenRequestContext requestContext = new TokenRequestContext(); requestContext.acquiredToken = request.requestToken; requestContext.bc = bc; request.acquiredStack.Push(requestContext); bc = bc.GetParentBWControllable(); } if (bc == null) { // successfully got the required tokens try { request.callback.Available(context.buckets[request.channel], (long)request.requestToken); } catch (Exception ex) { log.Error("Error calling request's callback", ex); } } } pendingList.Clear(); } } }
private void InvokeCallback(BWContext context) { for (int i = 0; i < 3; i++) { IList list = context.pendingRequestArray[i] as IList; if (list.Count > 0) { foreach (TokenRequest request in list) { IBWControllable bWControllable = context.GetBWControllable(); while (bWControllable != null) { BWContext context2 = this._contextMap[bWControllable] as BWContext; if (context2 == null) { break; } lock (context2) { if (!((context2.bwConfig == null) || this.ProcessNonblockingRequest(request, context2))) { break; } } TokenRequestContext context3 = new TokenRequestContext { acquiredToken = request.requestToken, bc = bWControllable }; request.acquiredStack.Push(context3); bWControllable = bWControllable.GetParentBWControllable(); } if (bWControllable == null) { try { request.callback.Available(context.buckets[request.channel], (long)request.requestToken); } catch (Exception exception) { log.Error("Error calling request's callback", exception); } } } list.Clear(); } } }
public void UpdateBWConfigure(IBWControlContext context) { if (!(context is BWContext)) { return; } BWContext c = (BWContext)context; IBWControllable bc = c.GetBWControllable(); lock (c) { if (bc.BandwidthConfiguration == null) { c.bwConfig = null; c.lastSchedule = -1; } else { long[] oldConfig = c.bwConfig; c.bwConfig = new long[4]; for (int i = 0; i < 4; i++) { c.bwConfig[i] = bc.BandwidthConfiguration.GetChannelBandwidth()[i]; } if (oldConfig == null) { // Initialize the last schedule timestamp if necessary c.lastSchedule = System.Environment.TickCount; long[] channelInitialBurst = bc.BandwidthConfiguration.GetChannelInitialBurst(); // Set the initial value to token resources as "defaultCapacity/2" for (int i = 0; i < 4; i++) { if (channelInitialBurst[i] >= 0) { c.tokenRc[i] = channelInitialBurst[i]; } else { c.tokenRc[i] = _defaultCapacity / 2; } } } else { // we have scheduled before, so migration of token is needed if (c.bwConfig[Constants.OverallChannel] >= 0 && oldConfig[Constants.OverallChannel] < 0) { c.tokenRc[Constants.OverallChannel] += c.tokenRc[Constants.AudioChannel] + c.tokenRc[Constants.VideoChannel] + c.tokenRc[Constants.DataChannel]; for (int i = 0; i < 3; i++) { c.tokenRc[i] = 0; } } else if (c.bwConfig[Constants.OverallChannel] < 0 && oldConfig[Constants.OverallChannel] >= 0) { for (int i = 0; i < 3; i++) { if (c.bwConfig[i] >= 0) { c.tokenRc[i] += c.tokenRc[Constants.OverallChannel]; break; } } c.tokenRc[Constants.OverallChannel] = 0; } } } } }
public void UpdateBWConfigure(IBWControlContext context) { if (context is BWContext) { BWContext context2 = (BWContext)context; IBWControllable bWControllable = context2.GetBWControllable(); lock (context2) { if (bWControllable.BandwidthConfiguration == null) { context2.bwConfig = null; context2.lastSchedule = -1L; } else { int num; long[] bwConfig = context2.bwConfig; context2.bwConfig = new long[4]; for (num = 0; num < 4; num++) { context2.bwConfig[num] = bWControllable.BandwidthConfiguration.GetChannelBandwidth()[num]; } if (bwConfig == null) { context2.lastSchedule = Environment.TickCount; long[] channelInitialBurst = bWControllable.BandwidthConfiguration.GetChannelInitialBurst(); for (num = 0; num < 4; num++) { if (channelInitialBurst[num] >= 0L) { context2.tokenRc[num] = channelInitialBurst[num]; } else { context2.tokenRc[num] = this._defaultCapacity / 2L; } } } else if ((context2.bwConfig[3] >= 0L) && (bwConfig[3] < 0L)) { context2.tokenRc[3] += (context2.tokenRc[0] + context2.tokenRc[1]) + context2.tokenRc[2]; for (num = 0; num < 3; num++) { context2.tokenRc[num] = 0.0; } } else if ((context2.bwConfig[3] < 0L) && (bwConfig[3] >= 0L)) { for (num = 0; num < 3; num++) { if (context2.bwConfig[num] >= 0L) { context2.tokenRc[num] += context2.tokenRc[3]; break; } } context2.tokenRc[3] = 0.0; } } } } }