<?xml version='1.0'?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" 
               "http://docbook.org/xml/4.2/docbookx.dtd"
	       [
	       <!ENTITY copyright SYSTEM "copyright.xml">
	       ]>

<chapter title="Architecture" id="23">
<title>Architecture</title>

<tocchap>
<title>
Contents
</title>

<toclevel1>
  <tocentry>
    <ulink url="#Threads"> Threads </ulink>
  </tocentry>
  <toclevel2>
    <tocentry>
      <ulink url="#LookupDiscovery threads">
        LookupDiscovery threads
      </ulink>
    </tocentry>
    <tocentry>
      <ulink url="#LeaseRenewalManager threads">
        LeaseRenewalManager threads
      </ulink>
    </tocentry>
  </toclevel2>
</toclevel1>
</tocchap>

<abstract>
This chapter looks at internal structures of Jini. This is
heavily based on the 1.0 implementation by Sun, and may not be
valid for any future implementations either by Sun or other
vendors.
</abstract>

<sect1>
<title>
LookupLocator
</title>
<para>
This is a simple class. The constructors perform some simple sanity checking
on their parameters. The method <code>getRegistrar()</code> attempts a 
socket connection to the host on port 4160 for a period of 1 minute, 
after which it times out
if no connection has been made. If it can connect, it reads an object from
the socket and coerces it to a <code>ServiceRegistrar</code> which it returns.
</para>

</sect1>

<sect1>
<title id="Threads">
Threads
</title>
<para>
Jini uses many threads in its internal workings. The knowledge
of these is not important to using Jini, but some may find it
valuable to know what is going on under the hood.
</para>

<sect2>
<title id="LookupDiscovery threads">
LookupDiscovery threads
</title>

<para>
A multicast request is made by creating a new <code>LookupDiscovery</code>
object with a non-empty set of groups, or by calling <code>setGroups()</code>.
This must broadcast the service, looking for service locators.
This is done using a thread of type <code>Requestor</code>.
This creates a <code>MulticastSocket</code>, sets its time-to-live
field and sends out a number (currently eight) of announcements
</para>

<para>
A class <code>ResponseListener</code> is used to handle replies.
This runs as its own thread. It listens on a socket for responses
and adds them to a list of service locators. If a new locator is
found, then it calls each <code>DiscoveryListener</code>.
(The implementation is slightly more complex due to timing issues -
see the source code.)
</para>

<para>
Both of these run as <emphasis>daemon</emphasis> threads. That means
they run as background threads. A user thread is needed to keep the
application alive: an application will terminate if there are only
daemon threads alive. 
</para>

</sect2>

<sect2>
<title id="LeaseRenewalManager threads">
LeaseRenewalManager threads
</title>
<para>
A <code>LeaseRenewalManager</code> uses a thread of class
<code>RenewThread</code>. This thread looks after all
aspects of renewal.
</para>

</sect2>
</sect1>



&copyright;
</chapter>
