mirror of
https://github.com/ChronosX88/FreePastry.git
synced 2024-12-04 23:32:18 +00:00
160 lines
7.5 KiB
HTML
160 lines
7.5 KiB
HTML
|
<html><head>
|
||
|
<title>FreePastry Tutorial</title>
|
||
|
<link rel="stylesheet" href="tutorial.css" />
|
||
|
</head>
|
||
|
<body>
|
||
|
|
||
|
<div class="content">
|
||
|
<div class="frontmatter">
|
||
|
|
||
|
<h1>The FreePastry Tutorial.</h1>
|
||
|
|
||
|
<div class="abstract">This tutorial is designed to get you cooking quickly with the FreePastry
|
||
|
API and software toolkit.</div>
|
||
|
|
||
|
<h4>Version @tutorial_version@; @tutorial_date@. For <a
|
||
|
href="http://freepastry.org/">FreePastry</a> version @freepastry_version@. Maintained by @maintainer@.</h4>
|
||
|
|
||
|
</div>
|
||
|
|
||
|
<div class="nav">
|
||
|
<span class="nav-left"><a href="tut_beginning.html#lesson3">Previous (Lession 1,2,3)</a></span>
|
||
|
<span class="nav-center"><a href="index.html">Contents</a></span>
|
||
|
<span class="nav-right"><a href="tut_timertask.html#timer">Next (Timer)</a></span>
|
||
|
</div><br/><hr/>
|
||
|
|
||
|
<a name="lesson4"><h1>Lesson 4</h1></a>
|
||
|
<h2>Running multiple nodes in the same JVM.</h2>
|
||
|
<h3>Download the tutorial files:
|
||
|
<a href="./src/lesson4/DistTutorial.java">DistTutorial.java</a> (changed from Lesson 3!!!),
|
||
|
<a href="./src/lesson4/MyApp.java">MyApp.java</a>,
|
||
|
<a href="./src/lesson4/MyMsg.java">MyMsg.java</a> into a directory called rice/tutorial/lesson4/.</h3>
|
||
|
|
||
|
<p/>This tutorial will show you how to create and run multiple FreePastry nodes within the same JVM. We will continue to use the Socket transport layer. This tutorial is very simple, all we will be doing is modifying lesson 3 to have multiple nodes.<br>
|
||
|
|
||
|
Let's start with the changes to MyApp. We are going to make it keep a reference to the Node with a member variable named <code>node</code>. It will become apparent later in this tutorial.
|
||
|
<pre>
|
||
|
protected Node node;
|
||
|
</pre>
|
||
|
|
||
|
In the constructor:
|
||
|
<pre>
|
||
|
this.node = node;
|
||
|
</pre>
|
||
|
|
||
|
And here is the getter:
|
||
|
<pre>
|
||
|
public Node getNode() {
|
||
|
return node;
|
||
|
}
|
||
|
</pre>
|
||
|
|
||
|
Now we will look at the changes to DistTutorial. We have a member variable <code>apps</code> that will keep track of the list of apps.
|
||
|
<pre>
|
||
|
Vector apps = new Vector();
|
||
|
</pre>
|
||
|
|
||
|
We modify the constructor to take in how many nodes we wish to create:
|
||
|
<pre>
|
||
|
public DistTutorial(int bindport, InetSocketAddress bootaddress, int numNodes, Environment env) throws Exception {
|
||
|
</pre>
|
||
|
|
||
|
After constructing the <code>PastryNodeFactory</code> we create a loop to construct the nodes, and add them to our <code>apps</code> Vector.
|
||
|
<pre>
|
||
|
for (int curNode = 0; curNode < numNodes; curNode++) {
|
||
|
|
||
|
...
|
||
|
|
||
|
apps.add(app);
|
||
|
}
|
||
|
</pre>
|
||
|
|
||
|
When routing messages, we have created a subloop to do so for each app in the system:
|
||
|
<pre>
|
||
|
// for each app
|
||
|
Iterator appIterator = apps.iterator();
|
||
|
while(appIterator.hasNext()) {
|
||
|
MyApp app = (MyApp)appIterator.next();
|
||
|
|
||
|
...
|
||
|
|
||
|
}
|
||
|
</pre>
|
||
|
|
||
|
Note that we eliminated this code, because it is no longer important to not route if we are the bootstrap.
|
||
|
<pre>
|
||
|
// as long as we're not the first node
|
||
|
if (bootHandle != null) {
|
||
|
</pre>
|
||
|
|
||
|
|
||
|
In the send direct loop we use our getter <code>MyApp.getNode()</code>. This prevents us from having to remember a parallel data structure for the Nodes.
|
||
|
<pre>
|
||
|
// for each app
|
||
|
Iterator appIterator = apps.iterator();
|
||
|
while(appIterator.hasNext()) {
|
||
|
MyApp app = (MyApp)appIterator.next();
|
||
|
PastryNode node = (PastryNode)app.getNode();
|
||
|
</pre>
|
||
|
|
||
|
Other than that, we changed the delay in several locations so the program doesn't take as long to execute. Compile and run this program as before, but make sure to specify some the number of nodes to run as the 4th argument.
|
||
|
<pre>
|
||
|
<span class="input">java -cp .:FreePastry-@freepastry_version@.jar rice.tutorial.lesson4.DistTutorial 9001 10.9.8.7 9001 10</span>
|
||
|
<span class="output">:1122933905343:Error connecting to address /10.9.8.7:9001: java.net.ConnectException: Connection refused: no further information
|
||
|
:1122933905359:No bootstrap node provided, starting a new ring...
|
||
|
Finished creating new node SocketNodeHandle (<0x93426F..>/FOO/10.9.8.7:9001 [6666451457797044406])
|
||
|
Finished creating new node SocketNodeHandle (<0xAE1B63..>/FOO/10.9.8.7:9002 [8904287830673843378])
|
||
|
Finished creating new node SocketNodeHandle (<0x3E99E3..>/FOO/10.9.8.7:9003 [-1171813548315184530])
|
||
|
Finished creating new node SocketNodeHandle (<0xC8715F..>/FOO/10.9.8.7:9004 [6496343980737954414])
|
||
|
Finished creating new node SocketNodeHandle (<0x688826..>/FOO/10.9.8.7:9005 [-6779179910423314388])
|
||
|
Finished creating new node SocketNodeHandle (<0x640179..>/FOO/10.9.8.7:9006 [3471226224877450778])
|
||
|
Finished creating new node SocketNodeHandle (<0x7A6F99..>/FOO/10.9.8.7:9007 [7101267768505206817])
|
||
|
Finished creating new node SocketNodeHandle (<0xD5DAAE..>/FOO/10.9.8.7:9008 [7899110252170216207])
|
||
|
Finished creating new node SocketNodeHandle (<0x19C832..>/FOO/10.9.8.7:9009 [-4206970387543598705])
|
||
|
Finished creating new node SocketNodeHandle (<0x490C38..>/FOO/10.9.8.7:9010 [-6742572645641651296])
|
||
|
MyApp <0x93426F..> sending to <0x0E510A..>
|
||
|
MyApp <0x19C832..> received MyMsg from <0x93426F..> to <0x0E510A..>
|
||
|
MyApp <0xAE1B63..> sending to <0xE704A5..>
|
||
|
MyApp <0xD5DAAE..> received MyMsg from <0xAE1B63..> to <0xE704A5..>
|
||
|
MyApp <0x3E99E3..> sending to <0x533803..>
|
||
|
MyApp <0x490C38..> received MyMsg from <0x3E99E3..> to <0x533803..>
|
||
|
MyApp <0xC8715F..> sending to <0x779E75..>
|
||
|
MyApp <0x7A6F99..> received MyMsg from <0xC8715F..> to <0x779E75..>
|
||
|
MyApp <0x688826..> sending to <0x3FFFB9..>
|
||
|
MyApp <0x3E99E3..> received MyMsg from <0x688826..> to <0x3FFFB9..>
|
||
|
|
||
|
...
|
||
|
|
||
|
MyApp <0x93426F..> sending direct to [SNH: <0x93426F..> -> <0xAE1B63..>/FOO/10.9.8.7:9002 [8904287830673843378]]
|
||
|
MyApp <0xAE1B63..> received MyMsg from <0x93426F..> to <0xAE1B63..>
|
||
|
MyApp <0x93426F..> sending direct to [SNH: <0x93426F..> -> <0xC8715F..>/FOO/10.9.8.7:9004 [6496343980737954414]]
|
||
|
MyApp <0xC8715F..> received MyMsg from <0x93426F..> to <0xC8715F..>
|
||
|
MyApp <0x93426F..> sending direct to [SNH: <0x93426F..> -> <0xD5DAAE..>/FOO/10.9.8.7:9008 [7899110252170216207]]
|
||
|
MyApp <0xD5DAAE..> received MyMsg from <0x93426F..> to <0xD5DAAE..>
|
||
|
MyApp <0x93426F..> sending direct to [SNH: <0x93426F..> -> <0x19C832..>/FOO/10.9.8.7:9009 [-4206970387543598705]]
|
||
|
MyApp <0x19C832..> received MyMsg from <0x93426F..> to <0x19C832..>
|
||
|
MyApp <0x93426F..> sending direct to [SNH: <0x93426F..> -> <0x3E99E3..>/FOO/10.9.8.7:9003 [-1171813548315184530]]
|
||
|
MyApp <0x3E99E3..> received MyMsg from <0x93426F..> to <0x3E99E3..>
|
||
|
MyApp <0x93426F..> sending direct to [SNH: <0x93426F..> -> <0x490C38..>/FOO/10.9.8.7:9010 [-6742572645641651296]]
|
||
|
MyApp <0x490C38..> received MyMsg from <0x93426F..> to <0x490C38..>
|
||
|
|
||
|
...
|
||
|
|
||
|
</span></pre>
|
||
|
<h3>Congratulations! You have just created an entire ring inside a single JVM. This should make it much easier to test your application.</h3>
|
||
|
|
||
|
<hr/><div class="nav">
|
||
|
<span class="nav-left"><a href="tut_beginning.html#lesson3">Previous (Lession 1,2,3)</a></span>
|
||
|
<span class="nav-center"><a href="index.html">Contents</a></span>
|
||
|
<span class="nav-right"><a href="tut_timertask.html#timer">Next (Timer)</a></span>
|
||
|
</div><br/>
|
||
|
|
||
|
<div class="footer">
|
||
|
Pastry tutorial version @tutorial_version@. Last updated @tutorial_date@.
|
||
|
For FreePastry @freepastry_version@. Maintained by @maintainer@.
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|