Examples of IBWControllable


Examples of org.red5.server.api.IBWControllable

      } else {
        oobCtrlMsg.setResult((long) 0);
      }
    } else if ("writeDelta".equals(oobCtrlMsg.getServiceName())) {
      long maxStream = 0;
      IBWControllable bwControllable = conn;
      // Search FC containing valid BWC
      while (bwControllable != null && bwControllable.getBandwidthConfigure() == null) {
        bwControllable = bwControllable.getParentBWControllable();
      }
      if (bwControllable != null && bwControllable.getBandwidthConfigure() != null) {
        IBandwidthConfigure bwc = bwControllable.getBandwidthConfigure();
        if (bwc instanceof IConnectionBWConfig) {
          maxStream = ((IConnectionBWConfig) bwc).getDownstreamBandwidth() / 8;
        }
      }
      if (maxStream <= 0) {
View Full Code Here

Examples of org.red5.server.api.IBWControllable

  }

  public void updateBWConfigure(IBWControlContext context) {
    if (!(context instanceof BWContext)) return;
    BWContext c = (BWContext) context;
    IBWControllable bc = c.getBWControllable();
    synchronized (c) {
      if (bc.getBandwidthConfigure() == 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.getBandwidthConfigure().getChannelBandwidth()[i];
        }
        if (oldConfig == null) {
          // initialize the last schedule timestamp if necessary
          c.lastSchedule = System.currentTimeMillis();
          long[] channelInitialBurst = bc.getBandwidthConfigure().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 {
View Full Code Here

Examples of org.red5.server.api.IBWControllable

  public void setDefaultCapacity(long capacity) {
    this.defaultCapacity = capacity;
  }
 
  protected boolean processRequest(TokenRequest request) {
    IBWControllable bc = request.initialBC;
    while (bc != null) {
      BWContext context = contextMap.get(bc);
      if (context == null) {
        rollbackRequest(request);
        return false;
      }
      synchronized (context) {
        if (context.bwConfig != null) {
          boolean 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);
    }
View Full Code Here

Examples of org.red5.server.api.IBWControllable

    for (int i = 0; i < 3; i++) {
      List<TokenRequest> pendingList = context.pendingRequestArray[i];
      if (!pendingList.isEmpty()) {
        // loop through all pending requests in a channel
        for (TokenRequest request : pendingList) {
          IBWControllable bc = context.getBWControllable();
          while (bc != null) {
            BWContext c = contextMap.get(bc);
            if (c == null) {
              // context has been unregistered, we should ignore
              // this callback
              break;
            }
            synchronized (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);
View Full Code Here

Examples of org.red5.server.api.IBWControllable

      }
    }

    public void reset() {
      // TODO wake up all blocked threads
      IBWControllable bc = this.bc;
      while (bc != null) {
        BWContext context = contextMap.get(bc);
        if (context == null) {
          break;
        }
        synchronized (context) {
          List<TokenRequest> pendingList = context.pendingRequestArray[channel];
          TokenRequest toRemove = null;
          for (TokenRequest request : pendingList) {
            if (request.initialBC == this.bc) {
              rollbackRequest(request);
              toRemove = request;
              break;
            }
          }
          if (toRemove != null) {
            pendingList.remove(toRemove);
            try {
              toRemove.callback.reset(this, (long) toRemove.requestToken);
            } catch (Throwable t) {
              log.error("Error reset request's callback", t);
            }
            break;
          }
        }
        bc = bc.getParentBWControllable();
      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.