Пример #1
0
 public void OnOOBControlMessage(IMessageComponent source, IPipe pipe, OOBControlMessage oobCtrlMsg)
 {
     if ("ConnectionConsumer".Equals(oobCtrlMsg.Target))
     {
         if ("pendingCount".Equals(oobCtrlMsg.ServiceName))
         {
             oobCtrlMsg.Result = this._connection.PendingMessages;
         }
         else if ("pendingVideoCount".Equals(oobCtrlMsg.ServiceName))
         {
             IClientStream streamByChannelId = null;
             if (this._connection is IStreamCapableConnection)
             {
                 streamByChannelId = (this._connection as IStreamCapableConnection).GetStreamByChannelId(this._video.ChannelId);
             }
             if (streamByChannelId != null)
             {
                 oobCtrlMsg.Result = this._connection.GetPendingVideoMessages(streamByChannelId.StreamId);
             }
             else
             {
                 oobCtrlMsg.Result = 0L;
             }
         }
         else if ("writeDelta".Equals(oobCtrlMsg.ServiceName))
         {
             long            num = 0L;
             IBWControllable parentBWControllable = this._connection as IBWControllable;
             while ((parentBWControllable != null) && (parentBWControllable.BandwidthConfiguration == null))
             {
                 parentBWControllable = parentBWControllable.GetParentBWControllable();
             }
             if ((parentBWControllable != null) && (parentBWControllable.BandwidthConfiguration != null))
             {
                 IBandwidthConfigure bandwidthConfiguration = parentBWControllable.BandwidthConfiguration;
                 if (bandwidthConfiguration is IConnectionBWConfig)
                 {
                     num = (bandwidthConfiguration as IConnectionBWConfig).DownstreamBandwidth / 8L;
                 }
             }
             if (num <= 0L)
             {
                 num = 0x1e000L;
             }
             oobCtrlMsg.Result = new long[] { this._connection.WrittenBytes - this._connection.ClientBytesRead, num / 2L };
         }
         else if ("chunkSize".Equals(oobCtrlMsg.ServiceName))
         {
             int num2 = (int)oobCtrlMsg.ServiceParameterMap["chunkSize"];
             if (num2 != this._chunkSize)
             {
                 this._chunkSize = num2;
                 ChunkSize message = new ChunkSize(this._chunkSize);
                 this._connection.GetChannel(2).Write(message);
             }
         }
     }
 }
Пример #2
0
        private bool ProcessRequest(TokenRequest request)
        {
            IBWControllable bc = request.initialBC;

            while (bc != null)
            {
                BWContext context = _contextMap[bc] as BWContext;
                if (context == null)
                {
                    RollbackRequest(request);
                    return(false);
                }
                lock (context)
                {
                    if (context.bwConfig != null)
                    {
                        bool result;
                        if (request.type == TokenRequestType.BLOCKING)
                        {
                            result = ProcessBlockingRequest(request, context);
                        }
                        else if (request.type == TokenRequestType.NONBLOCKING)
                        {
                            result = ProcessNonblockingRequest(request, context);
                        }
                        else
                        {
                            result = ProcessBestEffortRequest(request, context);
                        }
                        if (!result)
                        {
                            // for non-blocking mode, the callback is
                            // recorded and will be rolled back when being reset,
                            // so we don't need to do rollback here.
                            if (request.type != TokenRequestType.NONBLOCKING)
                            {
                                RollbackRequest(request);
                            }
                            return(false);
                        }
                    }
                    TokenRequestContext requestContext = new TokenRequestContext();
                    requestContext.acquiredToken = request.requestToken;
                    requestContext.bc            = bc;
                    request.acquiredStack.Push(requestContext);
                }
                bc = bc.GetParentBWControllable();
            }
            // for best effort request, we need to rollback over-charged tokens
            if (request.type == TokenRequestType.BEST_EFFORT)
            {
                RollbackRequest(request);
            }
            return(true);
        }
Пример #3
0
 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();
         }
     }
 }
Пример #4
0
 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();
         }
     }
 }
Пример #5
0
            public void Reset()
            {
                // TODO wake up all blocked threads
                IBWControllable bc = _bc;

                while (bc != null)
                {
                    BWContext context = _simpleBWControlService.ContextMap[bc] as BWContext;
                    if (context == null)
                    {
                        break;
                    }
                    lock (context)
                    {
                        IList        pendingList = context.pendingRequestArray[_channel] as IList;
                        TokenRequest toRemove    = null;
                        foreach (TokenRequest request in pendingList)
                        {
                            if (request.initialBC == _bc)
                            {
                                _simpleBWControlService.RollbackRequest(request);
                                toRemove = request;
                                break;
                            }
                        }
                        if (toRemove != null)
                        {
                            pendingList.Remove(toRemove);
                            try
                            {
                                toRemove.callback.Reset(this, (long)toRemove.requestToken);
                            }
                            catch (Exception ex)
                            {
                                log.Error("Error reset request's callback", ex);
                            }
                            break;
                        }
                    }
                    bc = bc.GetParentBWControllable();
                }
            }
Пример #6
0
        public void OnOOBControlMessage(IMessageComponent source, IPipe pipe, OOBControlMessage oobCtrlMsg)
        {
            if (!"ConnectionConsumer".Equals(oobCtrlMsg.Target))
            {
                return;
            }

            if ("pendingCount".Equals(oobCtrlMsg.ServiceName))
            {
                oobCtrlMsg.Result = _connection.PendingMessages;
            }
            else if ("pendingVideoCount".Equals(oobCtrlMsg.ServiceName))
            {
                IClientStream stream = null;
                if (_connection is IStreamCapableConnection)
                {
                    stream = (_connection as IStreamCapableConnection).GetStreamByChannelId(_video.ChannelId);
                }
                if (stream != null)
                {
                    oobCtrlMsg.Result = _connection.GetPendingVideoMessages(stream.StreamId);
                }
                else
                {
                    oobCtrlMsg.Result = (long)0;
                }
            }
            else if ("writeDelta".Equals(oobCtrlMsg.ServiceName))
            {
                long            maxStream      = 0;
                IBWControllable bwControllable = _connection as IBWControllable;
                // Search FC containing valid BWC
                while (bwControllable != null && bwControllable.BandwidthConfiguration == null)
                {
                    bwControllable = bwControllable.GetParentBWControllable();
                }
                if (bwControllable != null && bwControllable.BandwidthConfiguration != null)
                {
                    IBandwidthConfigure bwc = bwControllable.BandwidthConfiguration;
                    if (bwc is IConnectionBWConfig)
                    {
                        maxStream = (bwc as IConnectionBWConfig).DownstreamBandwidth / 8;
                    }
                }
                if (maxStream <= 0)
                {
                    // Use default value
                    // TODO: this should be configured somewhere and sent to the client when connecting
                    maxStream = 120 * 1024;
                }
                // Return the current delta between sent bytes and bytes the client
                // reported to have received, and the interval the client should use
                // for generating BytesRead messages (half of the allowed bandwidth).
                oobCtrlMsg.Result = new long[] { _connection.WrittenBytes - _connection.ClientBytesRead, maxStream / 2 };
            }
            else if ("chunkSize".Equals(oobCtrlMsg.ServiceName))
            {
                int newSize = (int)oobCtrlMsg.ServiceParameterMap["chunkSize"];
                if (newSize != _chunkSize)
                {
                    _chunkSize = newSize;
                    SendChunkSize();
                }
            }
        }
Пример #7
0
 public void Reset()
 {
     for (IBWControllable controllable = this._bc; controllable != null; controllable = controllable.GetParentBWControllable())
     {
         SimpleBWControlService.BWContext context = this._simpleBWControlService.ContextMap[controllable] as SimpleBWControlService.BWContext;
         if (context == null)
         {
             break;
         }
         lock (context)
         {
             IList list = context.pendingRequestArray[this._channel] as IList;
             SimpleBWControlService.TokenRequest request = null;
             foreach (SimpleBWControlService.TokenRequest request2 in list)
             {
                 if (request2.initialBC == this._bc)
                 {
                     this._simpleBWControlService.RollbackRequest(request2);
                     request = request2;
                     break;
                 }
             }
             if (request != null)
             {
                 list.Remove(request);
                 try
                 {
                     request.callback.Reset(this, (long)request.requestToken);
                 }
                 catch (Exception exception)
                 {
                     log.Error("Error reset request's callback", exception);
                 }
                 break;
             }
         }
     }
 }
Пример #8
0
 private bool ProcessRequest(TokenRequest request)
 {
     for (IBWControllable controllable = request.initialBC; controllable != null; controllable = controllable.GetParentBWControllable())
     {
         BWContext context = this._contextMap[controllable] as BWContext;
         if (context == null)
         {
             this.RollbackRequest(request);
             return(false);
         }
         lock (context)
         {
             if (context.bwConfig != null)
             {
                 bool flag;
                 if (request.type == TokenRequestType.BLOCKING)
                 {
                     flag = this.ProcessBlockingRequest(request, context);
                 }
                 else if (request.type == TokenRequestType.NONBLOCKING)
                 {
                     flag = this.ProcessNonblockingRequest(request, context);
                 }
                 else
                 {
                     flag = this.ProcessBestEffortRequest(request, context);
                 }
                 if (!flag)
                 {
                     if (request.type != TokenRequestType.NONBLOCKING)
                     {
                         this.RollbackRequest(request);
                     }
                     return(false);
                 }
             }
             TokenRequestContext context2 = new TokenRequestContext {
                 acquiredToken = request.requestToken,
                 bc            = controllable
             };
             request.acquiredStack.Push(context2);
         }
     }
     if (request.type == TokenRequestType.BEST_EFFORT)
     {
         this.RollbackRequest(request);
     }
     return(true);
 }