netsql wrote:
> Niklas Therning wrote:
>
...
>> 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.
>
>
>
> OK, but you said to do it in the factory above, and not to create
> another IoHandler, so I will use Factory, right?
No, you shouldn't write things back from your Decoder if that's what you
mean. The Decoder just takes a ByteBuffer and creates a corresponding
Java object which will then be forwarded to your IoHandler (this is what
happens when you write to the ProtocolDecoderOutput in your
MessageDecoder's decode 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
>>
>
>
> So I have no idea what Pong is?
> The message I write in encode method of Encoder and it makes a buffer
> where I add what message should be and then I write it.
Your encoder will only be called if you write a non-ByteBuffer message
to the session in your IoHandler. If you don't have a Java class
representing the response (this is the Pong class I was assuming you
had) there is no need for having an encoder. Just write the ByteBuffer
directly from your IoHandler.
I suggest that you have a look again at the sumup example. It seems to
come quite close to what you're trying to do. As you can see in
ServerSessionHandler it never have to deal with ByteBuffers directly.
Instead it receives AddMessage objects as requests and sends
ResultMessage objects as responses. The SumUpProtocolCodecFactory will
create decoders which convert receieved bytes into AddMessage objects
and encoders which convert written ResultMessage objects into bytes.
I think that you might have misunderstood the flow of messages when you
use the ProtocolCodecFilter and friends. It would help a lot if you
could post your code here on the list for us to take a peek.
--
Niklas Therning
Software Architect
www.spamdrain.net