示例#1
0
  public void start() throws Exception {
    if (can_bind_to_mcast_addr) // https://jira.jboss.org/jira/browse/JGRP-836 - prevent cross
      // talking on Linux
      mcast_sock =
          Util.createMulticastSocket(
              getSocketFactory(), Global.MPING_MCAST_SOCK, mcast_addr, mcast_port, log);
    else mcast_sock = getSocketFactory().createMulticastSocket(Global.MPING_MCAST_SOCK, mcast_port);

    mcast_sock.setTimeToLive(ip_ttl);

    if (receive_on_all_interfaces
        || (receive_interfaces != null && !receive_interfaces.isEmpty())) {
      List<NetworkInterface> interfaces;
      if (receive_interfaces != null) interfaces = receive_interfaces;
      else interfaces = Util.getAllAvailableInterfaces();
      bindToInterfaces(interfaces, mcast_sock, mcast_addr);
    } else {
      if (bind_addr != null) mcast_sock.setInterface(bind_addr);
      mcast_sock.joinGroup(mcast_addr);
    }

    // 3b. Create mcast sender socket
    if (send_on_all_interfaces || (send_interfaces != null && !send_interfaces.isEmpty())) {
      List interfaces;
      NetworkInterface intf;
      if (send_interfaces != null) interfaces = send_interfaces;
      else interfaces = Util.getAllAvailableInterfaces();
      mcast_send_sockets = new MulticastSocket[interfaces.size()];
      int index = 0;
      for (Iterator it = interfaces.iterator(); it.hasNext(); ) {
        intf = (NetworkInterface) it.next();
        mcast_send_sockets[index] = new MulticastSocket();
        mcast_send_sockets[index].setNetworkInterface(intf);
        mcast_send_sockets[index].setTimeToLive(ip_ttl);
        index++;
      }
    }

    startReceiver();
    super.start();
  }
示例#2
0
  public void start() throws Exception {
    for (int i = bind_port; i <= bind_port + port_range; i++) {
      try {
        sock = getSocketFactory().createDatagramSocket("jgroups.bping.sock", i);
        break;
      } catch (Throwable t) {
        if (i > bind_port + port_range)
          throw new RuntimeException(
              "failed to open a port in range ["
                  + bind_port
                  + " - "
                  + (bind_port + port_range)
                  + "]",
              t);
      }
    }

    sock.setBroadcast(true);
    startReceiver();
    super.start();
  }
示例#3
0
 public void stop() {
   Util.close(sock);
   sock = null;
   receiver = null;
   super.stop();
 }
示例#4
0
 public void init() throws Exception {
   super.init();
   dest_addr = InetAddress.getByName(dest);
   if (log.isDebugEnabled()) log.debug("listening on " + bind_port);
 }
 public Object getRequest(IoSession session) {
   return PING.duplicate();
 }
示例#6
0
 public void init() throws Exception {
   super.init();
   if (log.isDebugEnabled())
     log.debug(
         "bind_addr=" + bind_addr + " mcast_addr=" + mcast_addr + ", mcast_port=" + mcast_port);
 }