org.jgroups.protocols

Class 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 GossipServer. 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

Version: $Id: Discovery.java,v 1.14 2005/12/16 16:02:43 belaban Exp $

Author: Bela Ban

Method Summary
voiddown(Event evt)
An event is to be sent down the stack.
VectorfindInitialMembers()
Finds the initial membership
StringfindInitialMembersAsString()
intgetNumberOfDiscoveryRequestsSent()
intgetNumInitialMembers()
intgetNumPingRequests()
longgetTimeout()
voidhandleConnect()
voidhandleConnectOK()
Called when CONNECT_OK has been received
voidhandleDisconnect()
voidlocalAddressSet(Address addr)
Called after local_addr was set
protected ViewmakeView(Vector mbrs)
VectorprovidedUpServices()
voidresetStats()
abstract voidsendGetMembersRequest()
voidsetNumInitialMembers(int num_initial_members)
voidsetNumPingRequests(int num_ping_requests)
booleansetProperties(Properties props)
sets the properties of the PING protocol.
voidsetTimeout(long timeout)
voidstart()
voidstop()
voidup(Event evt)
An event was received from the layer below.

Method Detail

down

public void 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 using PassDown. 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 using passUp(). 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.

findInitialMembers

public Vector findInitialMembers()
Finds the initial membership

Returns: Vector

findInitialMembersAsString

public String findInitialMembersAsString()

getNumberOfDiscoveryRequestsSent

public int getNumberOfDiscoveryRequestsSent()

getNumInitialMembers

public int getNumInitialMembers()

getNumPingRequests

public int getNumPingRequests()

getTimeout

public long getTimeout()

handleConnect

public void handleConnect()

handleConnectOK

public void handleConnectOK()
Called when CONNECT_OK has been received

handleDisconnect

public void handleDisconnect()

localAddressSet

public void localAddressSet(Address addr)
Called after local_addr was set

makeView

protected View makeView(Vector mbrs)

providedUpServices

public Vector providedUpServices()

resetStats

public void resetStats()

sendGetMembersRequest

public abstract void sendGetMembersRequest()

setNumInitialMembers

public void setNumInitialMembers(int num_initial_members)

setNumPingRequests

public void setNumPingRequests(int num_ping_requests)

setProperties

public boolean setProperties(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

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

setTimeout

public void setTimeout(long timeout)

start

public void start()

stop

public void stop()

up

public void 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 using PassDown or c) the event (or another event) is sent up the stack using PassUp.

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

Parameters: evt - the event that has been sent from the layer below

Copyright ? 1998-2005 Bela Ban. All Rights Reserved.