Hi Minh,
Minh O wrote:
> Hi Jeanfrancois,
>
> I've been trying to implement a chat program where a user can send a
> message to his/her buddies. I've implemented it so that there are only
> 2 people that can send messages to each other but when I send a post to
> forward to a user, I get this message.
>
> 'java.lang.IllegalStateException: CometHandler cannot be null. This
> CometHandler
> was probably resumed and an invalid reference was made to it.'
>
> Below is the code that is invoked to forward the message to the user.
>
> {code}
> public void sendMessage(Message message, CometHandler handler) {
>
> if(handler != null) {
> try {
> CometEngine engine = CometEngine.getEngine();
> CometContext context =
> engine.getCometContext(CHAT_CONTEXT_PATH);
> int hashCode = handler.hashCode();
> sLogger.info('[CometChat2]\tSending message to: ' +
> message.getTo()
> + ' from: ' + message.getFrom() + ' handler
> hashcode: ' + hashCode);
> context.notify(message, CometEvent.NOTIFY, hashCode);
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> } else {
> sLogger.severe('[CometChat]\tHandler is null for sending
> message to: ' + message.getTo());
> }
> }
> {code}
>
>
> This is what is in the CometHandler implementation.
> {code}
> @Override
> public void onEvent(CometEvent event) throws IOException {
> // TODO Auto-generated method stub
> sLogger.info('[CometChatHandler]\tEvent type is: ' +
> event.getType());
> if(event.getType() == CometEvent.NOTIFY) {
> Object obj = event.attachment();
>
> if(obj != null && obj instanceof Message) {
> PrintWriter writer = response.getWriter();
> writer.write(XStreamUtil.objectToJSON('jsonMSG', obj));
> writer.flush();
>
> //event.getCometContext().resumeCometHandler(this);
> //event.getCometContext().registerAsyncRead(this);
> //event.getCometContext().registerAsyncWrite(this);
>
> } else {
> sLogger.severe('[CometChatHandler]\tEvent attachment is
> not a Message obj: ' + obj.getClass().getName());
> }
> }
> }
> {code}
>
> I've attach the servlet code and the handler code. If you could point
> me to the right direction, it would be greatly appreciated.
Hum...this is strange as your code that resume the CometHandler is
commented out. Let me take a look . Are you using GlassFish or Grizzly
standalone?
Thanks
-- Jeanfrancois
>
> Minh
>
> ------------------------------------------------------------------------
> Climb to the top of the charts! Play Star Shuffle: the word scramble
> challenge with star power. Play Now!
> <http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_oct>
> ------------------------------------------------------------------------
>
> Here is a simple AJAX Request.
>
>
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net