Package org.jgroups.protocols
Class Discovery
- java.lang.Object
-
- org.jgroups.stack.Protocol
-
- org.jgroups.protocols.Discovery
-
public abstract class Discovery extends Protocol
The Discovery protocol layer retrieves the initial membership (used by the GMS when started by sending event FIND_INITIAL_MBRS down the stack). We do this by specific subclasses, e.g. by mcasting PING requests to an IP MCAST address or, if gossiping is enabled, by contacting the GossipRouter. The responses should allow us to determine the coordinator whom we have to contact, e.g. in case we want to join the group. When we are a server (after having received the BECOME_SERVER event), we'll respond to PING requests with a PING response.The FIND_INITIAL_MBRS event will eventually be answered with a FIND_INITIAL_MBRS_OK event up the stack. The following properties are available
- timeout - the timeout (ms) to wait for the initial members, default is 3000=3 secs
- num_initial_members - the minimum number of initial members for a FIND_INITAL_MBRS, default is 2
- num_ping_requests - the number of GET_MBRS_REQ messages to be sent (min=1), distributed over timeout ms
- Version:
- $Id: Discovery.java,v 1.32.2.6 2008/09/19 10:56:43 belaban Exp $
- Author:
- Bela Ban
-
-
Constructor Summary
Constructors Constructor Description Discovery()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.Object
down(Event evt)
An event is to be sent down the stack.java.util.List<PingRsp>
findInitialMembers(Promise<JoinRsp> promise)
Finds the initial membership: sends a GET_MBRS_REQ to all members, waits 'timeout' ms or until 'num_initial_members' have been retrievedjava.lang.String
findInitialMembersAsString()
int
getNumberOfDiscoveryRequestsSent()
int
getNumInitialMembers()
int
getNumPingRequests()
long
getTimeout()
void
handleConnect()
void
handleDisconnect()
void
init()
Called after instance has been created (null constructor) and before protocol is started.void
localAddressSet(Address addr)
Called after local_addr was setprotected View
makeView(java.util.Vector mbrs)
java.util.Vector<java.lang.Integer>
providedUpServices()
List of events that are provided to layers above (they will be handled when sent down from above).void
resetStats()
abstract void
sendGetMembersRequest()
void
setNumInitialMembers(int num_initial_members)
void
setNumPingRequests(int num_ping_requests)
boolean
setProperties(java.util.Properties props)
sets the properties of the PING protocol.void
setTimeout(long timeout)
void
start()
This method is called on aChannel.connect(String)
.void
stop()
This method is called on aChannel.disconnect()
.java.lang.Object
up(Event evt)
An event was received from the layer below.-
Methods inherited from class org.jgroups.stack.Protocol
destroy, downThreadEnabled, dumpStats, enableStats, getDownProtocol, getName, getProperties, getProtocolStack, getThreadFactory, getTransport, getUpProtocol, printStats, providedDownServices, requiredDownServices, requiredUpServices, setDownProtocol, setPropertiesInternal, setProtocolStack, setUpProtocol, statsEnabled, upThreadEnabled
-
-
-
-
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.
-
localAddressSet
public void localAddressSet(Address addr)
Called after local_addr was set
-
sendGetMembersRequest
public abstract void sendGetMembersRequest()
-
handleDisconnect
public void handleDisconnect()
-
handleConnect
public void handleConnect()
-
getTimeout
public long getTimeout()
-
setTimeout
public void setTimeout(long timeout)
-
getNumInitialMembers
public int getNumInitialMembers()
-
setNumInitialMembers
public void setNumInitialMembers(int num_initial_members)
-
getNumPingRequests
public int getNumPingRequests()
-
setNumPingRequests
public void setNumPingRequests(int num_ping_requests)
-
getNumberOfDiscoveryRequestsSent
public int getNumberOfDiscoveryRequestsSent()
-
providedUpServices
public java.util.Vector<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
- Returns:
- Vector (of Integers)
-
setProperties
public boolean setProperties(java.util.Properties props)
sets the properties of the PING protocol. The following properties are available property: timeout - the timeout (ms) to wait for the initial members, default is 3000=3 secs property: num_initial_members - the minimum number of initial members for a FIND_INITAL_MBRS, default is 2- Overrides:
setProperties
in classProtocol
- Parameters:
props
- - a property set- Returns:
- returns true if all properties were parsed properly returns false if there are unrecnogized properties in the property set
-
resetStats
public void resetStats()
- Overrides:
resetStats
in classProtocol
-
start
public void start() throws java.lang.Exception
Description copied from class:Protocol
This method is called on aChannel.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, soChannel.connect(String)
will throw an exception
-
stop
public void stop()
Description copied from class:Protocol
This method is called on aChannel.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
-
findInitialMembers
public java.util.List<PingRsp> findInitialMembers(Promise<JoinRsp> promise)
Finds the initial membership: sends a GET_MBRS_REQ to all members, waits 'timeout' ms or until 'num_initial_members' have been retrieved- Returns:
- List
-
findInitialMembersAsString
public java.lang.String findInitialMembersAsString()
-
up
public java.lang.Object up(Event evt)
An event was received from the layer below. Usually the current layer 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 usingPassDown
or c) the event (or another event) is sent up the stack usingPassUp
. For the PING protocol, the Up operation does the following things. 1. If the event is a Event.MSG then PING will inspect the message header. If the header is null, PING simply passes up the event If the header is PingHeader.GET_MBRS_REQ then the PING protocol will PassDown a PingRequest message If the header is PingHeader.GET_MBRS_RSP we will add the message to the initial members vector and wake up any waiting threads. 2. If the event is Event.SET_LOCAL_ADDR we will simple set the local address of this protocol 3. For all other messages we simple pass it up to the protocol above
-
down
public java.lang.Object down(Event evt)
An event is to be sent down the stack. The layer 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 layer may need to add a header to it (or do nothing at all) before sending it down the stack usingPassDown
. In case of a GET_ADDRESS event (which tries to retrieve the stack's address from one of the bottom layers), the layer may need to send a new response event back up the stack usingup_prot.up()
. The PING protocol is interested in several different down events, Event.FIND_INITIAL_MBRS - sent by the GMS layer and expecting a GET_MBRS_OK Event.TMP_VIEW and Event.VIEW_CHANGE - a view change event Event.BECOME_SERVER - called after client has joined and is fully working group member Event.CONNECT, Event.DISCONNECT.
-
makeView
protected final View makeView(java.util.Vector mbrs)
-
-