// Mark the start time
long start = System.currentTimeMillis();
// Create a pointer to a new Invocation
EJBContainerInvocation newSi = null;
// Create a pointer to the response we'll return
InvocationResponse response = null;
/*
* Setup Environment (Stack/Thread)
*/
// Hold a reference to the existing TCL
ClassLoader originalLoader = Thread.currentThread().getContextClassLoader();
// Set the Container's CL as TCL, required to unmarshall methods from the bean impl class
Thread.currentThread().setContextClassLoader(this.getClassloader());
try
{
/*
* Obtain the target method (unmarshall from invocation)
*/
// Cast
assert invocation instanceof MethodInvocation : SessionContainer.class.getName()
+ ".dynamicInoke supports only " + MethodInvocation.class.getSimpleName()
+ ", but has been passed: " + invocation;
MethodInvocation si = (MethodInvocation) invocation;
// Get the method hash
long methodHash = si.getMethodHash();
log.debug("Received dynamic invocation for method with hash: " + methodHash);
// Get the Method via MethodInfo from the Advisor
Advisor advisor = this.getAdvisor();
MethodInfo info = advisor.getMethodInfo(methodHash);
Method unadvisedMethod = info.getMethod();
SerializableMethod unadvisedMethodSerializable = new SerializableMethod(unadvisedMethod);
try
{
invokeStats.callIn();
/*
* Set the invoked method
*/
//TODO Remove when CurrentInvocation is ironed out
// Get the invoked method from invocation metadata
Object objInvokedMethod = si.getMetaData(SessionSpecRemotingMetadata.TAG_SESSION_INVOCATION,SessionSpecRemotingMetadata.KEY_INVOKED_METHOD);
assert objInvokedMethod !=null : "Invoked Method must be set on invocation metadata";
assert objInvokedMethod instanceof SerializableMethod : "Invoked Method set on invocation metadata is not of type " + SerializableMethod.class.getName() + ", instead: " + objInvokedMethod;
SerializableMethod invokedMethod = (SerializableMethod)objInvokedMethod;
Class<?> invokedBusinessInterface = Class.forName(invokedMethod.getActualClassName(), false, this
.getClassloader());
if (!this.getBusinessInterfaces().contains(invokedBusinessInterface))
{
// Required because SerializableMethod will automatically set the actual class name to the declaring class name
invokedBusinessInterface = null;
}
Map responseContext = null;
Object rtn = null;
if (unadvisedMethod != null && isHomeMethod(unadvisedMethodSerializable))
{
rtn = invokeHomeMethod(info, si);
}
else if (info != null && unadvisedMethod != null && isEjbObjectMethod(unadvisedMethodSerializable))
{
rtn = invokeEJBObjectMethod(info, si);
}
else
{
newSi = new SessionContainerInvocation<StatelessContainer, StatelessBeanContext>(
invokedBusinessInterface, info, this.getAsynchronousExecutor());
newSi.setArguments(si.getArguments());
newSi.setMetaData(si.getMetaData());
//newSi.setAdvisor(getAdvisor());
try
{
rtn = newSi.invokeNext();
responseContext = newSi.getResponseContextInfo();
}
catch (Throwable throwable)
{
responseContext = newSi.getResponseContextInfo();
return marshallException(invocation, throwable, responseContext);
}
}
response = marshallResponse(invocation, rtn, responseContext);