Berkeley DB Java Edition Examples
version 4.0.103

je.rep.quote
Class StockQuotesRMIForwarding

java.lang.Object
  extended by je.rep.quote.StockQuotes
      extended by je.rep.quote.StockQuotesRMIForwarding

public class StockQuotesRMIForwarding
extends StockQuotes

This example is a small variation on the basic StockQuotes example. Instead of rejecting update requests made at a Replica's console, it illustrates how RMI could be used to forward write requests to a Master. The example is otherwise identical to StockQuotes and you should read the javadoc associated with it before proceeding with this example. The discussion that follows thus focusses entirely on the RMI based write-forwarding aspects of this example.

Each node in this example is an RMI server and hosts an RMI registry. The registry contains exactly one binding associated with the name: RMI_NAME. The object associated with the RMI binding (an instance of StockQuotesRMIForwarding.WriteServicesImpl) makes available all the high level database write operations that are part of the application. When this node is the Master, Replicas will use the remote methods to invoke write operations on it. All nodes are RMI servers, but only the current Master is actually used to serve write requests while it is in the Master state. The Replicas play the role of RMI clients making remote method calls to the Master to foward their write requests.

Please review the javadoc in StockQuotes for a detailed description of the arguments that must be supplied at startup. The only difference is that you must use the name of this class when invoking the Java VM.

For example, the first node can be started as follows:

 java je.rep.quote.StockQuotesWriteForwarding -env /tmp/stockQuotes1 \
                                               -nodeName n1 \
                                               -nodeHost node.acme.com:5001 \
                                               -helperHost node.acme.com:5001
 

This instance of the application will therefore use port 5001 for HA, and, by convention, port 5101 (5001 + RMI_PORT_DISPLACEMENT) for the RMI registry. If you are running on multiple machines you may (depending upon your DNS setup) need to specify the java.rmi.server.hostname property to ensure that RMI does not associate loopback addresses with entries in its registry.


Nested Class Summary
static interface StockQuotesRMIForwarding.WriteServices
           
 class StockQuotesRMIForwarding.WriteServicesImpl
          The class supplies the RMI implementation of the write methods.
 
Field Summary
static String RMI_NAME
           
 
Method Summary
static void main(String[] argv)
           
 void quit(PrintStream out)
          Performs the RMI associated cleanup so that the RMI serve can be shutdown cleanly.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RMI_NAME

public static final String RMI_NAME
See Also:
Constant Field Values
Method Detail

quit

public void quit(PrintStream out)
Performs the RMI associated cleanup so that the RMI serve can be shutdown cleanly.

Overrides:
quit in class StockQuotes

main

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

Berkeley DB Java Edition Examples
version 4.0.103

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