Blame | Last modification | View Log | RSS feed
package in.shop2020.alert.handler;import in.shop2020.alert.AlertMapper;import in.shop2020.alert.AlertService.Iface;import in.shop2020.alert.AlertServiceException;import in.shop2020.alert.AlertType;import in.shop2020.alert.AlertedEntity;import in.shop2020.alert.EntityType;import in.shop2020.alert.MonitoredEntity;import in.shop2020.alert.SearchFilter;import in.shop2020.alert.handler.EntityHandler;import java.util.List;import org.apache.thrift.TException;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class AlertServiceHandler implements Iface {private static Logger logger = LoggerFactory.getLogger(AlertServiceHandler.class);private EntityHandler entityHandler;private ApplicationContext context;public AlertServiceHandler() {logger.info("Creating context");context = new ClassPathXmlApplicationContext("context.xml");entityHandler = context.getBean(EntityHandler.class);}@Overridepublic void scheduleAlert(MonitoredEntity monitoredEntity)throws AlertServiceException, TException {entityHandler.scheduleAlert(monitoredEntity);}@Overridepublic void updateMonitoredObject(MonitoredEntity monitoredEntity)throws AlertServiceException, TException {entityHandler.updateMonitoredObject(monitoredEntity);}@Overridepublic void endMonitoringEntity(EntityType entityType, String key)throws AlertServiceException, TException {entityHandler.endMonitoring(entityType, key);}@Overridepublic List<MonitoredEntity> getEntities(SearchFilter searchFilter)throws AlertServiceException, TException {return entityHandler.getEntities(searchFilter);}@Overridepublic List<AlertedEntity> getAlertedEntities(SearchFilter searchFilter)throws AlertServiceException, TException {return entityHandler.getAlertedEntities(searchFilter);}@Overridepublic void registerEventType(AlertMapper alertMap)throws AlertServiceException, TException {entityHandler.registerEventType(alertMap);}@Overridepublic AlertMapper getAlertMapper(EntityType entityType, int eventType)throws AlertServiceException, TException {return entityHandler.getAlertMapper(entityType, eventType);}@Overridepublic void activateEntityMonitoring(EntityType entityType, String userIds)throws AlertServiceException, TException {entityHandler.activateEntityMonitoring(entityType, userIds);}@Overridepublic void deActivateEntityMonitoring(EntityType entityType)throws AlertServiceException, TException {entityHandler.deActivateEntityMonitoring(entityType);}@Overridepublic boolean isAlive() throws TException {try {return true;} catch (Exception e) {logger.error("Alert Service not running", e);return false;}}@Overridepublic void closeSession() throws TException {}public void setDataSourceUrl(String dbHost) {org.apache.commons.dbcp.BasicDataSource ds = (org.apache.commons.dbcp.BasicDataSource)context.getBean("dataSource");ds.setUrl(dbHost);}public String getDataSourceUrl() {org.apache.commons.dbcp.BasicDataSource ds = (org.apache.commons.dbcp.BasicDataSource)context.getBean("dataSource");return ds.getUrl();}}