camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: How to close Mina session ?
Date Fri, 20 Feb 2009 15:12:40 GMT
Ah yeah the UnitOfWork works on the processing of the exchange. So it
completes just as MinaConsumer will write the reponse back to the
client.

I have commited a new feature into the next version in Camel.

I am afraid I can not see an easy workaround.

You can now set this special header and Camel will close the session afterwards

exchange.getOut().setHeader(MinaConsumer.HEADER_CLOSE_SESSION_WHEN_COMPLETE,
true);


On Fri, Feb 20, 2009 at 1:52 PM, Nicolas Bouillon <nicolas@bouil.org> wrote:
> Claus,
>
> Thanks for the tip. Howerver, it dones't seem to work.
>
> I have added the following code at the end of my process method :
>
>
>        // add a hook to close the session after the exchange
>        exchange.getUnitOfWork().addSynchronization(new Synchronization() {
>
>            @Override
>            public void onComplete(Exchange exchange) {
>                MinaExchange minaExchange = (MinaExchange) exchange;
>                System.out.println("Closing session");
>                minaExchange.getSession().close().join();
>                System.out.println("Session closed");
>            }
>
>            @Override
>            public void onFailure(Exchange exchange) {
>
>            }
>
>        });
>
>
> But, as i can see as runtime and when debugging step by step in
> org.apache.camel.component.mina.MinaConsumer, the event onComplete is fired
> before the write to the the socket. So the problem keep the same.
>
> I've tried three ways : adding this to my process. Adding to a processor
> before mine, and after mine. Each time, the onComplete event is called
> before the MinaHelper.writeBody(session, body, exchange);
>
> Regards.
> Nicolas.
>
> On Fri, Feb 20, 2009 at 12:30, Claus Ibsen <claus.ibsen@gmail.com> wrote:
>
>> You can use the Synchronization hooks on the UnitOfWork
>>
>> Then you need to route with a processor where you can add the hook
>>
>>                from("mina").process(new Processor() {
>>                    public void process(Exchange exchange) throws Exception
>> {
>>
>> exchange.getUnitOfWork().addSynchronization(new
>> MyMinaMaybeCloseSession());
>>                    }
>>                }).to(xxxx);
>>
>> And in the MyMinaMaybeCloseSession you have callbacks for onComplete,
>> onFailure.
>> Then you can check in the exchange if the body is that special stop
>> command and then access the mina session and close it.
>>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/

Mime
View raw message