[RFA/JDWP] Event basics

Cedric Berger cedric@berger.to
Fri Jun 24 21:41:00 GMT 2005


Keith Seitz wrote:

>On Wed, 2005-06-22 at 23:45 +0200, Cedric Berger wrote:
>
>  
>
>>  public void toPacket(ByteBuffer bb, int requestId, byte suspendPolicy)
>>    {
>>      bb.put(suspendPolicy);
>>      bb.putInt(1);
>>      bb.put(_eventKind);
>>      bb.putInt(requestId);
>>      _writeData(bb);
>>    }
>>    
>>
>
>That looks simple enough except for one problem: ByteBuffers are fixed-
>size quantities, aren't they?
>  
>
Yeah, if you have many unbounded variable-length packet,
then using ByteBuffer is probably not the best idea.

>_writeData can put an arbitrarily large amount of data into the buffer.
>For simply event notifications like a ThreadStart, the only data is the
>eight-byte thread ID. For some events like ClassPrepare, we have random
>strings that are going to be inserted into the buffer.
>
>In order to accomplish allocating the properly sized buffer ahead of
>time, I'd need to add methods to all these things to compute the size of
>the data.
>
>Would this be worth the added complexity and computation? I dunno. What
>do you think?
>  
>
I don't think you should allocate ByteBuffer for each event.
There should be one big native ByteBuffer for each socket,
and you should reuse it for sending all messages.

So you could for example allocate one big 64k buffer and
do everything with it. Now if you cannot find a reasonable
upper limits for these packets, then it is probably easier
not to use nio and work with a DataOutputStream.

If you use DataOutputStream, then I think you should just
pass your global DataOutputStream to the toPacket() method,
instead of allocating temporary packet data.

Does that makes sense?
Cedric



More information about the Java-patches mailing list