/** * The method is called by a ProtocolProvider implementation whenever a change in the * registration state of the corresponding provider had occurred. * * @param evt ProviderStatusChangeEvent the event describing the status change. */ public void registrationStateChanged(RegistrationStateChangeEvent evt) { if (logger.isDebugEnabled()) logger.debug( "The provider changed state from: " + evt.getOldState() + " to: " + evt.getNewState()); if (evt.getNewState() == RegistrationState.REGISTERED) { opSetPersPresence = (OperationSetPresenceSipImpl) sipProvider.getOperationSet(OperationSetPersistentPresence.class); } }
/** * The method is called by a ProtocolProvider implementation whenever a change in the * registration state of the corresponding provider had occurred. The method is particularly * interested in events stating that the SIP provider has unregistered so that it would fire * status change events for all contacts in our buddy list. * * @param evt ProviderStatusChangeEvent the event describing the status change. */ public void registrationStateChanged(RegistrationStateChangeEvent evt) { if (evt.getNewState() == RegistrationState.UNREGISTERING || evt.getNewState() == RegistrationState.UNREGISTERED || evt.getNewState() == RegistrationState.AUTHENTICATION_FAILED || evt.getNewState() == RegistrationState.CONNECTION_FAILED) { // stop any task associated with the timer if (keepAliveTimer != null) { keepAliveTimer.cancel(); keepAliveTimer = null; } } else if (evt.getNewState().equals(RegistrationState.REGISTERED)) { String keepAliveMethod = provider .getAccountID() .getAccountPropertyString(ProtocolProviderFactory.KEEP_ALIVE_METHOD); if (logger.isTraceEnabled()) logger.trace("Keep alive method " + keepAliveMethod); // options is default keep-alive, if property is missing // then options is used if (keepAliveMethod != null && !(keepAliveMethod.equalsIgnoreCase("options") || keepAliveMethod.equalsIgnoreCase("crlf"))) return; int keepAliveInterval = provider .getAccountID() .getAccountPropertyInt(ProtocolProviderFactory.KEEP_ALIVE_INTERVAL, -1); if (logger.isTraceEnabled()) logger.trace("Keep alive interval is " + keepAliveInterval); if (keepAliveInterval > 0 && !provider.getRegistrarConnection().isRegistrarless()) { if (keepAliveTimer == null) keepAliveTimer = new Timer(); TimerTask keepAliveTask; // CRLF is used by default on Android if ((OSUtils.IS_ANDROID && keepAliveMethod == null) || "crlf".equalsIgnoreCase(keepAliveMethod)) { keepAliveTask = new CRLfKeepAliveTask(); } else { // OPTIONS keepAliveTask = new OptionsKeepAliveTask(); } if (logger.isDebugEnabled()) logger.debug("Scheduling keep alives: " + keepAliveTask); keepAliveTimer.schedule(keepAliveTask, 0, keepAliveInterval * 1000); } } }