org.jgroups.demos

Class QuoteServer

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

Method Summary

void
block()
Block sending and receiving of messages until viewAccepted() is called
Hashtable
getAllStocks()
float
getQuote(String stock_name)
byte[]
getState()
static void
main(args[] )
void
printAllStocks()
void
receive(Message msg)
void
setQuote(String stock_name, Float value)
void
setState(byte[] state)
void
start()
void
suspect(Address suspected_mbr)
Called when a member is suspected
void
viewAccepted(View new_view)
Called by JGroups to notify the target object of a change of membership.

Method Details

block

public void block()
Block sending and receiving of messages until viewAccepted() is called
Specified by:
block in interface MembershipListener


getAllStocks

public Hashtable getAllStocks()


getQuote

public float getQuote(String stock_name)
            throws Exception


getState

public byte[] getState()
Specified by:
getState in interface MessageListener


main

public static void main(args[] )


printAllStocks

public void printAllStocks()


receive

public void receive(Message msg)
Specified by:
receive in interface MessageListener


setQuote

public void setQuote(String stock_name,
                     Float value)


setState

public void setState(byte[] state)
Specified by:
setState in interface MessageListener


start

public void start()


suspect

public void suspect(Address suspected_mbr)
Called when a member is suspected
Specified by:
suspect in interface MembershipListener


viewAccepted

public void viewAccepted(View new_view)
Called by JGroups to notify the target object of a change of membership. No long running actions should be done in this callback in the case of Ensemble, as this would block Ensemble. If some long running action needs to be performed, it should be done in a separate thread (cf. ../Tests/QuoteServer.java).
Specified by:
viewAccepted in interface MembershipListener


Copyright B) 2001,2002 www.jgroups.com . All Rights Reserved.