You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "fred.ac" <fr...@scarlet.be> on 2007/05/16 10:02:08 UTC

messageReceived before the messageSent event

Dear all,

We are using Mina 1.1.0 with spring integration to implement a TCP protocol.
Sometimes when the client sends a message and is waiting for a
response it receives the messageReceived before the messageSent event
(IoHandler).
The problem we have is that the protocol is controlled by a state
machine (serviceCoordinator) and of course if we receive a response
before knowing that the request was sent it gives an error.
The server replies immediately when it receives a request, if we slown
down the server we correctly receive the messageReceived after the
messageSent event in the client.
When we were using Mina 0.9.4 we didn't have this problem.
Could someone explain me how to solve it, i.e. how to "force" a
messageSent before a messageReceived event.

Many thanks

Cheers,
Frédéric.

Here is our spring config :

<bean id="mapsBinding" class="org.apache.mina.integration.spring.Binding">
        <property name="address" value=":${tams.tci.maps.port}"/>
        <property name="handler">
            <ref local="serviceCoordinator"/>  <== implements
messageReceived and messageSent methods (IoHandler)

        </property>
        <property name="serviceConfig">
            <bean
class="org.apache.mina.transport.socket.nio.SocketAcceptorConfig">
                <property name="threadModel">
                    <bean
class="org.apache.mina.integration.spring.ExecutorThreadModelFactoryBean">
                        <property name="serviceName" value="MAPSIoWorker"/>
                        <property name="executor">
                            <bean
class="org.apache.mina.integration.spring.ThreadPoolExecutorFactoryBean">
                                <property name="corePoolSize" value="1"/>
                                <property name="maxPoolSize" value="10"/>
                                <property name="keepAliveSeconds" value="60"/>
                            </bean>
                        </property>
                    </bean>
                </property>
                <property name="filterChainBuilder">
                    <bean
class="org.apache.mina.integration.spring.DefaultIoFilterChainBuilderFactoryBean">
                        ...
                    </bean>
                </property>
                <property name="reuseAddress" value="true"/>
            </bean>
        </property>
</bean>

Re: messageReceived before the messageSent event

Posted by peter royal <pr...@apache.org>.
On May 16, 2007, at 11:12 AM, jian wu wrote:
> If I understand correctly, Mina treats the message A sent out
> and Message B received as two independent events, you might
> want to consider tracking "sending message A" in the
> filterWrite() of your last IoFilter before Mina actually writes out
> message A.

yup. could also put a callback on the WriteFuture for message A as well.

sounds like the remote end is just replying *really fast* before you  
have a chance to receive the "sent event"

perhaps you could re-architect how you are doing things so that you  
advance your state machine right before you write the message, so you  
are prepared for an immediate reply.. and then if the write fails,  
back it up and re-try the write. might side-step the issue nicely.

-pete

-- 
(peter.royal|osi)@pobox.com - http://fotap.org/~osi


-- 
proyal@apache.org - http://fotap.org/~osi




Re: messageReceived before the messageSent event

Posted by jian wu <he...@gmail.com>.
Hi,

If I understand correctly, Mina treats the message A sent out
and Message B received as two independent events, you might
want to consider tracking "sending message A" in the
filterWrite() of your last IoFilter before Mina actually writes out
message A.

Thanks,

Jian


On 5/16/07, fred. ac <fr...@scarlet.be> wrote:
> Dear all,
>
> We are using Mina 1.1.0 with spring integration to implement a TCP protocol.
> Sometimes when the client sends a message and is waiting for a
> response it receives the messageReceived before the messageSent event
> (IoHandler).
> The problem we have is that the protocol is controlled by a state
> machine (serviceCoordinator) and of course if we receive a response
> before knowing that the request was sent it gives an error.
> The server replies immediately when it receives a request, if we slown
> down the server we correctly receive the messageReceived after the
> messageSent event in the client.
> When we were using Mina 0.9.4 we didn't have this problem.
> Could someone explain me how to solve it, i.e. how to "force" a
> messageSent before a messageReceived event.
>
> Many thanks
>
> Cheers,
> Frédéric.
>
> Here is our spring config :
>
> <bean id="mapsBinding" class="org.apache.mina.integration.spring.Binding">
>         <property name="address" value=":${tams.tci.maps.port}"/>
>         <property name="handler">
>             <ref local="serviceCoordinator"/>  <== implements
> messageReceived and messageSent methods (IoHandler)
>
>         </property>
>         <property name="serviceConfig">
>             <bean
> class="org.apache.mina.transport.socket.nio.SocketAcceptorConfig">
>                 <property name="threadModel">
>                     <bean
> class="org.apache.mina.integration.spring.ExecutorThreadModelFactoryBean">
>                         <property name="serviceName" value="MAPSIoWorker"/>
>                         <property name="executor">
>                             <bean
> class="org.apache.mina.integration.spring.ThreadPoolExecutorFactoryBean">
>                                 <property name="corePoolSize" value="1"/>
>                                 <property name="maxPoolSize" value="10"/>
>                                 <property name="keepAliveSeconds" value="60"/>
>                             </bean>
>                         </property>
>                     </bean>
>                 </property>
>                 <property name="filterChainBuilder">
>                     <bean
> class="org.apache.mina.integration.spring.DefaultIoFilterChainBuilderFactoryBean">
>                         ...
>                     </bean>
>                 </property>
>                 <property name="reuseAddress" value="true"/>
>             </bean>
>         </property>
> </bean>
>