示例#1
0
  /** Initialize this JICPMediator */
  public void init(JICPMediatorManager mgr, String id, Properties props) throws ICPException {
    myMediatorManager = mgr;
    myID = id;
    myProperties = props;

    // Max disconnection time
    long maxDisconnectionTime = JICPProtocol.DEFAULT_MAX_DISCONNECTION_TIME;
    try {
      maxDisconnectionTime =
          Long.parseLong(props.getProperty(JICPProtocol.MAX_DISCONNECTION_TIME_KEY));
    } catch (Exception e) {
      // Keep default
    }

    // Keep-alive time
    keepAliveTime = JICPProtocol.DEFAULT_KEEP_ALIVE_TIME;
    try {
      keepAliveTime = Long.parseLong(props.getProperty(JICPProtocol.KEEP_ALIVE_TIME_KEY));
    } catch (Exception e) {
      // Keep default
    }

    // Server-keep-alive time
    enableServerKeepAlive = false;
    try {
      enableServerKeepAlive =
          Boolean.valueOf(props.getProperty("enable-server-keep-alive")).booleanValue();
    } catch (Exception e) {
      // Keep default
    }

    // inpCnt
    int inpCnt = 0;
    try {
      inpCnt = (Integer.parseInt(props.getProperty("lastsid")) + 1) & 0x0f;
    } catch (Exception e) {
      // Keep default
    }
    System.out.println("Next command for FE will have sessionID " + inpCnt);

    // lastSid
    int lastSid = 0x0f;
    try {
      lastSid = (byte) (Integer.parseInt(props.getProperty("outcnt")) - 1);
      if (lastSid < 0) {
        lastSid = 0x0f;
      }
    } catch (Exception e) {
      // Keep default
    }

    FrontEndStub st = new FrontEndStub(this);
    inpManager = new InputManager(inpCnt, st);

    BackEndSkel sk = startBackEndContainer(props);
    outManager = new OutputManager(lastSid, sk, maxDisconnectionTime);
  }
示例#2
0
 public static final Properties parseCreateMediatorRequest(String s) throws ICPException {
   StringTokenizer st = new StringTokenizer(s, "=#");
   Properties p = new Properties();
   while (st.hasMoreTokens()) {
     String key = st.nextToken();
     if (!st.hasMoreTokens()) {
       throw new ICPException("Wrong initialization properties format.");
     }
     p.setProperty(key, st.nextToken());
   }
   return p;
 }
示例#3
0
 /** Resets all the message slots. */
 public void reset() {
   source = null;
   // #MIDP_EXCLUDE_BEGIN
   dests.clear();
   if (reply_to != null) reply_to.clear();
   // #MIDP_EXCLUDE_END
   /*#MIDP_INCLUDE_BEGIN
   dests.removeAllElements();
   if (reply_to != null)
   reply_to.removeAllElements();
   #MIDP_INCLUDE_END*/
   performative = NOT_UNDERSTOOD;
   content = null;
   byteSequenceContent = null;
   reply_with = null;
   in_reply_to = null;
   encoding = null;
   language = null;
   ontology = null;
   reply_byInMillisec = 0;
   protocol = null;
   conversation_id = null;
   if (userDefProps != null) {
     userDefProps.clear();
   }
 }
示例#4
0
  private static Properties adjustProperties(Properties pp) {
    // A BackEndContainer is never a Main
    pp.setProperty(Profile.MAIN, "false");

    // Set default additional services if not already set
    String services = pp.getProperty(Profile.SERVICES);
    if (services == null) {
      services = "jade.core.event.NotificationService";
    }
    String additionalServices = pp.getProperty(BEManagementService.ADDITIONAL_SERVICES);
    if (additionalServices != null) {
      services += ";" + additionalServices;
    }
    pp.setProperty(Profile.SERVICES, services);

    // Merge back-end and front-end services
    String feServices = pp.getProperty(MicroRuntime.BE_REQUIRED_SERVICES_KEY);
    if (feServices != null) {
      Vector ss = Specifier.parseList(pp.getProperty(Profile.SERVICES), ';');
      Vector fess = Specifier.parseList(feServices, ';');
      for (int i = 0; i < fess.size(); ++i) {
        String s = (String) fess.get(i);
        if (!ss.contains(s)) {
          ss.add(s);
        }
      }
      pp.setProperty(Profile.SERVICES, Specifier.encodeList(ss, Specifier.SPECIFIER_SEPARATOR));
    }
    return pp;
  }
示例#5
0
 public static final String encodeProperties(Properties pp) {
   StringBuffer sb = new StringBuffer();
   Enumeration en = pp.keys();
   while (en.hasMoreElements()) {
     String key = (String) en.nextElement();
     appendProp(sb, key, pp, en.hasMoreElements());
   }
   return sb.toString();
 }
示例#6
0
  private static void initCouple(Properties basePP, String prefix, int index) {
    String senderClass = "jade.core.ScalabilityTest$BitrateSenderAgent";
    String receiverClass = "jade.core.ScalabilityTest$BitrateReceiverAgent";
    if (measure == RTT_MEASURE) {
      senderClass = "jade.core.ScalabilityTest$RTTSenderAgent";
      receiverClass = "jade.core.ScalabilityTest$RTTReceiverAgent";
    }

    Properties pp = (Properties) basePP.clone();
    /*Properties pp = new Properties();
    if (host != null) {
    	pp.setProperty(MicroRuntime.HOST_KEY, host);
    }
    if (port != null) {
    	pp.setProperty(MicroRuntime.PORT_KEY, port);
    }
    if (proto != null) {
    	pp.setProperty(MicroRuntime.PROTO_KEY, proto);
    }
    if (maxDiscTime != null) {
    	pp.setProperty(JICPProtocol.MAX_DISCONNECTION_TIME_KEY, maxDiscTime);
    }*/
    String sName = "S-" + prefix + "-" + index;
    pp.setProperty(PDPContextManager.MSISDN, sName);
    String rName = "R-" + prefix + "-" + index;
    String prop = sName + ":" + senderClass + "(" + rName + ")";
    pp.setProperty(MicroRuntime.AGENTS_KEY, prop);
    // pp.setProperty(JICPProtocol.KEEP_ALIVE_TIME_KEY, "-1");
    FrontEndContainer fes = new FrontEndContainer();
    fes.start(pp);

    pp = (Properties) basePP.clone();
    /*pp = new Properties();
    if (host != null) {
    	pp.setProperty(MicroRuntime.HOST_KEY, host);
    }
    if (port != null) {
    	pp.setProperty(MicroRuntime.PORT_KEY, port);
    }
    if (proto != null) {
    	pp.setProperty(MicroRuntime.PROTO_KEY, proto);
    }
    if (maxDiscTime != null) {
    	pp.setProperty(JICPProtocol.MAX_DISCONNECTION_TIME_KEY, maxDiscTime);
    }*/
    pp.setProperty(PDPContextManager.MSISDN, rName);
    prop = rName + ":" + receiverClass;
    pp.setProperty(MicroRuntime.AGENTS_KEY, prop);
    // pp.setProperty(JICPProtocol.KEEP_ALIVE_TIME_KEY, "-1");
    FrontEndContainer fer = new FrontEndContainer();
    fer.start(pp);
  }
示例#7
0
 private static final void appendProp(
     StringBuffer sb, String key, Properties pp, boolean appendHash) {
   Object val = pp.get(key);
   if (val != null) {
     String strVal = val.toString();
     if (strVal.length() > 0) {
       sb.append(key);
       sb.append('=');
       sb.append(val);
       if (appendHash) {
         sb.append('#');
       }
     }
   }
 }
示例#8
0
  // #MIDP_EXCLUDE_BEGIN
  public synchronized Object clone() {

    ACLMessage result;

    try {
      result = (ACLMessage) super.clone();
      result.persistentID = null;
      if (source != null) {
        result.source = (AID) source.clone();
      }

      // Deep clone receivers
      if (dests != null) {
        result.dests = new ArrayList(dests.size());
        Iterator it = dests.iterator();
        while (it.hasNext()) {
          AID id = (AID) it.next();
          result.dests.add(id.clone());
        }
      }

      // Deep clone reply_to
      if (reply_to != null) {
        result.reply_to = new ArrayList(reply_to.size());
        Iterator it = reply_to.iterator();
        while (it.hasNext()) {
          AID id = (AID) it.next();
          result.reply_to.add(id.clone());
        }
      }

      // Deep clone user-def-properties if present
      if (userDefProps != null) result.userDefProps = (Properties) userDefProps.clone();
      // Deep clone envelope if present
      if (messageEnvelope != null) result.messageEnvelope = (Envelope) messageEnvelope.clone();
    } catch (CloneNotSupportedException cnse) {
      throw new InternalError(); // This should never happen
    }

    return result;
  }
示例#9
0
  protected final BackEndSkel startBackEndContainer(Properties props) throws ICPException {
    try {
      String nodeName = myID.replace(':', '_');
      props.setProperty(Profile.CONTAINER_NAME, nodeName);

      myContainer = new BackEndContainer(props, this);
      if (!myContainer.connect()) {
        throw new ICPException("BackEnd container failed to join the platform");
      }
      // Possibly the node name was re-assigned by the main
      myID = myContainer.here().getName();
      if (myLogger.isLoggable(Logger.CONFIG)) {
        myLogger.log(
            Logger.CONFIG, "BackEndContainer " + myID + " successfully joined the platform");
      }
      return new BackEndSkel(myContainer);
    } catch (ProfileException pe) {
      // should never happen
      pe.printStackTrace();
      throw new ICPException("Error creating profile");
    }
  }
示例#10
0
  /** Create a BackEnd in the fixed network and return a stub to communicate with it */
  public BackEnd getBackEnd(FrontEnd fe, Properties p) throws IMTPException {
    props = p;

    beAddrsText = props.getProperty(FrontEnd.REMOTE_BACK_END_ADDRESSES);
    backEndAddresses = parseBackEndAddresses(beAddrsText);

    // Host
    String host = props.getProperty("host");
    if (host == null) {
      host = "localhost";
    }
    // Port
    int port = JICPProtocol.DEFAULT_PORT;
    try {
      port = Integer.parseInt(props.getProperty("port"));
    } catch (NumberFormatException nfe) {
      // Use default
    }
    // Compose URL. Note that we build a JICPAddress just to avoid loading the HTTPAddress class.
    mediatorTA = JICPProtocol.getInstance().buildAddress(host, String.valueOf(port), null, null);

    // Mediator class
    String tmp = props.getProperty(JICPProtocol.MEDIATOR_CLASS_KEY);
    if (tmp != null) {
      myMediatorClass = tmp;
    } else {
      // Set the default mediator class since this must be propagated to the mediator.
      props.setProperty(JICPProtocol.MEDIATOR_CLASS_KEY, myMediatorClass);
    }

    // Read re-connection retry time
    long retryTime = JICPProtocol.DEFAULT_RETRY_TIME;
    try {
      retryTime = Long.parseLong(props.getProperty(JICPProtocol.RECONNECTION_RETRY_TIME_KEY));
    } catch (Exception e) {
      // Use default
    }

    // Read Max disconnection time
    maxDisconnectionTime = JICPProtocol.DEFAULT_MAX_DISCONNECTION_TIME;
    try {
      maxDisconnectionTime =
          Long.parseLong(props.getProperty(JICPProtocol.MAX_DISCONNECTION_TIME_KEY));
    } catch (Exception e) {
      // Use default
      props.setProperty(
          JICPProtocol.MAX_DISCONNECTION_TIME_KEY, String.valueOf(maxDisconnectionTime));
    }

    // Read Keep-alive time
    keepAliveTime = JICPProtocol.DEFAULT_KEEP_ALIVE_TIME;
    try {
      keepAliveTime = Long.parseLong(props.getProperty(JICPProtocol.KEEP_ALIVE_TIME_KEY));
    } catch (Exception e) {
      // Use default
      props.setProperty(JICPProtocol.KEEP_ALIVE_TIME_KEY, String.valueOf(keepAliveTime));
    }

    if (myLogger.isLoggable(Logger.CONFIG)) {
      myLogger.log(Logger.CONFIG, "Remote URL = http://" + host + ":" + port);
      myLogger.log(Logger.CONFIG, "Mediator class = " + myMediatorClass);
      myLogger.log(Logger.CONFIG, "Reconnection retry time = " + retryTime);
      myLogger.log(Logger.CONFIG, "Max disconnection time = " + maxDisconnectionTime);
      myLogger.log(Logger.CONFIG, "Keep-alive time = " + keepAliveTime);
    }

    myDisconnectionManager = new DisconnectionManager(retryTime, maxDisconnectionTime);
    myKeepAliveManager = new KeepAliveManager(keepAliveTime);
    myInputManager = new InputManager();

    // Read the owner if any
    owner = props.getProperty("owner");

    // Create the BackEnd stub and the FrontEnd skeleton
    myStub = new BackEndStub(this);
    mySkel = new FrontEndSkel(fe);

    // Start the InputManager
    myInputManager.start();

    // Create the remote BackEnd
    createBackEnd();

    return myStub;
  }
示例#11
0
  /**
   * Send the CREATE_MEDIATOR command with the necessary parameter in order to create the BackEnd in
   * the fixed network. Executed - at bootstrap time by the thread that creates the
   * FrontEndContainer. - To re-attach to the platform after a fault of the BackEnd
   */
  private synchronized void createBackEnd() throws IMTPException {
    StringBuffer sb = BackEndStub.encodeCreateMediatorRequest(props);
    if (myMediatorID != null) {
      // This is a request to re-create my expired back-end
      BackEndStub.appendProp(sb, JICPProtocol.MEDIATOR_ID_KEY, myMediatorID);
      BackEndStub.appendProp(sb, "outcnt", String.valueOf(outCnt));
      BackEndStub.appendProp(sb, "lastsid", String.valueOf(lastSid));
    }
    JICPPacket pkt =
        new JICPPacket(
            JICPProtocol.CREATE_MEDIATOR_TYPE,
            JICPProtocol.DEFAULT_INFO,
            null,
            sb.toString().getBytes());

    // Try first with the current transport address, then with the various backup addresses
    for (int i = -1; i < backEndAddresses.length; i++) {

      if (i >= 0) {
        // Set the mediator address to a new address..
        String addr = backEndAddresses[i];
        int colonPos = addr.indexOf(':');
        String host = addr.substring(0, colonPos);
        String port = addr.substring(colonPos + 1, addr.length());
        mediatorTA = new JICPAddress(host, port, myMediatorID, "");
      }

      try {
        HTTPClientConnection hc = (HTTPClientConnection) getConnection(mediatorTA);
        myLogger.log(
            Logger.INFO,
            "Creating BackEnd on "
                + hc.getProtocol()
                + mediatorTA.getHost()
                + ":"
                + mediatorTA.getPort());
        pkt = deliver(pkt);

        String replyMsg = new String(pkt.getData());
        if (pkt.getType() != JICPProtocol.ERROR_TYPE) {
          // BackEnd creation successful
          BackEndStub.parseCreateMediatorResponse(replyMsg, props);
          myMediatorID = props.getProperty(JICPProtocol.MEDIATOR_ID_KEY);
          // Complete the mediator address with the mediator ID
          mediatorTA =
              new JICPAddress(mediatorTA.getHost(), mediatorTA.getPort(), myMediatorID, null);
          myDisconnectionManager.setReachable();
          myKeepAliveManager.update();
          myLogger.log(Logger.INFO, "BackEnd OK. Mediator ID is " + myMediatorID);
          return;
        } else {
          myLogger.log(Logger.WARNING, "Mediator error: " + replyMsg);
        }
      } catch (IOException ioe) {
        // Ignore it, and try the next address...
        myLogger.log(Logger.WARNING, "Connection error", ioe);
      }
    }

    // No address succeeded!
    throw new IMTPException("Error creating the BackEnd.");
  }
示例#12
0
 /**
  * Removes the key and its corresponding value from the list of user defined parameters in this
  * ACLMessage.
  *
  * @param key the key that needs to be removed
  * @return the value to which the key had been mapped or null if the key was not present
  */
 public Object clearUserDefinedParameter(String key) {
   if (userDefProps == null) return null;
   else return userDefProps.remove(key);
 }
示例#13
0
 /**
  * Searches for the user defined parameter with the specified key. The method returns <code>null
  * </code> if the parameter is not found.
  *
  * @param key the parameter key.
  * @return the value in this ACLMessage with the specified key value.
  */
 public String getUserDefinedParameter(String key) {
   if (userDefProps == null) return null;
   else return userDefProps.getProperty(key);
 }
示例#14
0
 /**
  * Add a new user defined parameter to this ACLMessage. Notice that according to the FIPA
  * specifications, the keyword of a user-defined parameter must not contain space inside. Note
  * that the user does not need to (and shall not) add the prefix "X-" to the keyword. This is
  * automatically added by the StringACLCodec.
  *
  * @param key the property key.
  * @param value the property value
  */
 public void addUserDefinedParameter(String key, String value) {
   userDefProps = (userDefProps == null ? new Properties() : userDefProps);
   userDefProps.setProperty(key, value);
 }
示例#15
0
 private void updateConnectedState() {
   myProperties.put(BEManagementHelper.CONNECTED, (isConnected() ? "true" : "false"));
 }