1 22 23 package org.jboss.aspects.asynchronous.aspects.jboss; 24 25 import org.jboss.aop.joinpoint.MethodInvocation; 26 import org.jboss.aspects.asynchronous.AsynchronousConstants; 27 import org.jboss.aspects.asynchronous.AsynchronousParameters; 28 import org.jboss.aspects.asynchronous.AsynchronousResponse; 29 import org.jboss.aspects.asynchronous.AsynchronousUserTask; 30 import org.jboss.aspects.asynchronous.common.AsynchronousResponseImpl; 31 32 import java.lang.reflect.Method ; 33 34 38 39 public class AsynchronousInvokeTask 40 41 implements AsynchronousUserTask, AsynchronousConstants 42 { 43 44 protected AsynchronousInvokeTask() 45 { 46 47 super(); 48 49 } 50 51 public AsynchronousResponse process(AsynchronousParameters jp) 52 { 53 54 try 55 { 56 57 InvokeTaskInputParameters ijp = (InvokeTaskInputParameters) jp; 58 59 MethodInvocation invocation = ijp.invocation; 60 61 Object res = invocation.invokeNext(); 62 63 return new AsynchronousResponseImpl(OK, res); 64 65 } 66 catch (Throwable e) 67 { 68 69 return new AsynchronousResponseImpl(EXCEPTIONCAUGHT, e); 70 71 } 72 73 } 74 75 private boolean invoke(Object targetedObject, 76 77 Class [] paramemeterTypes, 78 79 Object [] parameterObjects, 80 81 Class stringName) 82 { 83 84 try 85 { 86 87 Class aClass = null; 88 89 if (targetedObject == null) 90 91 aClass = stringName; 92 93 else 94 95 aClass = targetedObject.getClass(); 96 97 Method method = aClass.getMethod("cleanup", paramemeterTypes); 98 99 method.invoke(targetedObject, parameterObjects); 100 101 } 102 catch (Exception e) 103 { 104 105 return false; 106 107 } 108 109 return true; 110 111 } 112 113 public void cleanup(AsynchronousParameters jp) 114 { 115 116 try 117 { 118 119 InvokeTaskInputParameters ijp = (InvokeTaskInputParameters) jp; 120 121 MethodInvocation invocation = ijp.invocation; 122 123 Object targetedClass = invocation.getTargetObject(); 124 125 if (!invoke(targetedClass, 126 127 invocation.getActualMethod().getParameterTypes(), 128 129 invocation.getArguments(), 130 131 invocation.getActualMethod().getDeclaringClass())) 132 133 invoke(targetedClass, 134 135 null, 136 137 null, 138 139 invocation.getActualMethod().getDeclaringClass()); 140 141 } 142 catch (Exception e) 143 { 144 145 146 } 147 148 } 149 150 } 151 152 | Popular Tags |