public class HARouter extends Object
RouterDrivenStockQuotes. The router is built using the APIs provided by the
Monitor; it's a standalone application and does not itself access a JE Environment. The router forwards logical requests, that represent some service provided by the application. It only has knowledge of whether a request will potentially require an write to the database, but does not have any other application level logic, nor does it access a JE environment. The HARouter accepts a request from the console and dispatches it to the application running on the master, if it's a write request, or to one of the replicas if it's a read request. The HARouter keeps track of the current Master via the events that are delivered to the Monitor.
It's the HARouter instead of each individual node (as in the
UpdateForwardingStockQuotes example) that tracks the current Master
Monitor. Since the
router ensures that writes are directed to the master node, the logic in
the node itself is simpler: the node simply services the requests forwarded
to it by the router on a port dedicated for this purpose.
The protocol used to communicate between the router and the nodes has been deliberately kept very simple. In particular, it makes limited provisions for error reporting back to the router.
The router requires the following arguments:
java je.rep.quote.HARouter -nodeName <nodeName> \ -nodeHost <host:port> \ -helperHost <host:port>" The arguments are described below: -nodeName identifies the monitor name associated with this Router -nodeHost the hostname:port combination used by the Monitor to listen for election results and group level changes. -helperHost one or more nodes that may be used by the Monitor to locate the Master and register the Monitor with the Master.Note that the arguments are similar to the ones used to start a replication node. A key difference is that the -env option is absent, since the router is standalone and is not associated with one.
The router can be started as follows:
java je.rep.quote.HARouter -nodeName n1 \ -nodeHost node.acme.com:6000 \ -helperHost node.acme.com:5001The replication nodes involved in the routing can be started as described in
RouterDrivenStockQuotes. The Router and the nodes can be started in any convenient order.
Copyright (c) 2004, 2014 Oracle and/or its affiliates. All rights reserved.