/**
     * Overrides the TickerBehaviour, defining how to update the location on the df (registration to
     * DF has already been performed during agent setup). Three properties are defined for storing
     * latitude/longitude/altitude. Only latitude and longitude are used, though.
     */
    protected void onTick() {

      try {
        MsnAgent agent = (MsnAgent) myAgent;
        DFAgentDescription description = agent.getAgentDescription();

        ServiceDescription serviceDescription =
            (ServiceDescription) description.getAllServices().next();
        serviceDescription.clearAllProperties();

        // retrieve
        ContactLocation curMyLoc = ContactManager.getInstance().getMyContactLocation();
        if (!curMyLoc.equals(myContactLocation)) {

          Property p = new Property(PROPERTY_NAME_LOCATION_LAT, new Double(curMyLoc.getLatitude()));
          serviceDescription.addProperties(p);
          p = new Property(PROPERTY_NAME_LOCATION_LONG, new Double(curMyLoc.getLongitude()));
          serviceDescription.addProperties(p);
          p = new Property(PROPERTY_NAME_LOCATION_ALT, new Double(curMyLoc.getAltitude()));
          serviceDescription.addProperties(p);
          DFService.modify(myAgent, description);
          myContactLocation = curMyLoc;
        }

      } catch (FIPAException fe) {
        myLogger.log(Logger.SEVERE, "Error in updating DF", fe);
      } catch (Exception e) {
        myLogger.log(
            Logger.SEVERE,
            "***  Uncaught Exception for agent " + myAgent.getLocalName() + "  ***",
            e);
      }
    }
  /**
   * Overrides the Behaviour.action() method. This method is executed by the agent thread. It
   * basically defines two sub behaviours, which are in charge of periodically updating the DF and
   * receiving DF notifications.
   */
  public void action() {
    try {
      // first thing to do is to register on the df and save current location if any
      DFAgentDescription myDescription = new DFAgentDescription();
      // fill a msn service description
      ServiceDescription msnServiceDescription = new ServiceDescription();
      msnServiceDescription.setName(MsnAgent.msnDescName);
      msnServiceDescription.setType(MsnAgent.msnDescType);
      myDescription.addServices(msnServiceDescription);

      ContactManager.getInstance().resetModifications();

      DFAgentDescription[] onlineContacts = DFService.search(myAgent, myDescription);

      updateContactList(onlineContacts);

      MsnEvent event = MsnEventMgr.getInstance().createEvent(MsnEvent.VIEW_REFRESH_EVENT);

      Map<String, Contact> cMap = ContactManager.getInstance().getAllContacts();
      Map<String, ContactLocation> cLocMap = ContactManager.getInstance().getAllContactLocations();
      ContactListChanges changes = ContactManager.getInstance().getModifications();

      myLogger.log(
          Logger.FINE,
          "Thread "
              + Thread.currentThread().getId()
              + "After reading local contacts and first df query: "
              + "Adding to VIEW_REFRESH_EVENT this list of changes: "
              + changes.toString());
      event.addParam(MsnEvent.VIEW_REFRESH_PARAM_LISTOFCHANGES, changes);
      event.addParam(MsnEvent.VIEW_REFRESH_CONTACTSMAP, cMap);
      event.addParam(MsnEvent.VIEW_REFRESH_PARAM_LOCATIONMAP, cLocMap);
      MsnEventMgr.getInstance().fireEvent(event);

      DFUpdaterBehaviour updater =
          new DFUpdaterBehaviour(myAgent, msnUpdateTime, myContactLocation);
      MsnAgent agent = (MsnAgent) myAgent;
      DFSubscriptionBehaviour subBh =
          new DFSubscriptionBehaviour(myAgent, agent.getSubscriptionMessage());

      myAgent.addBehaviour(updater);
      myAgent.addBehaviour(subBh);
    } catch (Exception e) {
      // TODO Auto-generated catch block
      myLogger.log(Logger.SEVERE, "Severe error: ", e);
      e.printStackTrace();
    }
  }