users@grizzly.java.net

Re: attaching user data to GrizzlyWorkerThread

From: ThanhTran <thanhtb_at_gmail.com>
Date: Mon, 27 Oct 2008 17:48:56 -0700 (PDT)

Hi guys,

My usecase is easy.

I tried to use one simple client send a package as following:
HEADER: int | int | int | int (length of message = length ("HELLO") + 2
(due to utf) )
MESSAGE (BODY) : example "HELLO"

after server received message successfully (receive and parse succfully).
Connecton closed from client side. I tried to a new class extends
SelectionKeyHandler to handle closing connections.

I tried to use about 10 threads of client to send same content to server for
some minutes.

The result is: Some objects attached to the attribute AttributeHolder were
null, but the instance of AttributeHolder is not null.

Please suggest me a solution !

Thanks,
THanh Tran.





Jeanfrancois Arcand-2 wrote:
>
> Salut,
>
> ThanhTran wrote:
>> Hi guys,
>>
>> I tried as you comment, but, sometime with new connection,
>> AttributeHolder
>> still has instance and it's not null. I don't know why. Could you suggest
>> a
>> solution for that ?
>
> Hum...looks like a bug. Do you have a test case/easy way to reproduce
> the issue?
>
> Thanks!
>
> -- Jeanfrancois
>
>
>
>>
>> Thanks,
>> Thanh Tran.
>>
>>
>> Oleksiy Stashok wrote:
>>> Ahoj :)
>>> Inside your filter please do following:
>>>
>>> AttributeHolder connectionAttrs =
>>>
>>> ctx.getAttributeHolderByScope(AttributeScope.CONNECTION);
>>> if (connectionAttrs == null) {
>>> WorkerThread workerThread = (WorkerThread)
>>> Thread.currentThread();
>>> // Detach the current Thread data.
>>> ThreadAttachment threadAttachment =
>>> workerThread.getAttachment();
>>> // Attach it to the SelectionKey so the it can be resumed
>>> latter.
>>> key.attach(threadAttachment);
>>> connectionAttrs =
>>> ctx.getAttributeHolderByScope(AttributeScope.CONNECTION);
>>> }
>>>
>>> connectionAttrs.get/set
>>>
>>> Hope this will help.
>>>
>>> WBR,
>>> Alexey.
>>>
>>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>
>
>

-- 
View this message in context: http://www.nabble.com/attaching-user-data-to-GrizzlyWorkerThread-tp18966029p20199511.html
Sent from the Grizzly - Users mailing list archive at Nabble.com.