1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 14:22:05 +01:00

Improved comments.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@1801 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2003-01-17 07:12:57 +00:00 committed by mtucker
parent 8fb4e6a747
commit df62bffc48
2 changed files with 51 additions and 9 deletions

View file

@ -123,7 +123,7 @@ public class PacketCollector {
} }
/** /**
* Polls to see if a result is currently available and returns it, or * Polls to see if a packet is currently available and returns it, or
* immediately returns <tt>null</tt> if no packets are currently in the * immediately returns <tt>null</tt> if no packets are currently in the
* result queue. * result queue.
* *
@ -139,6 +139,12 @@ public class PacketCollector {
} }
} }
/**
* Returns the next available packet. The method call will block (not return)
* until a packet is available.
*
* @return the next available packet.
*/
public synchronized Packet nextResult() { public synchronized Packet nextResult() {
// Wait indefinitely until there is a result to return. // Wait indefinitely until there is a result to return.
while (resultQueue.isEmpty()) { while (resultQueue.isEmpty()) {
@ -150,6 +156,14 @@ public class PacketCollector {
return (Packet)resultQueue.removeLast(); return (Packet)resultQueue.removeLast();
} }
/**
* Returns the next available packet. The method call will block (not return)
* until a packet is available or the <tt>timeout</tt> has elapased. If the
* timeout elapses without a result, <tt>null</tt> will be returned.
*
* @param timeout the amount of time to wait for the next packet (in milleseconds).
* @return the next available packet.
*/
public synchronized Packet nextResult(long timeout) { public synchronized Packet nextResult(long timeout) {
// Wait up to the specified amount of time for a result. // Wait up to the specified amount of time for a result.
if (resultQueue.isEmpty()) { if (resultQueue.isEmpty()) {

View file

@ -55,8 +55,22 @@ package org.jivesoftware.smack.packet;
import org.jivesoftware.smack.*; import org.jivesoftware.smack.*;
/** /**
* Represents XMPP presence packets. Every presence packet has a type, while a * Represents XMPP presence packets. Every presence packet has a type, which is one of
* number of attributes are optional: * the following values:
* <ul>
* <li><tt>Presence.Type.AVAILABLE</tt> -- (Default) indicates the user is available to
* receive messages.
* <li><tt>Presence.Type.UNAVAILABLE</tt> -- the user is unavailable to receive messages.
* <li><tt>Presence.Type.SUBSCRIBE</tt> -- request subscription to recipient's presence.
* <li><tt>Presence.Type.SUBSCRIBED</tt> -- grant subscription to sender's presence.
* <li><tt>Presence.Type.UNSUBSCRIBE</tt> -- request removal of subscription to sender's
* presence.
* <li><tt>Presence.Type.UNSUBSCRIBED</tt> -- grant removal of subscription to sender's
* presence.
* <li><tt>Presence.Type.ERROR</tt> -- the presence packet contains an error message.
* </ul><p>
*
* A number of attributes are optional:
* <ul> * <ul>
* <li>Status -- free-form text describing a user's presence (i.e., gone to lunch). * <li>Status -- free-form text describing a user's presence (i.e., gone to lunch).
* <li>Priority -- non-negative numerical priority of a sender's resource. The * <li>Priority -- non-negative numerical priority of a sender's resource. The
@ -64,7 +78,7 @@ import org.jivesoftware.smack.*;
* to a particular resource. * to a particular resource.
* <li>Mode -- one of four presence modes: chat, away, xa (extended away, and * <li>Mode -- one of four presence modes: chat, away, xa (extended away, and
* dnd (do not disturb). * dnd (do not disturb).
* </ul> * </ul><p>
* *
* Presence packets are used for two purposes. First, to notify the server of our * Presence packets are used for two purposes. First, to notify the server of our
* the clients current presence status. Second, they are used to subscribe and * the clients current presence status. Second, they are used to subscribe and
@ -104,10 +118,20 @@ public class Presence extends Packet {
this.mode = mode; this.mode = mode;
} }
/**
* Returns the type of this presence packet.
*
* @return the type of the presence packet.
*/
public Type getType() { public Type getType() {
return type; return type;
} }
/**
* Sets the type of the presence packet.
*
* @param type the type of the presence packet.
*/
public void setType(Type type) { public void setType(Type type) {
this.type = type; this.type = type;
} }
@ -181,7 +205,10 @@ public class Presence extends Packet {
if (getFrom() != null) { if (getFrom() != null) {
buf.append("from=\"").append(getFrom()).append("\" "); buf.append("from=\"").append(getFrom()).append("\" ");
} }
buf.append("type=\"").append(type).append("\">"); if (type != Type.AVAILABLE) {
buf.append("type=\"").append(type).append("\"");
}
buf.append(">");
if (status != null) { if (status != null) {
buf.append("<status>").append(status).append("</status>"); buf.append("<status>").append(status).append("</status>");
} }
@ -206,6 +233,7 @@ public class Presence extends Packet {
public static final Type SUBSCRIBED = new Type("subscribed"); public static final Type SUBSCRIBED = new Type("subscribed");
public static final Type UNSUBSCRIBE = new Type("unsubscribe"); public static final Type UNSUBSCRIBE = new Type("unsubscribe");
public static final Type UNSUBSCRIBED = new Type("unsubscribed"); public static final Type UNSUBSCRIBED = new Type("unsubscribed");
public static final Type ERROR = new Type("error");
private String value; private String value;
@ -221,10 +249,7 @@ public class Presence extends Packet {
* Returns the type constant associated with the String value. * Returns the type constant associated with the String value.
*/ */
public static Type fromString(String value) { public static Type fromString(String value) {
if ("available".equals(value)) { if ("unavailable".equals(value)) {
return AVAILABLE;
}
else if ("unavailable".equals(value)) {
return UNAVAILABLE; return UNAVAILABLE;
} }
else if ("subscribe".equals(value)) { else if ("subscribe".equals(value)) {
@ -239,6 +264,9 @@ public class Presence extends Packet {
else if ("unsubscribed".equals(value)) { else if ("unsubscribed".equals(value)) {
return UNSUBSCRIBED; return UNSUBSCRIBED;
} }
else if ("error".equals(value)) {
return ERROR;
}
// Default to available. // Default to available.
else { else {
return AVAILABLE; return AVAILABLE;