[sip-comm-dev] Chat window - load messages from history problem


#1

Hi all,

I don't know if I mentioned before but now I'm working on invoking the queries to the history in separate threads to prevent the gui from blocking while waiting the history to finish. I need an advice for the following situation:

When opening a chat window we load 10 last messages from history. This is now invoked in a different thread for the reasons mentioned above. When we receive a message from someone and we don't have an opened chat with this person, three things should happen:
1) open the chat window
2) load the 10 last messages from history (in a new Thread which calls invokeLater to show messages coming from history)
3) show the message that was just received

Maybe you already see the problem..When the query to the history is invoked in another thread, the message that was just received is always shown before the messages from the history.

Thanks,
Yana

···

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


#2

Hi Yana

Yana Stamcheva wrote:

When opening a chat window we load 10 last messages from history. This
is now invoked in a different thread for the reasons mentioned above.

Yes I actually had a question here. Are you loading these messages one by one? Cause that's how it seems to fill the message pane. Wouldn't it be better to have them loaded all at once so that they show all in the same time?

When we receive a message from someone and we don't have an opened chat with this person, three things should happen:
1) open the chat window
2) load the 10 last messages from history (in a new Thread which calls invokeLater to show messages coming from history)
3) show the message that was just received

Maybe you already see the problem..When the query to the history is invoked in another thread, the message that was just received is always shown before the messages from the history.

I don't really see the problem. Why don't you simply insert all history messages in the beginning of the document instead of appending them to the end?

Emil

···

Thanks,
Yana

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


#3

Hi Emil,

Thanks a lot for your answer!

Emil Ivov wrote:

Hi Yana

Yana Stamcheva wrote:

When opening a chat window we load 10 last messages from history. This
is now invoked in a different thread for the reasons mentioned above.

Yes I actually had a question here. Are you loading these messages one by one? Cause that's how it seems to fill the message pane. Wouldn't it be better to have them loaded all at once so that they show all in the same time?

Til now I've used the same mechanism as when loading currently received messages. It's more natural I think, because I get messages from history as message events that are the same events when new messages are received. If I do it like you said I should process them one by one then save them as html and after that insert them in the document. Do you think it's worth it?

When we receive a message from someone and we don't have an opened chat with this person, three things should happen:
1) open the chat window
2) load the 10 last messages from history (in a new Thread which calls invokeLater to show messages coming from history)
3) show the message that was just received

Maybe you already see the problem..When the query to the history is invoked in another thread, the message that was just received is always shown before the messages from the history.

I don't really see the problem. Why don't you simply insert all history messages in the beginning of the document instead of appending them to the end?

I could try this. For now I insert the message in the same thread where history messages are loaded. WDYT about that?

···

Emil

Thanks,
Yana

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

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

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


#4

Hey,

Til now I've used the same mechanism as when loading currently received messages. It's more natural I think, because I get messages from history as message events that are the same events when new messages are received. If I do it like you said I should process them one by one then save them as html and after that insert them in the document. Do you think it's worth it?

Yes, because right now the gui is revalidated after each message that you append and it's this revalidation that slows down the whole thing. Whereas if you process them all together you could show them all with a single repaint (i.e. 10 times less :wink: ).

I could try this. For now I insert the message in the same thread where history messages are loaded. WDYT about that?

I think it would be better not to do so. You could add new incoming messages as they arrive, and only use the history thread to insert the history messages at index 0. Otherwise, if you do the concatenation of the new message and the history messages yourself, you would face the same race condition problem in the case where you have multiple incoming messages. For example: if history messages are H, and you have a new message A. As long as A is the only new message it would be ok for you to do

msgPane.append(H + A);

but the situation changes if while you are doing the concatenation you receive a new message B. You risk to end up with a
B
H
A
sequence in the message pane.

Wouldn't it be simpler to do

MessageReceptionThread
{
  msgPane.append(newMsg)
}

HistoryMessagesThread
{
  msgPane.insert(0, historyMessages)
}

WDYT?

Emil

···

Emil

Thanks,
Yana

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

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

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