users@grizzly.java.net

FW: comet help

From: Minh O <minh13_o_at_hotmail.com>
Date: Sun, 14 Oct 2007 03:42:31 +0000

My apologies if this is a repost.

From: minh13_o_at_hotmail.com
To: users_at_grizzly.dev.java.net
CC: jeanfrancois.arcand_at_sun.com; minh13_o_at_hotmail.com
Subject: comet help
Date: Sun, 14 Oct 2007 00:25:07 +0000








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.

Minh

Climb to the top of the charts! Play Star Shuffle: the word scramble challenge with star power. Play Now!

_________________________________________________________________
Help yourself to FREE treats served up daily at the Messenger Café. Stop by today.
http://www.cafemessenger.com/info/info_sweetstuff2.html?ocid=TXT_TAGLM_OctWLtagline