KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > core > alert > delivery > EmailAlerts


1 /**
2 * Copyright (c) 2004-2005 jManage.org. All rights reserved.
3 *
4 * This is a free software; you can redistribute it and/or
5 * modify it under the terms of the license at
6 * http://www.jmanage.org.
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */

14 package org.jmanage.core.alert.delivery;
15
16 import org.jmanage.core.util.CoreUtils;
17 import org.jmanage.core.alert.AlertInfo;
18
19 import java.io.File JavaDoc;
20
21 /**
22  * Queue for Email Alerts. This queue is used when jManage is not able
23  * to deliver emails.
24  *
25  * <p>
26  * Date: Nov 6, 2005
27  * @author Rakesh Kalra
28  */

29 public class EmailAlerts extends PersistedAlerts{
30
31     private static final String JavaDoc EMAIL_ALERTS_FILE =
32             CoreUtils.getDataDir() + File.separator + "email-alerts.xml";
33
34     private static final EmailAlerts instance = new EmailAlerts();
35
36     public static EmailAlerts getInstance(){
37         return instance;
38     }
39
40     private EmailAlerts(){
41         new EmailDeliveryThread().start();
42     }
43
44     protected String JavaDoc getPersistedFileName() {
45         return EMAIL_ALERTS_FILE;
46     }
47
48     private class EmailDeliveryThread extends Thread JavaDoc{
49
50         EmailDelivery delivery = new EmailDelivery();
51
52         public void run(){
53             while(true){
54                 AlertInfo alertInfo = EmailAlerts.this.remove();
55                 if(alertInfo != null){
56                     // todo: if deliver method can return boolean on success
57
// we can change this to process all queued alerts
58
delivery.deliver(alertInfo);
59                 }
60                 try {
61                     /* sleep for a minute */
62                     sleep(60*1000);
63                 } catch (InterruptedException JavaDoc e) {
64                 }
65             }
66         }
67     }
68 }
69
Popular Tags