Search in sources :

Example 1 with LaserObjectNotFoundException

use of cern.laser.business.LaserObjectNotFoundException 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)

Aggregations

LaserObjectNotFoundException (cern.laser.business.LaserObjectNotFoundException)1 AlarmCacheException (cern.laser.business.cache.AlarmCacheException)1 Alarm (cern.laser.business.data.Alarm)1