SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
EndpointRegistry epRegistry = spiProvider.getSPI(EndpointRegistryFactory.class).getEndpointRegistry();
JMSEndpointResolver resolver = spiProvider.getSPI(JMSEndpointResolver.class);
resolver.setDestination(destination);
Endpoint endpoint = epRegistry.resolve(resolver);
if (endpoint == null)
throw new IllegalStateException("Cannot find endpoint for destination: " + destination);
EndpointAssociation.setEndpoint(endpoint);
try
{
boolean debugEnabled = log.isDebugEnabled();
if (debugEnabled)
log.debug("dipatchMessage: " + endpoint.getName());
// [JBWS-1324]: workaround to prevent message processing before endpoint is started
EndpointState state = endpoint.getState();
ObjectName name = endpoint.getName();
long startTime = System.currentTimeMillis();
if (debugEnabled)
log.debug(name + " is in state: " + state);
while (state != EndpointState.STARTED && (System.currentTimeMillis() - startTime < 60000))
{
try
{
Thread.sleep(1000);
state = endpoint.getState();
if (debugEnabled)
log.debug(name + " is now in state: " + state);
}
catch (InterruptedException e)
{
throw new EJBException(e);
}
}
RequestHandler reqHandler = endpoint.getRequestHandler();
try
{
InvocationContext invContext = new InvocationContext();
invContext.setTargetBean(this);