Although your suggestion seems to improve the existing code base at
first glance, I am not convinced that its a good thing to do for
something like metrics collection, which could literally get called
millions of times (e.g. counting the bytes sent/received etc).. and
going through a list of observers, when the list would contain one
element most of the time seems like its not worth it to me
The number of calls to the observers for a single message is O(1), so
the overhead seems to be quite negligible.
Not necessarily.. for example with the NIO transport, we increment bytes
sent/received etc each time we write some data to the channels, and this
could be many times per message
Alternatively the scope could be reduced to error conditions: The
MetricsCollector would be unchanged and we would have a completely
separate concept of error listeners that can be registered with the
transport. Since they are only called when something goes wrong, we
don't care about a few microseconds lost in a for loop.
I prefer this solution, and I do not care about extra code when it does
error handling
asankha