System.err.println(getCluster().getMessageAddress() + " LoadAllocator:checkOverruns() the capacity has no role schedule");
System.err.println(getMessageAddress() + " LoadAllocator:checkOverruns() the capacity has no role schedule");
  private void checkOverruns(LACapacity mycapacity) {    //  	System.out.println(getCluster().getMessageAddress() + " LoadAllocator in checkOverruns");    Capacity capacity = mycapacity.getCapacity();    if (capacity == null) {      // This should never happen      System.err.println(getCluster().getMessageAddress() + " LoadAllocator:checkOverruns() no capacity object!");      return;    }    RoleSchedule rs = capacity.getRoleSchedule();    //	System.out.println(getCluster().getMessageAddress() + " LoadAllocator:checkOverruns() Capacity.RoleSchedule:" + rs);    if (rs == null) {      // This should never happen      System.err.println(getCluster().getMessageAddress() + " LoadAllocator:checkOverruns() the capacity has no role schedule");      return;    }    long currentDate = oplanStartTime;    boolean publishChanges = false;    boolean publishNew = false;    Schedule capacitySchedule = capacity.getScheduledContentPG().getSchedule();    if (capacitySchedule == null) {      // This should never happen      System.err.println(getCluster().getMessageAddress() + " LoadAllocator:checkOverruns() the capacity's ScheduleContentPG has no schedule");      return;    }    // Check for overruns on each day    while(currentDate < oplanEndTime)  {      double qtyAsked = 0;      double overrun = 0;      double qtyAvailable = 0;      // Find the elements that have allocations for current day      // Assume that oplan started at midnight.      Collection allocatedSet = rs.getOverlappingRoleSchedule(currentDate,							      currentDate +							   ScheduleUtilities.millisperday);      if (allocatedSet.size() > 0) {	//Find out how much we have allocated        qtyAsked = rs.addAspectValues(allocatedSet, AspectType.QUANTITY);	Collection capacitySet 	    = capacitySchedule.getOverlappingScheduleElements( currentDate,							       currentDate + 							       ScheduleUtilities.millisperday);	// Find out how much capacity we actually have	qtyAvailable = ScheduleUtilities.sumElements(capacitySet);	// Have we allocated more than we have?        overrun = qtyAsked - qtyAvailable;        //       		System.out.println(getCluster().getMessageAddress()         //        				   + " LoadAllocator:checkOverruns() overrun=" + overrun        //       				   + "  qtyAsked=" + qtyAsked         //      				   + "  qtyAvaiable=" + qtyAvailable);      } else {        //        		System.out.println(getCluster().getMessageAddress()         //        				   + " LoadAllocator:checkOverruns() No schedule for "         //        				   + currentDate);      }      // more capacity allocated than available?      if (overrun > 0){	        // create a new SupportRequest task there isn't one already        if (mycapacity.getSupportRequest() == null) {          publishNew = true;          Task supportRequest = createSupportRequest(capacity, overrun,                                                     currentDate, oplanEndTime);          mycapacity.setSupportRequest(supportRequest);          // add new qty schedule element to capcity           // this is the object that represents the optimistic assumption that the           // SupportRequest task is successful          NewQuantityScheduleElement cse = new QuantityScheduleElementImpl();          cse.setQuantity(overrun);          cse.setStartTime(currentDate);          // current date?          cse.setEndTime(oplanEndTime);          ((NewSchedule)capacitySchedule).addScheduleElement(cse);          mycapacity.setQSE((QuantityScheduleElement)cse);	  // Add the QSE to the annotation on the task	  ((MyAnnotation)supportRequest.getAnnotation()).setQSE((QuantityScheduleElement)cse);        } else {          // reset the start date and quantity preferences of the SupportRequest task          publishChanges = true;          QuantityScheduleElement qse = mycapacity.getQSE();          if (qse == null) {            // Don't know why this would happen, but...            System.err.println(getCluster().getMessageAddress() + " LoadAllocator QSE missing");            NewQuantityScheduleElement cse = new QuantityScheduleElementImpl();            cse.setQuantity(0d);            cse.setStartTime(currentDate);            cse.setEndTime(oplanEndTime);            ((NewSchedule)capacitySchedule).addScheduleElement(cse);            mycapacity.setQSE((QuantityScheduleElement)cse);	    // Add the QSE to the annotation on the task	    ((MyAnnotation)mycapacity.getSupportRequest().getAnnotation()).setQSE((QuantityScheduleElement)cse);          }          // this is null          double new_qty = qse.getQuantity() +overrun;          long newDate = qse.getStartDate().getTime();          if (newDate > currentDate)  {            ((NewQuantityScheduleElement)qse).setStartTime(currentDate);            newDate = currentDate;          }          modifySupportRequest(mycapacity.getSupportRequest(),                                capacity, new_qty, newDate);          // new quantity should always be more than old          ((NewQuantityScheduleElement)qse).setQuantity(new_qty);        }		      }      currentDate += ScheduleUtilities.millisperday;    }    if (publishNew || publishChanges) {      // send SupportRequest task to SupportForceProvider      publishSupportRequestAllocation(mycapacity);    }    if (publishNew) {      //  	    System.out.println(getCluster().getMessageAddress() + " LoadAllocator publishing changed capacity and new SupportRequest");      publishChange(capacity);      publishAdd(mycapacity.getSupportRequest());      publishNew = false;    } else if (publishChanges) {      //  	    System.out.println(getCluster().getMessageAddress() + " LoadAllocator publishing changed capacity and SupportRequest");      publishChange(capacity);      publishChange(mycapacity.getSupportRequest());      publishChanges = false;    }   }