Berkeley DB Java Edition Examples
version 4.1.21

je.rep.quote
Class SimpleRouter

java.lang.Object
  extended by je.rep.quote.SimpleRouter

public class SimpleRouter
extends Object

This example illustrates the use of a simple HA-unaware router that is used in conjunction with UpdateForwardingStockQuotes. The router is unaware of the state (Master or Replica) of each node and simply forwards requests entered at the router's console to each node in the group in Round Robin fashion.

The UpdateForwardingStockQuotes instance will in turn, if necessary, forward any write requests to the current master and return the results back to SimpleRouter. UpdateForwardingStockQuotes instances do not have their own consoles, they only service requests delivered over the network by this router.

SimpleRouter takes host:port pairs as arguments, one pair for each instance of the UpdateForwardingStockQuotes application. The port numbers in this case are application, not HA, port numbers on which the UpdateForwardingStockQuotes application listens for application messages forwarded by SimpleRouter. They must therefore be different from the ports used internally by HA, that is, from the HA port numbers specified as arguments to UpdateForwardingStockQuotes. The application port number is computed in this example by adding HARouter.APP_PORT_DISPLACEMENT (default value 100) to the HA port number associated with the node. So, if node "n1" uses port 5001 for HA, it must (based upon the conventions used in these examples) use port 5101, for application level communication.

SimpleRouter can thus be invoked as follows:

 java je.rep.quote.SimpleRouter node.acme.com:5101 node.acme.com:5102 node.acme.com:5103
 
for a three node group. In this case, the applications will use ports 5101, through 5103 for application messages, while HA will use ports 5001 through 5003.

SimpleRouter and UpdateForwardingStockQuotes can be started in any order.

See Also:
UpdateForwardingStockQuotes

Method Summary
static void main(String[] argv)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

main

public static void main(String[] argv)
                 throws Exception
Throws:
Exception

Berkeley DB Java Edition Examples
version 4.1.21

Copyright (c) 2004-2010 Oracle. All rights reserved.