ami
Class AMIrt

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--ami.AMIrt
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, Serializable

public class AMIrt
extends org.xml.sax.helpers.DefaultHandler
implements Serializable

AMI Routing Table, stores information about all known peers

Version:
1.0
Author:
Bertrand Florat
See Also:
Serialized Form

Field Summary
private  AMIPublicKey apk
           
private static AMIrt art
          Self instance used for signleton pattern
private  boolean bForget
          Boolean used to say this peer musn't be taken into account when parsing
private static Hashtable h
           
private  int i
           
private  Integer iDlc
           
private  Integer iPf
           
private  String sAl
           
private  String sCm
           
private  String[] sCurrent
           
private  String sIp
           
 
Constructor Summary
private AMIrt()
          The AMI routing table Singleton Entries in hashtable: pu 0: al 1: ip (ip:port:status) 2: pf 3: dlc 4: cm
 
Method Summary
static void addPeer(AMIPublicKey apk, String sAlias, String sIP)
          Idem with no comment
static void addPeer(AMIPublicKey apk, String sAlias, String sIP, String sComment)
          add a peer in the rt.
static AMIPublicKey addPeer(String sAlias, String sIP)
          Idem with no comment
static AMIPublicKey addPeer(String sAlias, String sIP, String sComment)
          Add a peer without public key ( usefull for eai for example )
(package private) static void alterPeer(AMIPublicKey apk, String sIP)
          Alter ip of a given pu after network validation
(package private) static void alterPeer(Hashtable hModif)
          Alters the rt entry given by pu and following instructions given in the hashtable: "pu" -> pu (mandatory) "al"-> "the alias" "cm" -> "the comment"
(package private) static void commit()
          Commit RT before quit
(package private) static boolean contains(AMIPublicKey apk)
          Used to know if a peer is in the RT
(package private) static void decPerf(AMIPublicKey apk)
          Decrease the performance of a peer
 void endElement(String sUri, String sName, String sQName)
          Called when we reach the end of an element
static String getAlias(AMIPublicKey apk)
          Get alias associated with a pu returns null if the apk not in RT
static Vector getAlIp(AMIPublicKey apk)
          Advance search Return the set [alias,ip] for the given peer pu
static String getComment(AMIPublicKey apk)
          Get comment associated with pu returns null if the apk not in RT
(package private) static int getConnectedPeerNumber()
          Return number of pingable peers Can be usefull to know if we are isolated
static Integer getDLC(AMIPublicKey apk)
          retruns the date in seconds since 1970 od the last successful check returns null if the apk not in RT
static String getFullIP(AMIPublicKey apk)
          Return the ip:port for the given peer Format: ip:port ex: 10.0.0.31:1111 returns null if the apk not in RT
static AMIrt getInstance()
          Return an instance of the RT Implementation of the singleton pattern
static String getIP(AMIPublicKey apk)
          Return IP for the given peer Format: ip ex: 10.0.0.1 returns null if the apk not in RT
static Enumeration getPeerEnumeration()
          Returns the enumeration on peers public keys.
static Integer getPerf(AMIPublicKey apk)
          Get performance of peer associated with pu returns null if the apk not in RT
static String getPort(AMIPublicKey apk)
          Return the port for the given peer Format: ip ex: 1111 returns null if the apk not in RT
(package private) static Vector getPuAl(String sIP)
          Advance search Return the set [pu,al,pu,al,...] for the given peer ip ip is in format xxx:xxx
(package private) static Vector getPuIp(String sAl)
          Advance search Return the set [pu,ip,pu,ip,...] for the given peer alias
(package private) static Enumeration getSortedPeerEnumeration()
          Returns the enumeration on peers public keys sorted by performance.
(package private) static void incPerf(AMIPublicKey apk)
          Increase the performance by the standard value
 void parseFromFile(String sURL)
          Get data from a file
static void removePeer(AMIPublicKey apk)
          Used to drop the entry identified by apk
static void setAlias(AMIPublicKey apk, String sValue)
          Set the alias of a peer
static void setComment(AMIPublicKey apk, String sComment)
          Set the comment of a peer
static void setDLC(AMIPublicKey apk, int iDate)
          Set the DLC of a peer
static void setIP(AMIPublicKey apk, String sValue)
          Set the ip of a peer
static void setPerf(AMIPublicKey apk, int iValue)
          Set the performance of a peer
 void startDocument()
          Called at parsing start
 void startElement(String sUri, String sName, String sQName, org.xml.sax.Attributes attributes)
          Called when we start an element
 void startPrefixMapping(String sPrefix, String sUri)
          Called to process namespaces
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
characters, endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

h

private static Hashtable h

apk

private AMIPublicKey apk

sAl

private String sAl

sIp

private String sIp

iPf

private Integer iPf

iDlc

private Integer iDlc

sCm

private String sCm

sCurrent

private String[] sCurrent

i

private int i

art

private static AMIrt art
Self instance used for signleton pattern

bForget

private boolean bForget
Boolean used to say this peer musn't be taken into account when parsing
Constructor Detail

AMIrt

private AMIrt()
       throws AMIException
The AMI routing table

Singleton

Entries in hashtable:

pu

0: al

1: ip (ip:port:status)

2: pf

3: dlc

4: cm

Method Detail

parseFromFile

public void parseFromFile(String sURL)
                   throws AMIException
Get data from a file

getInstance

public static AMIrt getInstance()
                         throws AMIException
Return an instance of the RT

Implementation of the singleton pattern


contains

static boolean contains(AMIPublicKey apk)
Used to know if a peer is in the RT
Returns:
true if the peer is known

commit

static void commit()
            throws AMIException
Commit RT before quit

getAlias

public static String getAlias(AMIPublicKey apk)
Get alias associated with a pu returns null if the apk not in RT
Parameters:
apk -  
Returns:
alias

getIP

public static String getIP(AMIPublicKey apk)
Return IP for the given peer Format: ip ex: 10.0.0.1 returns null if the apk not in RT
Parameters:
apkt -  
Returns:
ip

getPort

public static String getPort(AMIPublicKey apk)
Return the port for the given peer Format: ip ex: 1111 returns null if the apk not in RT
Parameters:
apkt -  
Returns:
port

getFullIP

public static String getFullIP(AMIPublicKey apk)
Return the ip:port for the given peer Format: ip:port ex: 10.0.0.31:1111 returns null if the apk not in RT
Parameters:
apkt -  
Returns:
full ip ( ip:port )

getPerf

public static Integer getPerf(AMIPublicKey apk)
Get performance of peer associated with pu returns null if the apk not in RT
Parameters:
apk -  
Returns:
performance

getDLC

public static Integer getDLC(AMIPublicKey apk)
retruns the date in seconds since 1970 od the last successful check returns null if the apk not in RT
Parameters:
apk -  
Returns:
dlc

getComment

public static String getComment(AMIPublicKey apk)
Get comment associated with pu returns null if the apk not in RT
Parameters:
apk -  
Returns:
comment

getAlIp

public static Vector getAlIp(AMIPublicKey apk)
Advance search Return the set [alias,ip] for the given peer pu
Returns:
pu vector

getPuIp

static Vector getPuIp(String sAl)
Advance search Return the set [pu,ip,pu,ip,...] for the given peer alias
Returns:
al vector

getPuAl

static Vector getPuAl(String sIP)
Advance search Return the set [pu,al,pu,al,...] for the given peer ip ip is in format xxx:xxx
Returns:
ip vector

setAlias

public static void setAlias(AMIPublicKey apk,
                            String sValue)
Set the alias of a peer
Parameters:
apk -  
sValue -  

setIP

public static void setIP(AMIPublicKey apk,
                         String sValue)
Set the ip of a peer
Parameters:
apk -  
sValue - like IP:PORT (use setStatus() to set the status )

incPerf

static void incPerf(AMIPublicKey apk)
Increase the performance by the standard value
Parameters:
apk -  

decPerf

static void decPerf(AMIPublicKey apk)
Decrease the performance of a peer
Parameters:
apk -  

setPerf

public static void setPerf(AMIPublicKey apk,
                           int iValue)
Set the performance of a peer
Parameters:
apk -  
iValue -  

setDLC

public static void setDLC(AMIPublicKey apk,
                          int iDate)
Set the DLC of a peer
Parameters:
apk -  
iValue -  

setComment

public static void setComment(AMIPublicKey apk,
                              String sComment)
Set the comment of a peer
Parameters:
apk -  
sComment -  

removePeer

public static void removePeer(AMIPublicKey apk)
Used to drop the entry identified by apk
Parameters:
apk -  
sComment -  

getPeerEnumeration

public static Enumeration getPeerEnumeration()
Returns the enumeration on peers public keys. Note that others peers can appear between the moment when we get the enumeration and the moment it is processed but it dosn't matter because none peer can be deleted during this period.
Parameters:
apk -  
sComment -  
Returns:
public key enumeration

getSortedPeerEnumeration

static Enumeration getSortedPeerEnumeration()
Returns the enumeration on peers public keys sorted by performance. Note that others peers can appear between the moment when we get the enumeration and the moment it is processed but it dosn't matter because none peer can be deleted during this period.
Parameters:
apk -  
sComment -  
Returns:
public key enumeration

addPeer

public static void addPeer(AMIPublicKey apk,
                           String sAlias,
                           String sIP,
                           String sComment)
                    throws AMIException
add a peer in the rt. Caution : the entry is only in memory, the AMI session must be commited to convert this entry to xml and write it to disk

The public key is get by amiping ( for network validation )

Caution: if the peer already exists, He will be overwritten.

sIP is under format : address:port


addPeer

public static void addPeer(AMIPublicKey apk,
                           String sAlias,
                           String sIP)
                    throws AMIException
Idem with no comment

addPeer

public static AMIPublicKey addPeer(String sAlias,
                                   String sIP,
                                   String sComment)
                            throws AMIException
Add a peer without public key ( usefull for eai for example )
Returns:
AMIPublicKey apk added public key

addPeer

public static AMIPublicKey addPeer(String sAlias,
                                   String sIP)
                            throws AMIException
Idem with no comment
Returns:
AMIPublicKey apk added public key

alterPeer

static void alterPeer(Hashtable hModif)
               throws AMIException
Alters the rt entry given by pu and following instructions given in the hashtable:

"pu" -> pu (mandatory)

"al"-> "the alias"

"cm" -> "the comment"


alterPeer

static void alterPeer(AMIPublicKey apk,
                      String sIP)
               throws AMIException
Alter ip of a given pu after network validation
Throws:
AMIException - if the peer is not altered

getConnectedPeerNumber

static int getConnectedPeerNumber()
Return number of pingable peers Can be usefull to know if we are isolated

startDocument

public void startDocument()
Called at parsing start
Overrides:
startDocument in class org.xml.sax.helpers.DefaultHandler

startElement

public void startElement(String sUri,
                         String sName,
                         String sQName,
                         org.xml.sax.Attributes attributes)
                  throws org.xml.sax.SAXException
Called when we start an element
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler

endElement

public void endElement(String sUri,
                       String sName,
                       String sQName)
                throws org.xml.sax.SAXException
Called when we reach the end of an element
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler

startPrefixMapping

public void startPrefixMapping(String sPrefix,
                               String sUri)
                        throws org.xml.sax.SAXException
Called to process namespaces
Overrides:
startPrefixMapping in class org.xml.sax.helpers.DefaultHandler