Commit 28b93732 authored by chiaming2000's avatar chiaming2000
Browse files

Added constructor to construct a heartbeat listener with the specified

network interface name. 
parent 9dadc8c4
Loading
Loading
Loading
Loading
+26 −3
Original line number Diff line number Diff line
@@ -58,6 +58,9 @@ public class HeartbeatListener implements Runnable {

    private Thread thread = null;

    // net interface name
    private String interfaceName = null;

    /**
     * Construct a heartbeat consumer with default address and port.
     *
@@ -67,6 +70,19 @@ public class HeartbeatListener implements Runnable {
        this.init();
    }

    /**
     * Construct a heartbeat listener with the specified network interface name.
     * 
     * @param netInterfaceName
     * @throws IOException
     */
    public HeartbeatListener(String netInterfaceName) throws IOException {

        this.interfaceName = netInterfaceName;

        this.init();
    }

    public HeartbeatListener(String address, int port) throws IOException {

        this.mcastDestination = address;
@@ -78,8 +94,14 @@ public class HeartbeatListener implements Runnable {

    private void init() throws IOException {

        // find network interface
        NetworkInterface ni = NetUtil.findMulticastNetworkInterface();
        // network interface
        NetworkInterface ni = null;

        if (this.interfaceName != null) {
            ni = NetworkInterface.getByName(interfaceName);
        } else {
            ni = NetUtil.findMulticastNetworkInterface();
        }

        // my multicast listening address
        mcastAddress = InetAddress.getByName(mcastDestination);
@@ -89,7 +111,8 @@ public class HeartbeatListener implements Runnable {

        // only set it if we are allowed to search
        if (ni != null) {
            // mcastSocket.setNetworkInterface(ni);
            logger.info("using network interface: " + ni.getDisplayName());
            mcastSocket.setNetworkInterface(ni);
        }

        // join the m group