コード例 #1
0
 /** 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;
 }
コード例 #2
0
 /** Tick action */
 public void tick() {
   if (this.subscribers.size() > 0) {
     for (Subscriber sub : this.subscribers) {
       // Check subscription date
       Date now = new Date();
       if (sub.getDate().after(now)) {
         this.notify(sub);
       } else {
         this.subscribers.remove(sub);
         break;
       }
     }
   }
 }
コード例 #3
0
 /** Notify the subscriber */
 private void notify(Subscriber subscriber) {
   try {
     Subscription subscription = subscriber.getSub();
     ACLMessage notification = subscription.getMessage().createReply();
     notification.setPerformative(ACLMessage.INFORM); // New message
     // Create context
     SendSubscriptionMessage smsg = this.buildingcs.getNotifyMessage(subscriber);
     this.buildingcs.getContentManager().fillContent(notification, smsg);
     subscription.notify(notification); // Send message
   } catch (Exception e) {
     e.printStackTrace();
   }
 }