This thread is archived
18 Replies Last post: Apr 19, 2003 6:00 AM by Joe  
Ravi Rajamiyer   2 posts since
Mar 11, 2003
Currently Being Moderated

Mar 11, 2003 1:45 PM

Roster problems in beta 3

I am using the following code to get the contact list for a given user. I am not getting the list at all. The Iterator comes back empty. I used Exodus client for the same user, and I am getting the contact list correctly. What am I doing wrong?

 

XMPPConnection conn1 = new XMPPConnection("localhost");

conn1.login("myself","mypass");

Roster ros = conn1.getRoster();

ros.reload();

Iterator it = ros.getGroups();

while(it.hasNext()) {

RosterGroup rgp = (RosterGroup) it.next();

rgp.getName();

}

 

 

Thanks

 

Rchandran

ribot   16 posts since
Mar 8, 2003
Currently Being Moderated
Mar 11, 2003 3:44 PM in response to: Ravi Rajamiyer
Re: Roster problems in beta 3

Silly question, but have you tried turning the debugging mode on with the following (set before you create connection):

 


XMPPConnection.DEBUG_ENABLED = true;

 

It worked for me, look at the xml that the server sends you (blue text in debug mode).

 

Cheers,

 

ribot.

ribot   16 posts since
Mar 8, 2003
Currently Being Moderated
Mar 11, 2003 3:51 PM in response to: ribot
Re: Roster problems in beta 3

Actually, trying to print the roster entries out returns nothing like you said...I, will keep trying and report back if I have any success.

 

Any ideas Matt?

 

Cheers,

 

ribot.

Claude-Nicolas Fiechter   3 posts since
Mar 17, 2003
Currently Being Moderated
Mar 17, 2003 5:38 PM in response to: Ravi Rajamiyer
Re: Roster problems in beta 3

Was there a resolution/workaround found for that problem. I have the exact same issue. Did that use to work on earlier version of the lib?

Iain Shigeoka Bronze 257 posts since
Jan 10, 2003
Currently Being Moderated
Mar 18, 2003 9:39 AM in response to: Claude-Nicolas Fiechter
Re: Roster problems in beta 3

Hi,

 

I don''t think roster support is complete in beta 3. The release notes indicate that it is only partially implemented. I''ll try to poke Matt on this to confirm/deny.

 

-iain

Matt Tucker Jiver 3,151 posts since
Jun 28, 2001
Currently Being Moderated
Mar 18, 2003 10:16 AM in response to: Iain Shigeoka
Re: Roster problems in beta 3

I think that code used to work. However, the roster code definitely needs to be polished up. I''ll see if I can get to that this weekend.

 

Regards,

Matt

ribot   16 posts since
Mar 8, 2003
Currently Being Moderated
Mar 19, 2003 6:36 PM in response to: Matt Tucker
Re: Roster problems in beta 3

Great, I eagerly await the ''post-polish'' era.

Ben   1 posts since
Mar 31, 2003
Currently Being Moderated
Mar 31, 2003 7:55 PM in response to: Ravi Rajamiyer
Re: Roster problems in beta 3

Anyone managed to get the roster up and going? My attempts so far have failed.

 

Has anyone tired hacking around with the Smack source?

 

I could do with a quick fix solution in case Beta 4 isn''t released in time for my hand in date.

 

Thanks

 

Ben

John Rubier   69 posts since
Apr 2, 2003
Currently Being Moderated
Apr 3, 2003 12:08 PM in response to: Ben
Re: Roster problems in beta 3

conn.getRoster() appears to operate async just like the Roster.Reload() method.

I''m sure someone more knowlegable in Java than me can come up with a better plan than this, but here was my temporary fix:


conn = new XMPPConnection("server", 5222);
conn.login("username","password","resource");
roster=conn.getRoster();
while (!roster.getGroups().hasNext()) {
    System.out.println("wait");
}
updateRosterDisplay(...);

I think you can still get a partial roster doing this..i.e. some items are loaded in the roster but others are still pending from the server.

Probably better to spawn a thread or something to do this but I haven''t gotten to that section of the book yet

Matt Tucker Jiver 3,151 posts since
Jun 28, 2001
Currently Being Moderated
Apr 3, 2003 12:56 PM in response to: John Rubier
Re: Roster problems in beta 3

I guess the real solution is to add a simple listener so that you can know when to load the roster after changes. I''ll try to get this done for the next beta.

 

Regards,

Matt

Matt Tucker Jiver 3,151 posts since
Jun 28, 2001
Currently Being Moderated
Apr 3, 2003 1:02 PM in response to: Matt Tucker
Re: Roster problems in beta 3

Oh, I guess another option is that I could make Smack wait to get the roster back from the server before returning from the login method. Currently, the following method is called during login (from the Roster class)

 

/**
 * Reloads the entire roster from the server. This is an asynchronous operation,
 * which means the method will return immediately, and the roster will be
 * reloaded at a later point when the server responds to the reload request.
 */
public void reload() {
    connection.sendPacket(new RosterPacket());
}

 

I could make another version of that method that waited for a reply instead. Anyone have an opinion on what would be better? I guess I''d lean towards making Smack load the roster synchronously during login since we''ve already seen the confusion that the current behavior causes.

 

Regards,

Matt

John Rubier   69 posts since
Apr 2, 2003
Currently Being Moderated
Apr 3, 2003 1:22 PM in response to: Matt Tucker
Re: Roster problems in beta 3

I would say that since the Roster is like the other high-level components of the library, I would make it act like the Message, Chat, GroupChat object with the same type of "PollMessage"/queue type arrangement. Or just add a "loadCompleted()" method call.

 

John

Matt Tucker Jiver 3,151 posts since
Jun 28, 2001
Currently Being Moderated
Apr 3, 2003 2:01 PM in response to: John Rubier
Re: Roster problems in beta 3

John,

 

I would say that since the Roster is like the other

high-level components of the library, I would make it

act like the Message, Chat, GroupChat object with the

same type of "PollMessage"/queue type arrangement. Or

just add a "loadCompleted()" method call.

 

I guess I was really looking for opinions on the login method. Should login wait for the roster to be loaded before returning, or no?

 

Regards,

Matt

John Rubier   69 posts since
Apr 2, 2003
Currently Being Moderated
Apr 3, 2003 4:10 PM in response to: Matt Tucker
Re: Roster problems in beta 3

Matt,

I don''t think the login method should block, but the conn.getRoster() probably should. Maybe even eliminate and roster stuff from the login method altogether though I guess it would speed things up if login went ahead and asked for it async but getRoster blocks until it''s completed.

 

Take care,

 

John

Matt Tucker Jiver 3,151 posts since
Jun 28, 2001
Currently Being Moderated
Apr 3, 2003 4:19 PM in response to: John Rubier
Re: Roster problems in beta 3

John,

 

Cool, that''s a good suggestion and I''ll implement it that way.

 

Thanks,

Matt

Joe   5 posts since
Mar 31, 2003
Currently Being Moderated
Apr 4, 2003 5:09 AM in response to: Matt Tucker
Re: Roster problems in beta 3

Hi Matt and John,

 

I agree with this approach.  I have tried to make the getRoster() method blocking and made the GUI application that is loading the roster to execute in a separate thread.  Here are some of my suggested codes:

 

private boolean isRosterReady = false;

 

  public Iterator getGroups() {

    while (!isRosterReady) {

      try {

        wait(); 

      } catch (InterruptedException ie) {

      }

    }

    synchronized (groups) {

      List groupsList = Collections.unmodifiableList(new ArrayList(groups.values()));

      return groupsList.iterator();

    }

  }

 

  private class RosterListener implements PacketListener {

public void processPacket(Packet packet) {

      isRosterReady = false;

 

// same as the rest of the code body

 

      // Notify waiting threads that the roster groups are ready.

      isRosterReady = true;

      notifyAll();

    }

}

 

 

Matt Tucker Jiver 3,151 posts since
Jun 28, 2001
Currently Being Moderated
Apr 7, 2003 12:45 AM in response to: Ravi Rajamiyer
Re: Roster problems in beta 3

Hey all,

 

Just thought you''d want to know that the latest build fixes the roster problem -- it now waits up to two seconds for a reply from the server before returning the roster. Daily builds are at:

 

http://www.jivesoftware.com/xmpp/smack/dailybuilds.jsp

 

-Matt

Joe   5 posts since
Mar 31, 2003
Currently Being Moderated
Apr 19, 2003 6:00 AM in response to: Matt Tucker
Re: Roster problems in beta 3

Hi,

 

I noted a number of other potential problems with the roster. 

 

1) The roster needs to have a blocking thread operation which fires an event when the roster is completely loaded. This can be done by implementing another static class (such as RosterSynchronizer) to handle roster synchronization.  A statement such as "RosterSynchronizer.getRosterSynchronizer().setRosterReady();" can be set at the end of the method "processPacket(Packet packet)" in class RosterListener now.

 

Similarly, the call to roster.getGroups() should be blocked by a statement like "RosterSynchronizer.getRosterSynchronizer().waitRoster();"

 

2) Another problem is that there could be a race problem between Presence messages that are sent by the server even before the roster packet is sent or completely loaded.  In this case, all Presence packets need to be pre-stored in an early-queue until the roster ready event is fired.  Once the roster is ready, the early Presence packets will need to be processed.  Else, the presence info will be lost! 

 

Hope I intepret the potential problems correctly and got the message across correctly

 

Cheers,

Joe

More Like This

  • Retrieving data ...