This is the JIRA for the mina-dev mailing list discussion here:
I would like to suggest that the invocations of increaseWrittenMessages() and increaseReceivedMessages() are moved from their current spot in AbstractIoFilter into the appropriate methods of TailFilter. The increaseWrittenBytes() and increaseReceivedBytes() invocations can stay where they are.
I have an IoFilter chain in which a SegmentationFilter takes in a single application message to filterWrite() and splits it into multiple packets. On the way back, it filters the messageSent() events for every packet sent, collating them into a single call to nextFilter#messageSent() for each original application-level message. Further down the chain, I have an ARQ filter which can re-send packets that weren't acknowledged in time. Both filters can cause a different number of messages to come out at the IoService end than went into them at the Application end (and vice versa).
In this scenario the writtenBytes/receivedBytes counters are fine as they are, but the writtenMessages/readMessages counters are basically useless in their current form. Their value depends on the size of the messages my application sends and on the quality of the network connection (i.e. if any retries were necessary) and even on whether the outgoing ACK packets can piggyback on a data packet or have to be sent out on their own. Compared to a message counter I keep at the application level, the messages sent/received values tracked in IoServiceStatistics diverge immediately.