Exemplo n.º 1
0
 public MediaDestination getMediaDestination(SessionDescription sessionDescription)
     throws NoCodecException {
   InetAddress destAddress = sessionDescription.getIpAddress();
   List<MediaDescription> mediaDescriptions = sessionDescription.getMediaDescriptions();
   for (MediaDescription mediaDescription : mediaDescriptions) {
     if (RFC4566.MEDIA_AUDIO.equals(mediaDescription.getType())) {
       for (Codec offerCodec : mediaDescription.getCodecs()) {
         if (supportedCodecs.contains(offerCodec)) {
           String offerCodecName = offerCodec.getName();
           if (offerCodecName.equalsIgnoreCase(RFC3551.PCMU)
               || offerCodecName.equalsIgnoreCase(RFC3551.PCMA)) {
             int destPort = mediaDescription.getPort();
             if (mediaDescription.getIpAddress() != null) {
               destAddress = mediaDescription.getIpAddress();
             }
             MediaDestination mediaDestination = new MediaDestination();
             mediaDestination.setDestination(destAddress.getHostAddress());
             mediaDestination.setPort(destPort);
             mediaDestination.setCodec(offerCodec);
             return mediaDestination;
           }
         }
       }
     }
   }
   throw new NoCodecException();
 }
Exemplo n.º 2
0
  public void setup() {
    System.out.println("ASU.setup()");

    getContentManager().registerLanguage(codec);
    getContentManager().registerOntology(ontology);

    ACLMessage aclmsg = new ACLMessage(ACLMessage.REQUEST);
    AssignPowerRequest apr = new AssignPowerRequest();
    apr.setAssignedPower(100000);

    aclmsg.setLanguage(codec.getName());
    aclmsg.setOntology(ontology.getName());
    aclmsg.setProtocol(FIPANames.InteractionProtocol.FIPA_REQUEST);
    aclmsg.setReplyByDate(new Date(System.currentTimeMillis() + 30000));

    AMSAgentDescription[] agents = null;
    try {
      SearchConstraints c = new SearchConstraints();
      c.setMaxResults(new Long(-1));

      agents = AMSService.search(this, new AMSAgentDescription(), c);
    } catch (Exception e) {
      System.out.println("Problem searching AMS: " + e);
      e.printStackTrace();
    }

    for (AMSAgentDescription agent : agents) {

      AID agentID = agent.getName();

      try {
        getContentManager().fillContent(aclmsg, new Action(agentID, apr));
      } catch (Exception e) {
        e.printStackTrace();
      }

      System.out.println(agentID.getLocalName());

      if (agentID.getLocalName().compareTo("TURBINE") != 0) continue;

      aclmsg.clearAllReceiver();
      aclmsg.addReceiver(agentID);

      System.out.println("Sending to " + agentID);

      addBehaviour(new ASURequestInitiatorBehaviour(this, aclmsg));

      try {
        Thread.yield();
        Thread.sleep(5000);
      } catch (Exception e) {
        System.out.println("INTERRUPT");
      }

      ACLMessage aclmsg2 = new ACLMessage(ACLMessage.REQUEST);
      BeginPowerTransitionRequest bptr = new BeginPowerTransitionRequest();
      bptr.setAssignedPowerValid(false);

      aclmsg2.setLanguage(codec.getName());
      aclmsg2.setOntology(ontology.getName());
      aclmsg2.setProtocol(FIPANames.InteractionProtocol.FIPA_REQUEST);
      aclmsg2.setReplyByDate(new Date(System.currentTimeMillis() + 30000));

      try {
        getContentManager().fillContent(aclmsg2, new Action(agentID, bptr));
      } catch (Exception e) {
        e.printStackTrace();
      }

      aclmsg2.clearAllReceiver();
      aclmsg2.addReceiver(agentID);

      System.out.println("Sending to " + agentID);

      addBehaviour(new ASURequestInitiatorBehaviour(this, aclmsg2));
    }
  }