public class Roster extends Object implements Cacheable, Externalizable
A roster is a list of users that the user wishes to know if they are online.
Rosters are similar to buddy groups in popular IM clients. The Roster class is a representation of the roster data.
Updates to this roster is effectively a change to the user's roster. To reflect this, the changes to this class will automatically update the persistently stored roster, as well as send out update announcements to all logged in user sessions.
Modifier and Type | Field and Description |
---|---|
protected ConcurrentMap<String,Set<String>> |
implicitFrom
Contacts with subscription FROM that only exist due to shared groups
key: jabberid string; value: groups why the implicit roster item exists (aka invisibleSharedGroups).
|
protected ConcurrentMap<String,RosterItem> |
rosterItems
Roster item cache - table: key jabberid string; value roster item.
|
Constructor and Description |
---|
Roster()
Constructor added for Externalizable.
|
Modifier and Type | Method and Description |
---|---|
void |
broadcast(RosterItem item,
boolean optimize)
Broadcasts the RosterItem to all the connected resources of this user.
|
void |
broadcastPresence(org.xmpp.packet.Presence packet)
Broadcast the presence update to all subscribers of the roster.
|
RosterItem |
createRosterItem(org.xmpp.packet.JID user,
boolean push,
boolean persistent)
Create a new item to the roster.
|
RosterItem |
createRosterItem(org.xmpp.packet.JID user,
String nickname,
List<String> groups,
boolean push,
boolean persistent)
Create a new item to the roster.
|
void |
createRosterItem(org.xmpp.packet.Roster.Item item)
Create a new item to the roster based as a copy of the given item.
|
RosterItem |
deleteRosterItem(org.xmpp.packet.JID user,
boolean doChecking)
Remove a user from the roster.
|
boolean |
equals(Object o) |
int |
getCachedSize()
Returns the approximate size of the Object in bytes.
|
org.xmpp.packet.Roster |
getReset()
Obtain a 'roster reset', a snapshot of the full cached roster as an Roster.
|
RosterItem |
getRosterItem(org.xmpp.packet.JID user)
Returns the roster item that is associated with the specified JID.
|
Collection<RosterItem> |
getRosterItems()
Returns a collection of users in this roster.
|
String |
getUsername()
Return the username of the user or chatbot that owns this roster.
|
int |
hashCode() |
boolean |
isRosterItem(org.xmpp.packet.JID user)
Returns true if the specified user is a member of the roster, false otherwise.
|
protected RosterItem |
provideRosterItem(org.xmpp.packet.JID user,
String nickname,
List<String> groups,
boolean push,
boolean persistent)
Generate a new RosterItem for use with createRosterItem.
|
void |
readExternal(ObjectInput in) |
void |
updateRosterItem(RosterItem item)
Update an item that is already in the roster.
|
void |
writeExternal(ObjectOutput out) |
protected ConcurrentMap<String,RosterItem> rosterItems
protected ConcurrentMap<String,Set<String>> implicitFrom
public Roster()
public boolean isRosterItem(org.xmpp.packet.JID user)
user
- the user object to check.public Collection<RosterItem> getRosterItems()
Note: Roster items with subscription type FROM that exist only because of shared groups are not going to be returned.
public RosterItem getRosterItem(org.xmpp.packet.JID user) throws UserNotFoundException
user
- the XMPPAddress for the roster item to retrieveUserNotFoundException
- if no roster item was found for the specified JID.public RosterItem createRosterItem(org.xmpp.packet.JID user, boolean push, boolean persistent) throws UserAlreadyExistsException, SharedGroupException
user
- The item to add to the roster.push
- True if the new item must be pushed to the user.persistent
- True if the new roster item should be persisted to the DB.UserAlreadyExistsException
- if the user is already in the rosterSharedGroupException
- if the group is a shared grouppublic RosterItem createRosterItem(org.xmpp.packet.JID user, String nickname, List<String> groups, boolean push, boolean persistent) throws UserAlreadyExistsException, SharedGroupException
user
- The item to add to the roster.nickname
- The nickname for the roster entry (can be null).push
- True if the new item must be push to the user.persistent
- True if the new roster item should be persisted to the DB.groups
- The list of groups to assign this roster item to (can be null)UserAlreadyExistsException
- if the user is already in the rosterSharedGroupException
- if the group is a shared grouppublic void createRosterItem(org.xmpp.packet.Roster.Item item) throws UserAlreadyExistsException, SharedGroupException
item
- the item to copy and add to the roster.UserAlreadyExistsException
- if the user is already in the rosterSharedGroupException
- if the group is a shared groupprotected RosterItem provideRosterItem(org.xmpp.packet.JID user, String nickname, List<String> groups, boolean push, boolean persistent) throws UserAlreadyExistsException, SharedGroupException
user
- The roster jid address to create the roster item for.nickname
- The nickname to assign the item (or null for none).groups
- The groups the item belongs to (or null for none).push
- True if the new item must be push to the user.persistent
- True if the new roster item should be persisted to the DB.UserAlreadyExistsException
- if the user is already in the rosterSharedGroupException
- if the group is a shared grouppublic void updateRosterItem(RosterItem item) throws UserNotFoundException
item
- the item to update in the roster.UserNotFoundException
- If the roster item for the given user doesn't already existpublic RosterItem deleteRosterItem(org.xmpp.packet.JID user, boolean doChecking) throws SharedGroupException
user
- the user to remove from the roster.doChecking
- flag that indicates if checkings should be done before deleting the user.SharedGroupException
- if the user to remove belongs to a shared grouppublic String getUsername()
Return the username of the user or chatbot that owns this roster.
public org.xmpp.packet.Roster getReset()
Obtain a 'roster reset', a snapshot of the full cached roster as an Roster.
public void broadcastPresence(org.xmpp.packet.Presence packet)
Broadcast the presence update to all subscribers of the roster.
Any presence change typically results in a broadcast to the roster members.
packet
- The presence packet to broadcastpublic void broadcast(RosterItem item, boolean optimize)
item
- the item to broadcast.optimize
- true indicates that items that exists only because of a shared
group with subscription status FROM will not be sentpublic int getCachedSize() throws CannotCalculateSizeException
Cacheable
getCachedSize
in interface Cacheable
CannotCalculateSizeException
- if the size cannot be calculatedpublic void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
IOException
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
IOException
ClassNotFoundException
Copyright © 2003–2019 Ignite Realtime. All rights reserved.