1) Updating Smack.

2) Fixing Reconnection issue when making an explicit attempt.

git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@9012 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Derek DeMoro
2007-08-27 22:19:30 +00:00
committed by derek
parent 68af71b241
commit 0b68a58b4e
4 changed files with 36 additions and 20 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -12,12 +12,18 @@ package org.jivesoftware.spark.ui;
import org.jivesoftware.resource.Res; import org.jivesoftware.resource.Res;
import org.jivesoftware.resource.SparkRes; import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.ReconnectionManager;
import org.jivesoftware.spark.SparkManager; import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.component.RolloverButton; import org.jivesoftware.spark.component.RolloverButton;
import org.jivesoftware.spark.util.ModelUtil; import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.spark.util.SwingTimerTask; import org.jivesoftware.spark.util.SwingTimerTask;
import org.jivesoftware.spark.util.TaskEngine; import org.jivesoftware.spark.util.TaskEngine;
import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.text.html.HTMLEditorKit;
import java.awt.Color; import java.awt.Color;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
@ -26,22 +32,16 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.TimerTask; import java.util.TimerTask;
import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.text.html.HTMLEditorKit;
/** /**
* RetryPanel is the UI/Function class to handle reconnection logic. This allows for a simple card layout to replace the current * RetryPanel is the UI/Function class to handle reconnection logic. This allows for a simple card layout to replace the current
* roster when the connection has been lost. * roster when the connection has been lost.
* *
* @author Derek DeMoro * @author Derek DeMoro
*/ */
public class RetryPanel extends JPanel { public class RetryPanel extends JPanel implements ConnectionListener {
private JEditorPane pane; private JEditorPane pane;
private RolloverButton retryButton; private RolloverButton retryButton;
private boolean closedOnError = false; private boolean closedOnError;
private boolean connecting;
/** /**
* Construct the RetryPanel. * Construct the RetryPanel.
@ -69,10 +69,11 @@ public class RetryPanel extends JPanel {
setBackground(Color.white); setBackground(Color.white);
retryButton.setText("Reconnect"); retryButton.setText("Reconnect");
SparkManager.getConnection().addConnectionListener(this);
} }
private void attemptReconnection() { private void attemptReconnection() {
connecting = true;
retryButton.setText("Attempting..."); retryButton.setText("Attempting...");
retryButton.setEnabled(false); retryButton.setEnabled(false);
@ -82,14 +83,13 @@ public class RetryPanel extends JPanel {
} }
}; };
TaskEngine.getInstance().schedule(task, 2000); TaskEngine.getInstance().schedule(task, 100);
} }
private void reconnect() { private void reconnect() {
try { try {
if (closedOnError) { if (closedOnError) {
SparkManager.getConnection().connect(); ReconnectionManager.forced = true;
} }
else { else {
SparkManager.getMainWindow().logout(false); SparkManager.getMainWindow().logout(false);
@ -98,11 +98,6 @@ public class RetryPanel extends JPanel {
catch (Exception ex) { catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
connecting = false;
retryButton.setEnabled(true);
retryButton.setText("Reconnect....");
} }
@ -139,9 +134,6 @@ public class RetryPanel extends JPanel {
* @param text the text to display on the reconnect button. * @param text the text to display on the reconnect button.
*/ */
protected void setReconnectText(String text) { protected void setReconnectText(String text) {
if (connecting) {
return;
}
retryButton.setVisible(true); retryButton.setVisible(true);
retryButton.setText(text); retryButton.setText(text);
} }
@ -156,4 +148,28 @@ public class RetryPanel extends JPanel {
public void setClosedOnError(boolean onError) { public void setClosedOnError(boolean onError) {
closedOnError = onError; closedOnError = onError;
} }
public void connectionClosed() {
retryButton.setVisible(true);
retryButton.setEnabled(true);
}
public void connectionClosedOnError(Exception e) {
retryButton.setVisible(true);
retryButton.setEnabled(true);
}
public void reconnectingIn(int seconds) {
}
public void reconnectionSuccessful() {
retryButton.setVisible(false);
retryButton.setEnabled(true);
}
public void reconnectionFailed(Exception e) {
retryButton.setVisible(true);
retryButton.setEnabled(true);
}
} }