Package org.jgroups.protocols
Class Discovery
- java.lang.Object
-
- org.jgroups.stack.Protocol
-
- org.jgroups.protocols.Discovery
-
- Direct Known Subclasses:
DNS_PING
,FILE_PING
,LOCAL_PING
,MULTI_PING
,PING
,SHARED_LOOPBACK_PING
,TCPGOSSIP
,TCPPING
public abstract class Discovery extends Protocol
The Discovery protocol retrieves the initial membership (used by GMS and MERGE3) by sending discovery requests. We do this in subclasses of Discovery, e.g. by mcasting a discovery request (PING
) or, if gossiping is enabled, by contacting the GossipRouter (TCPGOSSIP
). The responses should allow us to determine the coordinator which we have to contact, e.g. in case we want to join the group, or to see if we have diverging views in case of MERGE2. When we are a server (after having received the BECOME_SERVER event), we'll respond to discovery requests with a discovery response.- Author:
- Bela Ban
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
Discovery.DiscoveryCacheDisseminationTask
-
Field Summary
Fields Modifier and Type Field Description protected boolean
async_discovery
protected boolean
async_discovery_use_separate_thread_per_request
protected boolean
break_on_coord_rsp
protected java.lang.String
cluster_name
protected Address
current_coord
protected java.util.List<java.util.concurrent.Future<?>>
discovery_req_futures
protected java.util.function.Consumer<PingData>
discovery_rsp_callback
protected long
discovery_rsp_expiry_time
protected boolean
is_coord
protected boolean
is_leaving
protected boolean
is_server
protected Address
local_addr
protected int
max_members_in_discovery_request
protected int
max_rank_to_reply
protected int
num_discovery_requests
protected int
num_discovery_runs
protected java.util.Map<java.lang.Long,Responses>
ping_responses
protected boolean
return_entire_cache
protected boolean
send_cache_on_join
protected boolean
sends_can_block
protected long
stagger_timeout
protected TimeScheduler
timer
protected TP
transport
protected boolean
transport_supports_multicasting
protected boolean
use_disk_cache
protected boolean
use_ip_addrs
protected View
view
protected static byte[]
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 Discovery()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected boolean
addDiscoveryResponseToCaches(Address mbr, java.lang.String logical_name, PhysicalAddress physical_addr)
protected void
addResponse(PingData rsp, boolean overwrite)
void
addResponse(Responses rsp)
protected static java.lang.String
addressAsString(Address address)
void
addToCache(java.lang.String filename)
boolean
breakOnCoordResponse()
<T extends Discovery>
TbreakOnCoordResponse(boolean flag)
protected void
clearRequestFutures()
protected static PingData
deserialize(byte[] data)
void
discoveryRequestReceived(Address sender, java.lang.String logical_name, PhysicalAddress physical_addr)
<T extends Discovery>
TdiscoveryRspExpiryTime(long t)
protected void
disseminateDiscoveryInformation(java.util.List<Address> current_mbrs, java.util.List<Address> left_mbrs, java.util.List<Address> new_mbrs)
Disseminates cache information (UUID/IP adddress/port/name) to the given membersjava.lang.Object
down(Event evt)
An event is to be sent down the stack.void
dumpCache(java.lang.String output_filename)
java.lang.String
findInitialMembersAsString()
Responses
findMembers(java.util.List<Address> members, boolean initial_discovery, boolean async, long timeout)
protected abstract void
findMembers(java.util.List<Address> members, boolean initial_discovery, Responses responses)
Fetches information (e.g.java.lang.String
getClusterName()
java.lang.String
getCurrentCoord()
int
getNumberOfDiscoveryRequestsSent()
java.lang.String
getView()
ViewId
getViewId()
void
handleConnect()
void
handleDisconnect()
protected void
handleDiscoveryResponse(PingData data, Address sender)
void
init()
Called after instance has been created (null constructor) and before protocol is started.protected void
invokeFindMembers(java.util.List<Address> members, boolean initial_discovery, Responses rsps, boolean async)
protected boolean
isCoord(Address member)
abstract boolean
isDynamic()
protected boolean
isMergeRunning()
static Buffer
marshal(PingData data)
java.util.List<java.lang.Integer>
providedUpServices()
List of events that are provided to layers above (they will be handled when sent down from above)protected java.util.List<PingData>
read(java.io.InputStream in)
protected PingData
readPingData(byte[] buffer, int offset, int length)
void
resetStats()
boolean
returnEntireCache()
<T extends Discovery>
TreturnEntireCache(boolean flag)
void
sendCacheInformation()
protected void
sendDiscoveryResponse(Address logical_addr, PhysicalAddress physical_addr, java.lang.String logical_name, Address sender, boolean coord)
protected byte[]
serializeWithoutView(PingData data)
Creates a byte[] representation of the PingData, but DISCARDING the view it contains.<T extends Discovery>
TsetClusterName(java.lang.String n)
long
staggerTimeout()
<T extends Discovery>
TstaggerTimeout(long timeout)
void
start()
This method is called on aJChannel.connect(String)
.protected void
startCacheDissemination(java.util.List<Address> curr_mbrs, java.util.List<Address> left_mbrs, java.util.List<Address> new_mbrs)
void
stop()
This method is called on aJChannel.disconnect()
.java.lang.Object
up(Event evt)
An event was received from the protocol below.java.lang.Object
up(Message msg)
A single message was received.boolean
useDiskCache()
<T extends Discovery>
TuseDiskCache(boolean flag)
void
weedOutCompletedDiscoveryResponses()
Removes responses which are done or whose timeout has expired (in the latter case, an expired response is marked as done)protected void
write(java.util.List<PingData> list, java.io.OutputStream out)
-
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
-
break_on_coord_rsp
protected boolean break_on_coord_rsp
-
return_entire_cache
protected boolean return_entire_cache
-
stagger_timeout
protected long stagger_timeout
-
use_disk_cache
protected boolean use_disk_cache
-
max_members_in_discovery_request
protected int max_members_in_discovery_request
-
discovery_rsp_expiry_time
protected long discovery_rsp_expiry_time
-
async_discovery
protected boolean async_discovery
-
async_discovery_use_separate_thread_per_request
protected boolean async_discovery_use_separate_thread_per_request
-
send_cache_on_join
protected boolean send_cache_on_join
-
max_rank_to_reply
protected int max_rank_to_reply
-
num_discovery_runs
protected int num_discovery_runs
-
num_discovery_requests
protected int num_discovery_requests
-
is_server
protected volatile boolean is_server
-
is_leaving
protected volatile boolean is_leaving
-
timer
protected TimeScheduler timer
-
view
protected volatile View view
-
is_coord
protected volatile boolean is_coord
-
local_addr
protected volatile Address local_addr
-
current_coord
protected volatile Address current_coord
-
cluster_name
protected java.lang.String cluster_name
-
transport
protected TP transport
-
ping_responses
protected final java.util.Map<java.lang.Long,Responses> ping_responses
-
discovery_req_futures
protected final java.util.List<java.util.concurrent.Future<?>> discovery_req_futures
-
transport_supports_multicasting
protected boolean transport_supports_multicasting
-
use_ip_addrs
protected boolean use_ip_addrs
-
sends_can_block
protected boolean sends_can_block
-
discovery_rsp_callback
protected java.util.function.Consumer<PingData> discovery_rsp_callback
-
WHITESPACE
protected static final byte[] WHITESPACE
-
-
Method Detail
-
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 classProtocol
- 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
-
isDynamic
public abstract boolean isDynamic()
-
handleDisconnect
public void handleDisconnect()
-
handleConnect
public void handleConnect()
-
discoveryRequestReceived
public void discoveryRequestReceived(Address sender, java.lang.String logical_name, PhysicalAddress physical_addr)
-
getClusterName
public java.lang.String getClusterName()
-
setClusterName
public <T extends Discovery> T setClusterName(java.lang.String n)
-
getNumberOfDiscoveryRequestsSent
public int getNumberOfDiscoveryRequestsSent()
-
breakOnCoordResponse
public boolean breakOnCoordResponse()
-
breakOnCoordResponse
public <T extends Discovery> T breakOnCoordResponse(boolean flag)
-
returnEntireCache
public boolean returnEntireCache()
-
returnEntireCache
public <T extends Discovery> T returnEntireCache(boolean flag)
-
staggerTimeout
public long staggerTimeout()
-
staggerTimeout
public <T extends Discovery> T staggerTimeout(long timeout)
-
useDiskCache
public boolean useDiskCache()
-
useDiskCache
public <T extends Discovery> T useDiskCache(boolean flag)
-
discoveryRspExpiryTime
public <T extends Discovery> T discoveryRspExpiryTime(long t)
-
getView
public java.lang.String getView()
-
getViewId
public ViewId getViewId()
-
getCurrentCoord
public java.lang.String getCurrentCoord()
-
isMergeRunning
protected boolean isMergeRunning()
-
sendCacheInformation
public void sendCacheInformation()
-
providedUpServices
public java.util.List<java.lang.Integer> providedUpServices()
Description copied from class:Protocol
List of events that are provided to layers above (they will be handled when sent down from above)- Overrides:
providedUpServices
in classProtocol
-
resetStats
public void resetStats()
- Overrides:
resetStats
in classProtocol
-
addResponse
public void addResponse(Responses rsp)
-
findMembers
protected abstract void findMembers(java.util.List<Address> members, boolean initial_discovery, Responses responses)
Fetches information (e.g. physical address, logical name) for the given member addresses. Needs to add responses to theResponses
object. Ifasync_discovery
is true, this method will be called in a separate thread, otherwise the caller's thread will be used.- Parameters:
members
- A list of logical addresses (typicallyUUID
s). If null, then information for all members is fetchedinitial_discovery
- Set to true if this is for the initial membership discovery. Some protocols (e.g. file based ones) may return only the information for the coordinator(s).responses
- The list to which responses should be added
-
invokeFindMembers
protected void invokeFindMembers(java.util.List<Address> members, boolean initial_discovery, Responses rsps, boolean async)
-
findMembers
public Responses findMembers(java.util.List<Address> members, boolean initial_discovery, boolean async, long timeout)
-
findInitialMembersAsString
public java.lang.String findInitialMembersAsString()
-
addToCache
public void addToCache(java.lang.String filename) throws java.lang.Exception
- Throws:
java.lang.Exception
-
dumpCache
public void dumpCache(java.lang.String output_filename) throws java.lang.Exception
- Throws:
java.lang.Exception
-
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()
.
-
up
public java.lang.Object up(Message msg)
Description copied from class:Protocol
A single message was received. Protocols may examine the message and do something (e.g. add a header) with it before passing it up.
-
down
public java.lang.Object down(Event evt)
Description copied from class:Protocol
An event is to be sent down the stack. A protocol may want to examine its type and perform some action on it, depending on the event's type. If the event is a message MSG, then the protocol may need to add a header to it (or do nothing at all) before sending it down the stack usingdown_prot.down()
.
-
read
protected java.util.List<PingData> read(java.io.InputStream in)
-
write
protected void write(java.util.List<PingData> list, java.io.OutputStream out) throws java.lang.Exception
- Throws:
java.lang.Exception
-
addResponse
protected void addResponse(PingData rsp, boolean overwrite)
-
weedOutCompletedDiscoveryResponses
public void weedOutCompletedDiscoveryResponses()
Removes responses which are done or whose timeout has expired (in the latter case, an expired response is marked as done)
-
addDiscoveryResponseToCaches
protected boolean addDiscoveryResponseToCaches(Address mbr, java.lang.String logical_name, PhysicalAddress physical_addr)
-
clearRequestFutures
protected void clearRequestFutures()
-
startCacheDissemination
protected void startCacheDissemination(java.util.List<Address> curr_mbrs, java.util.List<Address> left_mbrs, java.util.List<Address> new_mbrs)
-
serializeWithoutView
protected byte[] serializeWithoutView(PingData data)
Creates a byte[] representation of the PingData, but DISCARDING the view it contains.- Parameters:
data
- the PingData instance to serialize.- Returns:
-
deserialize
protected static PingData deserialize(byte[] data) throws java.lang.Exception
- Throws:
java.lang.Exception
-
readPingData
protected PingData readPingData(byte[] buffer, int offset, int length)
-
sendDiscoveryResponse
protected void sendDiscoveryResponse(Address logical_addr, PhysicalAddress physical_addr, java.lang.String logical_name, Address sender, boolean coord)
-
addressAsString
protected static java.lang.String addressAsString(Address address)
-
isCoord
protected boolean isCoord(Address member)
-
disseminateDiscoveryInformation
protected void disseminateDiscoveryInformation(java.util.List<Address> current_mbrs, java.util.List<Address> left_mbrs, java.util.List<Address> new_mbrs)
Disseminates cache information (UUID/IP adddress/port/name) to the given members- Parameters:
current_mbrs
- The current members. Guaranteed to be non-null. This is a copy and can be modified.left_mbrs
- The members which left. These are excluded from dissemination. Can be null if no members leftnew_mbrs
- The new members that we need to disseminate the information to. Will be all members if null.
-
-