myLoggingService.debug("key " +(String)it.next());
myLoggingService.debug("key " + key);
  protected void handleChangedServiceContractRelays(Collection changedRelays) {    if (myLoggingService.isDebugEnabled()) {      myLoggingService.debug(getAgentIdentifier() +                             " handleChangedServiceContractRelays " +changedRelays.size());    }    for (Iterator iterator = changedRelays.iterator();	   iterator.hasNext();) {      ServiceContractRelay relay = (ServiceContractRelay)iterator.next();      //if the role is now completely covered, discard the history      if(checkProviderCompletelyCovered(relay.getServiceRequest().getServiceRole())) {        if (myLoggingService.isDebugEnabled()) {          myLoggingService.debug(getAgentIdentifier() +                                 " handleChangedServiceContractRelays, completely covered for "                                 + relay.getServiceRequest().getServiceRole());        }        serviceRequestHistories.remove(relay.getServiceRequest().getServiceRole().toString());      }      //only take action if you are the client agent      // (not if you are the provider)      //if your service contract got revoked, or your requested      //service time interval was not satistied, do a new service query      if (myLoggingService.isDebugEnabled()) {        myLoggingService.debug(getAgentIdentifier() +                               " revoked " + relay.getServiceContract().isRevoked() +                               " !satisfied " + !timeIntervalRequestedCompletelySatisfied(relay) +                               " client " + relay.getClient().equals(getSelfOrg()));      }      if ((relay.getServiceContract().isRevoked() ||           !timeIntervalRequestedCompletelySatisfied(relay) ) &&           (relay.getClient().equals(getSelfOrg()))) {        if (myLoggingService.isDebugEnabled()) {          myLoggingService.debug(getAgentIdentifier() +                                 " queryServices because a service contract was revoked or did not satisfy the request for " +                                 relay.getServiceContract().getServiceRole().toString());        }        //if this request is not in the history (because it previously        //completely satisfied the request) put it in        ServiceRequestHistory srh = (ServiceRequestHistory)serviceRequestHistories.get(            relay.getServiceContract().getServiceRole().toString());        if(srh == null) {          if (myLoggingService.isDebugEnabled()) {            myLoggingService.debug(getAgentIdentifier() +                                   " handleChangedServiceContractRelays, put into history " +                                   relay.getProviderName() + " "                                   + relay.getServiceRequest().getServiceRole());          }          long start = (long)SDFactory.getPreference(relay.getServiceRequest().getServicePreferences(),              Preference.START_TIME);          long end = (long)SDFactory.getPreference(relay.getServiceRequest().getServicePreferences(),              Preference.END_TIME);          TimeInterval timeInterval = new TimeInterval(start, end);          ServiceRequestRecord srr = new ServiceRequestRecord(relay.getProviderName(),              timeInterval);          srh = new ServiceRequestHistory(relay.getServiceContract().getServiceRole(),              timeInterval, srr);          serviceRequestHistories.put(relay.getServiceContract().getServiceRole().toString(),                                      srh);          Iterator it = serviceRequestHistories.keySet().iterator();          while(it.hasNext()) {            if (myLoggingService.isDebugEnabled()) {              myLoggingService.debug("key " +(String)it.next());            }          }        }        //change the relay. If revoked, change request to zero.        //If contract doesnt cover request, shrink request        if(relay.getServiceContract().isRevoked()) {          //todo, doesn't matter much now because we won't look at revoked ones        }        else { //change request to match contract          if (myLoggingService.isDebugEnabled()) {            myLoggingService.debug(getAgentIdentifier() +                                   " change request to match contract for " +                                   relay.getProviderName() + " " +                                   relay.getServiceContract().getServiceRole().toString());          }          ServiceRequest request =              mySDFactory.newServiceRequest(getSelfOrg(),              relay.getServiceContract().getServiceRole(),              relay.getServiceContract().getServicePreferences());          relay.setServiceRequest(request);          publishChange(relay);        }        if (myLoggingService.isDebugEnabled()) {          myLoggingService.debug(getAgentIdentifier() +                                 " do another queryServices for " +                                 relay.getServiceContract().getServiceRole().toString());        }        queryServices(relay.getServiceContract().getServiceRole());        //publishRemove(relay);      }      else if (timeIntervalRequestedCompletelySatisfied(relay) &&             relay.getClient().equals(getSelfOrg())) {          if (myLoggingService.isDebugEnabled()) {            myLoggingService.debug(getAgentIdentifier() +                                   " handleChangedServiceContractRelays timeIntervalRequestedCompletelySatisfied " +                                   relay.getServiceContract().getServiceRole().toString());          }        }      else if (!timeIntervalRequestedCompletelySatisfied(relay) &&             relay.getClient().equals(getSelfOrg())) {          if (myLoggingService.isDebugEnabled()) {            myLoggingService.debug(getAgentIdentifier() +                                   " handleChangedServiceContractRelays not timeIntervalRequestedCompletelySatisfied " +                                   relay.getServiceContract().getServiceRole().toString());          }        }    }  }