public long schedule(int tenantId,double costEstimate) throws InterruptedException {
  Tenant tenant=tenants.get(tenantId);
  DiskRequest request=current_request.get();
  if (request.isActive()) {
    request.reenter();
    if (DEBUG)     print("reenter","thread has reentered scheduler, reentrance_count=%d",request.entrance_count);
    return 0;
  }
 else {
    request.reset(tenant,costEstimate);
    tenant.addNewRequest(request);
  }
  if (slots.addRequest()) {
    if (DEBUG)     print("enqueue","can schedule immediately");
    triggerNextRequest();
  }
 else {
    if (DEBUG)     print("enqueue","cannot schedule immediately");
  }
  long beginWait=System.nanoTime();
  boolean waited=request.await();
  if (DEBUG)   print("execute","executing request");
  if (waited) {
    return System.nanoTime() - beginWait;
  }
 else {
    return 0;
  }
}

public long schedule ( int tenantId , double costEstimate ) throws InterruptedException { Tenant tenant = tenants . get ( tenantId ) ; DiskRequest request = current_request . get ( ) ; if ( request . isActive ( ) ) { request . reenter ( ) ; if ( DEBUG ) print ( "reenter" , "thread has reentered scheduler, reentrance_count=%d" , request . entrance_count ) ; return 0 ; } else { request . reset ( tenant , costEstimate ) ; tenant . addNewRequest ( request ) ; } if ( slots . addRequest ( ) ) { if ( DEBUG ) print ( "enqueue" , "can schedule immediately" ) ; triggerNextRequest ( ) ; } else { if ( DEBUG ) print ( "enqueue" , "cannot schedule immediately" ) ; } long beginWait = System . nanoTime ( ) ; boolean waited = request . await ( ) ; if ( DEBUG ) print ( "execute" , "executing request" ) ; if ( waited ) { return System . nanoTime ( ) - beginWait ; } else { return 0 ; } }
schedule a request for the specified tenant , that has the specified estimated cost . the thread will wait until the scheduler deems it ok to proceed . the thread can be interrupted while waiting .
