エンティティーへの参照の削除

エージェントがバインド・エンティティーを削除する前に、他のエージェントからこのエンティティーへのすべての参照を削除する必要があります。

エージェントは、次のようにさまざまな方法でエンティティーへの参照を削除することができます。

通知イベントの発行

以下のパターンは、フライト・エンティティーの削除を示しています。フライト・エンティティーには、出発空港と到着空港があります。

このフライトを削除するためのイベントは外界から送信されます。フライト・エージェントは、Remove Flight Event を listen し、以下のルールでイベントを処理します。

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'; 

空港エージェントは、Removing Flight Event を listen し、以下のルールでイベントを処理します。

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 Removed Event を listen し、以下のルールでイベントを処理します。

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

すべてのエージェントから削除イベントへのサブスクリプション

エンティティーへの参照を削除するもう 1 つの方法は、すべてのエージェントが削除イベントをサブスクライブすることです。

フライト・エージェントは、Remove Flight Event を listen し、遅延付きでイベントを処理します。この遅延により、このイベントを listen している他のエージェントは、エンティティーへの参照を削除するための時間を確保することができます。

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

空港エージェントは、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';