Page History
...
UI를 업데이트할수있는 전용 Dispatcher 입니다.
...
TEST1-액터내에서 블락킹되는경우
...
| Code Block | ||||||||
|---|---|---|---|---|---|---|---|---|
| ||||||||
public class ReActor : ReceiveActor
{
private ILoggingAdapter log = Context.GetLogger();
public ReActor()
{
Receive<string>(message => {
if(message == "slow") //slow메시지를 받으면, 지연시킵니다.(테스트 지연코드)
{
Task.Delay(500).Wait();
}
string reply = string.Format("I'am {0} RE:{1}", Self.Path, message);
log.Info(reply);
Sender.Tell(reply);
});
}
} |
...
이와같은 전력을 통해 스레드수분리가 가능합니다. ( 기본 메시지처리기에 부하를 분리)
적용2-ACTOR내에서 논블럭킹처리
...
RestAPI를 대신하여 호출해주는 Actor 설계시 다음과 같은 조건을 가집니다.
- 결과에따른 호출 순서 상관없음
- Actor Task에서 분리되어 , RestAPI 결과값을 반환해야함
- 성능을 위해 동시에 실행
C#의 비동기 프로그래밍의 힘을 빌려 Task에 완료된 비동기처리를 Pipe로 연결하여
결과가 완료되면, 완료 처리를 하게 합니다.
| Code Block | ||||||
|---|---|---|---|---|---|---|
| ||||||
public class DelayReply { public string message; } public class ReActor : ReceiveActor { private ILoggingAdapter log = Context.GetLogger(); public ReActor() { string myPath = Self.Path.ToString(); Receive<string>(message => { Handle(message); }); Receive<DelayReply>(message => { Handle(message); }); } public void Handle(string str) //InMessage { Task.Run(async () => { await Task.Delay(1000); //어떠한 값을 기다림 DelayReply reply = new DelayReply(); reply.message = str; return reply; }).PipeTo(Self); } public void Handle(DelayReply data) //Out { string logtrace = string.Format("I'am {0} RE:{1}", Self.Path, data.message); log.Info(data.message); Sender.Tell(data); } } |