Search in sources :

Example 1 with Actor

use of im.actor.runtime.actors.Actor in project actor-platform by actorapp.

the class ActorDispatcher method processEnvelope.

/**
     * Processing of envelope
     *
     * @param envelope envelope
     */
private void processEnvelope(Envelope envelope) {
    ActorScope scope = envelope.getScope();
    if (actorSystem.getTraceInterface() != null) {
        actorSystem.getTraceInterface().onEnvelopeDelivered(envelope);
    }
    long start = ActorTime.currentTime();
    if (scope.getActor() == null) {
        if (envelope.getMessage() == PoisonPill.INSTANCE) {
            // Not creating actor for PoisonPill
            return;
        }
        try {
            Actor actor = scope.getProps().create();
            actor.initActor(scope.getPath(), new ActorContext(scope), scope.getMailbox());
            ThreadDispatcher.pushDispatcher(actor.getDispatcher());
            try {
                actor.preStart();
            } finally {
                ThreadDispatcher.popDispatcher();
            }
            scope.onActorCreated(actor);
        } catch (Exception e) {
            e.printStackTrace();
            if (envelope.getSender() != null) {
                envelope.getSender().send(new DeadLetter("Unable to create actor"));
            }
            return;
        }
    }
    try {
        if (envelope.getMessage() == StartActor.INSTANCE) {
        // Already created actor
        } else if (envelope.getMessage() == PoisonPill.INSTANCE) {
            ThreadDispatcher.pushDispatcher(scope.getActor().getDispatcher());
            try {
                scope.getActor().postStop();
            } finally {
                ThreadDispatcher.popDispatcher();
            }
            onActorDie(scope);
        } else {
            scope.getActor().handleMessage(envelope.getMessage(), envelope.getSender());
        }
    } catch (Exception e) {
        if (actorSystem.getTraceInterface() != null) {
            actorSystem.getTraceInterface().onActorDie(scope.getActorRef(), envelope, e);
        }
        ThreadDispatcher.pushDispatcher(scope.getActor().getDispatcher());
        try {
            scope.getActor().postStop();
        } finally {
            ThreadDispatcher.popDispatcher();
        }
        onActorDie(scope);
    } finally {
        if (actorSystem.getTraceInterface() != null) {
            actorSystem.getTraceInterface().onEnvelopeProcessed(envelope, ActorTime.currentTime() - start);
        }
    }
}
Also used : DeadLetter(im.actor.runtime.actors.messages.DeadLetter) StartActor(im.actor.runtime.actors.messages.StartActor) Actor(im.actor.runtime.actors.Actor) ActorScope(im.actor.runtime.actors.ActorScope) ActorContext(im.actor.runtime.actors.ActorContext)

Example 2 with Actor

use of im.actor.runtime.actors.Actor in project actor-platform by actorapp.

the class AuthActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    authActor = ActorSystem.system().actorOf(Props.create(new ActorCreator() {

        @Override
        public Actor create() {
            return new Actor();
        }
    }), "actor/auth_promises_actor");
    signType = getIntent().getIntExtra(SIGN_TYPE_KEY, SIGN_TYPE_IN);
    PreferencesStorage preferences = messenger().getPreferences();
    currentPhone = preferences.getLong("currentPhone", 0);
    currentEmail = preferences.getString("currentEmail");
    transactionHash = preferences.getString("transactionHash");
    isRegistered = preferences.getBool("isRegistered", false);
    codeValidated = preferences.getBool("codeValidated", false);
    currentName = preferences.getString("currentName");
    signType = preferences.getInt("signType", signType);
    String savedState = preferences.getString("auth_state");
    state = Enum.valueOf(AuthState.class, savedState != null ? savedState : "AUTH_START");
    updateState(state, true);
}
Also used : AuthState(im.actor.core.AuthState) Actor(im.actor.runtime.actors.Actor) ActorCreator(im.actor.runtime.actors.ActorCreator) PreferencesStorage(im.actor.runtime.storage.PreferencesStorage)

Aggregations

Actor (im.actor.runtime.actors.Actor)2 AuthState (im.actor.core.AuthState)1 ActorContext (im.actor.runtime.actors.ActorContext)1 ActorCreator (im.actor.runtime.actors.ActorCreator)1 ActorScope (im.actor.runtime.actors.ActorScope)1 DeadLetter (im.actor.runtime.actors.messages.DeadLetter)1 StartActor (im.actor.runtime.actors.messages.StartActor)1 PreferencesStorage (im.actor.runtime.storage.PreferencesStorage)1