1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-06 02:51:11 +01:00

Added reconnection support. SMACK-172

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@5367 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2006-09-14 19:16:40 +00:00 committed by gato
parent 96e4201f61
commit 3af86fd462
22 changed files with 501 additions and 194 deletions

View file

@ -150,8 +150,19 @@ public class ServiceDiscoveryManager {
}
public void connectionClosedOnError(Exception e) {
// Unregister this instance since the connection has been closed
instances.remove(connection);
// ignore
}
public void reconnectionFailed(Exception e) {
// ignore
}
public void reconnectingIn(int seconds) {
// ignore
}
public void reconectionSuccessful() {
// ignore
}
});

View file

@ -218,6 +218,30 @@ public class EnhancedDebugger implements SmackDebugger {
});
}
public void reconnectingIn(final int seconds){
SwingUtilities.invokeLater(new Runnable() {
public void run() {
statusField.setValue("Attempt to reconnect in " + seconds + " seconds");
}
});
}
public void reconectionSuccessful() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
statusField.setValue("Reconnection stablished");
EnhancedDebuggerWindow.connectionEstablished(EnhancedDebugger.this);
}
});
}
public void reconnectionFailed(Exception e) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
statusField.setValue("Reconnection failed");
}
});
}
};
}
@ -551,7 +575,7 @@ public class EnhancedDebugger implements SmackDebugger {
connPanel.add(
label,
new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
field = new JFormattedTextField(new Integer(connection.getPort()));
field = new JFormattedTextField(connection.getPort());
field.setMinimumSize(new java.awt.Dimension(150, 20));
field.setMaximumSize(new java.awt.Dimension(150, 20));
field.setEditable(false);
@ -618,16 +642,9 @@ public class EnhancedDebugger implements SmackDebugger {
packetsPanel.setBorder(BorderFactory.createTitledBorder("Transmitted Packets"));
statisticsTable =
new DefaultTableModel(new Object[][]{{"IQ", new Integer(0), new Integer(0)}, {
"Message", new Integer(0), new Integer(0)
}, {
"Presence", new Integer(0), new Integer(0)
}, {
"Other", new Integer(0), new Integer(0)
}, {
"Total", new Integer(0), new Integer(0)
}
}, new Object[]{"Type", "Received", "Sent"}) {
new DefaultTableModel(new Object[][]{{"IQ", 0, 0}, {"Message", 0, 0},
{"Presence", 0, 0}, {"Other", 0, 0}, {"Total", 0, 0}},
new Object[]{"Type", "Received", "Sent"}) {
public boolean isCellEditable(int rowIndex, int mColIndex) {
return false;
}
@ -719,7 +736,7 @@ public class EnhancedDebugger implements SmackDebugger {
private void addReadPacketToTable(final SimpleDateFormat dateFormatter, final Packet packet) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
String messageType = null;
String messageType;
String from = packet.getFrom();
String type = "";
Icon packetTypeIcon;
@ -780,7 +797,7 @@ public class EnhancedDebugger implements SmackDebugger {
private void addSentPacketToTable(final SimpleDateFormat dateFormatter, final Packet packet) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
String messageType = null;
String messageType;
String to = packet.getTo();
String type = "";
Icon packetTypeIcon;
@ -840,9 +857,10 @@ public class EnhancedDebugger implements SmackDebugger {
// Surround this setting in a try/catch for compatibility with Java 1.4. This setting is required
// for Java 1.5
try {
tFactory.setAttribute("indent-number", new Integer(2));
tFactory.setAttribute("indent-number", 2);
}
catch (IllegalArgumentException e) {
// Ignore
}
Transformer transformer = tFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");

View file

@ -29,7 +29,6 @@ import java.awt.event.*;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Vector;
/**
@ -90,7 +89,7 @@ public class EnhancedDebuggerWindow {
private JFrame frame = null;
private JTabbedPane tabbedPane = null;
private java.util.List debuggers = new ArrayList();
private java.util.List<EnhancedDebugger> debuggers = new ArrayList<EnhancedDebugger>();
private EnhancedDebuggerWindow() {
}
@ -178,6 +177,12 @@ public class EnhancedDebuggerWindow {
connectionClosedOnErrorIcon);
}
synchronized static void connectionEstablished(EnhancedDebugger debugger) {
getInstance().tabbedPane.setIconAt(
getInstance().tabbedPane.indexOfComponent(debugger.tabbedPane),
connectionActiveIcon);
}
/**
* Creates the main debug window that provides information about Smack and also shows
* a tab panel for each connection that is being debugged.
@ -264,7 +269,7 @@ public class EnhancedDebuggerWindow {
if (tabbedPane.getSelectedIndex() < tabbedPane.getComponentCount() - 1) {
int index = tabbedPane.getSelectedIndex();
// Notify to the debugger to stop debugging
EnhancedDebugger debugger = (EnhancedDebugger) debuggers.get(index);
EnhancedDebugger debugger = debuggers.get(index);
debugger.cancel();
// Remove the debugger from the root window
tabbedPane.remove(debugger.tabbedPane);
@ -281,18 +286,17 @@ public class EnhancedDebuggerWindow {
menuItem = new JMenuItem("Close All Not Active");
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ArrayList debuggersToRemove = new ArrayList();
ArrayList<EnhancedDebugger> debuggersToRemove = new ArrayList<EnhancedDebugger>();
// Remove all the debuggers of which their connections are no longer valid
for (int index = 0; index < tabbedPane.getComponentCount() - 1; index++) {
EnhancedDebugger debugger = (EnhancedDebugger) debuggers.get(index);
EnhancedDebugger debugger = debuggers.get(index);
if (!debugger.isConnectionActive()) {
// Notify to the debugger to stop debugging
debugger.cancel();
debuggersToRemove.add(debugger);
}
}
for (Iterator it = debuggersToRemove.iterator(); it.hasNext();) {
EnhancedDebugger debugger = (EnhancedDebugger) it.next();
for (EnhancedDebugger debugger : debuggersToRemove) {
// Remove the debugger from the root window
tabbedPane.remove(debugger.tabbedPane);
debuggers.remove(debugger);
@ -324,8 +328,7 @@ public class EnhancedDebuggerWindow {
*/
public void rootWindowClosing(WindowEvent evt) {
// Notify to all the debuggers to stop debugging
for (Iterator it = debuggers.iterator(); it.hasNext();) {
EnhancedDebugger debugger = (EnhancedDebugger) it.next();
for (EnhancedDebugger debugger : debuggers) {
debugger.cancel();
}
// Release any reference to the debuggers

View file

@ -35,6 +35,7 @@ import org.jivesoftware.smackx.packet.StreamInitiation;
import java.net.URLConnection;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
* Manages the negotiation of file transfers according to JEP-0096. If a file is
@ -64,7 +65,8 @@ public class FileTransferNegotiator {
private static final String[] PROTOCOLS = {BYTE_STREAM, INBAND_BYTE_STREAM};
private static final Map transferObject = new HashMap();
private static final Map<XMPPConnection, FileTransferNegotiator> transferObject =
new ConcurrentHashMap<XMPPConnection, FileTransferNegotiator>();
private static final String STREAM_INIT_PREFIX = "jsi_";
@ -92,7 +94,7 @@ public class FileTransferNegotiator {
}
if (transferObject.containsKey(connection)) {
return (FileTransferNegotiator) transferObject.get(connection);
return transferObject.get(connection);
}
else {
FileTransferNegotiator transfer = new FileTransferNegotiator(
@ -114,12 +116,12 @@ public class FileTransferNegotiator {
final boolean isEnabled) {
ServiceDiscoveryManager manager = ServiceDiscoveryManager
.getInstanceFor(connection);
for (int i = 0; i < NAMESPACE.length; i++) {
for (String ns : NAMESPACE) {
if (isEnabled) {
manager.addFeature(NAMESPACE[i]);
manager.addFeature(ns);
}
else {
manager.removeFeature(NAMESPACE[i]);
manager.removeFeature(ns);
}
}
}
@ -132,9 +134,8 @@ public class FileTransferNegotiator {
* @return True if all related services are enabled, false if they are not.
*/
public static boolean isServiceEnabled(final XMPPConnection connection) {
for (int i = 0; i < NAMESPACE.length; i++) {
if (!ServiceDiscoveryManager.getInstanceFor(connection)
.includesFeature(NAMESPACE[i]))
for (String ns : NAMESPACE) {
if (!ServiceDiscoveryManager.getInstanceFor(connection).includesFeature(ns))
return false;
}
return true;
@ -198,14 +199,26 @@ public class FileTransferNegotiator {
public void connectionClosedOnError(Exception e) {
cleanup(connection);
}
public void reconnectionFailed(Exception e) {
// ignore
}
public void reconectionSuccessful() {
// ignore
}
public void reconnectingIn(int seconds) {
// ignore
}
});
}
private void cleanup(final XMPPConnection connection) {
transferObject.remove(connection);
byteStreamTransferManager.cleanup();
inbandTransferManager.cleanup();
if (transferObject.remove(connection) != null) {
byteStreamTransferManager.cleanup();
inbandTransferManager.cleanup();
}
}
/**

View file

@ -2614,6 +2614,18 @@ public class MultiUserChat {
cancel();
}
public void reconnectingIn(int seconds) {
// ignore
}
public void reconectionSuccessful() {
// ignore
}
public void reconnectionFailed(Exception e) {
// ignore
}
/**
* Initializes the listeners to detect received room invitations and to detect when the
* connection gets closed. As soon as a room invitation is received the invitations

View file

@ -109,6 +109,18 @@ class RoomListenerMultiplexor implements ConnectionListener {
cancel();
}
public void reconnectingIn(int seconds) {
// ignore
}
public void reconectionSuccessful() {
// ignore
}
public void reconnectionFailed(Exception e) {
// ignore
}
/**
* Initializes the listeners to detect received room invitations and to detect when the
* connection gets closed. As soon as a room invitation is received the invitations