org.jgroups.demos
Class QuoteServer
java.lang.Object
org.jgroups.demos.QuoteServer
- MembershipListener, MessageListener
public class QuoteServer
extends java.lang.Object
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.
void | block() - Called whenever the member needs to stop sending messages.
|
Hashtable | getAllStocks()
|
float | getQuote(String stock_name)
|
byte[] | getState() - Answers the group state; e.g., when joining.
|
static void | main(args[] )
|
void | printAllStocks()
|
void | receive(Message msg) - Called when a message is received.
|
void | setQuote(String stock_name, 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.
|
block
public void block()
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.
- block in interface MembershipListener
getAllStocks
public Hashtable getAllStocks()
getQuote
public float getQuote(String stock_name)
throws Exception
getState
public byte[] getState()
Answers the group state; e.g., when joining.
- getState in interface MessageListener
main
public static void main(args[] )
printAllStocks
public void printAllStocks()
setQuote
public void setQuote(String stock_name,
Float value)
setState
public void setState(byte[] state)
Sets the group state; e.g., when joining.
- setState in interface MessageListener
suspect
public void suspect(Address suspected_mbr)
Called whenever a member is suspected of having crashed,
but has not yet been excluded.
- suspect in interface MembershipListener
viewAccepted
public void viewAccepted(View new_view)
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.
- viewAccepted in interface MembershipListener
Copyright B) 1998-2005 Bela Ban. All Rights Reserved.