Ejemplo n.º 1
0
 /**
  * @param properties <br>
  *     All are required<br>
  *     1. mcastPort - the port to listen to<br>
  *     2. mcastAddress - the mcast group address<br>
  *     4. bindAddress - the bind address if any - only one that can be null<br>
  *     5. memberDropTime - the time a member is gone before it is considered gone.<br>
  *     6. mcastFrequency - the frequency of sending messages<br>
  *     7. tcpListenPort - the port this member listens to<br>
  *     8. tcpListenHost - the bind address of this member<br>
  * @exception java.lang.IllegalArgumentException if a property is missing.
  */
 @Override
 public void setProperties(Properties properties) {
   hasProperty(properties, "mcastPort");
   hasProperty(properties, "mcastAddress");
   hasProperty(properties, "memberDropTime");
   hasProperty(properties, "mcastFrequency");
   hasProperty(properties, "tcpListenPort");
   hasProperty(properties, "tcpListenHost");
   this.properties = properties;
 }
Ejemplo n.º 2
0
  @Override
  public void start(int level) throws java.lang.Exception {
    hasProperty(properties, "mcastPort");
    hasProperty(properties, "mcastAddress");
    hasProperty(properties, "memberDropTime");
    hasProperty(properties, "mcastFrequency");
    hasProperty(properties, "tcpListenPort");
    hasProperty(properties, "tcpListenHost");
    hasProperty(properties, "tcpSecurePort");
    hasProperty(properties, "udpListenPort");

    if (impl != null) {
      impl.start(level);
      return;
    }
    String host = getProperties().getProperty("tcpListenHost");
    int port = Integer.parseInt(getProperties().getProperty("tcpListenPort"));
    int securePort = Integer.parseInt(getProperties().getProperty("tcpSecurePort"));
    int udpPort = Integer.parseInt(getProperties().getProperty("udpListenPort"));

    if (localMember == null) {
      localMember = new MemberImpl(host, port, 100);
      localMember.setUniqueId(UUIDGenerator.randomUUID(true));
    } else {
      localMember.setHostname(host);
      localMember.setPort(port);
      localMember.setMemberAliveTime(100);
    }
    localMember.setSecurePort(securePort);
    localMember.setUdpPort(udpPort);
    if (this.payload != null) localMember.setPayload(payload);
    if (this.domain != null) localMember.setDomain(domain);
    localMember.setServiceStartTime(System.currentTimeMillis());
    java.net.InetAddress bind = null;
    if (properties.getProperty("mcastBindAddress") != null) {
      bind = java.net.InetAddress.getByName(properties.getProperty("mcastBindAddress"));
    }
    int ttl = -1;
    int soTimeout = -1;
    if (properties.getProperty("mcastTTL") != null) {
      try {
        ttl = Integer.parseInt(properties.getProperty("mcastTTL"));
      } catch (Exception x) {
        log.error(sm.getString("McastService.parseTTL", properties.getProperty("mcastTTL")), x);
      }
    }
    if (properties.getProperty("mcastSoTimeout") != null) {
      try {
        soTimeout = Integer.parseInt(properties.getProperty("mcastSoTimeout"));
      } catch (Exception x) {
        log.error(
            sm.getString("McastService.parseSoTimeout", properties.getProperty("mcastSoTimeout")),
            x);
      }
    }

    impl =
        new McastServiceImpl(
            localMember,
            Long.parseLong(properties.getProperty("mcastFrequency")),
            Long.parseLong(properties.getProperty("memberDropTime")),
            Integer.parseInt(properties.getProperty("mcastPort")),
            bind,
            java.net.InetAddress.getByName(properties.getProperty("mcastAddress")),
            ttl,
            soTimeout,
            this,
            this,
            Boolean.valueOf(properties.getProperty("localLoopbackDisabled", "false"))
                .booleanValue());
    String value = properties.getProperty("recoveryEnabled", "true");
    boolean recEnabled = Boolean.valueOf(value).booleanValue();
    impl.setRecoveryEnabled(recEnabled);
    int recCnt = Integer.parseInt(properties.getProperty("recoveryCounter", "10"));
    impl.setRecoveryCounter(recCnt);
    long recSlpTime = Long.parseLong(properties.getProperty("recoverySleepTime", "5000"));
    impl.setRecoverySleepTime(recSlpTime);

    impl.start(level);
  }