当前位置: 首页>>代码示例>>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;未经允许,请勿转载。