Class Discovery
- All Implemented Interfaces:
Lifecycle
- Direct Known Subclasses:
DNS_PING,FILE_PING,LOCAL_PING,PING,SHARED_LOOPBACK_PING,TCPGOSSIP,TCPPING
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.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected booleanprotected booleanprotected Stringprotected Addressprotected longprotected booleanprotected booleanprotected booleanprotected intprotected intprotected intprotected intprotected booleanprotected booleanprotected booleanprotected longprotected TimeSchedulerprotected TPprotected booleanprotected booleanprotected Viewprotected static final byte[]Fields inherited from class org.jgroups.stack.Protocol
after_creation_hook, down_prot, ergonomics, id, local_addr, log, policies, stack, stats, up_prot -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanaddDiscoveryResponseToCaches(Address mbr, String logical_name, PhysicalAddress physical_addr) protected voidaddResponse(PingData rsp, boolean overwrite) voidaddResponse(Responses rsp) protected static StringaddressAsString(Address address) voidaddToCache(String filename) boolean<T extends Discovery>
TbreakOnCoordResponse(boolean flag) protected voidcallFindMembersInAllDiscoveryProtocols(List<Address> mbrs, boolean initial_discovery, Responses rsps) CallsfindMembers(List, boolean, Responses)in this protocol and all discovery protocols belowprotected voiddeserialize(byte[] data, int offset, int length) voiddiscoveryRequestReceived(Address sender, String logical_name, PhysicalAddress physical_addr) <T extends Discovery>
TdiscoveryRspExpiryTime(long t) protected voiddisseminateDiscoveryInformation(List<Address> current_mbrs, List<Address> left_mbrs, List<Address> new_mbrs) Disseminates cache information (UUID/IP adddress/port/name) to the given membersAn event is to be sent down the stack.voidfindMembers(List<Address> members, boolean initial_discovery, boolean async, long timeout) protected abstract voidfindMembers(List<Address> members, boolean initial_discovery, Responses responses) Fetches information (e.g.protected DiscoveryFinds the top-most discovery protocol, starting from this.intgetView()protected Objecthandle(PingHeader hdr, Message msg) voidvoidprotected voidhandleDiscoveryResponse(List<PingData> data, Address sender) protected voidhandleDiscoveryResponse(PingData data, Address sender) voidinit()Called after a protocol has been created and before the protocol is started.protected booleanabstract booleanprotected booleanstatic ByteArraystatic ByteArraystatic ByteArrayprotected static StringList of events that are provided to layers above (they will be handled when sent down from above)read(InputStream in) readPingData(byte[] buffer, int offset, int length) voidboolean<T extends Discovery>
TreturnEntireCache(boolean flag) voidboolean<T extends Discovery>
TsendCacheOnJoin(boolean b) protected voidsendDiscoveryResponse(List<PingData> list, Address sender) protected voidsendDiscoveryResponse(Address logical_addr, PhysicalAddress physical_addr, String logical_name, Address sender, boolean coord) protected ByteArrayserializeWithoutView(PingData data) Creates a byte[] representation of the PingData, but DISCARDING the view it contains.<T extends Discovery>
Tlong<T extends Discovery>
TstaggerTimeout(long timeout) voidstart()This method is called on aJChannel.connect(String); starts work.protected voidvoidstop()Called on aJChannel.disconnect(); stops work (e.g.An event was received from the protocol below.A single message was received.voidup(MessageBatch batch) Sends up a multiple messages in aMessageBatch.boolean<T extends Discovery>
TuseDiskCache(boolean flag) voidRemoves responses which are done or whose timeout has expired (in the latter case, an expired response is marked as done)protected voidwrite(List<PingData> list, OutputStream out) Methods inherited from class org.jgroups.stack.Protocol
accept, addPolicy, addr, addr, afterCreationHook, destroy, down, down, enableStats, getAddress, getComponents, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getPolicies, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, policies, providedDownServices, removePolicy, requiredDownServices, requiredUpServices, resetStatistics, setAddress, setDownProtocol, setErgonomics, setId, setLevel, setPolicies, setProtocolStack, setSocketFactory, setUpProtocol, setValue, statsEnabled, toString
-
Field Details
-
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
-
view
-
is_coord
protected volatile boolean is_coord -
current_coord
-
cluster_name
-
transport
-
ping_responses
-
discovery_req_futures
-
transport_supports_multicasting
protected boolean transport_supports_multicasting -
sends_can_block
protected boolean sends_can_block -
discovery_rsp_callback
-
WHITESPACE
protected static final byte[] WHITESPACE
-
-
Constructor Details
-
Discovery
public Discovery()
-
-
Method Details
-
init
Description copied from class:ProtocolCalled 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. -
start
Description copied from class:ProtocolThis method is called on aJChannel.connect(String); starts work. Protocols are connected ready to receive events. Will be called from bottom to top. -
stop
public void stop()Description copied from class:ProtocolCalled on aJChannel.disconnect(); stops work (e.g. by closing multicast socket). Will be called from top to bottom. -
isDynamic
public abstract boolean isDynamic() -
handleDisconnect
public void handleDisconnect() -
handleConnect
public void handleConnect() -
discoveryRequestReceived
public void discoveryRequestReceived(Address sender, String logical_name, PhysicalAddress physical_addr) -
getClusterName
-
setClusterName
-
getNumberOfDiscoveryRequestsSent
public int getNumberOfDiscoveryRequestsSent() -
breakOnCoordResponse
public boolean breakOnCoordResponse() -
breakOnCoordResponse
-
returnEntireCache
public boolean returnEntireCache() -
returnEntireCache
-
staggerTimeout
public long staggerTimeout() -
staggerTimeout
-
useDiskCache
public boolean useDiskCache() -
useDiskCache
-
discoveryRspExpiryTime
-
sendCacheOnJoin
public boolean sendCacheOnJoin() -
sendCacheOnJoin
-
getView
-
getViewId
-
getCurrentCoord
-
isMergeRunning
protected boolean isMergeRunning() -
sendCacheInformation
public void sendCacheInformation() -
providedUpServices
Description copied from class:ProtocolList of events that are provided to layers above (they will be handled when sent down from above)- Overrides:
providedUpServicesin classProtocol
-
resetStats
public void resetStats()- Overrides:
resetStatsin classProtocol
-
addResponse
-
findMembers
protected abstract void findMembers(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 theResponsesobject. Ifasync_discoveryis 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 (typicallyUUIDs). 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
-
findMembers
-
findInitialMembersAsString
-
addToCache
- Throws:
Exception
-
dumpCache
- Throws:
Exception
-
up
Description copied from class:ProtocolAn 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
Description copied from class:ProtocolA single message was received. Protocols may examine the message and do something (e.g. add a header) with it before passing it up. -
up
Description copied from class:ProtocolSends up a multiple messages in aMessageBatch. The sender of the batch is always the same, and so is the destination (null == multicast messages). Messages in a batch can be OOB messages, regular messages, or mixed messages, although the transport itself will create initial MessageBatches that contain only either OOB or regular messages.The default processing below sends messages up the stack individually, based on a matching criteria (calling
Protocol.accept(Message)), and - if true - callsProtocol.up(org.jgroups.Event)for that message and removes the message. If the batch is not empty, it is passed up, or else it is dropped.Subclasses should check if there are any messages destined for them (e.g. using
MessageBatch.iterator(Predicate)), then possibly remove and process them and finally pass the batch up to the next protocol. Protocols can also modify messages in place, e.g. ENCRYPT could decrypt all encrypted messages in the batch, not remove them, and pass the batch up when done. -
handle
-
callFindMembersInAllDiscoveryProtocols
protected void callFindMembersInAllDiscoveryProtocols(List<Address> mbrs, boolean initial_discovery, Responses rsps) CallsfindMembers(List, boolean, Responses)in this protocol and all discovery protocols below -
findTopmostDiscoveryProtocol
Finds the top-most discovery protocol, starting from this. If none is found, returns this -
handleDiscoveryResponse
-
handleDiscoveryResponse
-
down
Description copied from class:ProtocolAn 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
-
write
- Throws:
Exception
-
addResponse
-
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, String logical_name, PhysicalAddress physical_addr) -
clearRequestFutures
protected void clearRequestFutures() -
startCacheDissemination
-
serializeWithoutView
Creates a byte[] representation of the PingData, but DISCARDING the view it contains.- Parameters:
data- the PingData instance to serialize.- Returns:
-
deserialize
- Throws:
Exception
-
marshal
-
marshal
-
marshal
-
readPingData
-
sendDiscoveryResponse
protected void sendDiscoveryResponse(Address logical_addr, PhysicalAddress physical_addr, String logical_name, Address sender, boolean coord) -
sendDiscoveryResponse
-
print
-
addressAsString
-
isCoord
-
disseminateDiscoveryInformation
protected void disseminateDiscoveryInformation(List<Address> current_mbrs, List<Address> left_mbrs, 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.
-