Skip to content
Samy Sadi edited this page Apr 7, 2018 · 1 revision

Overview

During a simulation, multiple events execute resulting in the alteration of the state and data of several entities. For instance, the execution of an application might be started and stopped, a storage disk may fail, etc. It usually hard to keep track of all those modifications as their origin may be tracked back to several different events. Thus, if you want to take a specific action, say when a storage disk fail, you would need to add your code directly inside the event that caused the failure or by modifying the storage disk entity, which is not really practical.

Fortunately, ACS defines a easy mechanism to achieve the same result while you use a clean and independent code in a separate class without having to alter any pre-existing entities or events, by using notifications.

A notification is defined by a numeral code and eventually some data. This notification is fired each time a specific action happens. For example, a notification for a storage disk failure is fired each time the storage disk entity fails. After, you can listen to this notification and take whatever action you need everytime it is fired by registering a NotificationListener.

ACS predefined notifications codes can be found in the NotificationCodes class. You can define your own notification codes, but please note that notification codes in the form of 0x8XXXXXXX are reserved.

Code example: registering a notification listener

// add a notification listener for a host failure
myHost.addListener(NotificationCodes.FAILURE_STATE_CHANGED, new NotificationListener() {
	@Override
	protected void notificationPerformed(Notifier notifier, int notification_code, Object data) {
		Host myHost = (Host) notifier;
		if (e.getFailureState() == FailureState.FAILED)
			Simulator.getSimulator().getLogger().log("The host just failed.");
	}
});