I would most prefer to come up with a solution that passes the socket's output/inputstream directly to the marshaller without wrapping at all. I have coded up something for this that works like this, yet still able to keep the socket alive via pings. Only problem is that it is twice as slow, so need to profile it some. Will need a little more time to work on it. Will post back when get it worked out.
I have opened a Jira issue for this at (http://jira.jboss.com/jira/browse/JBREM-111)
There is another way to solve but it requires some refactoring to move the ping handling to intermediate filter streams. In this way, even if the marshallers wraps the stream with an Object*Stream, the intermediate streams will manage the pings.
Raw*Stream -> Buffered*Stream -> Ping*Stream (-> Object*Stream)
The PingOutputStream wraps the raw socket output stream and adds a thin layer of ping management. The PingOutputStream contains a timer that generates a ping at predefined intervals. The ping timer is reset every time some real data is written so a ping is only generated when needed. The logic for this is located within the write(int) method and is synchronized so no other data can be written during pings. Immediately after sending the ping the stream will try to read the responding pong packet.
A corresponding PongInputStream similiarly wraps the raw socket input stream and adds a thin layer looking for the arrival of a ping packets. If a ping packet is received it immediately replies by sending back a pong packet. Otherwise the data is just forwarded as usual.
Since the ping/pong packets are totally managed within the intermediate filter streams there is no need to issue a reset on the Object*Streams used by the marshallers.