Esempio n. 1
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;
  }