Exemplo n.º 1
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);
  }
Exemplo n.º 2
0
 /** Return the local member */
 @Override
 public Member getLocalMember(boolean alive) {
   if (alive && localMember != null && impl != null)
     localMember.setMemberAliveTime(System.currentTimeMillis() - impl.getServiceStartTime());
   return localMember;
 }