Removendo referências a uma entidade
Antes que um agente exclua sua entidade de limite, todas as referências a essa entidade devem ser removidas de outros agenteS.
- Assinando eventos que os notificam sobre a exclusão da entidade, consulte Emissão de eventos de notificação.
- Assinando o mesmo evento de exclusão. O agente ligado à entidade deve processar o evento de exclusão com um atraso, consulte Assinatura de todos os agente para o evento de exclusão.
Emissão de eventos de notificação
O padrão a seguir ilustra a exclusão de uma entidade de voo. A entidade de voo tem um aeroporto de partida e um aeroporto de chegada.
Um evento para a remoção desse voo é enviado do mundo externo. Um agente Voo atende o Remove Flight Event e processa o evento na seguinte regra:
when a Remove Flight Event occurs
então
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';
Os agentes Aeroporto atendem Removing Flight Event e processam o evento na seguinte regra:
when a Removing Flight Event occurs
se
the departing flights of 'the airport' contain the flight of this Removing Flight Event
então
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
se
the arrival flights of 'the airport' contain the flight of this Removing Flight Event
então
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;
O agente Voo atende o Flight Removed Event e processa os eventos na seguinte regra:
se
there are 2 Flight Removed Events
então
set 'the flight' to null;
Assinatura de todos os agente para o evento de exclusão
Outra forma de remover as referências à entidade é fazendo com que todos os agentes assinem o evento de exclusão.
O agente Voo atende o Remove Flight Event e processa o evento com um atraso. Esse atraso assegura que outros agentes que atendem esse evento tenham tempo de remover a referência à entidade.
when a Remove Flight Event has occurred 1 minute ago
se
'the flight' is not null
então
set 'the flight' to null;
O agente Aeroporto processa o Remove Flight Event assim que ele chega e remove a referência ao voo.
when a Remove Flight Event occurs, called 'this event'
então
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';