stasis/je-7.5.11/docs/examples/je/rep/quote/StockQuotes.html

411 lines
17 KiB
HTML
Raw Normal View History

2019-06-25 20:12:40 +00:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_151) on Tue Oct 31 17:36:52 EDT 2017 -->
<title>StockQuotes (Oracle - Berkeley DB Java Edition Examples)</title>
<meta name="date" content="2017-10-31">
<link rel="stylesheet" type="text/css" href="../../../style.css" title="Style">
<script type="text/javascript" src="../../../script.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="StockQuotes (Oracle - Berkeley DB Java Edition Examples)";
}
}
catch(err) {
}
//-->
var methods = {"i0":9,"i1":10};
var tabs = {65535:["t0","All Methods"],1:["t1","Static Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]};
var altColor = "altColor";
var rowColor = "rowColor";
var tableTab = "tableTab";
var activeTableTab = "activeTableTab";
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar.top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.top.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../je/rep/quote/package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../index-all.html">Index</a></li>
<li><a href="../../../help-doc.html">Help</a></li>
</ul>
<div class="aboutLanguage"><b>Berkeley DB Java Edition Examples</b><br><font size=\"-1\"> version 7.5.11</font>
</div>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../je/rep/quote/SimpleRouter.html" title="class in je.rep.quote"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../je/rep/quote/StockQuotesRMIForwarding.html" title="class in je.rep.quote"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../index.html?je/rep/quote/StockQuotes.html" target="_top">Frames</a></li>
<li><a href="StockQuotes.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a name="skip.navbar.top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">je.rep.quote</div>
<h2 title="Class StockQuotes" class="title">Class StockQuotes</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>je.rep.quote.StockQuotes</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<dl>
<dt>Direct Known Subclasses:</dt>
<dd><a href="../../../je/rep/quote/RouterDrivenStockQuotes.html" title="class in je.rep.quote">RouterDrivenStockQuotes</a>, <a href="../../../je/rep/quote/StockQuotesRMIForwarding.html" title="class in je.rep.quote">StockQuotesRMIForwarding</a></dd>
</dl>
<hr>
<br>
<pre>public class <span class="typeNameLabel">StockQuotes</span>
extends java.lang.Object</pre>
<div class="block">The most basic demonstration of a replicated application. It's intended to
help gain an understanding of basic HA concepts and demonstrate use of the
HA APIs to create a replicated environment and issue read and write
transactions.
<p>
Be sure to read the <a href="../../../je/rep/quote/package-summary.html"><code>Example Overview</code></a> first to put this
example into context.
<p>
The program can be used to start up multiple stock quote servers supplying
the following arguments:
<pre>
java je.rep.quote.StockQuotes -env &lt;environment home&gt; \
-nodeName &lt;nodeName&gt; \
-nodeHost &lt;hostname:port&gt; \
-helperHost &lt;hostname:port&gt;
</pre>
The argument names resemble the <a href="../../../../java/com/sleepycat/je/rep/ReplicationConfig.html?is-external=true" title="class or interface in com.sleepycat.je.rep"><code>ReplicationConfig</code></a> names to draw
attention to the connection between the program argument names and
ReplicationConfig APIs.
<pre>
-env a pre-existing directory for the replicated JE environment
-nodeName the name used to uniquely identify this node in the replication
-nodeHost the unique hostname, port pair for this node
-helperHost the hostname, port pair combination for the helper node. It's
the same as the nodeHost only if this node is intended to
become the initial Master, during the formation of the
replication group.
</pre>
A typical demo session begins with a set of commands such as the following
to start each node. The first node can be started as below:
<pre>
java je.rep.quote.StockQuotes -env dir1 -nodeName n1 \
-nodeHost node.acme.com:5001 \
-helperHost node.acme.com:5001
</pre>
Note that the <code>helperHost</code> and the <code>nodeHost</code> are the
same, since it's the first node in the group. HA uses this fact to start a
brand new replication group of size one, with this node as the master if
there is no existing environment in the environment directory
<code>dir1</code>.
<p>
Nodes can be added to the group by using a variation of the above. The
second and third node can be started as follows:
<pre>
java je.rep.quote.StockQuotes -env dir2 -nodeName n2 \
-nodeHost node.acme.com:5002 \
-helperHost node.acme.com:5001
java je.rep.quote.StockQuotes -env dir3 -nodeName n3 \
-nodeHost node.acme.com:5003 \
-helperHost node.acme.com:5002
</pre>
Note that each node has its own unique node name, and a distinct directory
for its replicated environment. This and any subsequent nodes can use the
first node as a helper to get itself going. In fact, you can pick any node
already in the group to serve as a helper. So, for example when adding the
third node, node 2 or node 1, could serve as helper nodes. The helper nodes
simply provide a mechanism to help a new node get itself admitted into the
group. The helper node is not needed once a node becomes part of the group.
<p>
When initially running the example, please use a group of at least three
nodes. A two node group is a special case, and it is best to learn how to
run larger groups first. For more information, see
<a href="../../../../ReplicationGuide/lifecycle.html#twonode">
Two-Node Replication Groups</a>. When initially creating the nodes, it is
also important to start the master first.
<p>
But once the nodes have been created, the order in which the nodes are
started up does not matter. It minimizes the initial overall group startup
time to have the master (the one where the <code>helperHost</code> and the
<code>nodeHost</code> are the same) node started first, since the master
initializes the replicated environment and is ready to start accepting and
processing commands even as the other nodes concurrently join the group.
<p>
The above commands start up a group with three nodes all running locally on
the same machine. You can start up nodes on different machines connected by
a TCP/IP network by executing the above commands on the respective machines.
It's important in this case that the clocks on these machines, be reasonably
synchronized, that is, they should be within a couple of seconds of each
other. You can do this manually, but it's best to use a protocol like <a
href="http://www.ntp.org/">NTP</a> for this purpose.
<p>
Upon subsequent restarts the nodes will automatically hold an election and
select one of the nodes in the group to be the master. The choice of master
is made visible by the master/replica prompt that the application uses to
make the distinction clear. Note that at least a simple majority of nodes
must be started before the application will respond with a prompt because
it's only after a simple majority of nodes is available that an election can
be held and a master elected. For a two node group, both nodes must be
started before an election can be held.
<p>
Commands are submitted directly at the command prompt in the console
established by the application at each node. Update commands are only
accepted at the console associated with the current master, identified by
the <i>master</i> prompt as below:
<pre>StockQuotes-2 (master)&gt;</pre>
After issuing a few commands, you may want to experiment with shutting down
or killing some number of the replicated environments and bringing them back
up to see how the application behaves.
<p>
If you type stock updates at an application that is currently running as a
replica node, the update is refused and you must manually re-enter the
updates on the console associated with the master. This is of course quite
cumbersome and serves as motivation for the subsequent examples.
<p>
As shown below, there is no routing of requests between nodes in this
example, which is why write requests fail when they are issued on a Replica
node.
<pre>
-----------------------
| StockQuotes | Read and Write requests both succeed,
| Instance 1: Master | because this is the Master.
-----------------------
-----------------------
| StockQuotes | Read requests succeed,
| Instance 2: Replica | but Write requests fail on a Replica.
-----------------------
-----------------------
| StockQuotes | Read requests succeed,
| Instance 3: Replica | but Write requests fail on a Replica.
-----------------------
...more Replica instances...
</pre>
<p>
See <a href="../../../je/rep/quote/UpdateForwardingStockQuotes.html" title="class in je.rep.quote"><code>UpdateForwardingStockQuotes</code></a> for an example that uses
<a href="../../../je/rep/quote/SimpleRouter.html" title="class in je.rep.quote"><code>SimpleRouter</code></a>, along with application supplied inter-node request
routing to direct write requests to the master.
<p>
See <a href="../../../je/rep/quote/RouterDrivenStockQuotes.html" title="class in je.rep.quote"><code>RouterDrivenStockQuotes</code></a> along with <a href="../../../je/rep/quote/HARouter.html" title="class in je.rep.quote"><code>HARouter</code></a>for an
example that uses an external router built using the
<a href="../../../../java/com/sleepycat/je/rep/monitor/Monitor.html?is-external=true" title="class or interface in com.sleepycat.je.rep.monitor"><code>Monitor</code></a> to route write
requests externally to the master and provide primitive load balancing
across the nodes in the replication group.</div>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method.summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd">&nbsp;</span></span><span id="t1" class="tableTab"><span><a href="javascript:show(1);">Static Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd">&nbsp;</span></span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr id="i0" class="altColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../je/rep/quote/StockQuotes.html#main-java.lang.String:A-">main</a></span>(java.lang.String[]&nbsp;argv)</code>&nbsp;</td>
</tr>
<tr id="i1" class="rowColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../je/rep/quote/StockQuotes.html#quit-java.io.PrintStream-">quit</a></span>(java.io.PrintStream&nbsp;out)</code>
<div class="block">Implements the "quit" command.</div>
</td>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.java.lang.Object">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;java.lang.Object</h3>
<code>equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method.detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a name="quit-java.io.PrintStream-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>quit</h4>
<pre>public&nbsp;void&nbsp;quit(java.io.PrintStream&nbsp;out)</pre>
<div class="block">Implements the "quit" command. Subclasses can override to take
additional cleanup measures.</div>
</li>
</ul>
<a name="main-java.lang.String:A-">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>main</h4>
<pre>public static&nbsp;void&nbsp;main(java.lang.String[]&nbsp;argv)
throws java.lang.Exception</pre>
<dl>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code>java.lang.Exception</code></dd>
</dl>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.bottom.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../je/rep/quote/package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../index-all.html">Index</a></li>
<li><a href="../../../help-doc.html">Help</a></li>
</ul>
<div class="aboutLanguage"><b>Berkeley DB Java Edition Examples</b><br><font size=\"-1\"> version 7.5.11</font>
</div>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../je/rep/quote/SimpleRouter.html" title="class in je.rep.quote"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../je/rep/quote/StockQuotesRMIForwarding.html" title="class in je.rep.quote"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../index.html?je/rep/quote/StockQuotes.html" target="_top">Frames</a></li>
<li><a href="StockQuotes.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a name="skip.navbar.bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<p class="legalCopy"><small><font size=1>Copyright (c) 2002, 2017 Oracle and/or its affiliates. All rights reserved.</font> </small></p>
</body>
</html>