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

124 Views Asked by At

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>
2

There are 2 best solutions below

5
Stephen C On BEST ANSWER

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.

0
Andrés Alcarraz On

The timeout of the request method is the time it waits for a response.

The timeout of the channel is the time after which it disconnects without any activity.

They are two different things, that's why you need to specify one on the request method.

If you don't want to wait for a response, you can use the send method. If you want to wait forever, you can use a timeout of zero, but this is not recommended.

One more thing, the mux doesn't have a reference to the channel, it talks to it through its queues, so it cannot override any configuration in any way.