Search in sources :

Example 16 with RpcException

use of im.actor.core.network.RpcException in project actor-platform by actorapp.

the class SenderActor method performSendApiContent.

private void performSendApiContent(final Peer peer, final long rid, ApiMessage message, final WakeLock wakeLock) {
    final ApiOutPeer outPeer = buidOutPeer(peer);
    final ApiPeer apiPeer = buildApiPeer(peer);
    if (outPeer == null || apiPeer == null) {
        return;
    }
    request(new RequestSendMessage(outPeer, rid, message, null, null), new RpcCallback<ResponseSeqDate>() {

        @Override
        public void onResult(ResponseSeqDate response) {
            self().send(new MessageSent(peer, rid));
            updates().onUpdateReceived(new SeqUpdate(response.getSeq(), response.getState(), UpdateMessageSent.HEADER, new UpdateMessageSent(apiPeer, rid, response.getDate()).toByteArray()));
            wakeLock.releaseLock();
        }

        @Override
        public void onError(RpcException e) {
            self().send(new MessageError(peer, rid));
            wakeLock.releaseLock();
        }
    });
}
Also used : UpdateMessageSent(im.actor.core.api.updates.UpdateMessageSent) SeqUpdate(im.actor.core.api.base.SeqUpdate) RequestSendMessage(im.actor.core.api.rpc.RequestSendMessage) RpcException(im.actor.core.network.RpcException) ApiOutPeer(im.actor.core.api.ApiOutPeer) ResponseSeqDate(im.actor.core.api.rpc.ResponseSeqDate) UpdateMessageSent(im.actor.core.api.updates.UpdateMessageSent) ApiPeer(im.actor.core.api.ApiPeer)

Example 17 with RpcException

use of im.actor.core.network.RpcException in project actor-platform by actorapp.

the class SettingsSyncActor method preStart.

@Override
public void preStart() {
    super.preStart();
    syncState = new SettingsSyncState();
    byte[] data = preferences().getBytes(SYNC_STATE);
    if (data != null) {
        try {
            syncState = SettingsSyncState.fromBytes(data);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    for (SettingsSyncAction action : syncState.getPendingActions()) {
        performSync(action);
    }
    if (!preferences().getBool(SYNC_STATE_LOADED, false)) {
        // TODO: Avoid race conditions
        request(new RequestGetParameters(), new RpcCallback<ResponseGetParameters>() {

            @Override
            public void onResult(ResponseGetParameters response) {
                for (ApiParameter p : response.getParameters()) {
                    context().getSettingsModule().onUpdatedSetting(p.getKey(), p.getValue());
                }
                context().getSettingsModule().notifySettingsChanged();
                preferences().putBool(SYNC_STATE_LOADED, true);
                context().getConductor().getConductor().onSettingsLoaded();
            }

            @Override
            public void onError(RpcException e) {
            // Ignore
            }
        });
    } else {
        context().getConductor().getConductor().onSettingsLoaded();
    }
}
Also used : SettingsSyncState(im.actor.core.modules.settings.entity.SettingsSyncState) SettingsSyncAction(im.actor.core.modules.settings.entity.SettingsSyncAction) ApiParameter(im.actor.core.api.ApiParameter) RpcException(im.actor.core.network.RpcException) IOException(java.io.IOException) RequestGetParameters(im.actor.core.api.rpc.RequestGetParameters) ResponseGetParameters(im.actor.core.api.rpc.ResponseGetParameters)

Aggregations

RpcException (im.actor.core.network.RpcException)17 RpcCallback (im.actor.core.network.RpcCallback)8 ApiOutPeer (im.actor.core.api.ApiOutPeer)6 ArrayList (java.util.ArrayList)6 SeqUpdate (im.actor.core.api.base.SeqUpdate)5 User (im.actor.core.entity.User)5 ApiSupportConfiguration (im.actor.core.modules.api.ApiSupportConfiguration)5 ApiUser (im.actor.core.api.ApiUser)4 ApiUserOutPeer (im.actor.core.api.ApiUserOutPeer)4 ResponseVoid (im.actor.core.api.rpc.ResponseVoid)4 IOException (java.io.IOException)4 ResponseSeq (im.actor.core.api.rpc.ResponseSeq)3 AbsModule (im.actor.core.modules.AbsModule)3 ModuleActor (im.actor.core.modules.ModuleActor)3 ModuleContext (im.actor.core.modules.ModuleContext)3 Modules (im.actor.core.modules.Modules)3 Command (im.actor.core.viewmodel.Command)3 Log (im.actor.runtime.Log)3 Void (im.actor.runtime.actors.messages.Void)3 Promise (im.actor.runtime.promise.Promise)3