pl.gda.pg.eti.ask.przemyslawbielicki.aeh.ejb
Class ExceptionControllerBean

java.lang.Object
  extended bypl.gda.pg.eti.ask.przemyslawbielicki.aeh.ejb.ExceptionControllerBean
All Implemented Interfaces:
EnterpriseBean, Serializable, SessionBean

public class ExceptionControllerBean
extends Object
implements SessionBean

ExceptionController class gives methods for safe method invocation from EJB objects. It enables to invoke methods once invokeOnce(Object, String, Object[]), with repeat invokeAndRepeat(Object, String, Object[], int), invokeAndRepeat(Object, String, Object[], int, long), and invoke equal or similar methods from different EJB objects invokeNVariant(Object[], String[], Object[][]).

If any of invoked method throws an exception information about it is passed to MethodInfo class which updates information (statistics) about invoked method.

Version:
1.0 alfa
Author:
Przemyslaw Bielicki
Gdansk University of Technology
Faculty of Electronics, Telecommunication and Computer Science
Distributed Computer Systems
See Also:
MethodInfo, Serialized Form

Field Summary
private static UTL.ResultLoggerLocal LOG
           
 
Constructor Summary
ExceptionControllerBean()
           
 
Method Summary
private  Class[] createParameterTypes(Object[] args)
          Creates parameterType array for given object list.
 void ejbActivate()
          Activate method
 void ejbCreate()
          Create method for EJB
 void ejbPassivate()
          Passivate method
 void ejbRemove()
          Remove method
 void initialize(String path)
           
 boolean invokeAndCheck(Object object, String methodName, Object[] args, Object expectedValue)
          Invokes method methodName from object with given arguments (args) and checks if returnValue equals expectedValue.
 Object invokeAndRepeat(Object object, String methodName, Object[] args, int repeat)
          Invokes method methodName from object with given arguments (args).
 Object invokeAndRepeat(Object object, String methodName, Object[] args, int repeat, long delay)
          Invokes method methodName from object with given arguments (args).
 Object invokeNVariant(Object[] objects, String[] methodNames, Object[][] args)
          Invokes method methodNames from objects with given arguments (args).
 Object invokeOnce(Object object, String methodName, Object[] args)
          Invokes method methodName from object with given arguments (args).
 void setSessionContext(SessionContext context)
          Setter method for session context
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

private static UTL.ResultLoggerLocal LOG
Constructor Detail

ExceptionControllerBean

public ExceptionControllerBean()
Method Detail

ejbCreate

public void ejbCreate()
               throws CreateException
Create method for EJB

Throws:
CreateException

ejbActivate

public void ejbActivate()
                 throws EJBException,
                        RemoteException
Activate method

Specified by:
ejbActivate in interface SessionBean
Throws:
EJBException
RemoteException

ejbPassivate

public void ejbPassivate()
                  throws EJBException,
                         RemoteException
Passivate method

Specified by:
ejbPassivate in interface SessionBean
Throws:
EJBException
RemoteException

ejbRemove

public void ejbRemove()
               throws EJBException,
                      RemoteException
Remove method

Specified by:
ejbRemove in interface SessionBean
Throws:
EJBException
RemoteException

setSessionContext

public void setSessionContext(SessionContext context)
                       throws EJBException,
                              RemoteException
Setter method for session context

Specified by:
setSessionContext in interface SessionBean
Throws:
EJBException
RemoteException

initialize

public void initialize(String path)
Parameters:
path -

createParameterTypes

private Class[] createParameterTypes(Object[] args)
Creates parameterType array for given object list. Simply gets from each object its class and adds to array. This parameter array is necessary for getting Method object.

Parameters:
args - array of arguments to convert to class list
Returns:
class array of parameterTypes
See Also:
Method.getParameterTypes()

invokeOnce

public Object invokeOnce(Object object,
                         String methodName,
                         Object[] args)
                  throws InvocationTargetException

Invokes method methodName from object with given arguments (args). Return value is stored in returnValue argument.

Invokes given method only once. When invoking method methodName finishes with exception throwing method update statistics about invoking method (add exception invocation). Also when invoked method throws an exception it (exception) is passed to caller by putting thrown exception object into targetException argument.

Every exception thrown during invocation operation is logged to LOG MANAGER. This is TODO logging.

Parameters:
object - user wants to invoke method from this object; TODO what if method is static???
methodName - name of the method we want to invoke
args - arguments for invoking method
Returns:
value returned by invoked method
Throws:
InvocationTargetException - exception thrown during methodName invocation

invokeAndRepeat

public Object invokeAndRepeat(Object object,
                              String methodName,
                              Object[] args,
                              int repeat)
                       throws InvocationTargetException

Invokes method methodName from object with given arguments (args). Return value is stored in returnValue argument.

Invokes given method repeat (maximum) times. When invoking method methodName finishes with exception throwing method update statistics about invoking method (add exception invocation) and method methodName is invoked again and againg (till loop counter doesn't approach repeat value). If method invocation doesn't throw exception method breaks loop and goes further. It means that method invoked correctly.

Generally this method calls method invokeOnce - maximum repeat times.

Every exception thrown during invocation operation is logged to LOG MANAGER. This is TODO logging.

Parameters:
object - user wants to invoke method from this object; TODO what if method is static???
methodName - name of the method we want to invoke
args - arguments for invoking method
repeat - how many times (maximum) try to invoke method methodName
Returns:
value returned by invoked method
Throws:
InvocationTargetException - exception thrown during methodName invocation
See Also:
invokeOnce(Object, String, Object[])

invokeAndRepeat

public Object invokeAndRepeat(Object object,
                              String methodName,
                              Object[] args,
                              int repeat,
                              long delay)
                       throws InvocationTargetException

Invokes method methodName from object with given arguments (args). Return value is stored in returnValue argument.

Invokes given method repeat (maximum) times. When invoking method finishes with exception throwing method update statistics about invoking method (add exception invocation) and method methodName is invoked again and againg (till loop counter doesn't approach repeat value). Loop stops every exceptional invocation for delay milliseconds. If method invocation doesn't throw exception method breaks loop and goes further. It means that method invoked correctly.

Generally this method calls method invokeOnce - maximum repeat times.

Every exception thrown during invocation operation is logged to LOG MANAGER. This is TODO logging.

Parameters:
object - user wants to invoke method from this object; TODO what if method is static???
methodName - name of the method we want to invoke
args - arguments for invoking method
repeat - how many times (maximum) try to invoke method methodName
delay - time in milliseconds to wait between invocations (when invocation of methodName finishes with exception)
Returns:
value returned by invoked method
Throws:
InvocationTargetException - exception thrown during methodName invocation
See Also:
invokeOnce(Object, String, Object[]), invokeAndRepeat(Object, String, Object[], int)

invokeNVariant

public Object invokeNVariant(Object[] objects,
                             String[] methodNames,
                             Object[][] args)
                      throws IllegalArgumentException

Invokes method methodNames from objects with given arguments (args). Return value is stored in returnValue argument.

Invokes methods in order of objects array. If first method from first object throw an exception method invoke next method from objects array. And so on. If any of these invoked methods finishes correctly method ends and returnValue contains return object from last invoked method. Generally this method calls method invokeOnce with specific arguments for each method.

Every exception thrown during invocation operation is logged to LOG MANAGER. This is TODO logging.

Parameters:
objects - array of objects that contain methods to invoke TODO what if any of these method is static???
methodNames - array of names of the methods we want to invoke
args - array of arguments for invoking methods correctly and didn't throw an exception)
Returns:
value returned by invoked method (this which was invoked
Throws:
IllegalArgumentException - argument arrays length mismatch
See Also:
invokeOnce(Object, String, Object[])

invokeAndCheck

public boolean invokeAndCheck(Object object,
                              String methodName,
                              Object[] args,
                              Object expectedValue)
                       throws InvocationTargetException

Invokes method methodName from object with given arguments (args) and checks if returnValue equals expectedValue.

Parameters:
object - user wants to invoke method from this object; TODO what if method is static???
methodName - name of the method we want to invoke
args - arguments for invoking method
expectedValue - expected object to be returned from invoking method
Returns:
true if method invoked correctly and value returned by this method equals expected value; false in other case
Throws:
InvocationTargetException - exception thrown during methodName invocation
See Also:
invokeOnce(Object, String, Object[])