mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 22:12:05 +01:00
Throws an exception when trying to create entries using a non-initialized roster.
The packet-reply-timeout is obtained from SmackConfiguration git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2192 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
f7de4be1f9
commit
76c0e90f18
1 changed files with 17 additions and 11 deletions
|
@ -96,16 +96,6 @@ public class Roster {
|
||||||
*/
|
*/
|
||||||
public static final int SUBSCRIPTION_MANUAL = 2;
|
public static final int SUBSCRIPTION_MANUAL = 2;
|
||||||
|
|
||||||
/**
|
|
||||||
* Value that indicates the number of milliseconds to wait for a response from
|
|
||||||
* the server.
|
|
||||||
*
|
|
||||||
* The reply timeout value can be assigned by setting this field to the required
|
|
||||||
* timeout, or by modifying the smack.configuration file that holds the default value
|
|
||||||
* to use.
|
|
||||||
*/
|
|
||||||
public static int REPLY_TIMEOUT = 5000;
|
|
||||||
|
|
||||||
private XMPPConnection connection;
|
private XMPPConnection connection;
|
||||||
private Map groups;
|
private Map groups;
|
||||||
private List entries;
|
private List entries;
|
||||||
|
@ -176,8 +166,14 @@ public class Roster {
|
||||||
* Reloads the entire roster from the server. This is an asynchronous operation,
|
* Reloads the entire roster from the server. This is an asynchronous operation,
|
||||||
* which means the method will return immediately, and the roster will be
|
* 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.
|
* reloaded at a later point when the server responds to the reload request.
|
||||||
|
*
|
||||||
|
* @throws IllegalStateException if the roster has not been initialized. The roster gets
|
||||||
|
* initialized when the user has logged in a a roster packet was received.
|
||||||
*/
|
*/
|
||||||
public void reload() {
|
public void reload() {
|
||||||
|
if (!rosterInitialized) {
|
||||||
|
throw new IllegalStateException("Roster not initialized yet.");
|
||||||
|
}
|
||||||
connection.sendPacket(new RosterPacket());
|
connection.sendPacket(new RosterPacket());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,9 +210,14 @@ public class Roster {
|
||||||
* after a logout/login. This is due to the way that XMPP stores group information.
|
* after a logout/login. This is due to the way that XMPP stores group information.
|
||||||
*
|
*
|
||||||
* @param name the name of the group.
|
* @param name the name of the group.
|
||||||
|
* @throws IllegalStateException if the roster has not been initialized. The roster gets
|
||||||
|
* initialized when the user has logged in a a roster packet was received.
|
||||||
* @return a new group.
|
* @return a new group.
|
||||||
*/
|
*/
|
||||||
public RosterGroup createGroup(String name) {
|
public RosterGroup createGroup(String name) {
|
||||||
|
if (!rosterInitialized) {
|
||||||
|
throw new IllegalStateException("Roster not initialized yet.");
|
||||||
|
}
|
||||||
synchronized (groups) {
|
synchronized (groups) {
|
||||||
if (groups.containsKey(name)) {
|
if (groups.containsKey(name)) {
|
||||||
throw new IllegalArgumentException("Group with name " + name + " alread exists.");
|
throw new IllegalArgumentException("Group with name " + name + " alread exists.");
|
||||||
|
@ -235,8 +236,13 @@ public class Roster {
|
||||||
* @param name the nickname of the user.
|
* @param name the nickname of the user.
|
||||||
* @param groups the list of group names the entry will belong to, or <tt>null</tt> if the
|
* @param groups the list of group names the entry will belong to, or <tt>null</tt> if the
|
||||||
* the roster entry won't belong to a group.
|
* the roster entry won't belong to a group.
|
||||||
|
* @throws IllegalStateException if the roster has not been initialized. The roster gets
|
||||||
|
* initialized when the user has logged in a a roster packet was received.
|
||||||
*/
|
*/
|
||||||
public void createEntry(String user, String name, String [] groups) throws XMPPException {
|
public void createEntry(String user, String name, String [] groups) throws XMPPException {
|
||||||
|
if (!rosterInitialized) {
|
||||||
|
throw new IllegalStateException("Roster not initialized yet.");
|
||||||
|
}
|
||||||
// Create and send roster entry creation packet.
|
// Create and send roster entry creation packet.
|
||||||
RosterPacket rosterPacket = new RosterPacket();
|
RosterPacket rosterPacket = new RosterPacket();
|
||||||
rosterPacket.setType(IQ.Type.SET);
|
rosterPacket.setType(IQ.Type.SET);
|
||||||
|
@ -251,7 +257,7 @@ public class Roster {
|
||||||
PacketCollector collector = connection.createPacketCollector(
|
PacketCollector collector = connection.createPacketCollector(
|
||||||
new PacketIDFilter(rosterPacket.getPacketID()));
|
new PacketIDFilter(rosterPacket.getPacketID()));
|
||||||
connection.sendPacket(rosterPacket);
|
connection.sendPacket(rosterPacket);
|
||||||
IQ response = (IQ)collector.nextResult(REPLY_TIMEOUT);
|
IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
throw new XMPPException("No response from the server.");
|
throw new XMPPException("No response from the server.");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue