> I'm not sure why you need to hack Velocity for this.  You can create your
> own Writer that is wired up to do whatever you need, for example write to a
> ByteBuffer.  Then pass your custom Writer to the merge.  Is there any
> functionality that this approach wouldn't accommodate?

That approach is certainly "functional", but it's not as efficient as
the approach I'm describing. The approach I have in mind does away
with the extra copying of the static parts of the output.

In Velocity, the static parts of the output, if I understand right,
are internally represented at runtime as char arrays (in ASTText), no?
 I'm suggesting if we managed to create a ByteBuffer representation
along-side that char array (e.g. UTF-8 encoded), then we could
"collect" these ByteBuffers by just returning a new (read-only) view
of them. I'm thinking since most of the generated content is in fact
made up of static parts, the memory savings might be significant.


On Tue, Apr 21, 2009 at 11:09 PM, Byron Foster <[email protected]> wrote:
> On Apr 21, 2009, at 19:18 , Babak Farhang wrote:
>
>> I'm tinkering with a java, non-blocking, HTTP server implementation
>> and am considering tweaking Velocity (because of its
>> container-agnostic design) so that I can use it's output in such an
>> environment.
>>
>> Specifically, instead of having the Velocity Template "merge" its
>> output to a Writer, I want to create a Template that "merges" output
>> to something like a java.util.List<java.nio.ByteBuffer>.
>>
>> The purpose of this modified output would be to ultimately pass (it in
>> the form of a ByteBuffer array) as the argument to a
>> java.nio.channels.SocketChannel.write -- a non-blocking "gathering"
>> operation.
>>
>> The idea with the java.util.List<java.nio.ByteBuffer> is that the
>> content of some ByteBuffers will be dynamically generated; the
>> contents of the rest would be static.
>>
>> So how to pull this off?  The first place I considered hacking was the
>> Template class itself (something like intercepting every ASTText
>> instance's render method for static content and doing something else
>> with the dynamic bits of content).  Needless to say, this has a
>> 'hacky' feel to it ;)  And since I'm new to Velocity, I'm thinking
>> maybe there's a more elegant approach.
>
>
> I'm not sure why you need to hack Velocity for this.  You can create your
> own Writer that is wired up to do whatever you need, for example write to a
> ByteBuffer.  Then pass your custom Writer to the merge.  Is there any
> functionality that this approach wouldn't accommodate?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to