How to use TCPNIOAsyncQueueReader?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to use TCPNIOAsyncQueueReader?

yelingbug
Hi!
  I am going to use Grizzly-2.0 to construct NIO server, so recently I took a little of time to research Grizzly-2.0 source code and run into a question about the use of 'TCPNIOAsyncQueueReader(extends AbstractNIOAsyncQueueReader)'.

 With my understanding to 'AbstractNIOAsyncQueueReader', in which 'processAsync(Connection)' method should work in conjunction with 'read(Connection, Buffer, CompletionHandler, Interceptor)' method, but I can't  find any source code even sample code to prove it, so anybody can tell me what scene 'AbstractNIOAsyncQueueReader' can be used?

  The best can give me some sample code, I'll appreciate it! Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: How to use TCPNIOAsyncQueueReader?

oleksiys
Administrator
Hi,

TCPNIOAsyncQueueReader is used in standalone mode only, otherwise we
don't use it in FilterChain mode, which is the basic mode.
Here are samples you may want to check [1], and user guide [2].

WBR,
Alexey.

[1]
http://java.net/projects/grizzly/sources/git/show/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/
[2] http://grizzly.java.net/nonav/docs/docbkx2.0/html/grizzly-docs.html

On 09/05/2011 10:48 AM, yelingbug wrote:

> Hi!
>    I am going to use Grizzly-2.0 to construct NIO server, so recently I took
> a little of time to research Grizzly-2.0 source code and run into a question
> about the use of 'TCPNIOAsyncQueueReader(extends
> AbstractNIOAsyncQueueReader)'.
>
>   With my understanding to 'AbstractNIOAsyncQueueReader', in which
> 'processAsync(Connection)' method should work in conjunction with
> 'read(Connection, Buffer, CompletionHandler, Interceptor)' method, but I
> can't  find any source code even sample code to prove it, so anybody can
> tell me what scene 'AbstractNIOAsyncQueueReader' can be used?
>
>    The best can give me some sample code, I'll appreciate it! Thanks!
>
> --
> View this message in context: http://grizzly.1045725.n5.nabble.com/How-to-use-TCPNIOAsyncQueueReader-tp4769708p4769708.html
> Sent from the Grizzly - Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: How to use TCPNIOAsyncQueueReader?

yelingbug
Hi!
  Thanks for you replying.
 
  But I still have a question about 'AbstractNIOAsyncQueueReader' used in 'StandaloneProcessor'.

  For pieces of code as following:

    StandaloneProcessor#process(Context context):
           .......
            if (reader.isReady(connection)) {
                reader.processAsync(connection);

            }

           ......

    AbstractNIOAsyncQueueReader#processAsync(Connection connection):
           .........
           
           final Queue<AsyncReadQueueRecord> queue = connectionQueue.getQueue();
           final AtomicReference<AsyncReadQueueRecord> currentElement =
                connectionQueue.getCurrentElementAtomic();
           AsyncReadQueueRecord queueRecord = currentElement.get();          --------(1)
           if (queueRecord == LOCK_RECORD) return;

           try {
             while (queueRecord != null) {                                                   --------(2)
            ...........
           }


   When execution gets to (2), I think that it will never get into the loop, because the variable
   of 'queueRecord' may always be null as there can't find any other places to initialize or set
   'queueRecord' like

              getCurrentElementAtomic().set(...)

    so am I right?


yelingbug.
       
 
Reply | Threaded
Open this post in threaded view
|

Re: How to use TCPNIOAsyncQueueReader?

oleksiys
Administrator
Hi,

I think you have old Grizzly sources.
Please checkout the latest sources from Git repository:
git clone git://java.net/grizzly~git

Thanks.

WBR,
Alexey.

On 09/06/2011 04:55 AM, yelingbug wrote:

> Hi!
>    Thanks for you replying.
>
>    But I still have a question about 'AbstractNIOAsyncQueueReader' used in
> 'StandaloneProcessor'.
>
>    For pieces of code as following:
>
>      StandaloneProcessor#process(Context context):
>             .......
>             */ if (reader.isReady(connection)) {
>                  reader.processAsync(connection);/
>              }*
>             ......
>
>      AbstractNIOAsyncQueueReader#processAsync(Connection connection):
>             .........
>            * /
>             final Queue<AsyncReadQueueRecord>  queue =
> connectionQueue.getQueue();
>             final AtomicReference<AsyncReadQueueRecord>  currentElement =
>                  connectionQueue.getCurrentElementAtomic();
>             AsyncReadQueueRecord queueRecord = currentElement.get();
> --------(1)
>             if (queueRecord == LOCK_RECORD) return;
>
>             try {
>               while (queueRecord != null) {
> --------(2)
>              ...........
>             }/*
>
>     When execution gets to (2), I think that it will never get into the loop,
> because the variable
>     of 'queueRecord' may always be null as there can't find any other places
> to initialize or set
>     'queueRecord' like
>
>                */getCurrentElementAtomic().set(...)/*
>
>      so am I right?
>
>
> yelingbug.
>
>
>
> --
> View this message in context: http://grizzly.1045725.n5.nabble.com/How-to-use-TCPNIOAsyncQueueReader-tp4769708p4772975.html
> Sent from the Grizzly - Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: How to use TCPNIOAsyncQueueReader?

yelingbug
You are right, I missed the right version! Many thanks!