Search in sources :

Example 11 with AlarmCacheException

use of cern.laser.business.cache.AlarmCacheException in project ACS by ACS-Community.

the class CoreServiceImpl method getAlarmsByCategory.

/*
   * (non-Javadoc)
   * 
   * @see cern.laser.business.ejb.CoreServiceSessionEJB#getAlarmsByCategory(java.lang.Integer)
   */
public Collection getAlarmsByCategory(Integer categoryId) {
    Collection result = null;
    //    Category category = categoryDAO.getCategory(categoryId);
    //    if (category != null) {
    String[] alarms = categoryDAO.getAlarms(categoryId);
    result = new ArrayList(alarms.length);
    for (int i = 0; i < alarms.length; i++) {
        Alarm alarm;
        try {
            alarm = alarmCache.getReference(alarms[i]);
        } catch (AlarmCacheException e) {
            LOGGER.error("unable to get alarm " + alarms[i] + " from cache", e);
            throw new LaserRuntimeException("unable to get alarm " + alarms[i] + " from cache", e);
        }
        result.add(alarm);
    }
    return result;
}
Also used : Alarm(cern.laser.business.data.Alarm) ArrayList(java.util.ArrayList) Collection(java.util.Collection) AlarmCacheException(cern.laser.business.cache.AlarmCacheException) LaserRuntimeException(cern.laser.business.LaserRuntimeException)

Example 12 with AlarmCacheException

use of cern.laser.business.cache.AlarmCacheException in project ACS by ACS-Community.

the class ACSAlarmCacheImpl method getReference.

/**
	 * Get a reference to the alarm with the passed identifier.
	 * The alarm is searched in the configuration database delegating
	 * to the {@link ACSAlarmDAOImpl}.
	 * <P>
	 * If the alarm is not found then an alarm is built to be sent to the client
	 * but it is marked with a special property to identify it as a misconfigured 
	 * alarm. In the case of the alarm panel, such alarms will be displayed in a 
	 * dedicated tab.
	 * 
	 * @param identifier The ID of the alarm to get from the cache
	 */
public Alarm getReference(String identifier) throws AlarmCacheException {
    lock.lock();
    Alarm retAl;
    try {
        // Check the integrity of internal data structs
        if (alarms == null || dao == null) {
            System.err.println("*** ACSAlarmCache internal data corrupted!");
            throw new AlarmCacheException("ACSAlarmCache internal data corrupted!");
        }
        if (!alarms.containsKey(identifier)) {
            // Get the alarm from the database
            try {
                retAl = (Alarm) dao.findAlarm(identifier);
            } catch (LaserObjectNotFoundException lonfe) {
                // The alarm is not in the configuration database
                //
                // Built an alarm to be sent to the clients 
                // with an special property
                logger.finer(identifier + " is not in TM/CDB: building an unconfigured alarm");
                retAl = buildUnconfiguredAlarm(identifier);
            } catch (Throwable t) {
                System.err.println("*** Exception reading from CDB " + t.getMessage());
                throw new AlarmCacheException(t.getMessage());
            }
            if (retAl == null) {
                System.err.println("*** Alarm not found in database");
                throw new AlarmCacheException("Alarm not found in database");
            } else {
                // Add the alarm to the cache
                alarms.put(identifier, retAl);
            }
        } else {
            // Get the alarm from the cache
            retAl = alarms.get(identifier);
        }
        if (retAl == null) {
            System.err.println("*** Invalid Alarm");
            throw new AlarmCacheException("Invalid Alarm");
        }
        return retAl;
    } finally {
        lock.unlock();
    }
}
Also used : Alarm(cern.laser.business.data.Alarm) AlarmCacheException(cern.laser.business.cache.AlarmCacheException) LaserObjectNotFoundException(cern.laser.business.LaserObjectNotFoundException)

Example 13 with AlarmCacheException

use of cern.laser.business.cache.AlarmCacheException 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 14 with AlarmCacheException

use of cern.laser.business.cache.AlarmCacheException in project ACS by ACS-Community.

the class CoreServiceImpl method getMultiplicityThreshold.

/*
   * (non-Javadoc)
   * 
   * @see cern.laser.business.ejb.CoreServiceSessionEJB#getMultiplicityThreshold(java.lang.Integer)
   */
public Integer getMultiplicityThreshold(String parentId) {
    Integer result = new Integer(0);
    try {
        Alarm parent = alarmCache.getReference(parentId);
        result = parent.getMultiplicityThreshold();
    } catch (AlarmCacheException onf) {
        LOGGER.warn("multiplicity parent " + parentId + " not found");
    } catch (Exception e) {
        LOGGER.error("unable to get multiplicity threshold for " + parentId, e);
    //throw new EJBException("unable to get multiplicity threshold for " + parentId, e);
    }
    return result;
}
Also used : Alarm(cern.laser.business.data.Alarm) AlarmCacheException(cern.laser.business.cache.AlarmCacheException) LaserRuntimeException(cern.laser.business.LaserRuntimeException) LaserProcessingException(cern.laser.business.LaserProcessingException) AlarmCacheException(cern.laser.business.cache.AlarmCacheException)

Example 15 with AlarmCacheException

use of cern.laser.business.cache.AlarmCacheException in project ACS by ACS-Community.

the class CoreServiceImpl method archiveSearch.

/**
   * @param categoryIds
   * @param sql
   * @param clientId
   */
public void archiveSearch(Integer[] categoryIds, String sql, String clientId) {
    String destination = getSearchRootTopic() + "." + clientId;
    String category_constraints = buildCategorySQLFilter(categoryIds);
    String select_sql = "select alarm_id from alarm_definition where " + sql + " and alarm_id in " + "(select alarm_id from alarm_category where " + category_constraints + ")";
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("search sql " + select_sql);
    Collection search_result = alarmDAO.archiveSearch(select_sql);
    Collection found_alarms = new ArrayList(search_result.size());
    try {
        for (Iterator iter = search_result.iterator(); iter.hasNext(); ) {
            Alarm alarm = alarmCache.getReference((String) iter.next());
            found_alarms.add(alarm);
        }
    } catch (AlarmCacheException e) {
        throw new LaserRuntimeException("unable to search alarms", e);
    }
    alarmPublisher.sendSearch(found_alarms, destination);
}
Also used : Alarm(cern.laser.business.data.Alarm) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Collection(java.util.Collection) AlarmCacheException(cern.laser.business.cache.AlarmCacheException) LaserRuntimeException(cern.laser.business.LaserRuntimeException)

Aggregations

AlarmCacheException (cern.laser.business.cache.AlarmCacheException)15 Alarm (cern.laser.business.data.Alarm)14 Collection (java.util.Collection)10 ArrayList (java.util.ArrayList)9 LaserRuntimeException (cern.laser.business.LaserRuntimeException)8 LaserProcessingException (cern.laser.business.LaserProcessingException)6 Category (cern.laser.business.data.Category)3 Iterator (java.util.Iterator)3 AdminUser (cern.laser.business.data.AdminUser)2 CategoryActiveList (cern.laser.business.data.CategoryActiveList)2 LaserDefinitionNotAllowedException (cern.laser.business.definition.LaserDefinitionNotAllowedException)2 LaserDefinitionNotFoundException (cern.laser.business.definition.LaserDefinitionNotFoundException)2 LaserDefinitionNotValidException (cern.laser.business.definition.LaserDefinitionNotValidException)2 LaserObjectNotFoundException (cern.laser.business.LaserObjectNotFoundException)1 ProcessingController (cern.laser.business.ProcessingController)1 LaserDefinitionDuplicationException (cern.laser.business.definition.LaserDefinitionDuplicationException)1 HashSet (java.util.HashSet)1