private synchronized void schedulePingServerTask ( ) { enableExecutorService ( ) ; stopPingServerTask ( ) ; if ( pingInterval > 0 ) { periodicPingTask = periodicPingExecutorService . schedule ( new Runnable ( ) { @ Override public void run ( ) { Ping ping = new Ping ( ) ; PacketFilter responseFilter = new PacketIDFilter ( ping . getID ( ) ) ; Connection connection = weakRefConnection . get ( ) ; final PacketCollector response = pingFailedListeners . isEmpty ( ) ? null : connection . createPacketCollector ( responseFilter ) ; connection . sendPacket ( ping ) ; if ( response != null ) { // Schedule a collector for the ping reply, // notify listeners if none is received. periodicPingExecutorService . schedule ( new Runnable ( ) { @ Override public void run ( ) { Packet result = response . nextResult ( 1 ) ; // Stop queuing results response . cancel ( ) ; // The actual result of the // reply can be ignored since we // only care if we actually got // one. if ( result == null ) { for ( PingFailedListener listener : pingFailedListeners ) { listener . pingFailed ( ) ; } } } } , SmackConfiguration . getPacketReplyTimeout ( ) , TimeUnit . MILLISECONDS ) ; } } } , getPingInterval ( ) , TimeUnit . MILLISECONDS ) ; } }
Cancels any existing periodic ping task if there is one and schedules a new ping task if pingInterval is greater then zero .