docs: @SuppressWarnings({"checkstyle:npathcomplexity"})
  	protected void fireAgentDestroyed(Agent agent) {
  		final ListenerCollection<SpawnServiceListener> list;
  		synchronized (getAgentLifecycleListenerMutex()) {
  			list = this.agentLifecycleListeners.get(agent.getID());
  		}
  		final SpawnServiceListener[] ilisteners;
  		if (list != null) {
  			ilisteners = list.getListeners(SpawnServiceListener.class);
  		} else {
  			ilisteners = null;
  		}
  		final SpawnServiceListener[] ilisteners2 = this.globalListeners.getListeners(SpawnServiceListener.class);
  		// Retrieve the agent's contexts
  		final List<Pair<AgentContext, Address>> contextRegistrations = new ArrayList<>();
  		try {
  			final SynchronizedIterable<AgentContext> allContexts = BuiltinCapacityUtil.getContextsOf(agent);
  			synchronized (allContexts.mutex()) {
  				for (final AgentContext context : allContexts) {
  					final EventSpace defSpace = context.getDefaultSpace();
  					final Address address = defSpace.getAddress(agent.getID());
  					contextRegistrations.add(Pair.of(context, address));
  				}
  			}
  		} catch (RuntimeException e) {
  			throw e;
  		} catch (Exception e) {
  			throw new RuntimeException(e);
  		}
  		// Local agent and framework destruction
  		if (ilisteners != null) {
  			for (final SpawnServiceListener l : ilisteners) {
  				l.agentDestroy(agent);
  			}
  		}
  		for (final SpawnServiceListener l : ilisteners2) {
  			l.agentDestroy(agent);
  		}
  		// Fire AgentKilled into the associated contexts
  		try {
  			final UUID killedAgentId = agent.getID();
  			final Scope<Address> scope = address -> {
  				final UUID receiver = address.getUUID();
  				return !receiver.equals(killedAgentId);
  			};
  			final String killedAgentType = agent.getClass().getName();
  			for (final Pair<AgentContext, Address> registration : contextRegistrations) {
  				final EventSpace defSpace = registration.getKey().getDefaultSpace();
  				defSpace.emit(
  						// No need to give an event source because it is explicitly set below.
  						null,
  						new AgentKilled(
  								registration.getValue(), killedAgentId, killedAgentType),
  						scope);
  			}
  		} catch (RuntimeException e) {
  			throw e;
  		} catch (Exception e) {
  			throw new RuntimeException(e);
  		}
  	}