📄 overview-4.html.svn-base
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.6">
<TITLE>A quick overview of JNS: Internals of a simulation run</TITLE>
<LINK HREF="Overview-5.html" REL=next>
<LINK HREF="Overview-3.html" REL=previous>
<LINK HREF="Overview.html#toc4" REL=contents>
</HEAD>
<BODY>
<A HREF="Overview-5.html">Next</A>
<A HREF="Overview-3.html">Previous</A>
<A HREF="Overview.html#toc4">Contents</A>
<HR>
<H2><A NAME="s4">4. Internals of a simulation run</A></H2>
<P>
<P>Simulations are normally started by calling the <CODE>run()</CODE> function of the
Simulator class. The Simulator class uses a priority queue of <CODE>Command</CODE>
objects that have been put in there by any element of JNS (Command objects are
simply objects that define an <CODE>execute()</CODE> function. JNS will call this
function at the time when the command should be executed). The "priority" is
given by the time at which the command should occur.
<P>
<P>To rephrase this in an
understandable way, if a <CODE>Command</CODE> is added for execution, it will be
put in the right position in the queue so that when JNS finds the next command
to execute, the one with the lowest time gets picked.
<P>
<P>This algorithm guarantees that events are always executed in the right order.
Before a command is executed, the current simulator time will be set to the
time contained in this command. Have a look at the <CODE>Command</CODE> class in
<B>jns.command</B> and the <CODE>Simulator.run()</CODE> function in <B>jns</B>
and it should be immediately clear what happens.
<P>
<P>The commands added to the simulator can be of any kind of nature: You could
extend the <CODE>Command</CODE> class to provide an <CODE>execute()</CODE> function
that starts sending random data or a function that will change the error
characteristic of a link, or whatever you want to do really... A special
class called <CODE>StopCommand</CODE> is provided. If you schedule a call to this
class, it will stop the simulator at the time you choose.
<P>
<P>Look at the source files <B>jns/Simulator.java</B>,
<B>jns/command/Command.java</B>, and <B>jns/command/StopCommand.java</B>
to see what is meant by this section.
<P>
<P>
<P>
<HR>
<A HREF="Overview-5.html">Next</A>
<A HREF="Overview-3.html">Previous</A>
<A HREF="Overview.html#toc4">Contents</A>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -