Search in sources :

Example 6 with MRetryableTask

use of org.infobip.mobile.messaging.mobile.common.MRetryableTask in project mobile-messaging-sdk-android by infobip.

the class RegistrationSynchronizer method reportCloudToken.

private void reportCloudToken(final String cloudToken) {
    if (StringUtils.isBlank(cloudToken)) {
        return;
    }
    new MRetryableTask<String, Registration>() {

        @Override
        public Registration run(String[] params) {
            String cloudToken = params.length > 0 ? params[0] : null;
            MobileMessagingLogger.v("REGISTRATION >>>", cloudToken);
            RegistrationResponse registrationResponse = mobileApiRegistration.upsert(cloudToken, null);
            MobileMessagingLogger.v("REGISTRATION <<<", registrationResponse);
            return new Registration(cloudToken, registrationResponse.getDeviceApplicationInstanceId(), registrationResponse.getPushRegistrationEnabled());
        }

        @Override
        public void after(Registration registration) {
            setPushRegistrationEnabled(registration.enabled);
            setPushRegistrationId(registration.registrationId);
            setRegistrationIdReported(true);
            MobileMessagingCore.getInstance(context).reportSystemData();
            broadcaster.registrationCreated(registration.cloudToken, registration.registrationId);
        }

        @Override
        public void error(Throwable error) {
            MobileMessagingLogger.e("MobileMessaging API returned error (registration)!");
            setRegistrationIdReported(false);
            mobileMessagingCore.setLastHttpException(error);
            stats.reportError(MobileMessagingStatsError.PUSH_REGISTRATION_STATUS_UPDATE_ERROR);
            broadcaster.error(MobileMessagingError.createFrom(error));
        }
    }.retryWith(retryPolicyProvider.DEFAULT()).execute(executor, cloudToken);
}
Also used : MRetryableTask(org.infobip.mobile.messaging.mobile.common.MRetryableTask) MobileApiRegistration(org.infobip.mobile.messaging.api.registration.MobileApiRegistration) RegistrationResponse(org.infobip.mobile.messaging.api.registration.RegistrationResponse)

Aggregations

MRetryableTask (org.infobip.mobile.messaging.mobile.common.MRetryableTask)6 MobileApiRegistration (org.infobip.mobile.messaging.api.registration.MobileApiRegistration)2 RegistrationResponse (org.infobip.mobile.messaging.api.registration.RegistrationResponse)2 List (java.util.List)1 Message (org.infobip.mobile.messaging.Message)1 SystemData (org.infobip.mobile.messaging.SystemData)1 UserData (org.infobip.mobile.messaging.UserData)1 SystemDataReport (org.infobip.mobile.messaging.api.data.SystemDataReport)1 UserDataReport (org.infobip.mobile.messaging.api.data.UserDataReport)1 SyncMessagesBody (org.infobip.mobile.messaging.api.messages.SyncMessagesBody)1 SyncMessagesResponse (org.infobip.mobile.messaging.api.messages.SyncMessagesResponse)1 LatestReleaseResponse (org.infobip.mobile.messaging.api.version.LatestReleaseResponse)1 BackendBaseExceptionWithContent (org.infobip.mobile.messaging.mobile.common.exceptions.BackendBaseExceptionWithContent)1 BackendInvalidParameterException (org.infobip.mobile.messaging.mobile.common.exceptions.BackendInvalidParameterException)1