KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > core > alert > source > NotificationAlertSource


1 /**
2 * Copyright (c) 2004-2005 jManage.org
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.source;
15
16 import org.jmanage.core.config.AlertSourceConfig;
17 import org.jmanage.core.management.*;
18 import org.jmanage.core.util.Loggers;
19 import org.jmanage.core.alert.AlertSource;
20 import org.jmanage.core.alert.AlertInfo;
21
22 import java.util.logging.Logger JavaDoc;
23 import java.util.logging.Level JavaDoc;
24 import java.io.IOException JavaDoc;
25
26 /**
27  *
28  * Date: Jul 31, 2005
29  * @author Rakesh Kalra
30  */

31 public class NotificationAlertSource extends AlertSource {
32
33     private static final Logger JavaDoc logger =
34             Loggers.getLogger(NotificationAlertSource.class);
35
36     private ObjectNotificationListener listener;
37     private ObjectNotificationFilterSupport filter;
38
39     public NotificationAlertSource(AlertSourceConfig sourceConfig){
40         super(sourceConfig);
41     }
42
43     protected void registerInternal() {
44
45         /* start looking for this notification */
46         listener = new ObjectNotificationListener(){
47             public void handleNotification(ObjectNotification notification,
48                                            Object JavaDoc handback) {
49                 try {
50                     NotificationAlertSource.this.handler.handle(
51                             new AlertInfo(notification));
52                 } catch (Exception JavaDoc e) {
53                     logger.log(Level.SEVERE, "Error while handling alert", e);
54                 }
55             }
56         };
57         filter = new ObjectNotificationFilterSupport();
58         filter.enableType(sourceConfig.getNotificationType());
59         connection.addNotificationListener(new ObjectName(sourceConfig.getObjectName()),
60                 listener, filter, null);
61     }
62
63     protected void unregisterInternal() {
64
65         assert connection != null;
66
67         try {
68             /* remove notification listener */
69             connection.removeNotificationListener(
70                     new ObjectName(sourceConfig.getObjectName()),
71                     listener, filter, null);
72         } catch (Exception JavaDoc e) {
73             logger.log(Level.WARNING,
74                     "Error while Removing Notification Listener. error: " +
75                     e.getMessage());
76         }
77
78         listener = null;
79         filter = null;
80     }
81 }
82
Popular Tags