public ISOMsg request (ISOMsg m, long timeout) throws ISOException { long maxWait = System.currentTimeMillis() + timeout; MUX mux = getMUX(m,maxWait); if (mux != null) { timeout = maxWait - System.currentTimeMillis(); if (timeout >= 0) return mux.request (m, timeout); } return null; } public void send (ISOMsg m) throws ISOException, IOException {
public void request (ISOMsg m, long timeout, final ISOResponseListener r, final Object handBack) throws ISOException { long maxWait = System.currentTimeMillis() + timeout; MUX mux = getMUX(m,maxWait); if (mux != null) { timeout = maxWait - System.currentTimeMillis(); if (timeout >= 0) mux.request(m, timeout,r, handBack); else { new Thread() { public void run() { r.expired (handBack); } }.start(); } } else throw new ISOException ("No MUX available"); } private boolean overrideMTI(String mtiReq) {
@Test @SuppressWarnings("unchecked") public void testExpiredMessage() throws Exception { mux.request(createMsg("000001"), 500L, this, "Handback One"); assertFalse("expired called too fast", expiredCalled); assertNotNull("Space doesn't contain message key", getInternalSpace(mux).rdp("send.0800000000029110001000001.req")); Thread.sleep(1000L); assertTrue("expired has not been called after 1 second", expiredCalled); assertNull("Cleanup failed, Space still contains message key", getInternalSpace(mux).rdp("send.0800000000029110001000001.req")); assertEquals("Handback One not received", "Handback One", receivedHandback); }
ISOMsg resp = mux.request(entry.msg, waitForResponse); if (resp == null) {
public void run () { LogEvent evt = new LogEvent (Connector.this, "connector-request-listener"); try { ISOMsg c = (ISOMsg) m.clone(); evt.addMessage (c); if (muxName != null) { MUX destMux = (MUX) NameRegistrar.get (muxName); ISOMsg response = destMux.request (c, timeout); if (response != null) { if (preserveSourceHeader) response.setHeader (c.getISOHeader()); source.send(response); } } else if (channelName != null) { Channel destChannel = (Channel) NameRegistrar.get (channelName); destChannel.send (c); } } catch (ISOException e) { evt.addMessage (e); } catch (IOException e) { evt.addMessage (e); } catch (NotFoundException e) { evt.addMessage(e); } Logger.log (evt); }
@Test public void testAnsweredMessage() throws Exception { mux.request(createMsg("000002"), 500L, this, "Handback Two"); assertFalse("expired called too fast", expiredCalled); ISOMsg m = (ISOMsg) sp.in("send", 500L); assertNotNull("Message not received by pseudo-channel", m); assertNotNull("Space doesn't contain message key", getInternalSpace(mux).rdp("send.0800000000029110001000002.req")); m.setResponseMTI(); sp.out("receive", m); Thread.sleep(100L); assertNotNull("Response not received", responseMsg); Thread.sleep(1000L); assertFalse("Response received but expired was called", expiredCalled); assertNull("Cleanup failed, Space still contains message key", getInternalSpace(mux).rdp("send.0800000000029110001000002.req")); assertEquals("Handback Two not received", "Handback Two", receivedHandback); }
tc.start(); if (tc.getExpectedResponse() != null) { tc.setResponse(mux.request(m, tc.getTimeout())); tc.end(); assertResponse(tc, bsh, evt_error);