001/* 002 * Copyright 2010 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.ametys.web.alerts; 018 019import java.util.List; 020 021/** 022 * Alerts scheduler: launches a cron which sends the alerts each night. 023 * This scheduler is the same as the CMS' AlertScheduler, except it runs the web version of AlertEngine. 024 */ 025public class AlertScheduler extends org.ametys.cms.alerts.AlertScheduler 026{ 027 @Override 028 public void run() 029 { 030 AlertEngine alertEngine = new AlertEngine(); 031 032 try 033 { 034 // Initialize and configure the engine. 035 alertEngine.initialize(_manager, _context); 036 alertEngine.configure(_configuration); 037 } 038 catch (Exception e) 039 { 040 throw new RuntimeException("Unable to initialize the alerts engine", e); 041 } 042 043 // The thread will be started as daemon, as the scheduler is marked daemon itself. 044 new Thread(alertEngine, "AlertEngine").start(); 045 } 046 047 @Override 048 public void sendInstantAlerts(List<String> contentIds, String message) 049 { 050 AlertEngine alertEngine = new AlertEngine(contentIds, message); 051 052 try 053 { 054 // Initialize and configure the engine. 055 alertEngine.initialize(_manager, _context); 056 alertEngine.configure(_configuration); 057 } 058 catch (Exception e) 059 { 060 throw new RuntimeException("Unable to initialize the alerts engine", e); 061 } 062 063 // The thread will be started as daemon, as the scheduler is marked daemon itself. 064 new Thread(alertEngine, "AlertEngine").start(); 065 } 066 067}