Class MPING

All Implemented Interfaces:
Runnable, Lifecycle

public class MPING extends PING implements Runnable
Uses its own IP multicast socket to send and receive discovery requests/responses. Can be used in conjuntion with a non-UDP transport, e.g. TCP.

The discovery is asymmetric: discovery requests are broadcast via the multicast socket, and received via the multicast socket by everyone in the group. However, the discovery responses are sent back via the regular transport (e.g. TCP) to the sender (discovery request contains sender's regular address, e.g. 192.168.0.2:7800).

  • Field Details

    • bind_addr

      protected InetAddress bind_addr
    • bind_interface_str

      protected String bind_interface_str
    • ip_ttl

      protected int ip_ttl
    • mcast_addr

      protected InetAddress mcast_addr
    • mcast_port

      protected int mcast_port
    • receive_on_all_interfaces

      protected boolean receive_on_all_interfaces
    • receive_interfaces

      protected List<NetworkInterface> receive_interfaces
      List of interfaces to receive multicasts on. The multicast receive socket will listen on all of these interfaces. This is a comma-separated list of IP addresses or interface names. E.g. "192.168.5.1,eth1,127.0.0.1". Duplicates are discarded; we only bind to an interface once. If this property is set, it overrides receive_on_all_interfaces.
    • send_on_all_interfaces

      protected boolean send_on_all_interfaces
      If true, the transport should use all available interfaces to send multicast messages. This means the same multicast message is sent N times, so use with care
    • send_interfaces

      protected List<NetworkInterface> send_interfaces
      List of interfaces to send multicasts on. The multicast send socket will send the same multicast message on all of these interfaces. This is a comma-separated list of IP addresses or interface names. E.g. "192.168.5.1,eth1,127.0.0.1". Duplicates are discarded. If this property is set, it override send_on_all_interfaces.
    • mcast_receive_sock

      protected MulticastSocket mcast_receive_sock
    • mcast_send_sock

      protected MulticastSocket mcast_send_sock
    • mcast_send_sockets

      protected MulticastSocket[] mcast_send_sockets
    • receiver

      protected volatile Thread receiver
  • Constructor Details

    • MPING

      public MPING()
  • Method Details

    • getBindAddr

      public InetAddress getBindAddr()
    • setBindAddr

      public MPING setBindAddr(InetAddress b)
    • getReceiveInterfaces

      public List<NetworkInterface> getReceiveInterfaces()
    • getSendInterfaces

      public List<NetworkInterface> getSendInterfaces()
    • isReceiveOnAllInterfaces

      public boolean isReceiveOnAllInterfaces()
    • isSendOnAllInterfaces

      public boolean isSendOnAllInterfaces()
    • getTTL

      public int getTTL()
    • setTTL

      public MPING setTTL(int ip_ttl)
    • getMcastAddr

      public InetAddress getMcastAddr()
    • mcastAddress

      public MPING mcastAddress(InetAddress a)
    • setMcastAddr

      public MPING setMcastAddr(InetAddress a)
    • getMcastPort

      public int getMcastPort()
    • setMcastPort

      public MPING setMcastPort(int p)
    • setMulticastAddress

      public MPING setMulticastAddress(String a) throws UnknownHostException
      Throws:
      UnknownHostException
    • up

      public Object up(Event evt)
      Description copied from class: Protocol
      An event was received from the protocol below. Usually the current protocol will want to examine the event type and - depending on its type - perform some computation (e.g. removing headers from a MSG event type, or updating the internal membership list when receiving a VIEW_CHANGE event). Finally, the event is either a) discarded, or b) an event is sent down the stack using down_prot.down() or c) the event (or another event) is sent up the stack using up_prot.up().
      Overrides:
      up in class Discovery
    • init

      public void init() throws Exception
      Description copied from class: Protocol
      Called after a protocol has been created and before the protocol is started. Attributes are already set. Other protocols are not yet connected and events cannot yet be sent.
      Specified by:
      init in interface Lifecycle
      Overrides:
      init in class Discovery
      Throws:
      Exception - Thrown if protocol cannot be initialized successfully. This will cause the ProtocolStack to fail, so the the channel constructor will throw an exception
    • start

      public void start() throws Exception
      Description copied from class: Protocol
      This method is called on a JChannel.connect(String); starts work. Protocols are connected ready to receive events. Will be called from bottom to top.
      Specified by:
      start in interface Lifecycle
      Overrides:
      start in class Discovery
      Throws:
      Exception - Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, so JChannel.connect(String) will throw an exception
    • stop

      public void stop()
      Description copied from class: Protocol
      Called on a JChannel.disconnect(); stops work (e.g. by closing multicast socket). Will be called from top to bottom.
      Specified by:
      stop in interface Lifecycle
      Overrides:
      stop in class Discovery
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • createMulticastSocket

      protected MulticastSocket createMulticastSocket(String service_name, int port) throws Exception
      Throws:
      Exception
    • setInterface

      protected <T extends MPING> T setInterface(InetAddress intf, MulticastSocket s)
    • bindToInterfaces

      protected void bindToInterfaces(List<NetworkInterface> interfaces, MulticastSocket s, InetAddress mcast_addr) throws IOException
      Throws:
      IOException
    • startReceiver

      protected void startReceiver()
    • sendMcastDiscoveryRequest

      protected void sendMcastDiscoveryRequest(Message msg)
      Overrides:
      sendMcastDiscoveryRequest in class PING