long stateC0 = ((Date)(myPrivateState.opInfo.getCDate())).getTime(); if (logger.isDebugEnabled()) logger.debug("GLSInitServlet- stateC0 is: " +((Date)(myPrivateState.opInfo.getCDate()))); SortedSet stateSentStages = myPrivateState.opInfo.getSentStages();
boolean haveOpInfo = (myPrivateState.opInfo != null); if (logger.isDebugEnabled()) logger.debug("GLSInitServlet- stateC0 is: " + (haveOpInfo ? ((Date)(myPrivateState.opInfo.getCDate())).toString() : "<undefined -- No OpInfo yet!>")); SortedSet stateSentStages = (haveOpInfo ? myPrivateState.opInfo.getSentStages() : new TreeSet());
  protected void setupSubscriptions()   {     logger = LoggingServiceWithPrefix.add(logger, getAgentIdentifier()+": ");        Collection params = getParameters();    if ((params == null) ||        (params.size() == 0)) {      throw new IllegalArgumentException("GLSInitServlet: Missing plugin parameter.");    }    // Get the OPLAN ID from the args.    oplanId = (String) params.iterator().next();    try {      dbp = DBProperties.readQueryFile(QUERY_FILE);      database = dbp.getProperty("Database");      username = dbp.getProperty("Username");      password = dbp.getProperty("Password");    }catch (IOException ioe) {      throw new RuntimeException("Can't read query file: "+QUERY_FILE, ioe);    }    glsSubscription = (IncrementalSubscription) blackboard.subscribe(glsPredicate);    myorgassets = (IncrementalSubscription) blackboard.subscribe(orgAssetPred);    requestSubscription = (IncrementalSubscription) blackboard.subscribe(requestPredicate);    regSrvcsSubscription = (IncrementalSubscription) blackboard.subscribe(regSrvcsPredicate);    findProvSubscription = (IncrementalSubscription) blackboard.subscribe(findProvPredicate);    // Set up the local private state object    // It is put on the blackboard for persistence and recovered     // on rehydration    Collection stateColl = blackboard.query(statePredicate);    // DEBUGGING    if (blackboard.didRehydrate()){      if ( stateColl.isEmpty()) {        if (logger.isErrorEnabled()) logger.error("GLSInitServlet: myPrivateState object did not persist!" );      }      else {        //get c0 and next stage info from state object        myPrivateState = (MyPrivateState)stateColl.iterator().next();        long stateC0 = ((Date)(myPrivateState.opInfo.getCDate())).getTime();        if (logger.isDebugEnabled()) logger.debug("GLSInitServlet- stateC0 is: " +((Date)(myPrivateState.opInfo.getCDate())));         SortedSet stateSentStages = myPrivateState.opInfo.getSentStages();         if (logger.isDebugEnabled()) logger.debug("GLSInitServlet- stateSentStages has size: " +stateSentStages.size());         //get c0 and next stage info from gls task        if (glsSubscription.isEmpty()) {          if (logger.isWarnEnabled()) logger.warn("GLSInitServlet- glsSubscription is empty on rehydration.");         }        else {          PlanElement pe = (PlanElement) glsSubscription.first();          Task gls = pe.getTask();          PrepositionalPhrase stagespp = gls.getPrepositionalPhrase(FOR_OPLAN_STAGES);          SortedSet glsStages = (SortedSet)stagespp.getIndirectObject();           if (logger.isDebugEnabled()) logger.debug("GLSInitServlet- glsStages have size: " +glsStages.size());           PrepositionalPhrase c0pp = gls.getPrepositionalPhrase(WITH_C0);          long  gls_c0 = ((Long)(c0pp.getIndirectObject())).longValue();          Date gls_c0_date = new Date(gls_c0);          if (logger.isDebugEnabled()) logger.debug("GLSInitServlet- gls_c0_date is: " +gls_c0_date);           //compare c0 from private state to c0 in gls task          //TO_DO          //compare number of sent stages  from private state to sent stages in gls task          if (stateSentStages.size() != glsStages.size()) {            if (logger.isErrorEnabled()) {              logger.error("GLSInitServlet: myPrivateState sent Stages do not match GLS task after rehyration.");            }          }        }      }    }    // EMD DEBUGGING    if (stateColl.isEmpty()){      myPrivateState = new MyPrivateState();      blackboard.publishAdd(myPrivateState);    }    else {      myPrivateState = (MyPrivateState)stateColl.iterator().next();    }    // register with servlet service    try {      servletService.register("/glsinit", new GLSServlet());      servletService.register("/glsreply", new GLSReplyServlet());    } catch (Exception e) {      e.printStackTrace();    }        //if (logger.isDebugEnabled()) logger.debug("GLSInitServlet: "     //                                          + PUBLISH_ON_SELF_ORG + " = " +     //                                          globalParameters.get(PUBLISH_ON_SELF_ORG));  }	   		 