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 {
protected boolean isConnected (MUX mux) { if (mux.isConnected()) return true; long timeout = System.currentTimeMillis() + waitTimeout; while (System.currentTimeMillis() < timeout) { if (mux.isConnected()) return true; ISOUtil.sleep (500); } return false; } }
public void send (ISOMsg m) throws ISOException, IOException { long maxWait = 1000L; // reasonable default MUX mux = getMUX(m,maxWait); if (mux == null) throw new ISOException ("No available MUX"); mux.send(m); } public boolean isConnected() {
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) {
public String getStatus() { StringBuffer sb = new StringBuffer(); sb.append("mux="); sb.append(mux.isConnected() ? "ready" : "not-ready"); if (psp instanceof JDBMSpace) { sb.append(", queue-size="); sb.append(((JDBMSpace) psp).size(queue)); } Entry latched = (Entry) psp.rdp(head); if (latched != null) { if (latched.count > 0) sb.append(" head transmitted " + latched.count + " time(s)"); } return sb.toString(); }
@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); }
@SuppressWarnings("unchecked") private boolean isUsable (MUX mux) { if (!checkEnabled || !(mux instanceof QMUX)) return mux.isConnected(); QMUX qmux = (QMUX) mux; String enabledKey = qmux.getName() + ".enabled"; String[] readyNames = qmux.getReadyIndicatorNames(); if (readyNames != null && readyNames.length == 1) { // check that 'mux.enabled' entry has the same content as 'ready' return mux.isConnected() && sp.rdp (enabledKey) == sp.rdp (readyNames[0]); } return mux.isConnected() && sp.rdp (enabledKey) != null; } }
ISOUtil.sleep(initialDelay); while (running()) { if (!mux.isConnected()) { ISOUtil.sleep(1000); continue;
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); }