|
From: Fabrice M. <fab...@if...> - 2003-05-10 00:28:13
|
> Hi,
Hi,
>
> the following problem can occur:
>
> XNap's joscar plugin receives an incoming IncomingMessage__4_7 for which
it
> doesn't have a ChatChannel yet, so it creates one and adds the message to
the
> channel to display it. Now it can happen that the first message is
displayed
> twice, that's because of the following code:
>
> private void notifyIncomingMessage(OscarConnection connection) {
> IncomingMessageEvent e = new IncomingMessageEvent(this);
> for (int i = 0; i < connection.getOscarListeners().size(); i++) {
> OscarListener l = (OscarListener) connection.getOscarListeners().
> elementAt(i);
> l.onIncomingMessage(e);
> }
>
> XNap's new Channel object calls:
>
> oscar_connection.addOscarListener(this);
>
> in order to be notified of future chat messages. But since it's added to
the
> listener vector in OscarConnection it sometimes gets the message twice.
>
> I'd recommend to change the code above to:
>
> private void notifyIncomingMessage(OscarConnection connection) {
> IncomingMessageEvent e = new IncomingMessageEvent(this);
> Object[] array = connection.getOscarListeners().toArray();
> for (int i = 0; i < array.length; i++) {
> ((OscarListener)array[i]).onIncomingMessage(e);
> }
> }
>
> Thus we don't run into any concurrent modifications and ensure each
listener
> gets the message exactly once. This should be done for all listener
events.
>
Huuum, i don't really see the difference between the two implementations,
except
that yours will take more time to execute, as you copy all elements from the
vector to an array
before working with them.
The only explication why you don't receive the message twice with your
implementation, is that when you enter the for :
for (int i = 0; i < array.length; i++)
a new listener has been added but you work on an outdated copy of it.
It's not a bug, but a bad use of Listeners... here is, I think, 2 good ways
of using them :
1 - ONLY 1 LISTENER
only your main class add a listener, and then dispatch msg to the differents
tab (i.e TabbedPane).
2 - X LISTENERS
At the beginning create an invisible Tab with a Listener. When you receive
the first message, make the first tab visible and create a new invisible one
with a new Listener. Repeat for every different users.
Then, each Tab will only display messages from 1 users, even if they receive
all messages.
> The method connectToServer() doesn't have any effect. As far as I could
see as
> soon as you instantiate a new OscarConnection it connects to the server.
If
> you call a
>
> connection.getClient().disconnect();
>
> it's properly disconnect, but a
>
> connection.getClient().connectToServer();
>
> doesn't work since it simply calls a thread.start(). But a thread that's
> already dead can't be restarted again in java, you have to create a new
> thread and start that one.
>
Sure, it's impossible to restart a dead thread... I will add the code that
create a new Thread, if the first one has been killed.
> Sincerely,
> Felix
>
> P.S.: An xnap3 release is planned at the end of next week it'd be great if
you
> could fix the jar location problem, the other stuff is not so important.
> --
> Use Debian GNU/Linux!
> http://www.felix.beldesign.de
>
>
>
> -------------------------------------------------------
> Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara
> The only event dedicated to issues related to Linux enterprise solutions
> www.enterpriselinuxforum.com
>
> _______________________________________________
> Ooimlib-joscarlib mailing list
> Ooi...@li...
> https://lists.sourceforge.net/lists/listinfo/ooimlib-joscarlib
> _____________________________________________________________________
> Envie de discuter en "live" avec vos amis ? Télécharger MSN Messenger
> http://www.ifrance.com/_reloc/m la 1ère messagerie instantanée de France
_____________________________________________________________________
Envie de discuter en "live" avec vos amis ? Télécharger MSN Messenger
http://www.ifrance.com/_reloc/m la 1ère messagerie instantanée de France
|