Java 类org.jivesoftware.smack.ConnectionListener 实例源码

项目:SmackStudy    文件:XMPPUtil.java   
/**
 * 工厂模式获取连接对象 还没有连接服务器
 * @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;
}
项目:androidPN-client.    文件:BOSHConnection.java   
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();
        }
    }
}
项目:androidPN-client.    文件:BOSHConnection.java   
/**
 * 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();
        }
    }
}
项目:xmppsupport_v2    文件:BOSHConnection.java   
/**
 * 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();
        }
    }
}
项目:java-bells    文件:JingleSession.java   
/**
 * 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);
    }
}
项目:telegraph    文件:BOSHConnection.java   
/**
 * 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();
        }
    }
}
项目:NewCommunication-Android    文件:BOSHConnection.java   
/**
 * 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();
        }
    }
}
项目:xmppsupport_v2    文件:BOSHConnection.java   
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();
        }
    }
}
项目:androidHarmony    文件:ClientBase.java   
protected ClientBase(String aHarmonyHubIP, int aXmppPort, HubClientSessionLoggedInListener hubClientSessionLoggedInListener,
        ConnectionListener connectionListenerDelegate) {
    harmonyHubIP = aHarmonyHubIP;
    xmppPort = aXmppPort;
    clientSessionLoggedInDelegate = hubClientSessionLoggedInListener;
    connectionDelegate = connectionListenerDelegate;
}
项目:java-bells    文件:KeepAliveManager.java   
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();
}
项目:prive-android    文件:XmppStreamHandlerTest.java   
@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();
}
项目:telegraph    文件:BOSHConnection.java   
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();
        }
    }
}
项目:NewCommunication-Android    文件:BOSHConnection.java   
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();
        }
    }
}
项目:androidpn-client    文件:XmppManager.java   
public ConnectionListener getConnectionListener() {
    return connectionListener;
}
项目:MessagePushClient    文件:XmppManager.java   
public ConnectionListener getConnectionListener() {
    return connectionListener;
}
项目:androidpn_enhanced_client    文件:XmppManager.java   
public ConnectionListener getConnectionListener() {
    return connectionListener;
}
项目:ShoppingMall    文件:XmppManager.java   
public ConnectionListener getConnectionListener() {
    return connectionListener;
}
项目:FastOmiai    文件:XmppManager.java   
public ConnectionListener getConnectionListener() {
    return connectionListener;
}
项目:androidPN-client.    文件:PingManager.java   
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();
}
项目:androidPN-client.    文件:XmppManager.java   
public ConnectionListener getConnectionListener() {
    return connectionListener;
}
项目:openyu-commons    文件:XmppFactoryImpl.java   
public Set<ConnectionListener> getConnectionListeners() {
    return connectionListeners;
}
项目:openyu-commons    文件:XmppFactoryImpl.java   
public void setConnectionListeners(Set<ConnectionListener> connectionListeners) {
    this.connectionListeners = connectionListeners;
}
项目:openyu-commons    文件:PoolableXmppConnection.java   
@SuppressWarnings("unchecked")
protected void removeAllListeners(XMPPTCPConnection conn) {

    // addAsyncStanzaListener(packetListener, packetFilter)
    @SuppressWarnings("rawtypes")
    Map asyncRecvListeners = ClassHelper.getDeclaredFieldValue(conn, "asyncRecvListeners");
    if (CollectionHelper.notEmpty(asyncRecvListeners)) {
        asyncRecvListeners.clear();
    }
    // addConnectionListener(connectionListener)
    Set<ConnectionListener> connectionListeners = ClassHelper.getDeclaredFieldValue(conn, "connectionListeners");
    if (CollectionHelper.notEmpty(connectionListeners)) {
        connectionListeners.clear();
    }

    // addPacketInterceptor(packetInterceptor, packetFilter)
    @SuppressWarnings("rawtypes")
    Map interceptors = ClassHelper.getDeclaredFieldValue(conn, "interceptors");
    if (CollectionHelper.notEmpty(interceptors)) {
        interceptors.clear();
    }

    // addPacketSendingListener(packetListener, packetFilter)
    @SuppressWarnings("rawtypes")
    Map sendListeners = ClassHelper.getDeclaredFieldValue(conn, "sendListeners");
    if (CollectionHelper.notEmpty(sendListeners)) {
        sendListeners.clear();
    }

    // addSyncStanzaListener(packetListener, packetFilter)
    @SuppressWarnings("rawtypes")
    Map syncRecvListeners = ClassHelper.getDeclaredFieldValue(conn, "syncRecvListeners");
    if (CollectionHelper.notEmpty(syncRecvListeners)) {
        syncRecvListeners.clear();
    }

    // registerIQRequestHandler(final IQRequestHandler iqRequestHandler)
    @SuppressWarnings("rawtypes")
    Map setIqRequestHandler = ClassHelper.getDeclaredFieldValue(conn, "setIqRequestHandler");
    if (CollectionHelper.notEmpty(setIqRequestHandler)) {
        setIqRequestHandler.clear();
    }
    @SuppressWarnings("rawtypes")
    Map getIqRequestHandler = ClassHelper.getDeclaredFieldValue(conn, "getIqRequestHandler");
    if (CollectionHelper.notEmpty(getIqRequestHandler)) {
        getIqRequestHandler.clear();
    }
    //
    conn.removeAllRequestAckPredicates();
    conn.removeAllStanzaAcknowledgedListeners();
    conn.removeAllStanzaIdAcknowledgedListeners();
}
项目:openyu-commons    文件:PoolableXmppConnection.java   
public void addConnectionListener(ConnectionListener connectionListener) {
    delegate.addConnectionListener(connectionListener);
}
项目:openyu-commons    文件:PoolableXmppConnection.java   
public void removeConnectionListener(ConnectionListener connectionListener) {
    delegate.removeConnectionListener(connectionListener);
}
项目:openyu-commons    文件:XmppConnectionFactoryImpl.java   
public Set<ConnectionListener> getConnectionListeners() {
    return connectionListeners;
}
项目:openyu-commons    文件:XmppConnectionFactoryImpl.java   
public void setConnectionListeners(Set<ConnectionListener> connectionListeners) {
    this.connectionListeners = connectionListeners;
}
项目:Zom-Android    文件:XmppStreamHandler.java   
public XmppStreamHandler(XMPPTCPConnection connection, ConnectionListener connectionListener) {
    mConnection = connection;
    mConnectionListener = connectionListener;
    startListening();
}
项目:AndroidPNClient    文件:XmppManager.java   
public ConnectionListener getConnectionListener() {
    return connectionListener;
}
项目:Fastpath-webchat    文件:ChatSession.java   
private boolean connect() throws Exception {
    if (port == -1 || port == 5222) {
        connection = new XMPPConnection(host);
    }
    else {
        ConnectionConfiguration config = new ConnectionConfiguration(host, port);
        connection = new XMPPConnection(config);
    }

    connection.connect();

    if (!connection.isConnected()) {
        return false;
    }

    composingNotificationsReceived = false;

    // Add a connection listener.
    connection.addConnectionListener(new ConnectionListener() {
        public void connectionClosed() {
            workgroup = null;
            groupChat = null;
            connection = null;
            messageEventManager = null;
            presenceList.add("The connection has been closed.");
        }

        public void connectionClosedOnError(Exception e) {
            workgroup = null;
            groupChat = null;
            connection = null;
            messageEventManager = null;
            //e.printStackTrace();
            presenceList.add("The connection has been closed.");
        }


        public void reconnectingIn(int i) {
        }

        public void reconnectionSuccessful() {
        }

        public void reconnectionFailed(Exception exception) {
        }
    });

    return true;
}
项目:Androidpn    文件:XmppManager.java   
public ConnectionListener getConnectionListener() {
    return connectionListener;
}
项目:Androidpn    文件:XmppManager.java   
private void submitLoginTask(ConnectionListener connectionListener) {
    Log.d(LOGTAG, "submitLoginTask()...");
    submitRegisterTask();
    runTask(new LoginTask(connectionListener));
}
项目:Androidpn    文件:XmppManager.java   
public static void reconnect(XmppManager xmppManager,
        ConnectionListener connectionListener) {
    xmppManager.submitLoginTask(connectionListener);
}
项目:Androidpn    文件:XmppManager.java   
public ConnectionListener getConnectionListener() {
    return connectionListener;
}
项目:Androidpn    文件:XmppManager.java   
private LoginTask(ConnectionListener connectionListener) {
    this.xmppManager = XmppManager.this;
    this.connectionListener = connectionListener;
}
项目:Androidpn    文件:XmppManager.java   
public ConnectionListener getConnectionListener() {
    return connectionListener;
}
项目:Androidpn    文件:XmppManager.java   
private void submitLoginTask(ConnectionListener connectionListener) {
    Log.d(LOGTAG, "submitLoginTask()...");
    submitRegisterTask();
    runTask(new LoginTask(connectionListener));
}
项目:Androidpn    文件:XmppManager.java   
public static void reconnect(XmppManager xmppManager,
        ConnectionListener connectionListener) {
    xmppManager.submitLoginTask(connectionListener);
}
项目:Androidpn    文件:XmppManager.java   
public ConnectionListener getConnectionListener() {
    return connectionListener;
}
项目:Androidpn    文件:XmppManager.java   
private LoginTask(ConnectionListener connectionListener) {
    this.xmppManager = XmppManager.this;
    this.connectionListener = connectionListener;
}