org.jgroups.protocols
Class Discovery

java.lang.Object
  extended by org.jgroups.stack.Protocol
      extended by org.jgroups.protocols.Discovery
Direct Known Subclasses:
FILE_PING, PING, TCPGOSSIP, TCPPING

public abstract class Discovery
extends Protocol

The Discovery protocol retrieves the initial membership (used by GMS and MERGE2) 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
protected static class Discovery.Responses
           
 
Field Summary
protected  boolean break_on_coord_rsp
           
protected  Address current_coord
           
protected  boolean force_sending_discovery_rsps
           
protected  java.lang.String group_addr
           
protected  boolean is_coord
           
protected  boolean is_leaving
           
protected  boolean is_server
           
protected  Address local_addr
           
protected  java.util.List<Address> members
           
protected  int num_discovery_requests
           
protected  int num_initial_members
           
protected  int num_initial_srv_members
          Deprecated. 
protected  java.util.Set<Discovery.Responses> ping_responses
           
protected  boolean return_entire_cache
           
protected  long stagger_timeout
           
protected  long timeout
           
protected  TimeScheduler timer
           
protected  boolean use_disk_cache
           
protected  View view
           
 
Fields inherited from class org.jgroups.stack.Protocol
down_prot, ergonomics, id, log, name, stack, stats, up_prot
 
Constructor Summary
Discovery()
           
 
Method Summary
protected  PingData deserialize(byte[] data)
           
 void discoveryRequestReceived(Address sender, java.lang.String logical_name, java.util.Collection<PhysicalAddress> physical_addrs)
           
 java.lang.Object down(Event evt)
          An event is to be sent down the stack.
abstract  java.util.Collection<PhysicalAddress> fetchClusterMembers(java.lang.String cluster_name)
          Grab all current cluster members
 java.util.List<PingData> findAllViews(Promise<JoinRsp> promise)
           
 java.lang.String findAllViewsAsString()
           
 java.util.List<PingData> findInitialMembers(Promise<JoinRsp> promise)
          Finds initial members
 java.lang.String findInitialMembersAsString()
           
protected  java.util.List<PingData> findMembers(Promise<JoinRsp> promise, int num_expected_rsps, boolean break_on_coord, ViewId view_id)
           
 java.lang.String getCurrentCoord()
           
 int getNumberOfDiscoveryRequestsSent()
           
 int getNumInitialMembers()
           
 long getTimeout()
           
 java.lang.String getView()
           
 ViewId getViewId()
           
 void handleConnect()
           
 void handleDisconnect()
           
 void init()
          Called after instance has been created (null constructor) and before protocol is started.
abstract  boolean isDynamic()
           
protected  boolean isMergeRunning()
           
 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)
 void resetStats()
           
 void sendDiscoveryRequest(java.lang.String cluster_name, Promise promise, ViewId view_id)
           
abstract  boolean sendDiscoveryRequestsInParallel()
          Whether or not to send each discovery request on a separate (timer) thread.
protected  void sendDiscoveryResponse(Address logical_addr, java.util.List<PhysicalAddress> physical_addrs, boolean is_server, boolean return_view_only, java.lang.String logical_name, Address sender)
           
protected  void sendMcastDiscoveryRequest(Message discovery_request)
           
protected  byte[] serializeWithoutView(PingData data)
          Creates a byte[] representation of the PingData, but DISCARDING the view it contains.
 void setForceSendingDiscoveryRsps(boolean flag)
           
 void setNumInitialMembers(int num_initial_members)
           
 void setTimeout(long timeout)
           
 void start()
          This method is called on a Channel.connect(String).
 void stop()
          This method is called on a Channel.disconnect().
 java.lang.Object up(Event evt)
          An event was received from the layer below.
 
Methods inherited from class org.jgroups.stack.Protocol
destroy, dumpStats, enableStats, getConfigurableObjects, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getName, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, printStats, providedDownServices, requiredDownServices, requiredUpServices, resetStatistics, setDownProtocol, setErgonomics, setId, setLevel, setProtocolStack, setSocketFactory, setUpProtocol, setValue, setValues, statsEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

timeout

protected long timeout

num_initial_members

protected int num_initial_members

num_initial_srv_members

@Deprecated
protected int num_initial_srv_members
Deprecated. 

break_on_coord_rsp

protected boolean break_on_coord_rsp

return_entire_cache

protected boolean return_entire_cache

stagger_timeout

protected long stagger_timeout

force_sending_discovery_rsps

protected boolean force_sending_discovery_rsps

use_disk_cache

protected boolean use_disk_cache

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 View view

members

protected final java.util.List<Address> members

is_coord

protected boolean is_coord

local_addr

protected Address local_addr

current_coord

protected Address current_coord

group_addr

protected java.lang.String group_addr

ping_responses

protected final java.util.Set<Discovery.Responses> ping_responses
Constructor Detail

Discovery

public Discovery()
Method Detail

setForceSendingDiscoveryRsps

public void setForceSendingDiscoveryRsps(boolean flag)

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.

Overrides:
init in class Protocol
Throws:
java.lang.Exception - Thrown if protocol cannot be initialized successfully. This will cause the ProtocolStack to fail, so the channel constructor will throw an exception

fetchClusterMembers

public abstract java.util.Collection<PhysicalAddress> fetchClusterMembers(java.lang.String cluster_name)
Grab all current cluster members

Parameters:
cluster_name -
Returns:
A list of the cluster members (usually IpAddresses), or null if the transport is multicast-enabled. Returns an empty list if no cluster members could be found.

sendDiscoveryRequestsInParallel

public abstract boolean sendDiscoveryRequestsInParallel()
Whether or not to send each discovery request on a separate (timer) thread. If disabled, a discovery request will be sent to all members fetched by fetchClusterMembers(String) sequentially


isDynamic

public abstract boolean isDynamic()

handleDisconnect

public void handleDisconnect()

handleConnect

public void handleConnect()

discoveryRequestReceived

public void discoveryRequestReceived(Address sender,
                                     java.lang.String logical_name,
                                     java.util.Collection<PhysicalAddress> physical_addrs)

getTimeout

public long getTimeout()

setTimeout

public void setTimeout(long timeout)

getNumInitialMembers

public int getNumInitialMembers()

setNumInitialMembers

public void setNumInitialMembers(int num_initial_members)

getNumberOfDiscoveryRequestsSent

public int getNumberOfDiscoveryRequestsSent()

getView

public java.lang.String getView()

getViewId

public ViewId getViewId()

getCurrentCoord

public java.lang.String getCurrentCoord()

isMergeRunning

protected boolean isMergeRunning()

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 class Protocol

resetStats

public void resetStats()
Overrides:
resetStats in class Protocol

start

public void start()
           throws java.lang.Exception
Description copied from class: Protocol
This method is called on a Channel.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 class Protocol
Throws:
java.lang.Exception - Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, so Channel.connect(String) will throw an exception

stop

public void stop()
Description copied from class: Protocol
This method is called on a Channel.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

Overrides:
stop in class Protocol

findInitialMembers

public java.util.List<PingData> findInitialMembers(Promise<JoinRsp> promise)
Finds initial members

Parameters:
promise -
Returns:

findAllViews

public java.util.List<PingData> findAllViews(Promise<JoinRsp> promise)

findMembers

protected java.util.List<PingData> findMembers(Promise<JoinRsp> promise,
                                               int num_expected_rsps,
                                               boolean break_on_coord,
                                               ViewId view_id)

sendDiscoveryRequest

public void sendDiscoveryRequest(java.lang.String cluster_name,
                                 Promise promise,
                                 ViewId view_id)
                          throws java.lang.Exception
Throws:
java.lang.Exception

sendMcastDiscoveryRequest

protected void sendMcastDiscoveryRequest(Message discovery_request)

findInitialMembersAsString

public java.lang.String findInitialMembersAsString()

findAllViewsAsString

public java.lang.String findAllViewsAsString()

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 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

Overrides:
up in class Protocol
Parameters:
evt - - the event that has been sent from the layer below

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 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 up_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.

Overrides:
down in class Protocol

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 PingData deserialize(byte[] data)

sendDiscoveryResponse

protected void sendDiscoveryResponse(Address logical_addr,
                                     java.util.List<PhysicalAddress> physical_addrs,
                                     boolean is_server,
                                     boolean return_view_only,
                                     java.lang.String logical_name,
                                     Address sender)


Copyright © 1998-2012 Bela Ban / Red Hat. All Rights Reserved.