AnsweredAssumed Answered

Newbie needs help re ConnectionListener.reconnectingIn control (?)

Question asked by Shakeel Ahmed on Apr 5, 2017

Hi, I am relatively new to the world of using Smack 4.1.9 which I am using for XMPP based communication to Firebase for the purposes of issuing Push Notifications from a server application. The implementation that I have, is effectively the one available from Google after translation to latest version of Smack (after much hair pulling). My implementation of a ConnectionListener is currently minimal - no more than an empty implementations of the methods that need to be overridden (numerous examples available on the net). One of those methods is reconnectingIn. Now when I look at my server side log files I find that this method is invoked many times ( approx once each second for some 400+ seconds ). This of course keeps the server unnecessarily busy for that time period - not good :-) There does not appear to be any error caught earlier.

 

2017-04-01 13:20:09,011(WS) INFO  (com.xmpp.client.CCSClient:?) - Reconnecting in 419 secs
2017-04-01 13:20:10,011(WS) INFO  (com.xmpp.client.CCSClient:?) - Reconnecting in 418 secs
2017-04-01 13:20:11,011(WS) INFO  (com.xmpp.client.CCSClient:?) - Reconnecting in 417 secs
..

Is there anybody who can offer any guidance/insight into what is going on and why ? How this may be controlled  (I've tried to dig my way through documentation but have had no luck yet) Any good examples of ConnectionListener out there ?

 

// Create the connection
this.connection = new XMPPTCPConnection( config.build() );

 

// Enable automatic reconnection
ReconnectionManager reconnectionManager = ReconnectionManager.getInstanceFor( this.connection );
reconnectionManager.enableAutomaticReconnection();
reconnectionManager.setReconnectionPolicy( ReconnectionManager.ReconnectionPolicy.FIXED_DELAY );
reconnectionManager.setFixedDelay( 20 );

this.connection.addConnectionListener( new ConnectionListener()
{ @Override
public void reconnectionSuccessful() { logger.info( "Reconnection successful ..." ); }
@Override
public void reconnectionFailed( final Exception e ) { logger.info( "Reconnection failed: ", e ); close();}
@Override
public void reconnectingIn( final int seconds ) { logger.info( String.format( "Reconnecting in %d secs", seconds ) );}
@Override
public void connectionClosedOnError( final Exception e ) { logger.info( "Connection closed on error", e );}
@Override
public void connectionClosed() { logger.info( "Connection closed" ); }
@Override public void authenticated( final XMPPConnection aConnection, final boolean parameter ) { logger.info( "User authenticated" ); // TODO: handle the authentication } @Override public void connected( final XMPPConnection arg0 ) { logger.info( "Connection established" ); }
} );

Outcomes