org.jgroups.protocols
Class PING

java.lang.Object
  extended by org.jgroups.stack.Protocol
      extended by org.jgroups.protocols.Discovery
          extended by org.jgroups.protocols.PING
Direct Known Subclasses:
MPING

public class PING
extends Discovery

The PING 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 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 property: gossip_host - if you are using GOSSIP then this defines the host of the GossipRouter, default is null property: gossip_port - if you are using GOSSIP then this defines the port of the GossipRouter, default is null

Version:
$Id: PING.java,v 1.36.2.5 2008/12/08 13:18:49 belaban Exp $
Author:
Bela Ban

Field Summary
protected  Promise<java.lang.Boolean> discovery_reception
           
static java.lang.String name
           
 
Fields inherited from class org.jgroups.stack.Protocol
down_prot, log, props, stack, stats, up_prot
 
Constructor Summary
PING()
           
 
Method Summary
 int getGossipPort()
           
 long getGossipRefresh()
           
 java.lang.String getName()
           
 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 set
 void sendGetMembersRequest()
           
 void setGossipPort(int gossip_port)
           
 void setGossipRefresh(long gossip_refresh)
           
 boolean setProperties(java.util.Properties props)
          sets the properties of the PING protocol.
 void stop()
          This method is called on a Channel.disconnect().
 java.lang.Object up(Event evt)
          An event was received from the layer below.
protected  void waitForDiscoveryRequestReception()
           
 
Methods inherited from class org.jgroups.protocols.Discovery
down, findInitialMembers, findInitialMembersAsString, getNumberOfDiscoveryRequestsSent, getNumInitialMembers, getNumPingRequests, getTimeout, makeView, providedUpServices, resetStats, setNumInitialMembers, setNumPingRequests, setTimeout, start
 
Methods inherited from class org.jgroups.stack.Protocol
destroy, downThreadEnabled, dumpStats, enableStats, getDownProtocol, getProperties, getProtocolStack, getThreadFactory, getTransport, getUpProtocol, printStats, providedDownServices, requiredDownServices, requiredUpServices, setDownProtocol, setPropertiesInternal, setProtocolStack, setUpProtocol, statsEnabled, upThreadEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

discovery_reception

protected final Promise<java.lang.Boolean> discovery_reception

name

public static final java.lang.String name
See Also:
Constant Field Values
Constructor Detail

PING

public PING()
Method Detail

getName

public java.lang.String getName()
Specified by:
getName in class Protocol

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 property: gossip_host - if you are using GOSSIP then this defines the host of the GossipRouter, default is null property: gossip_port - if you are using GOSSIP then this defines the port of the GossipRouter, default is null

Overrides:
setProperties in class Discovery
Parameters:
props - - a property set containing only PING properties
Returns:
returns true if all properties were parsed properly returns false if there are unrecnogized properties in the property set

getGossipPort

public int getGossipPort()

setGossipPort

public void setGossipPort(int gossip_port)

getGossipRefresh

public long getGossipRefresh()

setGossipRefresh

public void setGossipRefresh(long gossip_refresh)

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

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 Discovery

localAddressSet

public void localAddressSet(Address addr)
Description copied from class: Discovery
Called after local_addr was set

Overrides:
localAddressSet in class Discovery

handleConnect

public void handleConnect()
Overrides:
handleConnect in class Discovery

handleDisconnect

public void handleDisconnect()
Overrides:
handleDisconnect in class Discovery

sendGetMembersRequest

public void sendGetMembersRequest()
Specified by:
sendGetMembersRequest in class Discovery

up

public java.lang.Object up(Event evt)
Description copied from class: Discovery
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 Discovery
Parameters:
evt - - the event that has been sent from the layer below

waitForDiscoveryRequestReception

protected void waitForDiscoveryRequestReception()


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