Package jade.tools

Examples of jade.tools.ToolNotifier$SynchEventInformer


 
  ////////////////////////////
  // Utility methods
  ////////////////////////////
  private ToolNotifier findNotifier(AID observerName) {
    ToolNotifier tn = null;
    // Note that if a ToolNotifier exists it must be among the messageListeners
    // --> There is no need to search it also among the agentListeners.
    List l = messageListeners.startScanning();
    if (l != null) {
      Iterator it = l.iterator();
      while(it.hasNext()) {
        Object obj = it.next();
        if(obj instanceof ToolNotifier) {
          ToolNotifier tni = (ToolNotifier) obj;
          AID id = tni.getObserver();
          if(id.equals(observerName)) {
            tn = tni;
            break;
          }
        }
View Full Code Here


     
      return null;
    }
   
    private void sniffOn(AID snifferName, AID targetName) throws IMTPException {
      ToolNotifier tn = findNotifier(snifferName);
      if(tn == null) { // Need a new notifier
        tn = new ToolNotifier(snifferName);
        AID id = new AID(snifferName.getLocalName() + "-on-" + myID().getName(), AID.ISLOCALNAME);
        try {
          myContainer.initAgent(id, tn, null, null); // FIXME: Modify to use a proper owner Principal
          myContainer.powerUpLocalAgent(id);
          helper.registerMessageListener(tn);
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }
      tn.addObservedAgent(targetName);
    }
View Full Code Here

      }
      tn.addObservedAgent(targetName);
    }
   
    private void sniffOff(AID snifferName, AID targetName) throws IMTPException {
      ToolNotifier tn = findNotifier(snifferName);
      if(tn != null) {
        tn.removeObservedAgent(targetName);
      }
    }
View Full Code Here

        return;
      }
     
      // Get the ToolNotifier for the indicated debugger (or create a new one
      // if not yet there)
      ToolNotifier tn = findNotifier(introspectorName);
      if(tn == null) { // Need a new notifier
        tn = new ToolNotifier(introspectorName);
        AID id = new AID(introspectorName.getLocalName() + "-on-" + myID().getName(), AID.ISLOCALNAME);
        try {
          myContainer.initAgent(id, tn, null, null); // FIXME: Modify to use a proper owner Principal
          myContainer.powerUpLocalAgent(id);
          if (targetName.equals(myContainer.getAMS())) {
            // If we are debugging the AMS, let's wait for the ToolNotifier
            // to be ready to avoid deadlock problems. Note also that in
            // this case this code is executed by the ams-debug-helper thread and not
            // by the AMS thread
            tn.waitUntilStarted();
          }
          // Wait a bit to let the ToolNotifier pass in ACTIVE_STATE
          try {Thread.sleep(1000);} catch (Exception e) {};
          helper.registerMessageListener(tn);
          helper.registerAgentListener(tn);
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }
      tn.addObservedAgent(targetName);
     
      // Update the map of debuggers currently debugging the targetName agent
      synchronized (debuggers) {
        List l = (List) debuggers.get(targetName);
        if (l == null) {
          l = new LinkedList();
          debuggers.put(targetName, l);
        }
        if (!l.contains(introspectorName)) {
          l.add(introspectorName);
        }
      }
     
      Agent a = myContainer.acquireLocalAgent(targetName);
     
      // Activate generation of behaviour-related events on the
      // target agent
      a.setGenerateBehaviourEvents(true);
     
      // Retrieve the current agent state
      AgentState as = a.getAgentState();
     
      // Retrieve the list of pending ACL messages
      List messages = new LinkedList();
      myContainer.fillListFromMessageQueue(messages, a);
     
      // Retrieve the list of ready and blocked agent behaviour IDs
      List readyBehaviours = new LinkedList();
      myContainer.fillListFromReadyBehaviours(readyBehaviours, a);
      List blockedBehaviours = new LinkedList();
      myContainer.fillListFromBlockedBehaviours(blockedBehaviours, a);
     
      myContainer.releaseLocalAgent(targetName);
     
      // Notify all the needed events 
      fireChangedAgentState(targetName, as, as);
     
      Iterator itReady = readyBehaviours.iterator();
      while(itReady.hasNext()) {
        BehaviourID bid = (BehaviourID)itReady.next();
        AgentEvent ev = new AgentEvent(AgentEvent.ADDED_BEHAVIOUR, targetName, bid, myContainer.getID());
        tn.addedBehaviour(ev);
      }
     
      Iterator itBlocked = blockedBehaviours.iterator();
      while(itBlocked.hasNext()) {
        BehaviourID bid = (BehaviourID)itBlocked.next();
        AgentEvent ev = new AgentEvent(AgentEvent.ADDED_BEHAVIOUR, targetName, bid, myContainer.getID());
        tn.addedBehaviour(ev);
        ev = new AgentEvent(AgentEvent.CHANGED_BEHAVIOUR_STATE, targetName, bid, Behaviour.STATE_READY, Behaviour.STATE_BLOCKED, myContainer.getID());
        tn.changedBehaviourState(ev);
      }
     
      Iterator itMessages = messages.iterator();
      while(itMessages.hasNext()) {
        ACLMessage msg = (ACLMessage)itMessages.next();
        MessageEvent ev = new MessageEvent(MessageEvent.POSTED_MESSAGE, msg, null, targetName, myContainer.getID());
        tn.postedMessage(ev);
      }
    }
View Full Code Here

        tn.postedMessage(ev);
      }
    }
   
    private void debugOff(AID introspectorName, AID targetName) throws IMTPException {
      ToolNotifier tn = findNotifier(introspectorName);
      if(tn != null) {
        tn.removeObservedAgent(targetName);
      }
     
      boolean resetGenerateBehaviourEvents = true;
      synchronized (debuggers) {
        List l = (List) debuggers.get(targetName);
View Full Code Here

TOP

Related Classes of jade.tools.ToolNotifier$SynchEventInformer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.