org.jgroups.demos
Class QuoteServer

java.lang.Object
  extended byorg.jgroups.demos.QuoteServer
All Implemented Interfaces:
MembershipListener, MessageListener

public class QuoteServer
extends java.lang.Object
implements MembershipListener, MessageListener

Example of a replicated quote server. The server maintains state which consists of a list of quotes and their corresponding values. When it is started, it tries to reach other quote servers to get its initial state. If it does not receive any response after 5 seconds, it assumes it is the first server and starts processing requests. When it receives a view notification it checks whether there are more members in the view than in its previous view. If this is the case, it broadcasts a request for the state to all members. Integration of different states is simply the union of all states (with the danger of overwriting mutually inconsistent state).

This mechanism allows both for fast discovery of initial servers, and - in the case of partition merging - for reintegration of existing servers. Broadcasting the state request upon every view change (only when new members are joined) causes potentially a lot of network traffic, but it is assumes that there will not be more than 5 quote servers at most.

Author:
Bela Ban

Constructor Summary
QuoteServer()
           
 
Method Summary
 void block()
          Called whenever the member needs to stop sending messages.
 java.util.Hashtable getAllStocks()
           
 float getQuote(java.lang.String stock_name)
           
 byte[] getState()
          Answers the group state; e.g., when joining.
static void main(java.lang.String[] args)
           
 void printAllStocks()
           
 void receive(Message msg)
          Called when a message is received.
 void setQuote(java.lang.String stock_name, java.lang.Float value)
           
 void setState(byte[] state)
          Sets the group state; e.g., when joining.
 void start()
           
 void suspect(Address suspected_mbr)
          Called whenever a member is suspected of having crashed, but has not yet been excluded.
 void viewAccepted(View new_view)
          Called when a change in membership has occurred.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QuoteServer

public QuoteServer()
Method Detail

viewAccepted

public void viewAccepted(View new_view)
Description copied from interface: MembershipListener
Called when a change in membership has occurred. No long running actions should be done in this callback. If some long running action needs to be performed, it should be done in a separate thread.

Specified by:
viewAccepted in interface MembershipListener

suspect

public void suspect(Address suspected_mbr)
Description copied from interface: MembershipListener
Called whenever a member is suspected of having crashed, but has not yet been excluded.

Specified by:
suspect in interface MembershipListener

block

public void block()
Description copied from interface: MembershipListener
Called whenever the member needs to stop sending messages. When the next view is received (viewAccepted()), the member can resume sending messages. If a member does not comply, the message(s) sent between a block() and a matching viewAccepted() callback will probably be delivered in the next view. The block() callback is only needed by the Virtual Synchrony suite of protocols (FLUSH protocol)3.2, otherwise it will never be invoked.

Specified by:
block in interface MembershipListener

start

public void start()

getQuote

public float getQuote(java.lang.String stock_name)
               throws java.lang.Exception
Throws:
java.lang.Exception

setQuote

public void setQuote(java.lang.String stock_name,
                     java.lang.Float value)

getAllStocks

public java.util.Hashtable getAllStocks()

printAllStocks

public void printAllStocks()

receive

public void receive(Message msg)
Description copied from interface: MessageListener
Called when a message is received.

Specified by:
receive in interface MessageListener
Parameters:
msg -

getState

public byte[] getState()
Description copied from interface: MessageListener
Answers the group state; e.g., when joining.

Specified by:
getState in interface MessageListener
Returns:
byte[]

setState

public void setState(byte[] state)
Description copied from interface: MessageListener
Sets the group state; e.g., when joining.

Specified by:
setState in interface MessageListener
Parameters:
state -

main

public static void main(java.lang.String[] args)


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