Search code examples
javaiso8583jpos

Why is QMUX.request() method designed to pass the timeout parameter compulsorily?


I am connecting to a host using the config below, which has the timeout property too. Now my question is why do I again need to pass the timeout param to QMUX.request(msg, timeout) ? my understanding is that, the purpose of <property name="timeout" value="60000"/> and timeout param of QMUX.request(msg,timeout) method same. please correct me if I am wrong.

 <channel-adaptor name="my-channel-adaptor"
                     class="org.jpos.q2.iso.ChannelAdaptor"
                     logger="Q2"
                     realm="my-channel-realm"
                     pool-size="50"
                     thread-pool-size="10">
      <channel class="org.jpos.iso.channel.ASCIIChannel"
               packager="org.jpos.iso.packager.GenericPackager">
        <property name="host" value="localhost"/>
        <property name="port" value="65000"/>
        <property name="timeout" value="60000"/>
        <property name="maxPacketLength" value="4096"/>
        <property name="header" value="600"/>
        <property name="lengthHeader" value="2"/>
        <property name="keepAlive" value="true"/>
      </channel>
    </channel-adaptor>

Solution

  • My understanding is that, the purpose of <property name="timeout" value="60000"/> and timeout param of QMUX.request(msg,timeout) method same.

    I don't think so.

    • The former results in setSOTimeout being called on each Socket as it is connected. According to the javadoc, setting an SO_Timeout has the following effect:

      Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a non-zero timeout, a read() call on the InputStream associated with this Socket will block for only this amount of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the Socket is still valid. The option must be enabled prior to entering the blocking operation to have effect. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.

      In other words, this is a transport level timeout. I haven't researched what happens when SocketTimeoutException is raised, but I imagine that the channel will be marked as failed ... in some way.

    • The latter is a timeout for the specific request. It is an application protocol timeout. When it occurs, it looks like the request(...) call returns null. The channel will still be alive.

      If you pass zero as the timeout, there is no request level timeout. The request call will wait indefinitely for the response.


    Why is QMUX.request() method designed to pass the timeout parameter compulsorily?

    That is something you would need to ask the org.jpos designers.