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;
}
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();
}
}
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);
}
}
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;
}
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);
}
Aggregations