Search in sources :

Example 1 with EventChannelFactory

use of org.omg.CosNotifyChannelAdmin.EventChannelFactory 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);
    }
}
Also used : ArrayList(java.util.ArrayList) AcsJException(alma.acs.exceptions.AcsJException) EventChannelFactory(org.omg.CosNotifyChannelAdmin.EventChannelFactory) NotificationServiceMonitorControl(gov.sandia.CosNotification.NotificationServiceMonitorControl) HashSet(java.util.HashSet)

Aggregations

AcsJException (alma.acs.exceptions.AcsJException)1 NotificationServiceMonitorControl (gov.sandia.CosNotification.NotificationServiceMonitorControl)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 EventChannelFactory (org.omg.CosNotifyChannelAdmin.EventChannelFactory)1