Trustin Lee wrote:
>
> Hi Haviv,
>
> On 3/26/07, Haviv <[EMAIL PROTECTED]> wrote:
>> I am working on MINA 1.0.1 , using a custom ProtocolDecoder which extends
>> the CumulativeProtocolDecoder.
>> I am also using an ExecutorFilter in front of the ProtocolCodecFilter -
>> meaning that my ProtocolDecoder runs
>> multi threaded.
>> Recently under Heavy load I have encountered some strange errors - my
>> received messages got corrupted.
>> After looking at the CumulativeProtocolDecoder - I was wondering why
>> there
>> isn't any synchronization block
>> on CumulativeProtocolDecoder.decode method which can prevent this kind of
>> behavior ?
>
> CumulativeProtocolDecoder doesn't need to synchronize anything because
> ExecutorFilter guarantees that only one event per session is processed
> at the same time.
>
> There is synch parts on the ExecutorFilter.fireEvent :
> synchronized( buf.eventQueue )
> {
> buf.eventQueue.add( event );
> if( buf.processingCompleted )
> {
> buf.processingCompleted = false;
> if ( logger.isDebugEnabled() ) {
> logger.debug( "Launching thread for " +
> session.getRemoteAddress() );
> }
>
> executor.execute( new ProcessEventsRunnable( buf ) );
> }
> }
> But this method just puts the Runnable on a Q, and the
> CumulativeProtocolDecoder runs on a different thread.
>
> There is another synch block in ProcessEventsRunnable:
> public void run()
> {
> while( true )
> {
> Event event;
>
> synchronized( buffer.eventQueue )
> {
> if( buffer.eventQueue.isEmpty() )
> {
> buffer.processingCompleted = true;
> break;
> }
>
> event = ( Event ) buffer.eventQueue.remove( 0 );
> }
>
> processEvent( event.getNextFilter(), buffer.session,
> event.getType(), event.getData() );
> }
>
> if ( logger.isDebugEnabled() ) {
> logger.debug( "Exiting since queue is empty for " +
> buffer.session.getRemoteAddress() );
> }
> }
> But as you can see the processEvent is actually outside of the block.
>
> Did wrapping the code with the synchronized block fix your problem?
> Could you provide us that reproduces the problem so we can make sure
> if it is really a bug of CumulativeProtocolDecoder before blindly
> applying your fix?
>
> Applying the synch part on the CumulativeProtocolDecoder actually solved
> the problem.
> Regarding the code -I think that any Decoder which extends the
> CumulativeProtocolDecoder should tackle this problem, tell me if you still
> need it.
>
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP Key ID: 0x0255ECA6
>
>
--
View this message in context:
http://www.nabble.com/CumulativeProtocolDecoder-BUG---tf3466819.html#a9688245
Sent from the mina dev mailing list archive at Nabble.com.