Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
titleResult

[INFO][2017-09-06 오전 4:53:45][Thread 0006][[akka://ServiceA/user/myactor#14600
16350]] BasicActor:GetSomeMessage 나는 살아있다.

[INFO][2017-09-06 오전 4:53:45][Thread 0004][[akka://ServiceA/user/watcher#11499
84538]] WatchActor:GetSomeMessage <Terminated>: [akka://ServiceA/user/myactor#14
60016350] - ExistenceConfirmed=True

[INFO][2017-09-06 오전 4:53:45][Thread 0004][[akka://ServiceA/user/watcher#11499
84538]] 감시대상이 사라짐


Forward message

...

No Format
target.Forward(result, Context);


tatget : 다른 액터
Context : me

다른액터로 받은 메시지를 전달할때 사용합니다.  이것은 라우터,로드밸런스,복제 등에서 유용하게 쓰입니다.


PoisonPill

...


No Format
myActor.Tell(PoisonPill.Instance, Sender);


메시지를 통해 액터를 멈추고자 할때 이용됩니다.


안전한 액터 종료(Graceful Stop)

...

 관리자 액터가 , 어떠한 액터를 감시하고있고, 모두 안전하게 종료후 자기자신도 마지막에

안전하게 종료할시 사용됩니다. 여기서 안전하다란 종료는 어플리케이션 레벨에서 설계해야하며

GracefulStop()은 종료시도와함께, 종속된 Actor( Watch에 등록된)가 모두 종료되었는가를 확인할수 있습니다. 

이것은 안전한 어플리케이션 종료시에 활용이됩니다.


Code Block
languagebash
themeEmacs
linenumberstrue
var manager = system.ActorOf<Manager>();

try
{
    await manager.GracefulStop(TimeSpan.FromMilliseconds(5), "shutdown");
    // the actor has been stopped
}
catch (TaskCanceledException)
{
    // the actor wasn't stopped within 5 seconds
}

...
public class Manager : UntypedActor
{
    private IActorRef worker = Context.Watch(Context.ActorOf<Cruncher>("worker"));

    protected override void OnReceive(object message)
    {
        switch (message)
        {
            case "job":
                worker.Tell("crunch");
                break;
            case Shutdown s:
                worker.Tell(PoisonPill.Instance, Self); //하위 worker의 작동을 중지시킵니다.
                Context.Become(ShuttingDown);
                break;
        }
    }

    private void ShuttingDown(object message)
    {
        switch (message)
        {
            case "job": //어떤 잡을 시키려고 할시,셧다운중임을 알립니다.
                Sender.Tell("service unavailable, shutting down", Self);
                break;
            case Terminated t:
                Context.Stop(Self);
                break;
        }
    }
}






액터접근 주소체계

...


잠시 실습없이, Actor를 접근하는 주소체계에대해 설명 드리겠습니다.  ActorPath는 총 4가지로 구분이 되며 

...