public Object handleCreateProducerDelegate(Invocation invocation) throws Throwable
{
// ProducerDelegates are not created on the server
ProducerDelegate producerDelegate = new ClientProducerDelegate();
DelegateSupport delegate = (DelegateSupport)producerDelegate;
SessionState sessionState = (SessionState)getState(invocation);
MethodInvocation mi = (MethodInvocation)invocation;
Destination dest = ((Destination)mi.getArguments()[0]);
ProducerState producerState = new ProducerState(sessionState, producerDelegate, dest);
if (sessionState.isEnableOrderingGroup())
{
producerState.setOrderingGroupEnabled(true);
producerState.setOrderingGroupName(sessionState.getDefaultOrderingGroupName());
}
delegate.setState(producerState);
// send an arbitrary invocation into the producer delegate, this will trigger AOP stack
// initialization and AOP aspect class loading, using the "good" class loader, which is set
// now. This will save us from having to switch the thread context class loader on every send.
producerDelegate.getDeliveryMode();
return producerDelegate;
}