엔티티에 대한 참조 제거

에이전트가 해당 바인드된 엔티티를 삭제하기 전에, 기타 에이전트에서 이 엔티티에 대한 모든 참조를 제거해야 합니다.

에이전트는 다양한 방식으로 엔티티에 대한 참조를 제거할 수 있습니다.

알림 이벤트의 생성

다음 패턴은 항공편 엔티티의 삭제를 예시합니다. 항공편 엔티티에는 출발 공항 및 도착 공항이 있습니다.

이벤트는 이 항공편을 제거할 수 있도록 외부 세계에서 전송됩니다. Flight 에이전트는 Remove Flight Event를 청취하며, 다음 규칙으로 이벤트를 처리합니다.

when a Remove Flight Event occurs
 then
 emit a new Removing Flight Event where the airport is the departure airport of 'the flight'; 
 emit a new Removing Flight Event where the airport is the arrival airport of 'the flight'; 

Airport 에이전트는 Removing Flight Event를 청취하며, 다음 규칙으로 이벤트를 처리합니다.

when a Removing Flight Event occurs
if	the departing flights of 'the airport' contain the flight of this Removing Flight Event
then	remove the flight of this Removing Flight Event from the departing flights of 'the airport';
	emit a new Flight Removed Event where the flight is the flight of this Removing Flight Event;
when a Removing Flight Event occurs
if	the arrival flights of 'the airport' contain the flight of this Removing Flight Event
then	remove the flight of this Removing Flight Event from the arrival flights of 'the airport'
	emit a new Flight Removed Event where the flight is the flight of this Removing Flight Event;

Flight 에이전트는 Flight Removed Event를 청취하며, 다음 규칙으로 이벤트를 처리합니다.

if	there are 2 Flight Removed Events 
then	set 'the flight' to null;

모든 에이전트에서 삭제 이벤트에 등록

엔티티에 대한 참조를 제거하는 다른 방법은 모든 에이전트가 삭제 이벤트에 등록하는 것입니다.

Flight 에이전트는 Remove Flight Event를 청취하며, 이벤트를 지연으로 처리합니다. 이 지연은 이 이벤트를 청취하는 기타 에이전트가 엔티티에 대한 참조를 제거하는 시간을 갖도록 보장합니다.

when a Remove Flight Event has occurred 1 minute ago
if	'the flight' is not null
then	set 'the flight' to null;

Airport 에이전트는 도착과 동시에 Remove Flight Event를 처리하며, 항공편에 대한 참조를 제거합니다.

when a Remove Flight Event occurs, called 'this event'
then
remove the flight of 'this event' from the departing flights of 'the airport';
remove the flight of 'this event' from the arrival flights of 'the airport';