⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connectorthread.java~

📁 JBother是纯Java开发的Jabber(即时消息开源软件)客户端。支持群组聊天
💻 JAVA~
📖 第 1 页 / 共 2 页
字号:
/* Copyright (C) 2003 Adam Olsen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */package com.valhalla.jbother;import java.awt.event.ActionEvent;import java.util.Locale;import java.util.ResourceBundle;import javax.swing.*;import org.jivesoftware.smack.Roster;import org.jivesoftware.smack.SSLXMPPConnection;import org.jivesoftware.smack.XMPPConnection;import org.jivesoftware.smack.XMPPException;import org.jivesoftware.smack.filter.OrFilter;import org.jivesoftware.smack.filter.PacketFilter;import org.jivesoftware.smack.filter.PacketTypeFilter;import org.jivesoftware.smack.packet.Message;import org.jivesoftware.smack.packet.Packet;import org.jivesoftware.smack.packet.Presence;import org.jivesoftware.smack.provider.ProviderManager;import org.jivesoftware.smackx.*;import org.jivesoftware.smackx.muc.MultiUserChat;import org.jivesoftware.smackx.packet.Time;import com.valhalla.gui.Standard;import com.valhalla.jbother.jabber.smack.*;import com.valhalla.jbother.jabber.smack.provider.*;import com.valhalla.misc.GnuPG;import com.valhalla.misc.SimpleXOR;import com.valhalla.settings.Settings;/** * Attempts to connect to the server. If the connection is made successfully, it * sets up the various packet listeners and displays the BuddyList * * @author Adam Olsen * @author Andrey Zakirov * @created April 10, 2005 * @version 1.0 */public class ConnectorThread implements Runnable {    private static ConnectorThread instance = null;    private Thread thread = null;    private ResourceBundle resources = ResourceBundle.getBundle(            "JBotherBundle", Locale.getDefault());    private String server, username, resource;    private String password = null;    private boolean ssl;    private int port = 0;    private String errorMessage;    private XMPPConnection connection = null;    private boolean hasHadError = false;    private com.valhalla.jbother.jabber.smack.ConnectionListener conListener = new com.valhalla.jbother.jabber.smack.ConnectionListener();    //private com.valhalla.jbother.jabber.smack.RosterListener    // rosterListener =    //	new com.valhalla.jbother.jabber.smack.RosterListener();    private MessagePacketListener messageListener = new MessagePacketListener();    private Presence.Mode connectMode = Presence.Mode.AVAILABLE;    private String statusString = null;    private boolean persistent = false;    private boolean cancelled = false;    private boolean away = false;    private MessageEventManager eventManager;    private String gnupgSecretKey = Settings.getInstance().getProperty(            "gnupgSecretKeyID");    private String gnupgTempPass = null;    private int connectCount = 0;    /**     * Sets up the connector thread     *     * @param connectMode     *            Description of the Parameter     * @param statusString     *            Description of the Parameter     * @param away     *            Description of the Parameter     */    private ConnectorThread() {        ProviderManager.addIQProvider("query", "jabber:iq:version",                new VersionProvider());        ProviderManager.addIQProvider("query", "jabber:iq:last",                new LastActivityProvider());        ProviderManager.addIQProvider("query", "jabber:iq:time",                new TimeProvider());        ProviderManager.addExtensionProvider("x", "jabber:x:encrypted",                new EncryptedProvider());        ProviderManager.addExtensionProvider("x", "jabber:x:signed",                new SignedProvider());        PrivateDataManager.addPrivateDataProvider("storage", "storage:bookmarks", new BookmarkProvider());        VCardIQProvider.Install();    }    public boolean isAlive()    {        if( thread == null ) return false;        else return thread.isAlive();    }    public void start()    {        thread = new Thread(this);        thread.start();    }    public static ConnectorThread getInstance()    {        if( instance == null ) instance = new ConnectorThread();        return instance;    }    public ConnectorThread init( Presence.Mode connectMode, String statusString,            boolean away )    {        this.server = Settings.getInstance().getProperty("defaultServer");        if( server != null ) server = server.toLowerCase();        this.username = Settings.getInstance().getProperty("username");        this.resource = Settings.getInstance().getProperty("resource");        this.ssl = Settings.getInstance().getBoolean("useSSL");        String p = Settings.getInstance().getProperty("port");        if (p != null) {            try {                port = Integer.parseInt(p);            } catch (NumberFormatException ex) {            }        }        hasHadError = false;        this.connectMode = connectMode;        this.statusString = statusString;        this.away = away;        connectCount = 0;        return instance;    }    public void resetCredentials() {        gnupgSecretKey = Settings.getInstance().getProperty("gnupgSecretKeyID");        password = Settings.getInstance().getProperty("password");        if (password != null)            password = SimpleXOR.decrypt(password, "JBother rules!");        gnupgTempPass = null;    }    /**     * Gets the messageEventManager attribute of the ConnectorThread class     *     * @return The messageEventManager value     */    public MessageEventManager getMessageEventManager() {        return eventManager;    }    /**     * Sets the cancelled attribute of the ConnectorThread class     *     * @param c     *            The new cancelled value     */    public void setCancelled(boolean c) {        cancelled = c;        connectCount = 0;    }    /**     * Sets whether or not this thread should try to reconnect if there is a     * connection error     *     * @param persistent     *            set to <tt>true</tt> if you want the thread to continue to     *            try and connect even if there's an error     */    public void setPersistent(boolean persistent) {        this.persistent = persistent;        connectCount = 0;    }    /**     * Returns the ConnectionListener     *     * @return the connection listener     */    public com.valhalla.jbother.jabber.smack.ConnectionListener getConnectionListener() {        return conListener;    }    /**     * Sets whether or not a connection error has already been thrown for this     * connection     *     * @param has     *            true if an error has already been thrown     */    public void setHasHadError(boolean has) {        hasHadError = has;    }    /**     * Called when the Threads .start() method is called     */    public void run() {        errorMessage = null;        com.valhalla.Logger.debug("Connector thread starting...");        if (!BuddyList.getInstance().getStatusMenu()                .blinkTimerIsRunning()) {            BuddyList.getInstance().getStatusMenu()                    .startBlinkTimer();        }        if( connectCount >= 15 )        {            BuddyList.getInstance().getStatusMenu().stopBlinkTimer();            SwingUtilities.invokeLater( new Runnable()                {                    public void run()                    {                        BuddyList.getInstance().getStatusMenu()                                .setModeChecked(null);                    }                } );            int result = JOptionPane.showConfirmDialog(                            null,                            resources.getString( "connectCountTooHigh" ),                            "JBother", JOptionPane.YES_NO_OPTION);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -