/** Delete subscriber */
 public boolean deregister(Subscription sub) throws FailureException {
   for (Subscriber subs : subscribers) {
     if (subs.getSub().equals(sub)) {
       subscribers.remove(new Subscriber(subs.getSub(), subs.getType(), subs.getDate()));
     }
   }
   //
   System.out.println(
       "Agent "
           + buildingcs.getAID().getName()
           + " deregistered the agent "
           + sub.getMessage().getSender().getName());
   return false;
 }
  /** Subscriber register */
  public boolean register(Subscription sub) throws RefuseException, NotUnderstoodException {
    Date date = null;
    SubscriptionMessageType type = null;
    //
    try {
      // Unpack message
      ContentElement ce = buildingcs.getContentManager().extractContent(sub.getMessage());
      if (ce instanceof SendSubscriptionMessage) {
        SendSubscriptionMessage smsg = (SendSubscriptionMessage) ce;
        type = smsg.getMessage().getType(); // Subscription type
        date = smsg.getMessage().getSendDate(); // Last message date
      }
    } catch (UngroundedException e) {
      e.printStackTrace();
    } catch (OntologyException e) {
      e.printStackTrace();
    } catch (jade.content.lang.Codec.CodecException e) {
      e.printStackTrace();
    }

    if (type != null) {
      subscribers.add(new Subscriber(sub, type, date));
      this.confirm(sub);
      System.out.println(
          "Agent "
              + buildingcs.getAID().getName()
              + " registered the agent "
              + sub.getMessage().getSender().getName());
      //
      if (subscribers.size() == 1) {
        buildingcs.addBehaviour(tick_behavior); // At first subscriber add tick behavior
      }
    }

    return true;
  }
 /** Agree to subscribe */
 private void confirm(Subscription sub) {
   try {
     ACLMessage notification = sub.getMessage().createReply();
     notification.setPerformative(ACLMessage.AGREE);
     sub.notify(notification); // Send message
     //
     System.out.println(
         "Agent "
             + buildingcs.getAID().getName()
             + " sent AGREE message to the agent "
             + sub.getMessage().getSender().getName());
   } catch (Exception e) {
     e.printStackTrace();
   }
 }