KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > management > alert > MailFilter


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.appserv.management.alert;
24
25 import javax.management.NotificationFilter JavaDoc;
26 import javax.management.Notification JavaDoc;
27
28 /**
29  * Class MailFilter by default filters out Warning messages.
30  *
31  * @AUTHOR: Hemanth Puttaswamy
32  */

33 public class MailFilter implements NotificationFilter JavaDoc {
34
35     private static String JavaDoc WARNING_LOG = "WarningLogMessages";
36
37     // SEVERE and WARNING messages are sent out as alerts. This filter
38
// is to filter out WARNING messages as Alerts as User by default
39
// may not be interested in recieving WARNING as alerts over e-mail
40
private boolean filterWarningMessages;
41
42     /**
43      * Zero arg constructor used by Alert Configuration Framework.
44      */

45     public MailFilter( ) {
46         filterWarningMessages = true;
47     }
48   
49     /**
50      * By Default Warning Log Messages are filtered out. If user is
51      * interested, filterWarningMessages can be set to false.
52      */

53     public void setFilterWarningMessages( boolean filter ) {
54         filterWarningMessages = filter;
55     }
56
57     boolean getFilterWarningMessages( ) {
58         return filterWarningMessages;
59     }
60
61     /**
62      * Implementation of javax.management.NotificationFilter method.
63      * Checks to see if WarningLogMessages need to be filtered or not.
64      */

65     public boolean isNotificationEnabled( Notification JavaDoc notification ) {
66         if( !filterWarningMessages ) return true;
67         return !notification.getType().equals( WARNING_LOG );
68     }
69
70     /**
71      * These are Unit Test Method provided for internal testing only.
72      */

73     public void setUnitTestData( String JavaDoc unitTestData ) {
74         new UnitTest(
75             UnitTest.UNIT_TEST_MAIL_FILTER, unitTestData, this ).start();
76     }
77 }
78
79
80
81
82
Popular Tags