mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-10 18:59:41 +02:00
SMACK-412 Added the pingMyServer back in, cleaned up unneeded synchronization and removed minimum ping interval.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/branches/smack_3_3_0@13588 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
999c86ef4c
commit
a14178990b
8 changed files with 174 additions and 42 deletions
|
@ -162,12 +162,10 @@ class PacketWriter {
|
|||
while (!done && (writerThread == thisThread)) {
|
||||
Packet packet = nextPacket();
|
||||
if (packet != null) {
|
||||
synchronized (writer) {
|
||||
writer.write(packet.toXML());
|
||||
writer.write(packet.toXML());
|
||||
writer.flush();
|
||||
if (queue.isEmpty()) {
|
||||
writer.flush();
|
||||
if (queue.isEmpty()) {
|
||||
writer.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -175,13 +173,11 @@ class PacketWriter {
|
|||
// we won't have time to entirely flush it before the socket is forced closed
|
||||
// by the shutdown process.
|
||||
try {
|
||||
synchronized (writer) {
|
||||
while (!queue.isEmpty()) {
|
||||
Packet packet = queue.remove();
|
||||
writer.write(packet.toXML());
|
||||
}
|
||||
writer.flush();
|
||||
while (!queue.isEmpty()) {
|
||||
Packet packet = queue.remove();
|
||||
writer.write(packet.toXML());
|
||||
}
|
||||
writer.flush();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
24
source/org/jivesoftware/smack/SmackError.java
Normal file
24
source/org/jivesoftware/smack/SmackError.java
Normal file
|
@ -0,0 +1,24 @@
|
|||
package org.jivesoftware.smack;
|
||||
|
||||
public enum SmackError {
|
||||
NO_RESPONSE_FROM_SERVER("No response from server.");
|
||||
|
||||
private String message;
|
||||
|
||||
private SmackError(String errMessage) {
|
||||
message = errMessage;
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public static SmackError getErrorCode(String message) {
|
||||
for (SmackError code : values()) {
|
||||
if (code.message.equals(message)) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -41,10 +41,12 @@ import java.io.PrintWriter;
|
|||
* @author Matt Tucker
|
||||
*/
|
||||
public class XMPPException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 6881651633890968625L;
|
||||
|
||||
private StreamError streamError = null;
|
||||
private XMPPError error = null;
|
||||
private Throwable wrappedThrowable = null;
|
||||
private SmackError smackError = null;
|
||||
|
||||
/**
|
||||
* Creates a new XMPPException.
|
||||
|
@ -62,6 +64,16 @@ public class XMPPException extends Exception {
|
|||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new XMPPException with a Smack specific error code.
|
||||
*
|
||||
* @param code the root cause of the exception.
|
||||
*/
|
||||
public XMPPException(SmackError code) {
|
||||
super(code.getErrorMessage());
|
||||
smackError = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new XMPPException with the Throwable that was the root cause of the
|
||||
* exception.
|
||||
|
@ -74,7 +86,7 @@ public class XMPPException extends Exception {
|
|||
}
|
||||
|
||||
/**
|
||||
* Cretaes a new XMPPException with the stream error that was the root case of the
|
||||
* Creates a new XMPPException with the stream error that was the root case of the
|
||||
* exception. When a stream error is received from the server then the underlying
|
||||
* TCP connection will be closed by the server.
|
||||
*
|
||||
|
@ -144,6 +156,16 @@ public class XMPPException extends Exception {
|
|||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SmackError asscociated with this exception, or <tt>null</tt> if there
|
||||
* isn't one.
|
||||
*
|
||||
* @return the SmackError asscociated with this exception.
|
||||
*/
|
||||
public SmackError getSmackError() {
|
||||
return smackError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the StreamError asscociated with this exception, or <tt>null</tt> if there
|
||||
* isn't one. The underlying TCP connection is closed by the server after sending the
|
||||
|
|
|
@ -57,8 +57,6 @@ import org.jivesoftware.smackx.ServiceDiscoveryManager;
|
|||
* @author Florian Schmaus
|
||||
*/
|
||||
public class ServerPingManager {
|
||||
public static final long PING_MINIMUM = 10000;
|
||||
|
||||
private static Map<Connection, ServerPingManager> instances = Collections
|
||||
.synchronizedMap(new WeakHashMap<Connection, ServerPingManager>());
|
||||
private static long defaultPingInterval = SmackConfiguration.getKeepAliveInterval();
|
||||
|
@ -173,12 +171,15 @@ public class ServerPingManager {
|
|||
* The new ping time interval in milliseconds.
|
||||
*/
|
||||
public void setPingInterval(long newPingInterval) {
|
||||
if (newPingInterval < PING_MINIMUM)
|
||||
newPingInterval = PING_MINIMUM;
|
||||
|
||||
if (pingInterval != newPingInterval) {
|
||||
pingInterval = newPingInterval;
|
||||
schedulePingServerTask();
|
||||
|
||||
if (pingInterval < 0) {
|
||||
stopPinging();
|
||||
}
|
||||
else {
|
||||
schedulePingServerTask();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ package org.jivesoftware.smack.util;
|
|||
import org.jivesoftware.smack.PacketCollector;
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.Connection;
|
||||
import org.jivesoftware.smack.SmackError;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
||||
|
@ -47,7 +48,7 @@ final public class SyncPacketSend
|
|||
response.cancel();
|
||||
|
||||
if (result == null) {
|
||||
throw new XMPPException("No response from " + packet.getTo());
|
||||
throw new XMPPException(SmackError.NO_RESPONSE_FROM_SERVER);
|
||||
}
|
||||
else if (result.getError() != null) {
|
||||
throw new XMPPException(result.getError());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue