pl.gda.pg.eti.ask.przemyslawbielicki.aeh.info
Class MethodInfo

java.lang.Object
  extended bypl.gda.pg.eti.ask.przemyslawbielicki.aeh.info.MethodInfo

public class MethodInfo
extends Object

MethodInfo contains information about classes and methods (more precisely: information about reliability). Every method statistics contains invocation counter. It also contains counters for erroreous and exceptional invocation. User can get those informations and can decide to use this method or not.

MethodInfo contains methods that enable retrieving methods statistics that exist in XML database. It also contains methods that enable adding new method statistics to database.

XML database is automatically loaded and saved from and to filesystem.

TODO convert to EJB class

Version:
0.9
Author:
Przemyslaw Bielicki
Gdansk University of Technology
Faculty of Electronics, Telecommunication and Computer Science
Distributed Computer Systems

Field Summary
private  Hashtable classStats_
          Table containing statistics for concrete class.
private static String databasePath_
          Path where XML database is stored - file name
private static boolean initialized_
          Indicates if object is initialized_ or not.
private static MethodInfo methodInfo_
          Instance of singleton class.
 
Constructor Summary
private MethodInfo()
          Default constructor is private to prevent calling it by anyone.
 
Method Summary
 void addClassStat(ClassStat stat)
          Adds class statistics to database.
 void addClassStat(Method method)
          Adds method statistics to database.
 void addCorrectInvocation(Method method)
          Increases correct invocation counter by 1 (one).
 void addErrorInvocation(Method method)
          Increases erroreous invocation counter by 1 (one).
 void addExceptionClientInvocation(Method method)
          Increases client exceptional invocation counter by 1 (one).
 void addExceptionServerInvocation(Method method)
          Increases server exceptional invocation counter by 1 (one).
 boolean deserializeMethodInfo(String fileName)
          Deserializes method statistics XML database from file fileName to objects form.
static MethodInfo getInstance()
          Typical getInstance method.
 MethodStat getMethodInfo(Method method)
          Retrieves method statistics.
 MethodStat getMethodInfo(Method method, boolean addNewStats)
          Retrieves method statistics for given method.
 boolean serializeMethodInfo(String fileName)
          Serializes method statistics XML database from objects form to file fileName.
static void setDatabasePath(String path)
          Setter method for XML database path
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

classStats_

private Hashtable classStats_
Table containing statistics for concrete class. Keys in this table are class names ClassStat.className_.


initialized_

private static boolean initialized_
Indicates if object is initialized_ or not.


methodInfo_

private static MethodInfo methodInfo_
Instance of singleton class.


databasePath_

private static String databasePath_
Path where XML database is stored - file name

Constructor Detail

MethodInfo

private MethodInfo()
Default constructor is private to prevent calling it by anyone. It is because this class is a singleton.

Method Detail

getInstance

public static MethodInfo getInstance()
Typical getInstance method. If object is not initialized_ this method runs private constructor MethodInfo() and creates a singleton instance.

Returns:
MethodInfo instance

setDatabasePath

public static void setDatabasePath(String path)
Setter method for XML database path

Parameters:
path - to XML database

addErrorInvocation

public void addErrorInvocation(Method method)
Increases erroreous invocation counter by 1 (one). If method statistics for method doesn't exist it will be automatically added to database by getMethodInfo(Method, boolean) method. After this operation method automatically serializes XML database to file.

Parameters:
method - to increase erroreous invocation counter to

addExceptionClientInvocation

public void addExceptionClientInvocation(Method method)
Increases client exceptional invocation counter by 1 (one). If method statistics for method doesn't exist it will be automatically added to database by getMethodInfo(Method, boolean) method. After this operation method automatically serializes XML database to file.

Parameters:
method - to increase client exceptional invocation counter to

addExceptionServerInvocation

public void addExceptionServerInvocation(Method method)
Increases server exceptional invocation counter by 1 (one). If method statistics for method doesn't exist it will be automatically added to database by getMethodInfo(Method, boolean) method. After this operation method automatically serializes XML database to file.

Parameters:
method - to increase server exceptional invocation counter to

addCorrectInvocation

public void addCorrectInvocation(Method method)
Increases correct invocation counter by 1 (one). If method statistics for method doesn't exist it will be automatically added to database by getMethodInfo(Method, boolean) method. After this operation method automatically serializes XML database to file.

Parameters:
method - to increase correct invocation counter to

addClassStat

public void addClassStat(ClassStat stat)
                  throws DuplicateClassStatException
Adds class statistics to database. If statistics for given class name already exists in database DuplicateClassStatException is thrown.

Parameters:
stat - class statistics to add
Throws:
DuplicateClassStatException - statistics for given class name already exists in database

addClassStat

public void addClassStat(Method method)
                  throws DuplicateMethodStatException
Adds method statistics to database. If statistics for class that method belongs to already exists in database this method try to add statistics to this existing subtree. In this case if statistics for method already exists in class subtree DuplicateMethodStatException is thrown.In other case (class subtree doesn't exist) this method creates statistics for class and then adds statistics for method.

Parameters:
method - user want to add statistics for
Throws:
DuplicateMethodStatException - statistics for method already exists in class subtree

getMethodInfo

public MethodStat getMethodInfo(Method method)
                         throws ClassNotFoundException,
                                MethodNotFoundException
Retrieves method statistics. If class that method belongs to doesn't exist in database ClassNotFoundException is thrown. If class subtree exists but given method statistics doesn't exist MethodNotFoundException is thrown.

Parameters:
method - user want statistics for
Throws:
ClassNotFoundException - class that method belongs to doesn't
MethodNotFoundException - method statistics doesn't exist

getMethodInfo

public MethodStat getMethodInfo(Method method,
                                boolean addNewStats)
                         throws ClassNotFoundException,
                                MethodNotFoundException
Retrieves method statistics for given method. If class that method belongs to doesn't exist in database ClassNotFoundException is thrown. If class subtree exists but given method statistics doesn't exist MethodNotFoundException is thrown. If addNewStats is set to true this method adds statistics for given method to database. If class that given method belongs to exists in database this method adds only method statistics. In other case this method first adds class subtree and then method statistics.

Parameters:
method - user want statistics for
addNewStats - indicate if user want to add statistics if they don't exist
Throws:
ClassNotFoundException - class that method belongs to doesn't
MethodNotFoundException - method statistics doesn't exist

deserializeMethodInfo

public boolean deserializeMethodInfo(String fileName)
Deserializes method statistics XML database from file fileName to objects form. Simply creates objects structure from XML file.

Parameters:
fileName - path to file where method statistics XML database is
Returns:
true when deserializing finishes correctly and false in other case

serializeMethodInfo

public boolean serializeMethodInfo(String fileName)
Serializes method statistics XML database from objects form to file fileName. Simply creates XML document and then writes it to file.

Parameters:
fileName - path to file where method statistics XML database is
Returns:
true when serializing finishes correctly and false in other case