Search in sources :

Example 1 with CategoryActiveList

use of cern.laser.business.data.CategoryActiveList in project ACS by ACS-Community.

the class ACSAlarmCacheImpl method updateCategoryActiveLists.

/**
	 * Update the CategoryActiveList for the alarm: all the CategoryActiveLists
	 * of the categories of the alarm will be updated.
	 * The alarmId is inserted or removed in the CategoryActiveList depending
	 * of the status of the alarm
	 * 
	 * @param alarm The alarm whose id must be inserted or removed for the
	 *     	        CategoryActiveLists of its categories
	 */
private void updateCategoryActiveLists(Alarm alarm) {
    if (alarm.getStatus() == null || alarm.getStatus().getActive() == null) {
        throw new IllegalArgumentException("Invalid alarm: status and/or status.active null");
    }
    boolean status = alarm.getStatus().getActive().booleanValue();
    String alarmId = alarm.getAlarmId();
    Iterator categoryIterator = alarm.getCategories().iterator();
    while (categoryIterator.hasNext()) {
        Integer categoryId = (Integer) ((Category) categoryIterator.next()).getCategoryId();
        CategoryActiveList catList = null;
        try {
            catList = getActiveListReference(categoryId);
        } catch (AlarmCacheException ace) {
            // In this implementation no exception can be thrown
            // by getActiveListReference
            // I write a message in case someone changes the things
            System.err.println("Exception " + ace.getMessage());
            ace.printStackTrace();
            continue;
        }
        if (status) {
            catList.addAlarm(alarmId);
        } else {
            catList.removeAlarm(alarmId);
        }
    }
}
Also used : CategoryActiveList(cern.laser.business.data.CategoryActiveList) Iterator(java.util.Iterator) AlarmCacheException(cern.laser.business.cache.AlarmCacheException)

Example 2 with CategoryActiveList

use of cern.laser.business.data.CategoryActiveList in project ACS by ACS-Community.

the class CoreServiceImpl method select.

//
// -- PRIVATE METHODS ---------------------------------------------
//
/*
   * (non-Javadoc)
   * 
   * @see cern.laser.business.ejb.CoreServiceSessionEJB#select(java.lang.Integer, java.lang.String)
   */
private void select(Integer categoryId, String clientId) throws LaserProcessingException {
    System.out.println("*** CoreServiceImpl::select: selecting category " + categoryId.toString() + " for client " + clientId);
    ProcessingController processingController = ProcessingController.getInstance();
    if (!processingController.isProcessing()) {
        throw new LaserProcessingException("server not initialized");
    }
    try {
        if (LOGGER.isInfoEnabled()) {
            Category category = categoryDAO.findCategory(categoryId);
            String category_path = category.getPath();
            LOGGER.info("requested category : " + category_path);
        }
        String destination = getClientRootTopic() + "." + clientId;
        CategoryActiveList active_list = alarmCache.getActiveListReference(categoryId);
        String[] active_alarms = active_list.getActiveAlarms();
        if (active_alarms.length > 0) {
            Collection init_alarms = new HashSet(active_alarms.length);
            for (int i = 0; i < active_alarms.length; i++) {
                Alarm alarm = alarmCache.getReference(active_alarms[i]);
                init_alarms.add(alarm);
            }
            LOGGER.info("found " + init_alarms.size() + " matching alarm(s)");
            alarmPublisher.sendInit(init_alarms, destination);
        }
    } catch (AlarmCacheException e) {
        System.err.println("*** Got an exception! " + e.getMessage());
        e.printStackTrace(System.out);
        System.err.println("*** Exception masked");
    //throw new EJBException("unable to select alarms", e);
    }
}
Also used : LaserProcessingException(cern.laser.business.LaserProcessingException) Category(cern.laser.business.data.Category) ProcessingController(cern.laser.business.ProcessingController) CategoryActiveList(cern.laser.business.data.CategoryActiveList) Alarm(cern.laser.business.data.Alarm) Collection(java.util.Collection) AlarmCacheException(cern.laser.business.cache.AlarmCacheException) HashSet(java.util.HashSet)

Example 3 with CategoryActiveList

use of cern.laser.business.data.CategoryActiveList in project ACS by ACS-Community.

the class ACSAlarmCacheImpl method getCategoryList.

/**
	 * Return the CategoryActiveList for the specified categoryId.
	 * If the CategoryActiveList does not exist than a new one is created and
	 * inserted in the activeList and then returned to the caller
	 * 
	 * @param categoryId The categoryId identifying the CategoryActiveList
	 * @return The CategoryActiveList for the specified categoryId
	 */
private CategoryActiveList getCategoryList(Integer categoryId) {
    if (activeLists.containsKey(categoryId)) {
        return activeLists.get(categoryId);
    } else {
        CategoryActiveList catList = new CategoryActiveList(categoryId);
        activeLists.put(categoryId, catList);
        return catList;
    }
}
Also used : CategoryActiveList(cern.laser.business.data.CategoryActiveList)

Example 4 with CategoryActiveList

use of cern.laser.business.data.CategoryActiveList in project ACS by ACS-Community.

the class ACSAlarmCacheImpl method getActiveListReference.

public CategoryActiveList getActiveListReference(Integer identifier) throws AlarmCacheException {
    lock.lock();
    try {
        if (activeLists.containsKey(identifier)) {
            return activeLists.get(identifier);
        } else {
            CategoryActiveList catList = new CategoryActiveList(identifier);
            activeLists.put(identifier, catList);
            return catList;
        }
    } finally {
        lock.unlock();
    }
}
Also used : CategoryActiveList(cern.laser.business.data.CategoryActiveList)

Aggregations

CategoryActiveList (cern.laser.business.data.CategoryActiveList)4 AlarmCacheException (cern.laser.business.cache.AlarmCacheException)2 LaserProcessingException (cern.laser.business.LaserProcessingException)1 ProcessingController (cern.laser.business.ProcessingController)1 Alarm (cern.laser.business.data.Alarm)1 Category (cern.laser.business.data.Category)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1