ami
Class AMIInputSpool

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

class AMIInputSpool
extends org.xml.sax.helpers.DefaultHandler
implements Runnable

Manages and stores incoming AMI packets

Singleton

The AMIInputSpool contains static parts and multi-threaded instance parts

There are the same number of AMIReader than of AMIInputSpool threads

Version:
1.0
Author:
Bertrand Florat

Field Summary
private  AMICriteria ac
          Used to parse crierias
private static AMIInputSpool ais
          Self instance used for signleton pattern
private  AMIQuery aqCurrent
          Currently processed AMI query
private  boolean bPing
          amiping flag, means that current packet is an amiping
private static boolean bStop
          boolean used to stop the thread
private  char[] cRawData
          Processed raw data
private static String sCurrentIP
          Processed packet ip address as got by socket properties
private static String sCurrentPort
          Processed packet reply port
private  String sCurrentSign
          Stores signature for further use
(package private)  String sProtocol
           
private  String sSystemID
          Contains the absolute path of the DTD used to validate the incoming XML stream
(package private)  Thread t
          Thread used for auto-start
(package private)  Vector vParam
           
private  Vector vPreQueries
          Vector with queries being checked
private static Vector vQueries
          Stores new parsed and checked queries, first elements = max priority : FIFO
private static Vector vRawData
          Raw data vector, contains a 2 entries Object array : char[] rawData and String sIP
 
Constructor Summary
private AMIInputSpool()
          Default constructor
 
Method Summary
private  void addQuery(AMIQuery aq)
          Adds and sorts queries by priority in vector vQueries
(package private)  boolean checkSignature(char[] cData, char[] cProposedSignature, AMIPublicKey apk)
          Check signature of a packet signature is the hashcode of data between and tags encoded with private key
 void endElement(String sUri, String sName, String sQName)
          Called when we end an element
static AMIInputSpool getInstance()
          Return a self instance Implementation of the singleton pattern
(package private) static void put(char[] cRawData, String sIP)
          Push an incoming packet to be parsed
 void run()
          Thread loop used to check raw data vector, parse them and fill a query buffer
 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
(package private) static void stop()
          Finalize the input spool
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
characters, endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

vRawData

private static Vector vRawData
Raw data vector, contains a 2 entries Object array : char[] rawData and String sIP

t

Thread t
Thread used for auto-start

ais

private static AMIInputSpool ais
Self instance used for signleton pattern

bStop

private static volatile boolean bStop
boolean used to stop the thread

sCurrentSign

private String sCurrentSign
Stores signature for further use

sCurrentIP

private static String sCurrentIP
Processed packet ip address as got by socket properties

sCurrentPort

private static String sCurrentPort
Processed packet reply port

cRawData

private char[] cRawData
Processed raw data

vQueries

private static Vector vQueries
Stores new parsed and checked queries, first elements = max priority : FIFO

bPing

private boolean bPing
amiping flag, means that current packet is an amiping

vPreQueries

private Vector vPreQueries
Vector with queries being checked

aqCurrent

private AMIQuery aqCurrent
Currently processed AMI query

ac

private AMICriteria ac
Used to parse crierias

sSystemID

private String sSystemID
Contains the absolute path of the DTD used to validate the incoming XML stream

sProtocol

String sProtocol

vParam

Vector vParam
Constructor Detail

AMIInputSpool

private AMIInputSpool()
               throws AMIException
Default constructor
Method Detail

getInstance

public static AMIInputSpool getInstance()
                                 throws AMIException
Return a self instance

Implementation of the singleton pattern


run

public void run()
Thread loop used to check raw data vector, parse them and fill a query buffer
Specified by:
run in interface Runnable

put

static void put(char[] cRawData,
                String sIP)
         throws AMIException
Push an incoming packet to be parsed
Parameters:
cRawData - raw packet data ( with headers dropped )
sIP - Incoming peer IP as detected by socket properties

stop

static void stop()
Finalize the input spool

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
Parameters:
sUri - Description of Parameter
sName - Description of Parameter
sQName - Description of Parameter
attributes - Description of Parameter
Throws:
org.xml.sax.SAXException - Description of Exception

endElement

public void endElement(String sUri,
                       String sName,
                       String sQName)
                throws org.xml.sax.SAXException
Called when we end an element
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Parameters:
sUri - Description of Parameter
sName - Description of Parameter
sQName - Description of Parameter
Throws:
org.xml.sax.SAXException - Description of Exception

addQuery

private void addQuery(AMIQuery aq)
Adds and sorts queries by priority in vector vQueries

checkSignature

boolean checkSignature(char[] cData,
                       char[] cProposedSignature,
                       AMIPublicKey apk)
                 throws AMIException
Check signature of a packet signature is the hashcode of data between and tags encoded with private key
Parameters:
cData - raw data
cProposedSignature - signature as given in amipacket
apk - the amipublic key of the packet sender
Returns:
true if the signature is ok