public EgovIntegrationMessage sendSync(EgovIntegrationMessage requestMessage, long timeout) { LOG.debug("sendSync called with timeout"); if (requestMessage == null) { LOG.error("requestMessage is null"); throw new IllegalArgumentException(); } LOG.debug("Create MessageSender without Callback"); MessageSender sender = new MessageSender(this, requestMessage, null); LOG.debug("Start MessageSender"); sender.start(); LOG.debug("Wait for the termination of MessageSender"); try { sender.join(timeout); } catch (InterruptedException e) { LOG.debug("MessageSender was interrupted", e); } if (sender.isAlive()) { LOG.debug("MessageSender is alive over 'timeout'."); sender.interrupt(); EgovIntegrationMessageHeader responseHeader = new SimpleMessageHeader(requestMessage.getHeader()); responseHeader.setResultCode(ResultCode.TIME_OUT); return new SimpleMessage(responseHeader); } else { LOG.debug("MessageSender finished to send and receive messages."); return sender.getResponseMessage(); } }
public EgovIntegrationMessage receive(long timeout) { LOG.debug("receive with timeout"); LOG.debug("wait for the termination of MessageSender"); try { sender.join(timeout); } catch (InterruptedException e) { LOG.debug("MessageSender was interrupted", e); } if (sender.isAlive()) { LOG.debug("MessageSender is alive over 'timeout'"); sender.interrupt(); EgovIntegrationMessageHeader responseHeader = new SimpleMessageHeader(sender.requestMessage.getHeader()); responseHeader.setResultCode(ResultCode.TIME_OUT); return new SimpleMessage(responseHeader); } else { LOG.debug("MessageSender finished to send and receive messages."); return sender.getResponseMessage(); } }