Confusion over some Comet functions in Grizzly

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

Confusion over some Comet functions in Grizzly

John C. Turnbull

I am not getting the exact behaviour I expected with the version of Grizzly that’s included in GlassFish v2 UR1 and looking at the code for Grizzly itself I see there are a couple of strange things.  I realise that the code for the standalone Grizzly and that for Grizzly in GF may be a little different but in the standalone Grizzly there is a class CometContext with the following method:

 

    protected void notify(CometEvent event, int eventType, SelectionKey key)

 

and it defines various event types.  However, the body of the method does nothing with the event type so all events have the same (default) type.  Is this intentional?

 

Also, I have been trying to notify Comet events using this method by creating a new CometEvent<MyAttachment> and attaching an attachment of type MyAttachment.  However, when I process the event in onEvent() of the CometHandler, the following code:

 

System.out.println("Attachment is a " + event.attachment().getClass());

 

prints out that the attachment is of type CometEvent and not MyAttachment as desired (and hence I can’t do anything with it).  Does anyone know why this would be so?

 

I am close to having Grizzly and GlassFish with Comet behaving as I want so it would be nice to finish things off.

 

Thanks,

 

-JCT

 

Reply | Threaded
Open this post in threaded view
|

Re: Confusion over some Comet functions in Grizzly

Jeanfrancois Arcand-2
Hi John,

John C. Turnbull wrote:

> I am not getting the exact behaviour I expected with the version of
> Grizzly that’s included in GlassFish v2 UR1 and looking at the code for
> Grizzly itself I see there are a couple of strange things.  I realise
> that the code for the standalone Grizzly and that for Grizzly in GF may
> be a little different but in the standalone Grizzly there is a class
> CometContext with the following method:
>
>  
>
>     protected void notify(CometEvent event, int eventType, SelectionKey key)

Right, but the method is protected, so you cannot use it (it's for an
internal call).

>
>  
>
> and it defines various event types.  However, the body of the method
> does nothing with the event type so all events have the same (default)
> type.  Is this intentional?
>
>  
>
> Also, I have been trying to notify Comet events using this method by
> creating a new CometEvent<MyAttachment> and attaching an attachment of
> type MyAttachment.  However, when I process the event in onEvent() of
> the CometHandler, the following code:

Hum are you sure you are using this method?

>
>  
>
> System.out.println("Attachment is a " + event.attachment().getClass());
>
>  
>
> prints out that the attachment is of type CometEvent and not
> MyAttachment as desired (and hence I can’t do anything with it).  Does
> anyone know why this would be so?
>
>  
>
> I am close to having Grizzly and GlassFish with Comet behaving as I want
> so it would be nice to finish things off.

You have 3 solutions:

(1) notify(Object attachment,int eventType) //
(NOTIFY|INITIALIZE|TERMINATE|INTERRUPT|READ);

Most of the time you only use the NOTIFY.

(2) notify(Object attachmenent);

same as above, but it force a NOTIFY event.

(3) notify(Object attachment,int eventType,int cometHandlerHash);

same as (1), but this time you can specify which cometHandler you want
to notify instead of all of them.

In you case (1) is what you are looking at. Can you try it and let me know?

Thanks

-- Jeanfrancois





>
>  
>
> Thanks,
>
>  
>
> -JCT
>
>  
>

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

Reply | Threaded
Open this post in threaded view
|

RE: Confusion over some Comet functions in Grizzly

John C. Turnbull
Hi Jeanfrancois,

> >     protected void notify(CometEvent event, int eventType,
> SelectionKey key)
>
> Right, but the method is protected, so you cannot use it (it's for an
> internal call).
>
> Hum are you sure you are using this method?

My bad, I am not using that method.  I am using the public notify() method
that also takes 3 parameters one of which is the attachment itself.
 

> > I am close to having Grizzly and GlassFish with Comet behaving as I
> want
> > so it would be nice to finish things off.
>
> You have 3 solutions:
>
> (1) notify(Object attachment,int eventType) //
> (NOTIFY|INITIALIZE|TERMINATE|INTERRUPT|READ);
>
> Most of the time you only use the NOTIFY.
>
> (2) notify(Object attachmenent);
>
> same as above, but it force a NOTIFY event.
>
> (3) notify(Object attachment,int eventType,int cometHandlerHash);
>
> same as (1), but this time you can specify which cometHandler you want
> to notify instead of all of them.
>
> In you case (1) is what you are looking at. Can you try it and let me
> know?

Yes, I am using (3) now successfully as I only want one handler notified in
this particular case.  It's working very well now.  Thanks!

-JCT

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