Package jade.mtp

Examples of jade.mtp.MTP


    private MTPDescriptor installMTP(String address, String className) throws IMTPException, ServiceException, MTPException {
     
      try {
        // Create the MTP
        Class c = Class.forName(className);
        MTP proto = (MTP)c.newInstance();
       
        InChannel.Dispatcher dispatcher = new InChannel.Dispatcher() {
          public void dispatchMessage(Envelope env, byte[] payload) {
            //log("Message from remote platform received", 2);

            if (myLogger.isLoggable(Logger.FINE))
              myLogger.log(Logger.FINE,"Message from remote platform received");
           
            // To avoid message loops, make sure that the ID of this ACC does
            // not appear in a previous 'received' stamp
           
            ReceivedObject[] stamps = env.getStamps();
            for(int i = 0; i < stamps.length; i++) {
              String id = stamps[i].getBy();
              if(CaseInsensitiveString.equalsIgnoreCase(id, accID)) {
                System.err.println("ERROR: Message loop detected !!!");
                System.err.println("Route is: ");
                for(int j = 0; j < stamps.length; j++)
                  System.err.println("[" + j + "]" + stamps[j].getBy());
                System.err.println("Message dispatch aborted.");
                return;
              }
            }
           
            // Put a 'received-object' stamp in the envelope
            ReceivedObject ro = new ReceivedObject();
            ro.setBy(accID);
            ro.setDate(new Date());
            env.setReceived(ro);
           
            Iterator it = env.getAllIntendedReceiver();
            // FIXME: There is a problem if no 'intended-receiver' is present,
            // but this should not happen
            while (it.hasNext()) {
              AID rcv = (AID)it.next();
              GenericMessage msg = new GenericMessage(env,payload);
              String traceId = getTraceId(env);
              if (traceId != null) {
                myLogger.log(Logger.INFO, "MTP In-Channel handling message from the outside for receiver "+rcv.getName()+". TraceID = "+traceId);
                msg.setTraceID(traceId);
              }
              myMessageManager.deliver(msg, rcv, MessagingService.this);
            }
          }
        };
       
        if(address == null) {
          // Let the MTP choose the address
          TransportAddress ta = proto.activate(dispatcher, myProfile);
          address = proto.addrToStr(ta);
        }
        else {
          // Convert the given string into a TransportAddress object and use it
          TransportAddress ta = proto.strToAddr(address);
          proto.activate(dispatcher, ta, myProfile);
        }
        MTPDescriptor result = new MTPDescriptor(proto.getName(), className, new String[] {address}, proto.getSupportedProtocols());
        routes.addLocalMTP(address, proto, result);
       
        String[] pp = result.getSupportedProtocols();
        for (int i = 0; i < pp.length; ++i) {
          //log("Added Route-Via-MTP for protocol "+pp[i], 1);
View Full Code Here


   
    private void uninstallMTP(String address) throws IMTPException, ServiceException, NotFoundException, MTPException {
     
      RoutingTable.MTPInfo info = routes.removeLocalMTP(address);
      if(info != null) {
        MTP proto = info.getMTP();
        TransportAddress ta = proto.strToAddr(address);
        proto.deactivate(ta);
        MTPDescriptor desc = info.getDescriptor();
        //MTPDescriptor desc = new MTPDescriptor(proto.getName(), proto.getClass().getName(), new String[] {address}, proto.getSupportedProtocols());
       
        String[] addresses = desc.getAddresses();
        for(int i = 0; i < addresses.length; i++) {
View Full Code Here

    // url = url.toLowerCase();
    CaseInsensitiveString urlTmp = new CaseInsensitiveString(url);
    // A local MTP appears both in the input and output port tables
    MTPInfo info = (MTPInfo) inPorts.remove(urlTmp);
    if(info != null) {
      MTP proto = info.getMTP();
      // Remove all outgoing ports associated with this MTP
      String[] protoNames = proto.getSupportedProtocols();
      for(int i = 0; i < protoNames.length; i++) {
        OutPort out = new OutViaMTP(proto, platformInfo);
        removeOutPort(protoNames[i], out);
      }
    }
View Full Code Here

TOP

Related Classes of jade.mtp.MTP

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.