示例#1
0
 /** Stop broadcasting and listening to membership pings */
 @Override
 public void stop(int svc) {
   try {
     if (impl != null && impl.stop(svc)) impl = null;
   } catch (Exception x) {
     log.error(sm.getString("McastService.stopFail", Integer.valueOf(svc)), x);
   }
 }
示例#2
0
 @Override
 public void setDomain(byte[] domain) {
   this.domain = domain;
   if (localMember != null) {
     localMember.setDomain(domain);
     localMember.getData(true, true);
     try {
       if (impl != null) impl.send(false);
     } catch (Exception x) {
       log.error(sm.getString("McastService.domain"), x);
     }
   }
 }
示例#3
0
 @Override
 public void setPayload(byte[] payload) {
   this.payload = payload;
   if (localMember != null) {
     localMember.setPayload(payload);
     localMember.getData(true, true);
     try {
       if (impl != null) impl.send(false);
     } catch (Exception x) {
       log.error(sm.getString("McastService.payload"), x);
     }
   }
 }
示例#4
0
  @Override
  public void broadcast(ChannelMessage message) throws ChannelException {
    if (impl == null || (impl.startLevel & Channel.MBR_TX_SEQ) != Channel.MBR_TX_SEQ)
      throw new ChannelException(sm.getString("mcastService.noStart"));

    byte[] data = XByteBuffer.createDataPackage((ChannelData) message);
    if (data.length > McastServiceImpl.MAX_PACKET_SIZE) {
      throw new ChannelException(
          sm.getString(
              "mcastService.exceed.maxPacketSize",
              Integer.toString(data.length),
              Integer.toString(McastServiceImpl.MAX_PACKET_SIZE)));
    }
    DatagramPacket packet = new DatagramPacket(data, 0, data.length);
    try {
      impl.send(false, packet);
    } catch (Exception x) {
      throw new ChannelException(x);
    }
  }
示例#5
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);
  }
示例#6
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;
 }