public final class ConnectionManager extends Object
Connections within SDK.
ConnectionManager is responsibile for instantiation and life-cycle
management of the connections. Any connection created outside
ConnectionManager (using various constructors of Connection
implementations) will not be managed by ConnectionManager which may
result in resource leak. Therefore SDK users (applications) SHOULD
instantiate Connection using ConnectionManager only.
In unstable network environments such as mobile devices, connectivity to
server is broken very frequently forcing SDK to reconnect with server.
ConnectionManager is the entity which manages reconnection
mechanism.However, it is important for ConnectionManager to know if
the underlying network is available on device; otherwise the reconnection
will be waste of efforts. Therefore, application developers must keep
ConnectionManager updated about the status of network availability on
device. If the network is not available on device, ConnectionManager
will not reconnect broken connections.| Modifier and Type | Method and Description |
|---|---|
void |
addConnectivityListener(NetConnectivityListener listener)
Add a
NetConnectivityListener to the listener list maintaned by
ConnectionManager |
void |
addReconnectionListener(ReconnectionListener listener)
Add a
ReconnectionListener to the listener list maintaned by
ConnectionManager |
void |
closeConnection(Connection conn)
Close a
Connection. |
void |
closeFileTransferConnection()
Close File transfer connection
|
void |
closeXMPPConnection(boolean closeAll)
Close xmpp connection.
|
boolean |
connect(boolean forceConnect,
boolean isXMPPConnection)
CONNECT is a command for
ConnectionManager to re-establish
underlying network connection which may be broken. |
boolean |
connectFileTransferConnection(boolean forceConnect) |
boolean |
connectXMPPConnection(boolean forceConnect) |
SFCMConnection |
getFileTransferConnection()
Get File Transfer connection held by this
ConnectionManager. |
static ConnectionManager |
getInstance()
Get
ConnectionManager instance. |
XMPPConnection |
getXmppConnection()
Get XMPP connection held by this
ConnectionManager. |
static void |
instantiate(ConnectionConfig config)
ConnectionManager is a singleton entity; it must be instantiated
with ConnectionConfig before
getInstance() can be invoked. |
static void |
instantiate(ConnectionConfig xmppConfig,
ConnectionConfig mimeConfig)
ConnectionManager is a singleton entity; it must be instantiated
with ConnectionConfig before
getInstance() can be invoked. |
static void |
instantiate(String xmppHost,
int xmppPort)
ConnectionManager is a singleton entity; it must be instantiated
with ConnectionConfig before
getInstance() can be invoked. |
static void |
instantiate(String xmppHost,
int xmppPort,
String sfcmHost,
int sfcmPort)
ConnectionManager is a singleton entity; it must be instantiated
with ConnectionConfig before
getInstance() can be invoked. |
boolean |
isNetworkConnectivity()
The application may choose to keep
ConnectionManager informed
about network connectivity on device. |
Future<Boolean> |
reconnectAsync()
Trigger connection reconnect on the persistent connection asynchronously.
|
void |
registerConnectionStateObserver(ConnectionStateObserver o)
Register
ConnectionStateObserver with Connection Manager |
void |
setNetworkConnectivity(boolean networkConnectivity)
Set network connectivity status.
|
void |
shutdown()
Shutdown this connection manager instance.
|
public static void instantiate(ConnectionConfig config)
ConnectionManager is a singleton entity; it must be instantiated
with ConnectionConfig before
getInstance() can be invoked.config - xmpp connection configurationspublic static void instantiate(String xmppHost, int xmppPort)
ConnectionManager is a singleton entity; it must be instantiated
with ConnectionConfig before
getInstance() can be invoked.xmppHost - server ip for xmpp servicexmppPort - server port of xmpp servicepublic static void instantiate(ConnectionConfig xmppConfig, ConnectionConfig mimeConfig)
ConnectionManager is a singleton entity; it must be instantiated
with ConnectionConfig before
getInstance() can be invoked.xmppConfig - xmpp connection configurationmimeConfig - file transfer connection configurationpublic static void instantiate(String xmppHost, int xmppPort, String sfcmHost, int sfcmPort)
ConnectionManager is a singleton entity; it must be instantiated
with ConnectionConfig before
getInstance() can be invoked.xmppHost - xmpp service ip addressxmppPort - xmpp service portsfcmHost - mime service IP addresssfcmPort - mime service portpublic static ConnectionManager getInstance()
ConnectionManager instance. ConnectionManager must be
instantiated before this call otherwise it throws
NotInitializedExceptionpublic XMPPConnection getXmppConnection()
ConnectionManager. It uses
ConnectionConfig instance held by the mananger; throws
NullPointerException if there is no ConnectionConfig
found.public SFCMConnection getFileTransferConnection()
ConnectionManager. It
uses ConnectionConfig instance held by the mananger; throws
NullPointerException if there is no ConnectionConfig
found.public boolean isNetworkConnectivity()
ConnectionManager informed
about network connectivity on device. Correct status of network
connectivity helps optimise the reconnection mechanism in SDK resulting
in power saving.ConnectionManager relies on the
application update its network connectivity flag as and when
there is a changepublic void setNetworkConnectivity(boolean networkConnectivity)
networkConnectivity - networkConnectivitypublic boolean connectXMPPConnection(boolean forceConnect)
throws NetworkException
NetworkExceptionpublic boolean connectFileTransferConnection(boolean forceConnect)
throws NetworkException
NetworkExceptionpublic boolean connect(boolean forceConnect,
boolean isXMPPConnection)
throws NetworkException
ConnectionManager to re-establish
underlying network connection which may be broken. If the connection is
reconnected, HeartBeatManger for the connection will also be
restarted.forceConnect - if true, a connect operation will be invoked
as long as device has network connectivity; If the value is
false, connect operation will be triggered only if
Connection.isConnected() returns falseisXMPPConnection - true if CONNECT needs to be issued on XMPP
Connection otherwise falseNetworkException - with NetworkException.Reason.NO_CONNECTIVITY when device
has no connectivity; the exception is also thrown if the
Connection.connect() operation fails. The
NetworkException.Reason specified in this case will be
NetworkException.Reason.IO_ERRORpublic void addReconnectionListener(ReconnectionListener listener)
ReconnectionListener to the listener list maintaned by
ConnectionManagerlistener - ReconnectionListener to be added to listpublic void addConnectivityListener(NetConnectivityListener listener)
NetConnectivityListener to the listener list maintaned by
ConnectionManagerlistener - ReconnectionListener to be added to listpublic void registerConnectionStateObserver(ConnectionStateObserver o)
ConnectionStateObserver with Connection Managero - ConnectionStateObserver instance to be registeredpublic Future<Boolean> reconnectAsync()
ReconnectionListeners will
be executed. Once reconnection is completed, ReconnectionListener
will be notified about success/failure.public void closeConnection(Connection conn)
Connection. If it is XMPP connection, file transfer
connections will not also be closed.conn - Connection to be closedpublic void closeXMPPConnection(boolean closeAll)
closeAll - flag to indicate of all the connections (inlcuding
non-XMPP) should be closedpublic void closeFileTransferConnection()
public void shutdown()
Copyright © 2019. All rights reserved.