For the Java 5 dependent branches, it would be awfully nice if we were
to make IoHandler and IoFilter type safe with regard to received
messages.
This can be done two ways -- the first is mere decoration -- you add a
type parameter for the message argument:
interface IoHandler<In> {
messageReceived(IoSession session, In msg);
...
}
interface IoFilter<In, Out> {
messageReceived(NextFilter<Out>, IoSession session, In msg);
}
In the "Decoration" approach the type is ignored at runtime and just
becomes an implicit cast. This lets you type what comes in as
documentation, at least.
A stronger approach would be to explicitly check the generic type via
reflection and raise an exception at bind() or connect() time. In this
case the In and Out types for the filter chain would be compared for
compatibility, and the final out on the filter chain compared to the
In on the handler. This would allow for raising an illegal state
exception describing the message type problem as early as possible.
Once running implicit casts are used for actual dispatch so as not to
impact performance.
Thoughts?
-Brian