public void invoke(NotificationContext changeContext) throws Exception
{
// This allows the listener to work with one change at a time
synchronized (_manager)
{
Builder keyBuilder = _accessor.keyBuilder();
long start = System.currentTimeMillis();
if (logger.isInfoEnabled())
{
logger.info(Thread.currentThread().getId() + " START:INVOKE "
// + changeContext.getPathChanged()
+ _path + " listener:" + _listener.getClass().getCanonicalName());
}
if (_changeType == IDEAL_STATE)
{
IdealStateChangeListener idealStateChangeListener =
(IdealStateChangeListener) _listener;
subscribeForChanges(changeContext, _path, true, true);
List<IdealState> idealStates = _accessor.getChildValues(keyBuilder.idealStates());
idealStateChangeListener.onIdealStateChange(idealStates, changeContext);
}
else if (_changeType == CONFIG)
{
ConfigChangeListener configChangeListener = (ConfigChangeListener) _listener;
subscribeForChanges(changeContext, _path, true, true);
List<InstanceConfig> configs =
_accessor.getChildValues(keyBuilder.instanceConfigs());
configChangeListener.onConfigChange(configs, changeContext);
}
else if (_changeType == LIVE_INSTANCE)
{
LiveInstanceChangeListener liveInstanceChangeListener =
(LiveInstanceChangeListener) _listener;
subscribeForChanges(changeContext, _path, true, true);
List<LiveInstance> liveInstances =
_accessor.getChildValues(keyBuilder.liveInstances());
liveInstanceChangeListener.onLiveInstanceChange(liveInstances, changeContext);
}
else if (_changeType == CURRENT_STATE)
{
CurrentStateChangeListener currentStateChangeListener;
currentStateChangeListener = (CurrentStateChangeListener) _listener;
subscribeForChanges(changeContext, _path, true, true);
String instanceName = PropertyPathConfig.getInstanceNameFromPath(_path);
String[] pathParts = _path.split("/");
// TODO: fix this
List<CurrentState> currentStates =
_accessor.getChildValues(keyBuilder.currentStates(instanceName,
pathParts[pathParts.length - 1]));
currentStateChangeListener.onStateChange(instanceName,
currentStates,
changeContext);
}
else if (_changeType == MESSAGE)
{
MessageListener messageListener = (MessageListener) _listener;
subscribeForChanges(changeContext, _path, true, false);
String instanceName = PropertyPathConfig.getInstanceNameFromPath(_path);
List<Message> messages =
_accessor.getChildValues(keyBuilder.messages(instanceName));
messageListener.onMessage(instanceName, messages, changeContext);
}
else if (_changeType == MESSAGES_CONTROLLER)
{
MessageListener messageListener = (MessageListener) _listener;
subscribeForChanges(changeContext, _path, true, false);
List<Message> messages =
_accessor.getChildValues(keyBuilder.controllerMessages());
messageListener.onMessage(_manager.getInstanceName(), messages, changeContext);
}
else if (_changeType == EXTERNAL_VIEW)
{
ExternalViewChangeListener externalViewListener =
(ExternalViewChangeListener) _listener;
subscribeForChanges(changeContext, _path, true, true);
List<ExternalView> externalViewList =
_accessor.getChildValues(keyBuilder.externalViews());
externalViewListener.onExternalViewChange(externalViewList, changeContext);
}
else if (_changeType == ChangeType.CONTROLLER)
{
ControllerChangeListener controllerChangelistener =
(ControllerChangeListener) _listener;
subscribeForChanges(changeContext, _path, true, false);
controllerChangelistener.onControllerChange(changeContext);
}
else if (_changeType == ChangeType.HEALTH)
{
HealthStateChangeListener healthStateChangeListener =
(HealthStateChangeListener) _listener;
subscribeForChanges(changeContext, _path, true, true); // TODO: figure out
// settings here
String instanceName = PropertyPathConfig.getInstanceNameFromPath(_path);
List<HealthStat> healthReportList =
_accessor.getChildValues(keyBuilder.healthReports(instanceName));
healthStateChangeListener.onHealthChange(instanceName,
healthReportList,
changeContext);
}