Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.fetish.directory
Class Fada  view Fada download Fada.java

java.lang.Object
  extended byjava.rmi.server.RemoteObject
      extended byjava.rmi.server.RemoteServer
          extended byjava.rmi.server.UnicastRemoteObject
              extended bycom.fetish.directory.Fada
All Implemented Interfaces:
Directory, LUSManager, java.rmi.Remote, java.io.Serializable

public final class Fada
extends java.rmi.server.UnicastRemoteObject
implements LUSManager, Directory, java.rmi.Remote

The Fetish Advanced Directory Architecture module (FADA)

Sample implementation of the LUSM node specification
This class provides an implementation of the LUSManager and Directory interfaces. It can manage Fetish services (registration, deregistration, lookup) and connect to the FADA architecture, thus allowing clients that contact this node to get proxies for Fetish services that are registered in any other place within the FADA architecture.


Nested Class Summary
private  class Fada.Explorer
          This class starts dedicated threads to extend the search
private  class Fada.Isolator
           
 
Field Summary
private  ServiceID id
           
private  Lease lease
           
private  java.util.EventListener listener
           
private static int LOCAL_SEARCH
           
private  LeaseRenewalManager lrm
           
private  int maxLookupTime
          Maximum time allowed for lookup in milliseconds
private static int NEIGHBOR_SEARCH
           
private  com.fetish.directory.tool.NeighborRegistry neighbors
           
private  ServiceRegistrar registrar
           
private  java.util.Hashtable registry
           
private  java.util.TreeSet searches
           
private  SearchSet searchSet
           
private  long seqNum
           
private  java.rmi.Remote thisStub
           
private  int threadCount
           
private  java.lang.String url
           
 
Fields inherited from class java.rmi.server.UnicastRemoteObject
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
Fada(ServiceRegistrar registrar, java.lang.String url)
          Sets up a node of the FADA architecture.
 
Method Summary
 void addLookupResult(SearchIDInterface searchID, ServiceMatches sm)
          Adds results obtained from a remote FADA.
 boolean connect(LUSManager node)
          Connects this node to another one, thus allowing to create a graph of FADA nodes.
private  LUSManager contactNeighbor(java.lang.String url, boolean delete)
           
 boolean disconnect(LUSManager node)
          Disconnects this node from the specified node, leaving all other connections untouched
 boolean disconnect(java.lang.String node)
          Disconnects this node from the specified node, leaving all other connections untouched
 boolean equals(java.lang.Object other)
          Compares with another object
private  void extendLookup(SearchCriteriaInterface criteria, java.lang.String excluded, java.lang.String target, SearchIDInterface searchID, int maxHops, long timeout, int maxResponses)
          Extends the search through the connections available from the node.
private  ServiceMatches filterResults(ServiceMatches sm)
          Returns a ServiceMatches object containing ServiceItems registered in this FADA.
 void finishedSearch(SearchIDInterface sid)
          Not used
 LookupLocator getLocator()
          Gets the Jini LookupLocator for this node.
 int getMaxTime()
          Get the default maximum time allowed for lookups in milliseconds
 LUSManager[] getNeighbors()
          Returns an array with all the nodes this one has been connected to
 ServiceID getServiceID()
          Returns the Jini ServiceID for this node.
 ServiceMatches getServices()
          Returns all services registered in this node.
 java.lang.String getUrl()
          Returns the Jini URL for this node.
 boolean isAlone()
          Tests if there is any connection with any other node
 void isolate()
          Disconnects this node from all nodes.
 boolean justConnect(LUSManager node)
          Add a new neighbor to the node.
 boolean justDisconnect(LUSManager node)
          Disconnects this node from the specified node, leaving all other connections untouched
 boolean justDisconnect(java.lang.String node)
          Disconnects this node from the specified node, leaving all other connections untouched
 ServiceMatches lookup(SearchCriteriaInterface criteria, int nHops, long timeout, int maxResponses)
          Starts the lookup process on a node.
 boolean lookup(SearchCriteriaInterface criteria, SearchIDInterface id, java.lang.String target, java.lang.String excluded, int maxHops, long timeout, int maxResponses)
          Lookup method for extension of lookup process between nodes.
static void main(java.lang.String[] args)
          Starts and registers the FADA node.
 ServiceRegistration register(ServiceItem item, long leaseDuration)
          Register a Fetish service within this node.
 void setLease(Lease lease)
           
 void setMaxTime(int maxTime)
          Set the default maximum time allowed for lookups in milliseconds
 void setServiceID(ServiceID id)
          Sets the Jini ServiceID for this node.
 void startedSearches(SearchIDInterface sid, int started)
          Not used
 void stop(java.lang.String password)
          Stops a FADA node.
 void unregister(ServiceID sid)
          Deletes a registration from the node.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

LOCAL_SEARCH

private static final int LOCAL_SEARCH
See Also:
Constant Field Values

NEIGHBOR_SEARCH

private static final int NEIGHBOR_SEARCH
See Also:
Constant Field Values

threadCount

private int threadCount

id

private ServiceID id

seqNum

private long seqNum

searchSet

private SearchSet searchSet

searches

private java.util.TreeSet searches

registrar

private ServiceRegistrar registrar

lrm

private LeaseRenewalManager lrm

lease

private Lease lease

url

private java.lang.String url

maxLookupTime

private int maxLookupTime
Maximum time allowed for lookup in milliseconds


listener

private java.util.EventListener listener

neighbors

private com.fetish.directory.tool.NeighborRegistry neighbors

registry

private java.util.Hashtable registry

thisStub

private java.rmi.Remote thisStub
Constructor Detail

Fada

public Fada(ServiceRegistrar registrar,
            java.lang.String url)
     throws java.rmi.RemoteException
Sets up a node of the FADA architecture.

Takes a Jini ServiceRegistrar as a parameter.

Method Detail

stop

public void stop(java.lang.String password)
          throws java.rmi.RemoteException
Stops a FADA node. Brings down a FADA node, deregistering all registered services from the Jini Lookup Service underneath (through Lease cancellation) and deregistering itself as well.

Specified by:
stop in interface LUSManager

setLease

public void setLease(Lease lease)

equals

public boolean equals(java.lang.Object other)
Compares with another object


getServiceID

public ServiceID getServiceID()
                       throws java.rmi.RemoteException
Returns the Jini ServiceID for this node.

Specified by:
getServiceID in interface LUSManager

getUrl

public java.lang.String getUrl()
                        throws java.rmi.RemoteException
Returns the Jini URL for this node.

Specified by:
getUrl in interface LUSManager

setServiceID

public void setServiceID(ServiceID id)
                  throws java.rmi.RemoteException
Sets the Jini ServiceID for this node.
For activation purposes (a Jini service should keep its ServiceID between activations and when restarting after a crash.


getLocator

public LookupLocator getLocator()
                         throws java.rmi.RemoteException
Gets the Jini LookupLocator for this node.
The LookupLocator is the Lookup Service this node is registered into. All Fetish services registered into this node are alse registered as a Jini service as well. This method allows this to happen.

Specified by:
getLocator in interface LUSManager

setMaxTime

public void setMaxTime(int maxTime)
                throws java.rmi.RemoteException
Set the default maximum time allowed for lookups in milliseconds

Specified by:
setMaxTime in interface LUSManager

getMaxTime

public int getMaxTime()
               throws java.rmi.RemoteException
Get the default maximum time allowed for lookups in milliseconds

Specified by:
getMaxTime in interface LUSManager

isAlone

public boolean isAlone()
                throws java.rmi.RemoteException
Tests if there is any connection with any other node

Specified by:
isAlone in interface LUSManager

contactNeighbor

private LUSManager contactNeighbor(java.lang.String url,
                                   boolean delete)
                            throws java.rmi.RemoteException

connect

public boolean connect(LUSManager node)
                throws java.rmi.RemoteException
Connects this node to another one, thus allowing to create a graph of FADA nodes.

Specified by:
connect in interface LUSManager

justConnect

public boolean justConnect(LUSManager node)
                    throws java.rmi.RemoteException
Description copied from interface: LUSManager
Add a new neighbor to the node. Adds the specified node to the list of neighbors, after checking if it's reachable.
This method does NOT call the node to perform a bidirectional connection. It is intended to be called by the method connect() on the remote node.

Specified by:
justConnect in interface LUSManager

disconnect

public boolean disconnect(LUSManager node)
                   throws java.rmi.RemoteException
Disconnects this node from the specified node, leaving all other connections untouched

Specified by:
disconnect in interface LUSManager

justDisconnect

public boolean justDisconnect(LUSManager node)
                       throws java.rmi.RemoteException
Disconnects this node from the specified node, leaving all other connections untouched

Specified by:
justDisconnect in interface LUSManager

disconnect

public boolean disconnect(java.lang.String node)
                   throws java.rmi.RemoteException
Disconnects this node from the specified node, leaving all other connections untouched

Specified by:
disconnect in interface LUSManager

justDisconnect

public boolean justDisconnect(java.lang.String node)
                       throws java.rmi.RemoteException
Disconnects this node from the specified node, leaving all other connections untouched

Specified by:
justDisconnect in interface LUSManager

isolate

public void isolate()
             throws java.rmi.RemoteException
Disconnects this node from all nodes.
The node becomes an isolated one, a Fetish community on its own.

Specified by:
isolate in interface LUSManager

getNeighbors

public LUSManager[] getNeighbors()
                          throws java.rmi.RemoteException
Returns an array with all the nodes this one has been connected to

Specified by:
getNeighbors in interface LUSManager

startedSearches

public void startedSearches(SearchIDInterface sid,
                            int started)
                     throws java.rmi.RemoteException
Not used

Specified by:
startedSearches in interface Directory

finishedSearch

public void finishedSearch(SearchIDInterface sid)
                    throws java.rmi.RemoteException
Not used


extendLookup

private void extendLookup(SearchCriteriaInterface criteria,
                          java.lang.String excluded,
                          java.lang.String target,
                          SearchIDInterface searchID,
                          int maxHops,
                          long timeout,
                          int maxResponses)
Extends the search through the connections available from the node.


lookup

public ServiceMatches lookup(SearchCriteriaInterface criteria,
                             int nHops,
                             long timeout,
                             int maxResponses)
                      throws java.rmi.RemoteException
Starts the lookup process on a node.
The lookup process will be extended to all connected nodes, which in turn will extend the search process to all connected nodes, granting full graph lookup. It follows a flooding-style algorithm.

Specified by:
lookup in interface Directory

getServices

public ServiceMatches getServices()
                           throws java.rmi.RemoteException
Returns all services registered in this node.

Specified by:
getServices in interface Directory

lookup

public boolean lookup(SearchCriteriaInterface criteria,
                      SearchIDInterface id,
                      java.lang.String target,
                      java.lang.String excluded,
                      int maxHops,
                      long timeout,
                      int maxResponses)
               throws java.rmi.RemoteException
Lookup method for extension of lookup process between nodes.

Specified by:
lookup in interface Directory

register

public ServiceRegistration register(ServiceItem item,
                                    long leaseDuration)
                             throws java.rmi.RemoteException
Register a Fetish service within this node.
@param item - The Jini ServiceItem to register inside the Lookup Service this node is registered into.

Specified by:
register in interface Directory

unregister

public void unregister(ServiceID sid)
                throws java.rmi.RemoteException
Description copied from interface: Directory
Deletes a registration from the node.

Specified by:
unregister in interface Directory

filterResults

private ServiceMatches filterResults(ServiceMatches sm)
Returns a ServiceMatches object containing ServiceItems registered in this FADA.


addLookupResult

public void addLookupResult(SearchIDInterface searchID,
                            ServiceMatches sm)
                     throws java.rmi.RemoteException
Description copied from interface: Directory
Adds results obtained from a remote FADA. This method is called from a FADA node that wants to return the results of a local search to a FADA node that has asked for them.

Specified by:
addLookupResult in interface Directory

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Starts and registers the FADA node. The first argument is the url of the Jini Lookup Service that will hold the FADA proxy.