當前位置: 首頁>>代碼示例>>Java>>正文


Java ConnectionListener類代碼示例

本文整理匯總了Java中org.jivesoftware.smack.ConnectionListener的典型用法代碼示例。如果您正苦於以下問題:Java ConnectionListener類的具體用法?Java ConnectionListener怎麽用?Java ConnectionListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ConnectionListener類屬於org.jivesoftware.smack包,在下文中一共展示了ConnectionListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createXMPPConnection

import org.jivesoftware.smack.ConnectionListener; //導入依賴的package包/類
/**
 * 工廠模式獲取連接對象 還沒有連接服務器
 * @param connectionTimeOut   連接超時的時間
 * @param reconnectionAllowed 是否準許重連接
 * @param isPresence          是否在線
 * @param debugEnable         是否調試
 * @param securityMode        安全模式
 * @param connectionListener  連接監聽器
 * @return
 */
public static XMPPConnection createXMPPConnection(int connectionTimeOut, boolean reconnectionAllowed, boolean isPresence, boolean debugEnable,
                                                  ConnectionConfiguration.SecurityMode securityMode, ConnectionListener connectionListener) {
    //設置是否開啟DEBUG模式
    XMPPConnection.DEBUG_ENABLED = debugEnable;
    //設置連接地址、端口
    ConnectionConfiguration configuration = new ConnectionConfiguration(SERVERADDRESS, PORT);
    //設置服務器名稱
    configuration.setServiceName(SERVERNAME);
    //設置是否需要SAS驗證
    configuration.setSASLAuthenticationEnabled(false);
    //設置安全類型
    configuration.setSecurityMode(securityMode);
    //設置用戶狀態
    configuration.setSendPresence(isPresence);
    //設置是否準許重連接
    configuration.setReconnectionAllowed(reconnectionAllowed);
    //實例化連接對象
    XMPPConnection xmppConnection = new XMPPConnection(configuration);
    //添加連接監聽器
    if (connectionListener != null) {
        xmppConnection.addConnectionListener(connectionListener);
    }
    return xmppConnection;
}
 
開發者ID:FanHuaRan,項目名稱:SmackStudy,代碼行數:35,代碼來源:XMPPUtil.java

示例2: disconnect

import org.jivesoftware.smack.ConnectionListener; //導入依賴的package包/類
public void disconnect(Presence unavailablePresence) {
    if (!connected) {
        return;
    }
    shutdown(unavailablePresence);

    // Reset the connection flags
    wasAuthenticated = false;
    isFirstInitialization = true;

    // Notify connection listeners of the connection closing if done hasn't already been set.
    for (ConnectionListener listener : getConnectionListeners()) {
        try {
            listener.connectionClosed();
        }
        catch (Exception e) {
            // Catch and print any exception so we can recover
            // from a faulty listener and finish the shutdown process
            e.printStackTrace();
        }
    }
}
 
開發者ID:CJC-ivotten,項目名稱:androidPN-client.,代碼行數:23,代碼來源:BOSHConnection.java

示例3: notifyConnectionError

import org.jivesoftware.smack.ConnectionListener; //導入依賴的package包/類
/**
 * Sends out a notification that there was an error with the connection
 * and closes the connection.
 *
 * @param e the exception that causes the connection close event.
 */
protected void notifyConnectionError(Exception e) {
    // Closes the connection temporary. A reconnection is possible
    shutdown(new Presence(Presence.Type.unavailable));
    // Print the stack trace to help catch the problem
    e.printStackTrace();
    // Notify connection listeners of the error.
    for (ConnectionListener listener : getConnectionListeners()) {
        try {
            listener.connectionClosedOnError(e);
        }
        catch (Exception e2) {
            // Catch and print any exception so we can recover
            // from a faulty listener
            e2.printStackTrace();
        }
    }
}
 
開發者ID:CJC-ivotten,項目名稱:androidPN-client.,代碼行數:24,代碼來源:BOSHConnection.java

示例4: notifyConnectionError

import org.jivesoftware.smack.ConnectionListener; //導入依賴的package包/類
/**
 * Sends out a notification that there was an error with the connection and
 * closes the connection.
 * 
 * @param e
 *            the exception that causes the connection close event.
 */
protected void notifyConnectionError(Exception e) {
	// Closes the connection temporary. A reconnection is possible
	shutdown(new Presence(Presence.Type.unavailable));
	// Print the stack trace to help catch the problem
	e.printStackTrace();
	// Notify connection listeners of the error.
	for (ConnectionListener listener : getConnectionListeners()) {
		try {
			listener.connectionClosedOnError(e);
		} catch (Exception e2) {
			// Catch and print any exception so we can recover
			// from a faulty listener
			e2.printStackTrace();
		}
	}
}
 
開發者ID:ikantech,項目名稱:xmppsupport_v2,代碼行數:24,代碼來源:BOSHConnection.java

示例5: installConnectionListeners

import org.jivesoftware.smack.ConnectionListener; //導入依賴的package包/類
/**
 * Configure a session, setting some action listeners...
 * 
 * @param connection
 *            The connection to set up
 */
private void installConnectionListeners(final Connection connection) {
    if (connection != null) {
        connectionListener = new ConnectionListener() {
            public void connectionClosed() {
                unregisterInstanceFor(connection);
            }

            public void connectionClosedOnError(java.lang.Exception e) {
                unregisterInstanceFor(connection);
            }

            public void reconnectingIn(int i) {
            }

            public void reconnectionSuccessful() {
            }

            public void reconnectionFailed(Exception exception) {
            }
        };
        connection.addConnectionListener(connectionListener);
    }
}
 
開發者ID:bejayoharen,項目名稱:java-bells,代碼行數:30,代碼來源:JingleSession.java

示例6: disconnect

import org.jivesoftware.smack.ConnectionListener; //導入依賴的package包/類
public void disconnect(Presence unavailablePresence) {
	if (!connected) {
		return;
	}
	shutdown(unavailablePresence);

	// Cleanup
	if (roster != null) {
		roster.cleanup();
		roster = null;
	}
	sendListeners.clear();
	recvListeners.clear();
	collectors.clear();
	interceptors.clear();

	// Reset the connection flags
	wasAuthenticated = false;
	isFirstInitialization = true;

	// Notify connection listeners of the connection closing if done hasn't
	// already been set.
	for (ConnectionListener listener : getConnectionListeners()) {
		try {
			listener.connectionClosed();
		} catch (Exception e) {
			// Catch and print any exception so we can recover
			// from a faulty listener and finish the shutdown process
			e.printStackTrace();
		}
	}
}
 
開發者ID:ikantech,項目名稱:xmppsupport_v2,代碼行數:33,代碼來源:BOSHConnection.java

示例7: ClientBase

import org.jivesoftware.smack.ConnectionListener; //導入依賴的package包/類
protected ClientBase(String aHarmonyHubIP, int aXmppPort, HubClientSessionLoggedInListener hubClientSessionLoggedInListener,
        ConnectionListener connectionListenerDelegate) {
    harmonyHubIP = aHarmonyHubIP;
    xmppPort = aXmppPort;
    clientSessionLoggedInDelegate = hubClientSessionLoggedInListener;
    connectionDelegate = connectionListenerDelegate;
}
 
開發者ID:itaybia,項目名稱:androidHarmony,代碼行數:8,代碼來源:ClientBase.java

示例8: init

import org.jivesoftware.smack.ConnectionListener; //導入依賴的package包/類
private void init() {
    connection.addConnectionListener(new ConnectionListener() {

        @Override
        public void connectionClosed() {
            stopPingServerTask();
            handleDisconnect(connection);
        }

        @Override
        public void connectionClosedOnError(Exception arg0) {
            stopPingServerTask();
            handleDisconnect(connection);
        }

        @Override
        public void reconnectionSuccessful() {
            handleConnect();
            schedulePingServerTask();
        }

        @Override
        public void reconnectingIn(int seconds) {
        }

        @Override
        public void reconnectionFailed(Exception e) {
        }
    });

    instances.put(connection, this);
    schedulePingServerTask();
}
 
開發者ID:bejayoharen,項目名稱:java-bells,代碼行數:34,代碼來源:KeepAliveManager.java

示例9: setUp

import org.jivesoftware.smack.ConnectionListener; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    connection = createMock(MyXMPPConnection.class);
    connectionListenerCapture = new Capture<ConnectionListener>();
    interceptorCapture = new Capture<PacketInterceptor>();
    listenerCapture = new Capture<PacketListener>();
    packetCapture = new Capture<Packet>(CaptureType.ALL);

    connection.addConnectionListener(capture(connectionListenerCapture));
    expectLastCall().anyTimes();
    connection.addPacketListener(capture(listenerCapture), anyObject(PacketFilter.class));
    expectLastCall().anyTimes();
    connection.addPacketInterceptor(capture(interceptorCapture), anyObject(PacketFilter.class));
    expectLastCall().anyTimes();
    connection.sendPacket(capture(packetCapture));
    expectLastCall().anyTimes();
    
    Roster roster = createNiceMock(Roster.class);
    expect(connection.getRoster()).andStubReturn(roster);
    
    replay(connection, roster);
    handler = new XmppStreamHandler(connection);
    // Set max queue size to 10 and acks at 10/2 = 5
    handler.setMaxOutgoingQueueSize(10);
    listener = listenerCapture.getValue();
    interceptor = interceptorCapture.getValue();
}
 
開發者ID:prive,項目名稱:prive-android,代碼行數:28,代碼來源:XmppStreamHandlerTest.java

示例10: disconnect

import org.jivesoftware.smack.ConnectionListener; //導入依賴的package包/類
public void disconnect(Presence unavailablePresence) {
    if (!connected) {
        return;
    }
    shutdown(unavailablePresence);

    // Cleanup
    if (roster != null) {
        roster.cleanup();
        roster = null;
    }
    sendListeners.clear();
    recvListeners.clear();
    collectors.clear();
    interceptors.clear();

    // Reset the connection flags
    wasAuthenticated = false;
    isFirstInitialization = true;

    // Notify connection listeners of the connection closing if done hasn't already been set.
    for (ConnectionListener listener : getConnectionListeners()) {
        try {
            listener.connectionClosed();
        }
        catch (Exception e) {
            // Catch and print any exception so we can recover
            // from a faulty listener and finish the shutdown process
            e.printStackTrace();
        }
    }
}
 
開發者ID:jtietema,項目名稱:telegraph,代碼行數:33,代碼來源:BOSHConnection.java

示例11: getConnectionListener

import org.jivesoftware.smack.ConnectionListener; //導入依賴的package包/類
public ConnectionListener getConnectionListener() {
    return connectionListener;
}
 
開發者ID:daktak,項目名稱:androidpn-client,代碼行數:4,代碼來源:XmppManager.java

示例12: getConnectionListener

import org.jivesoftware.smack.ConnectionListener; //導入依賴的package包/類
public ConnectionListener getConnectionListener() {
	return connectionListener;
}
 
開發者ID:samuelhehe,項目名稱:androidpn_enhanced_client,代碼行數:4,代碼來源:XmppManager.java

示例13: PingManager

import org.jivesoftware.smack.ConnectionListener; //導入依賴的package包/類
private PingManager(final Connection connection) {
    this.connection = connection;
    instances.put(connection, this);

    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
    sdm.addFeature(NAMESPACE);

    PacketFilter pingPacketFilter = new PacketTypeFilter(Ping.class);
    connection.addPacketListener(new PacketListener() {
        /**
         * Sends a Pong for every Ping
         */
        public void processPacket(Packet packet) {
            if (pingMinDelta > 0) {
                // Ping flood protection enabled
                long currentMillies = System.currentTimeMillis();
                long delta = currentMillies - lastPingStamp;
                lastPingStamp = currentMillies;
                if (delta < pingMinDelta) {
                    return;
                }
            }
            Pong pong = new Pong((Ping)packet);
            connection.sendPacket(pong);
        }
    }
    , pingPacketFilter);
    connection.addConnectionListener(new ConnectionListener() {

        @Override
        public void connectionClosed() {
            maybeStopPingServerTask();
        }

        @Override
        public void connectionClosedOnError(Exception arg0) {
            maybeStopPingServerTask();
        }

        @Override
        public void reconnectionSuccessful() {
            maybeSchedulePingServerTask();
        }

        @Override
        public void reconnectingIn(int seconds) {
        }

        @Override
        public void reconnectionFailed(Exception e) {
        }
    });
    maybeSchedulePingServerTask();
}
 
開發者ID:CJC-ivotten,項目名稱:androidPN-client.,代碼行數:55,代碼來源:PingManager.java

示例14: getConnectionListeners

import org.jivesoftware.smack.ConnectionListener; //導入依賴的package包/類
public Set<ConnectionListener> getConnectionListeners() {
	return connectionListeners;
}
 
開發者ID:mixaceh,項目名稱:openyu-commons,代碼行數:4,代碼來源:XmppFactoryImpl.java

示例15: setConnectionListeners

import org.jivesoftware.smack.ConnectionListener; //導入依賴的package包/類
public void setConnectionListeners(Set<ConnectionListener> connectionListeners) {
	this.connectionListeners = connectionListeners;
}
 
開發者ID:mixaceh,項目名稱:openyu-commons,代碼行數:4,代碼來源:XmppFactoryImpl.java


注:本文中的org.jivesoftware.smack.ConnectionListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。