netsql wrote:
> So w/ help; there is now code to:
> 1. Make an SocketAceptorConfig that uses ProtcolFactory to register a
> Decoder and adds it to the filter
> 2. This is bound to IoAcceptor and w/ a ProtocolHandler (and some minor
> optional simple message back by ProtocolHandler).
> Works great!
>
> Now I need to:
> Make a decoder that will write back a message stream for each ping (I
> called
> it PongEncoder, the project needs to Pong back on each message - it happes
> to be little edian like above 1&2).I have no idea how to invoke the
> encoder,
> the examples are for some prior version of Mina and I am using latest
> released.
So you have a single incoming message type, Ping, which you already have
a MessageDecoder for? And the response to such a message should always
be a Pong? If this is the case all you'd have to do is to make sure you
register your PongEncoder (which must implement MessageEncoder of
course) with the DemuxingProtocolCodecFactory you use in #1. When your
IoHandler receives a Ping message your write back a Pong message. MINA
will take care of invoking the PongEncoder.
Have a look at the sumup example. It's up to date and demonstrates how
to use the MessageEncoder/MessageDecoder stuff.
>
> A. If I register it as filter to #1 and #2 above...They are bound to the
> original ProtocolHandler, that makes no sense in the Pong case, it would
> have to be a different Handler?
No, there is no need for another IoHandler.
> B. If from the ProtocolHandler messageReceived I want to call the
> PongEncoder ... it does not have the "out" argument. that encoder needs?
To write the Pong response you just call
Pong pong = new Pong(...);
session.write( pong );
in your IoHandler's messageReceived method.
> So how to code the getMessageTypes()
It should return a Set containing the message classes your
MessageEncoder can encode. In your case:
public Set getMessageTypes()
{
Set types = new HashSet();
types.add( Pong.class );
return types;
}
HTH
--
Niklas Therning
Software Architect
www.spamdrain.net