public final RMMessage send(RMMessage request) throws Throwable
{
RMMessageRetransmissionConfig qos = RMTransportHelper.getSequence(request).getRMConfig().getMessageRetransmission();
if (qos == null)
throw new RMException("User must specify message retransmission configuration in JAX-WS WS-RM config");
int countOfAttempts = qos.getCountOfAttempts();
int inactivityTimeout = qos.getMessageTimeout();
int retransmissionInterval = qos.getRetransmissionInterval();
RMChannelResponse result = null;
long startTime = 0L;
long endTime = 0L;
int attemptNumber = 1;
for (int i = 0; i < countOfAttempts; i++)
{
logger.debug("Sending RM request - attempt no. " + attemptNumber++);
Future<RMChannelResponse> futureResult = rmTasksQueue.submit(new RMChannelTask(request));
try
{
startTime = System.currentTimeMillis();
result = futureResult.get(inactivityTimeout, TimeUnit.SECONDS);
if (result != null)
{
Throwable t = result.getFault();
if (t != null)
{
logger.warn(result.getFault().getClass().getName(), result.getFault());
}
else
{
endTime = System.currentTimeMillis();
if (result.getResponse() != null)
{
Map<String, Object> remotingCtx = result.getResponse().getMetadata().getContext(RMChannelConstants.REMOTING_INVOCATION_CONTEXT);
if (remotingCtx != null)
{
if (Integer.valueOf(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).equals(remotingCtx.get(HTTPMetadataConstants.RESPONSE_CODE)))
{
logger.debug("Response message received in " + (endTime - startTime) + " miliseconds, but contains internal server code, going to resend the request message");
continue;
}
}
}
logger.debug("Response message received in " + (endTime - startTime) + " miliseconds");
break;
}
try
{
Thread.sleep(retransmissionInterval * 1000);
}
catch (InterruptedException ie)
{
logger.warn(ie.getMessage(), ie);
}
}
}
catch (TimeoutException te)
{
endTime = System.currentTimeMillis();
logger.warn("Timeout - response message not received in " + (endTime - startTime) + " miliseconds");
try
{
Thread.sleep(retransmissionInterval * 1000);
}
catch (InterruptedException ie)
{
logger.warn(ie.getMessage(), ie);
}
}
}
if (result == null)
throw new RMException("Unable to deliver message with addressing id: " + RMTransportHelper.getAddressingMessageId(request) + ". Count of attempts to deliver the message was: " + countOfAttempts);
Throwable fault = result.getFault();
if (fault != null)
{
throw new RMException("Unable to deliver message with addressing id: " + RMTransportHelper.getAddressingMessageId(request) + ". Count of attempts to deliver the message was: " + countOfAttempts, fault);
}
else
{
return result.getResponse();
}