Beispiel #1
0
 public bool AcquireTokenNonblocking(long tokenCount, ITokenBucketCallback callback)
 {
     SimpleBWControlService.TokenRequest request = new SimpleBWControlService.TokenRequest {
         type         = SimpleBWControlService.TokenRequestType.NONBLOCKING,
         callback     = callback,
         channel      = this._channel,
         initialBC    = this._bc,
         requestToken = tokenCount
     };
     return(this._simpleBWControlService.ProcessRequest(request));
 }
Beispiel #2
0
 public long AcquireTokenBestEffort(long upperLimitCount)
 {
     SimpleBWControlService.TokenRequest request = new SimpleBWControlService.TokenRequest {
         type         = SimpleBWControlService.TokenRequestType.BEST_EFFORT,
         channel      = this._channel,
         initialBC    = this._bc,
         requestToken = upperLimitCount
     };
     if (this._simpleBWControlService.ProcessRequest(request))
     {
         return((long)request.requestToken);
     }
     return(0L);
 }
Beispiel #3
0
 public bool AcquireToken(long tokenCount, long wait)
 {
     if (wait < 0L)
     {
         return(false);
     }
     SimpleBWControlService.TokenRequest request = new SimpleBWControlService.TokenRequest {
         type         = SimpleBWControlService.TokenRequestType.BLOCKING,
         timeout      = wait,
         channel      = this._channel,
         initialBC    = this._bc,
         requestToken = tokenCount
     };
     return(this._simpleBWControlService.ProcessRequest(request));
 }
Beispiel #4
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;
             }
         }
     }
 }