Hi Rivas,
you can use FilterChain Codec to encoder/decode message to/from Buffer.
Here is a mailing thread, where we discussed similar usecase with Bo
Li [1].
The idea is to make TextLineFilter to implement Codec interface, which
will let you use FilterChain's Codec to encode/decode message in
standalone mode like:
--- *encoding ----
Transformer transformer =
transport.getFilterChain().getCodec().getEncoder();
Buffer buffer = (Buffer) transformer.encode(connection, stringMessage,
null);
--- *decoding ----
Transformer transformer =
transport.getFilterChain().getCodec().getDecoder();
String str = (String) transformer.encode(connection, buffer, null);
In the mentioned thread [1] you can find links to simple Filters,
which implement Codecs.
If you'll have any additional questions - just let us know.
Thanks.
WBR,
Alexey.
[1]
http://www.nabble.com/Grizzly-2.0-filter-chains-and-client-side-implementations-td23615467.html
* Transformer.encode() actually returns TransformationResult, not
ready encoded object. The TransformationResult may notify if message
was successfully encoded or there is not enough data for encoding etc..
> I'm testing the Grizzly Framework 2.0 and I'm stuck with one problem.
>
> I've created my filter chain as:
>
> FilterChain chain = transport.getFilterChain();
> chain.add(new TransportFilter());
> chain.add(new TextLineFilter());
> chain.add(new ServerLogicFilter());
>
> My class TextLineFilter, reads lines of text from the buffers and
> puts the lines as a message to the next filter using
>
> ctx.setMessage(line);
>
> Where ctx is the received instance of FilterChainContext.
>
> My class ServerLogicFilter is in charge of implementing the logic,
> but only deals with the string lines. In handeRead(...), I get the
> line with ctx.getMessage() and I could also write a new line using
> ctx.setMessage(...) in the handleWrite(...) method.
>
> Now I want to write a message to a client some time after the read
> operation was completed. I've kept the Connection that I got from
> the FilterChainContext (using getConnection()). I want to send a
> message through the connection but I only have
> Connection.write(Buffer) and similar.
>
> Is there any way I could write a message in the connection so the
> FilterChain could write this object (in my case, a String) with the
> filters I've already added to the chain?
>
> Thanks in advance,
> Rivas
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>