use of gov.sandia.CosNotification.NotificationServiceMonitorControl in project ACS by ACS-Community.
the class EventModel method discoverNotifyServices.
/**
* Checks the naming service for notify service instances and stores / updates them in {@link #notifyServices}.
* This update does not include the NCs owned by the notify services, so that {@link #discoverChannels(Binding[])}
* should be called after this.
* <p>
* This method is broken out from {@link #discoverNotifyServicesAndChannels()} to make it more readable.
* It should be called only from there, to keep services and NCs aligned.
*
* @param bindingMap Name service bindings in the form key = bindingName, value = bindingKind
*/
private synchronized void discoverNotifyServices(Map<String, String> bindingMap) {
// used for local logging only
ArrayList<String> newNotifyServiceNames = new ArrayList<String>();
// used to detect services that have disappeared
Set<String> oldServiceIds = new HashSet<String>(notifyServices.keySet());
for (String bindingName : bindingMap.keySet()) {
String bindingKind = bindingMap.get(bindingName);
try {
// to skip NCs and other objects that have a non-empty kind field and by accident use the name ending of a notify service.
if (bindingName.endsWith(NOTIFICATION_FACTORY_NAME.value) && !bindingName.startsWith("MC_") && bindingKind.isEmpty()) {
NotifyServiceData notifyService = notifyServices.get(bindingName);
if (notifyService != null) {
// because that would slow down a GUI refresh too much. (For that we have 'unreachableServiceChecker' running.)
if (notifyService.isReachable()) {
updateReachability(notifyService);
}
// Reachable or not, we got this notify service again from the naming service, which means it was not properly removed.
oldServiceIds.remove(bindingName);
// Todo: Should we update the notify service reference, just in case it was relocated to another machine?
} else {
// Found a new notify service in the naming service
// We skip the manager for access to services, because since ACS 10.2 only specially registered services
// would be available in the get_service call and we want more flexibility for this special tool.
org.omg.CORBA.Object obj = resolveNotifyService(bindingName);
// We create a new NotifyServiceData object even if the service is currently unreachable,
// so that this problem becomes visible.
boolean isNewServiceReachable = isNotifyServiceReachable(obj, bindingName);
String displayName = simplifyNotifyServiceName(bindingName);
newNotifyServiceNames.add(displayName);
EventChannelFactory efact = null;
NotificationServiceMonitorControl nsmc = null;
if (isNewServiceReachable) {
efact = EventChannelFactoryHelper.narrow(obj);
try {
nsmc = resolveMonitorControl(bindingName);
} catch (Exception ex) {
m_logger.log(Level.WARNING, "Failed to obtain the MonitorControl object for service '" + bindingName + "'.");
throw ex;
}
}
NotifyServiceData notifyServiceData = new NotifyServiceData(displayName, bindingName, efact, nsmc, m_logger);
notifyServiceData.setReachable(isNewServiceReachable);
notifyServices.put(bindingName, notifyServiceData);
}
}
} catch (Exception ex) {
m_logger.log(Level.WARNING, "Failed to check / process service '" + bindingName + "'.", ex);
}
}
// Log changes for this round of service discovery
if (!newNotifyServiceNames.isEmpty()) {
Collections.sort(newNotifyServiceNames);
m_logger.info("Found " + newNotifyServiceNames.size() + " notify service instances: " + StringUtils.join(newNotifyServiceNames, ' '));
}
if (!oldServiceIds.isEmpty()) {
// These notify services were no longer listed in the naming service. This means they were properly shut down, as opposed to messed up.
String msg = "Removed " + oldServiceIds.size() + " notify service instances: ";
for (String oldServiceId : oldServiceIds) {
notifyServices.remove(oldServiceId);
msg += simplifyNotifyServiceName(oldServiceId) + ' ';
}
m_logger.info(msg);
}
}
use of gov.sandia.CosNotification.NotificationServiceMonitorControl in project ACS by ACS-Community.
the class EventModel method resolveMonitorControl.
/**
* Resolves the TAO monitor-control object that is bound in the naming service with the given name.
*/
private NotificationServiceMonitorControl resolveMonitorControl(String notifyBindingName) throws CannotProceed, org.omg.CosNaming.NamingContextPackage.InvalidName, NotFound {
String name = "MC_" + notifyBindingName;
NameComponent[] ncomp = new NameComponent[1];
ncomp[0] = new NameComponent(name, "");
NotificationServiceMonitorControl nsmc = NotificationServiceMonitorControlHelper.narrow(nctx.resolve(ncomp));
return nsmc;
}
use of gov.sandia.CosNotification.NotificationServiceMonitorControl in project ACS by ACS-Community.
the class ChannelStats method setData.
public void setData(ChannelData channel) {
NotificationServiceMonitorControl nsm = channel.getParent().getMc();
String[] statsNames = nsm.get_statistic_names();
String channelName = "Channel " + channel.getName() + " - ";
long oldestEvent = -1;
for (int i = 0; i < statsNames.length; ++i) {
try {
if (statsNames[i].contains("ConsumerCount")) {
Monitor.Numeric n = nsm.get_statistic(statsNames[i]).data_union.num();
setValue(N_CONSUMERS, (long) n.last);
} else if (statsNames[i].contains("SupplierCount")) {
Monitor.Numeric n = nsm.get_statistic(statsNames[i]).data_union.num();
setValue(N_SUPPLIERS, (long) n.last);
} else if (statsNames[i].contains("QueueSize")) {
// n.count, n.maximum, n.last, n.average, n.dlist[0].value, n.dlist[0].timestamp
Monitor.Numeric n = nsm.get_statistic(statsNames[i]).data_union.num();
setQueueSize(statsNames[i], (long) n.maximum, n.average);
} else if (statsNames[i].contains("QueueElementCount")) {
Monitor.Numeric n = nsm.get_statistic(statsNames[i]).data_union.num();
setQueueElementCount(statsNames[i], (long) n.maximum);
} else if (statsNames[i].contains("OldestEvent")) {
Monitor.Numeric n = nsm.get_statistic(statsNames[i]).data_union.num();
this.oldestEvent = (long) n.last;
} else if (statsNames[i].contains("SlowestConsumers")) {
String[] slowestConsumers = nsm.get_statistic(statsNames[i]).data_union.list();
setArrayValues(CURR_SLOWEST_CONSUMERS, currStringLists, slowestConsumers);
addArrayValues(ALL_SLOWEST_CONSUMERS, allStringLists, slowestConsumers);
setValue(N_SLOWEST_CONSUMERS, slowestConsumers.length);
} else if (statsNames[i].contains("SupplierNames")) {
String[] supplierNames = nsm.get_statistic(statsNames[i]).data_union.list();
setArrayValues(CURR_SUPPLIERS, currStringLists, supplierNames);
addArrayValues(ALL_SUPPLIERS, allStringLists, supplierNames);
} else if (statsNames[i].contains("ConsumerNames")) {
String[] consumerNames = nsm.get_statistic(statsNames[i]).data_union.list();
setArrayValues(CURR_CONSUMERS, currStringLists, consumerNames);
addArrayValues(ALL_CONSUMERS, allStringLists, consumerNames);
} else if (statsNames[i].contains("SupplierAdminNames")) {
String[] supplierAdminNames = nsm.get_statistic(statsNames[i]).data_union.list();
setArrayValues(CURR_SUPPLIERS_ADMIN, currStringLists, supplierAdminNames);
addArrayValues(ALL_SUPPLIERS_ADMIN, allStringLists, supplierAdminNames);
setValue(N_SUPPLIERS_ADMIN, supplierAdminNames.length);
} else if (statsNames[i].contains("ConsumerAdminNames")) {
String[] consumerAdminNames = nsm.get_statistic(statsNames[i]).data_union.list();
setArrayValues(CURR_CONSUMERS_ADMIN, currStringLists, consumerAdminNames);
addArrayValues(ALL_CONSUMERS_ADMIN, allStringLists, consumerAdminNames);
setValue(N_CONSUMERS_ADMIN, consumerAdminNames.length);
}
} catch (InvalidName ex) {
//logger.log(AcsLogLevel.ERROR, "Invalid name in ncStatisticsService::logMCStats", ex);
// TODO
}
}
iterationDone();
}
Aggregations