Search in sources :

Example 1 with NotifyServices

use of alma.acs.nsstatistics.NotifyServices in project ACS by ACS-Community.

the class nsStatisticsService method run.

/**
	 * 
	 */
public void run() {
    // 1min
    long acqFreq = ACQUISITION_FREQUENCY;
    // at least 1min		
    long logFreq = params.getFrequency();
    if (logFreq < acqFreq) {
        logger.log(AcsLogLevel.WARNING, "Statistics of Notification Services will be obtained with a very high frequency (less than 1 minute time interval)");
        acqFreq = logFreq;
    }
    logger.log(AcsLogLevel.INFO, "Acquisition frequency: " + String.valueOf(acqFreq) + "ms");
    logger.log(AcsLogLevel.INFO, "Log frequency: " + String.valueOf(logFreq) + "ms");
    acqFreq = acqFreq / MAIN_LOOP_FREQUENCY;
    logFreq = logFreq / MAIN_LOOP_FREQUENCY;
    boolean nsExists = false;
    long counter = 0;
    while (stop == false) {
        try {
            if (// Time to get statistics from the channels
            counter % acqFreq == 0) {
                nsExists = eventModel.getChannelStatistics();
                if (false == nsExists) {
                    setServicesStatus(Status.UNKNOWN);
                    if (eventModel.reconnectNamingService() == false) {
                        logger.log(AcsLogLevel.ERROR, "Naming Service is unreachable");
                    } else {
                        nsExists = true;
                    }
                // Calculate statistics
                } else {
                    // Get notify services 
                    NotifyServices ns = eventModel.getNotifyServicesRoot();
                    // Get services to be treated
                    List<NotifyServiceData> services = getCurrentServices();
                    // Get channels to be treated
                    List<ChannelData> channels = getCurrentChannels(ns);
                    // Update status of services and channels
                    updateStatus(services, channels);
                }
            }
            // It's time to log statistics
            if (true == nsExists && (counter + 1) % logFreq == 0) {
                // Log services and channels statistics
                logStatus();
                // After logging statistics, we have to reset them
                resetStats();
            }
        } catch (Exception e) {
            logger.warning("Notification Service doesn't exist!");
            String str = "";
            StackTraceElement[] stack = e.getStackTrace();
            for (int k = 0; k < stack.length; ++k) {
                str += stack[k] + "\n";
            }
            logger.warning(e.getMessage() + "\n" + str);
        }
        try {
            ++counter;
            sleep(MAIN_LOOP_FREQUENCY);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    logger.info("nsStatisticsService thread has been finished");
}
Also used : ChannelData(alma.acs.nsstatistics.ChannelData) NotifyServiceData(alma.acs.nsstatistics.NotifyServiceData) NotifyServices(alma.acs.nsstatistics.NotifyServices) AcsJException(alma.acs.exceptions.AcsJException)

Example 2 with NotifyServices

use of alma.acs.nsstatistics.NotifyServices in project ACS by ACS-Community.

the class nsStatisticsService method getCurrentServices.

/**
	 * Get current services to be treated
	 * @return List of services
	 */
protected List<NotifyServiceData> getCurrentServices() {
    NotifyServices ns = eventModel.getNotifyServicesRoot();
    List<NotifyServiceData> selServices = new ArrayList<NotifyServiceData>();
    List<NotifyServiceData> services = ns.getServices();
    if (params.getSelectedServicesChannels().isEmpty()) {
        return services;
    } else {
        NotifyServiceData service = null;
        for (Iterator<NotifyServiceData> it = services.iterator(); it.hasNext(); ) {
            service = it.next();
            if (params.getSelectedServicesChannels().containsKey(service.getName())) {
                selServices.add(service);
            }
        }
    }
    return selServices;
}
Also used : NotifyServiceData(alma.acs.nsstatistics.NotifyServiceData) ArrayList(java.util.ArrayList) NotifyServices(alma.acs.nsstatistics.NotifyServices)

Aggregations

NotifyServiceData (alma.acs.nsstatistics.NotifyServiceData)2 NotifyServices (alma.acs.nsstatistics.NotifyServices)2 AcsJException (alma.acs.exceptions.AcsJException)1 ChannelData (alma.acs.nsstatistics.ChannelData)1 ArrayList (java.util.ArrayList)1