obj);
callbackRequest.setReturnPayload(callbackHandleObject);
}
InvokerCallbackHandler callbackHandler = callbackContainer.getCallbackHandler();
callbackHandler.handleCallback(callbackRequest);
}
else
{
log.error("Could not find callback handler to call upon for handleCallback " +
"where session id equals " + sessionId);
}
}
else if(InternalInvocation.ADDLISTENER.equals(methodName))
{
if(handler == null)
{
throw new InvalidConfigurationException(
"Can not accept a callback listener since there are no ServerInvocationHandlers " +
"registered. Please add via xml configuration or via the Connector's " +
"addInvocationHandler() method.");
}
ServerInvokerCallbackHandler callbackHandler = getCallbackHandler(invocation);
if (registerCallbackListeners)
{
connectionNotifier.addListenerFirst(callbackHandler);
if(leasePeriod > 0)
{
leaseManagement = true;
}
}
handler.addListener(callbackHandler);
}
else if(InternalInvocation.REMOVELISTENER.equals(methodName))
{
ServerInvokerCallbackHandler callbackHandler = removeCallbackHandler(invocation);
if(callbackHandler != null)
{
if (registerCallbackListeners)
{
// connectionNotifier.removeListener(callbackHandler);
removeConnectionListener(callbackHandler);
}
callbackHandler.destroy();
if(handler == null)
{
throw new InvalidConfigurationException(
"Can not remove a callback listener since there are no ServerInvocationHandlers " +
"registered. Please add via xml configuration or via the Connector's " +
"addInvocationHandler() method.");
}
if (registerCallbackListeners)
{
connectionNotifier.removeListener(callbackHandler);
}
handler.removeListener(callbackHandler);
if(trace) { log.trace("ServerInvoker (" + this + ") removing server callback handler " + callbackHandler + "."); }
}
else
{
String sessionId = ServerInvokerCallbackHandler.getId(invocation);
throw new RuntimeException("Can not remove callback listener from target server with " +
"id of " + sessionId + " as it does not exist as a registered callback listener.");
}
}
else if(InternalInvocation.GETCALLBACKS.equals(methodName))
{
ServerInvokerCallbackHandler callbackHandler = getCallbackHandler(invocation);
if(trace) { log.trace("ServerInvoker (" + this + ") getting callbacks for callback handler " + callbackHandler + "."); }
result = callbackHandler.getCallbacks(invocation.getRequestPayload());
}
else if(InternalInvocation.ACKNOWLEDGECALLBACK.equals(methodName))
{
ServerInvokerCallbackHandler callbackHandler = getCallbackHandler(invocation);
if(trace) { log.trace("ServerInvoker (" + this + ") acknowledge callback on callback handler " + callbackHandler + "."); }
callbackHandler.acknowledgeCallbacks(param);
}
else if(InternalInvocation.ADDCLIENTLISTENER.equals(methodName))
{
String sessionId = ServerInvokerCallbackHandler.getId(invocation);
Object[] params = param.getParameters();
// the only elements should be the callback handler and possibly the callback handle object
if(params == null || params.length < 0 || params.length > 3)
{
log.debug("Received addClientListener InternalInvocation, but getParameters() " +
"returned: " + params);
throw new RuntimeException(
"InvokerCallbackHandler and callback handle object (optional) must be supplied as " +
"the only parameter objects within the InternalInvocation when calling " +
"addClientListener.");
}
InvokerCallbackHandler callbackHandler = (InvokerCallbackHandler)params[0];
Object callbackHandleObject = params[1];
CallbackContainer callbackContainer =
new CallbackContainer(callbackHandler, callbackHandleObject);
clientCallbackListener.put(sessionId, callbackContainer);