On May 3, 2006, at 4:41 PM, Michael Bauroth wrote:
On May 3, 2006, at 2:03 PM, Michael Bauroth wrote:
1) In a decoder method I want to do a pattern search. Can I assume, that in the meantime (imagine the search takes longer) the incoming ByteBuffer doesn't increase?
yes. Just do it synchronously wrt the decoder method returning.

so I don't need an aquire at the beginning of the method and still set a local variable to in.remaining(). Right?

You don't need to acquire, and you don't need to store in.remaining() unless you plan on using it.

Depends on whether or not your ProtocolCodecFactory returns the same Decoder instance each time getDecoder is called, or a new instance. If you have the same instance, you're still fine, as long as you don't store state in class-level variables.

I only store attributes directly in the sessions. Is this ok?

Yup, no problem

Or must I modify the incoming ByteBuffer for such things in that way, that I create a new ByteBuffer, where I copy only a part from the incoming buffer and forward it?
If you pass the same ByteBuffer on, just be sure to acquire/ release it, since by default, the ProtocolCodecFilter assumes that the buffer is done once the decoder has run.

This part I haven't understand. In which case are the aquire() and release() methods related to my question?

You would want to .acquire() the buffer if you were to forward the same buffer that you were provided. If you create a new buffer, you don't need to worry about acquiring it.

Or better, let me write a little sample:

The ByteBuffer contains 2 bytes. I call

in.get()
in.get()

the position is now increased. When I leave it in this state, the two bytes are not any longer available in the messageReceived method from the session (they are already consumed). A call of in.remaining() in the messageReceived() method gets 0 bytes. Right?

Yup. Each call to get like that will increase the position in the buffer by one. If that is all that was in the buffer, if you forwarded it on, you wouldn't be able to see anything in it.

4) For a pattern search in the ByteBuffer I want to use a modified Boyer Moore algorithm. That means, that I have to skip chunks of bytes in the ByteBuffer and must use instead of simple get() the get (index) method. Two questions: Will the get(index) method change the position() of the ByteBuffer too?
no, get(index) will not change the position.

So I have to set the position manually afterwards or set it before and call a simple get(). Right?

Yes.

Once more. Thank you for your help.

np!
-pete

--
[EMAIL PROTECTED] - http://fotap.org/~osi


Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to