Grizzly 2.0 MessageParserFilter Problem

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

Grizzly 2.0 MessageParserFilter Problem

dragonken
Hi All,

I got a strange problem with MessageParserFilter with Grizzly 2.0.

My procotol is:

<STX><BODY><ETX>

I follow the sample source code under org\glassfish\grizzly\samples\filterchain. The test NIO server just stop reading / parsing after first (or sometime second) completed message. However, if I sleep 10 millis at client side between sending message. It works.

Please help.


writer = connection.getStreamWriter();

// Enable standalone mode for this connection
// (don't use Filter chains or other I/O event processors)
connection.setProcessorSelector(new StandaloneProcessorSelector());

for (int i = 0 ; i < 50 ; i++) {
    TestMessage sentMessage = new TestMessage();
    byte body[] = new String("Test Message Number : " + i).getBytes();
    sentMessage.setBody(body);
    writeTestMessage(writer, sentMessage);
   
    // need to sleep a while, otherwise server will stop reading after first completed message??
    Thread.sleep(2L);
}



src.zip


Reply | Threaded
Open this post in threaded view
|

Re: Grizzly 2.0 MessageParserFilter Problem

Oleksiy Stashok
Hi Ken,

my fault, example was not done right. I've fixed it.
Here is how the parser filter should look like [1].

Thank you.

WBR,
Alexey.

[1]
public class TestMessageParserFilter extends FilterAdapter {

     private static final Attribute<Integer> stateAttr =
             
Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute("TestParseState");
     private static final Attribute<TestMessage> preparsedMessageAttr =
             
Grizzly
.DEFAULT_ATTRIBUTE_BUILDER.createAttribute("PreparsedTestMessage");
     private static final int BUFFER_SIZE = 8192;
     private byte[] buffer = new byte[BUFFER_SIZE];
     private int index = 0;

     @Override
     public NextAction handleRead(FilterChainContext ctx,
             NextAction nextAction) throws IOException {
         Connection connection = ctx.getConnection();
         TestMessage message = preparsedMessageAttr.get(connection);
         Integer parseState = stateAttr.get(connection);

         if (message == null) {
             message = new TestMessage();
             parseState = new Integer(0);
         }

         StreamReader reader = ctx.getStreamReader();

         boolean isParsing = true;
         while (isParsing) {
             switch (parseState) {
                 case 0:  // STX
                     if (reader.availableDataSize() >= 1) {
                         if (reader.readByte() == TestMessage.STX) {
                             index = 0;
                             parseState++;
                         } else {
                             // drop the byte
                         }
                     } else {
                         isParsing = false;
                     }
                     break;
                 case 1:  // ETX
                     if (reader.availableDataSize() >= 1) {
                         byte b = reader.readByte();
                         if (b == TestMessage.ETX) {
                             if (index > 0) {
                                 byte[] body = new byte[index];
                                 System.arraycopy(buffer, 0, body, 0,  
index);
                                 message.setBody(body);
                                 parseState++;
                                 isParsing = false;
                             } else {
                                 parseState = new Integer(0);
                             }
                         } else {
                             buffer[index] = b;
                             index++;
                         }
                     } else {
                         isParsing = false;
                     }
                     break;
                 default:
                     break;
             }
         }

         if (parseState < 2) {  // Not enough data to parse whole  
message
             // Save the parsing state
             preparsedMessageAttr.set(connection, message);
             stateAttr.set(connection, parseState);

             // Stop the filterchain execution until more data available
             return ctx.getStopAction();
         } else {
             // Remove intermediate parsing state
             preparsedMessageAttr.remove(connection);
             stateAttr.remove(connection);

             // Set the parsed message on context
             ctx.setMessage(message);

             System.out.println("Message = " + new  
String(message.getBody()));
             return nextAction;
         }
     }

     /**
      * Post read is called to let FilterChain cleanup resources.
      *
      * @param ctx {@link FilterChainContext}
      * @param nextAction default {@link NextAction} next step  
instruction for the {@link FilterChain}
      * @return {@link NextAction} next step instruction for the  
{@link FilterChain}
      * @throws IOException
      */
     @Override
     public NextAction postRead(FilterChainContext ctx, NextAction  
nextAction)
             throws IOException {

         final StreamReader reader = ctx.getStreamReader();
         // Check, if there is some data remaining in the input stream
         if (reader.availableDataSize() > 0) {
             // if yes - rerun the parser filter to parse next message
             return ctx.getRerunChainAction();
         }

         return nextAction;
     }
}


On May 26, 2009, at 20:26 , [hidden email] wrote:

>
> Hi All,
>
> I got a strange problem with MessageParserFilter with Grizzly 2.0.
>
> My procotol is:
>
> <STX><BODY><ETX>
>
> I follow the sample source code under
> org\glassfish\grizzly\samples\filterchain. The test NIO server just  
> stop
> reading / parsing after first (or sometime second) completed message.
> However, if I sleep 10 millis at client side between sending  
> message. It
> works.
>
> Please help.
>
>
> writer = connection.getStreamWriter();
>
> // Enable standalone mode for this connection
> // (don't use Filter chains or other I/O event processors)
> connection.setProcessorSelector(new StandaloneProcessorSelector());
>
> for (int i = 0 ; i < 50 ; i++) {
>    TestMessage sentMessage = new TestMessage();
>    byte body[] = new String("Test Message Number : " + i).getBytes();
>    sentMessage.setBody(body);
>    writeTestMessage(writer, sentMessage);
>
>    // need to sleep a while, otherwise server will stop reading  
> after first
> completed message??
>    Thread.sleep(2L);
> }
>
>
> http://www.nabble.com/file/p23728698/src.zip src.zip
>
>
>
> --
> View this message in context: http://www.nabble.com/Grizzly-2.0-MessageParserFilter-Problem-tp23728698p23728698.html
> Sent from the Grizzly - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


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

Reply | Threaded
Open this post in threaded view
|

Re: Grizzly 2.0 MessageParserFilter Problem

dragonken
Thanks to your quick response.

The problem still exist. It stop parsing randomly.

the postRead() method did return ctx.getRerunChainAction() but handleRead didn't be called after.

Would you mind to send us the whole src folder to retry?

Regards,
Ken


Reply | Threaded
Open this post in threaded view
|

Re: Grizzly 2.0 MessageParserFilter Problem

Oleksiy Stashok
Hi Ken,

the issue could be more serious, than I expected, can you pls. fill  
the issue?
I'll come with the fix asap.

Thank you.

WBR,
Alexey.

On May 27, 2009, at 13:15 , [hidden email] wrote:

>
> Thanks to your quick response.
>
> The problem still exist. It stop parsing randomly.
>
> the postRead() method did return ctx.getRerunChainAction() but  
> handleRead
> didn't be called after.
>
> Would you mind to send us the whole src folder to retry?
>
> Regards,
> Ken
>
>
>
> --
> View this message in context: http://www.nabble.com/Grizzly-2.0-MessageParserFilter-Problem-tp23728698p23740392.html
> Sent from the Grizzly - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


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

Reply | Threaded
Open this post in threaded view
|

Re: Grizzly 2.0 MessageParserFilter Problem

Oleksiy Stashok
In reply to this post by dragonken
Hi Ken,

the issue should be fixed on 2dot0 branch.

https://grizzly.dev.java.net/issues/show_bug.cgi?id=627

WBR,
Alexey.


On May 27, 2009, at 13:15 , [hidden email] wrote:

>
> Thanks to your quick response.
>
> The problem still exist. It stop parsing randomly.
>
> the postRead() method did return ctx.getRerunChainAction() but  
> handleRead
> didn't be called after.
>
> Would you mind to send us the whole src folder to retry?
>
> Regards,
> Ken
>
>
>
> --
> View this message in context: http://www.nabble.com/Grizzly-2.0-MessageParserFilter-Problem-tp23728698p23740392.html
> Sent from the Grizzly - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


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

Reply | Threaded
Open this post in threaded view
|

Re: Grizzly 2.0 MessageParserFilter Problem

dragonken
It's work.

Thanks a lot!
Ken

Oleksiy Stashok wrote
Hi Ken,

the issue should be fixed on 2dot0 branch.

https://grizzly.dev.java.net/issues/show_bug.cgi?id=627

WBR,
Alexey.


On May 27, 2009, at 13:15 , Ken--@newsgroupstats.hk wrote:

>
> Thanks to your quick response.
>
> The problem still exist. It stop parsing randomly.
>
> the postRead() method did return ctx.getRerunChainAction() but  
> handleRead
> didn't be called after.
>
> Would you mind to send us the whole src folder to retry?
>
> Regards,
> Ken
>
>
>
> --
> View this message in context: http://www.nabble.com/Grizzly-2.0-MessageParserFilter-Problem-tp23728698p23740392.html
> Sent from the Grizzly - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@grizzly.dev.java.net
> For additional commands, e-mail: users-help@grizzly.dev.java.net
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@grizzly.dev.java.net
For additional commands, e-mail: users-help@grizzly.dev.java.net