Package org.jgroups.protocols
Class MPING
- java.lang.Object
-
- org.jgroups.stack.Protocol
-
- org.jgroups.protocols.Discovery
-
- org.jgroups.protocols.PING
-
- org.jgroups.protocols.MPING
-
- All Implemented Interfaces:
java.lang.Runnable
public class MPING extends PING implements java.lang.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).- Author:
- Bela Ban
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.jgroups.protocols.Discovery
Discovery.DiscoveryCacheDisseminationTask
-
-
Field Summary
Fields Modifier and Type Field Description protected java.net.InetAddress
bind_addr
protected java.lang.String
bind_interface_str
protected int
ip_ttl
protected java.net.InetAddress
mcast_addr
protected int
mcast_port
protected java.net.MulticastSocket
mcast_receive_sock
protected java.net.MulticastSocket
mcast_send_sock
protected java.net.MulticastSocket[]
mcast_send_sockets
protected java.util.List<java.net.NetworkInterface>
receive_interfaces
Listof interfaces to receive multicasts on. protected boolean
receive_on_all_interfaces
protected java.lang.Thread
receiver
protected java.util.List<java.net.NetworkInterface>
send_interfaces
Listof interfaces to send multicasts on. protected boolean
send_on_all_interfaces
If true, the transport should use all available interfaces to send multicast messages.-
Fields inherited from class org.jgroups.protocols.Discovery
async_discovery, async_discovery_use_separate_thread_per_request, break_on_coord_rsp, cluster_name, current_coord, discovery_req_futures, discovery_rsp_callback, discovery_rsp_expiry_time, is_coord, is_leaving, is_server, local_addr, max_members_in_discovery_request, max_rank_to_reply, num_discovery_requests, num_discovery_runs, ping_responses, return_entire_cache, send_cache_on_join, sends_can_block, stagger_timeout, timer, transport, transport_supports_multicasting, use_disk_cache, use_ip_addrs, view, WHITESPACE
-
Fields inherited from class org.jgroups.stack.Protocol
after_creation_hook, down_prot, ergonomics, id, log, stack, stats, up_prot
-
-
Constructor Summary
Constructors Constructor Description MPING()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
bindToInterfaces(java.util.List<java.net.NetworkInterface> interfaces, java.net.MulticastSocket s, java.net.InetAddress mcast_addr)
protected java.net.MulticastSocket
createMulticastSocket(java.lang.String service_name, int port)
java.net.InetAddress
getBindAddr()
java.net.InetAddress
getMcastAddr()
int
getMcastPort()
java.util.List<java.net.NetworkInterface>
getReceiveInterfaces()
java.util.List<java.net.NetworkInterface>
getSendInterfaces()
int
getTTL()
void
init()
Called after instance has been created (null constructor) and before protocol is started.boolean
isReceiveOnAllInterfaces()
boolean
isSendOnAllInterfaces()
MPING
mcastAddress(java.net.InetAddress a)
MPING
mcastPort(int p)
void
run()
protected void
sendMcastDiscoveryRequest(Message msg)
void
setBindAddr(java.net.InetAddress b)
protected <T extends MPING>
TsetInterface(java.net.InetAddress intf, java.net.MulticastSocket s)
void
setMcastAddr(java.net.InetAddress a)
void
setMcastPort(int p)
void
setMulticastAddress(java.lang.String a)
void
setTTL(int ip_ttl)
void
start()
This method is called on aJChannel.connect(String)
.protected void
startReceiver()
void
stop()
This method is called on aJChannel.disconnect()
.java.lang.Object
up(Event evt)
An event was received from the protocol below.-
Methods inherited from class org.jgroups.protocols.PING
findMembers, isDynamic, sendDiscoveryRequest
-
Methods inherited from class org.jgroups.protocols.Discovery
addDiscoveryResponseToCaches, addResponse, addResponse, addressAsString, addToCache, breakOnCoordResponse, breakOnCoordResponse, clearRequestFutures, deserialize, discoveryRequestReceived, discoveryRspExpiryTime, disseminateDiscoveryInformation, down, dumpCache, findInitialMembersAsString, findMembers, getClusterName, getCurrentCoord, getNumberOfDiscoveryRequestsSent, getView, getViewId, handleConnect, handleDisconnect, handleDiscoveryResponse, invokeFindMembers, isCoord, isMergeRunning, marshal, providedUpServices, read, readPingData, resetStats, returnEntireCache, returnEntireCache, sendCacheInformation, sendDiscoveryResponse, serializeWithoutView, setClusterName, staggerTimeout, staggerTimeout, startCacheDissemination, up, useDiskCache, useDiskCache, weedOutCompletedDiscoveryResponses, write
-
Methods inherited from class org.jgroups.stack.Protocol
accept, afterCreationHook, destroy, down, enableStats, getConfigurableObjects, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, providedDownServices, requiredDownServices, requiredUpServices, resetStatistics, setDownProtocol, setErgonomics, setId, setLevel, setProtocolStack, setSocketFactory, setUpProtocol, setValue, statsEnabled, up
-
-
-
-
Field Detail
-
bind_addr
protected java.net.InetAddress bind_addr
-
bind_interface_str
protected java.lang.String bind_interface_str
-
ip_ttl
protected int ip_ttl
-
mcast_addr
protected java.net.InetAddress mcast_addr
-
mcast_port
protected int mcast_port
-
receive_on_all_interfaces
protected boolean receive_on_all_interfaces
-
receive_interfaces
protected java.util.List<java.net.NetworkInterface> receive_interfaces
Listof 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 java.util.List<java.net.NetworkInterface> send_interfaces
Listof 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 java.net.MulticastSocket mcast_receive_sock
-
mcast_send_sock
protected java.net.MulticastSocket mcast_send_sock
-
mcast_send_sockets
protected java.net.MulticastSocket[] mcast_send_sockets
-
receiver
protected volatile java.lang.Thread receiver
-
-
Method Detail
-
getBindAddr
public java.net.InetAddress getBindAddr()
-
setBindAddr
public void setBindAddr(java.net.InetAddress b)
-
getReceiveInterfaces
public java.util.List<java.net.NetworkInterface> getReceiveInterfaces()
-
getSendInterfaces
public java.util.List<java.net.NetworkInterface> getSendInterfaces()
-
isReceiveOnAllInterfaces
public boolean isReceiveOnAllInterfaces()
-
isSendOnAllInterfaces
public boolean isSendOnAllInterfaces()
-
getTTL
public int getTTL()
-
setTTL
public void setTTL(int ip_ttl)
-
getMcastAddr
public java.net.InetAddress getMcastAddr()
-
mcastAddress
public MPING mcastAddress(java.net.InetAddress a)
-
setMcastAddr
public void setMcastAddr(java.net.InetAddress a)
-
setMulticastAddress
public void setMulticastAddress(java.lang.String a) throws java.net.UnknownHostException
- Throws:
java.net.UnknownHostException
-
getMcastPort
public int getMcastPort()
-
setMcastPort
public void setMcastPort(int p)
-
mcastPort
public MPING mcastPort(int p)
-
up
public java.lang.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 usingdown_prot.down()
or c) the event (or another event) is sent up the stack usingup_prot.up()
.
-
init
public void init() throws java.lang.Exception
Description copied from class:Protocol
Called after instance has been created (null constructor) and before protocol is started. Properties are already set. Other protocols are not yet connected and events cannot yet be sent.
-
start
public void start() throws java.lang.Exception
Description copied from class:Protocol
This method is called on aJChannel.connect(String)
. Starts work. Protocols are connected and queues are ready to receive events. Will be called from bottom to top. This call will replace the START and START_OK events.- Overrides:
start
in classDiscovery
- Throws:
java.lang.Exception
- Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, soJChannel.connect(String)
will throw an exception
-
stop
public void stop()
Description copied from class:Protocol
This method is called on aJChannel.disconnect()
. Stops work (e.g. by closing multicast socket). Will be called from top to bottom. This means that at the time of the method invocation the neighbor protocol below is still working. This method will replace the STOP, STOP_OK, CLEANUP and CLEANUP_OK events. The ProtocolStack guarantees that when this method is called all messages in the down queue will have been flushed
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
createMulticastSocket
protected java.net.MulticastSocket createMulticastSocket(java.lang.String service_name, int port) throws java.lang.Exception
- Throws:
java.lang.Exception
-
setInterface
protected <T extends MPING> T setInterface(java.net.InetAddress intf, java.net.MulticastSocket s)
-
bindToInterfaces
protected void bindToInterfaces(java.util.List<java.net.NetworkInterface> interfaces, java.net.MulticastSocket s, java.net.InetAddress mcast_addr) throws java.io.IOException
- Throws:
java.io.IOException
-
startReceiver
protected void startReceiver()
-
sendMcastDiscoveryRequest
protected void sendMcastDiscoveryRequest(Message msg)
- Overrides:
sendMcastDiscoveryRequest
in classPING
-
-