KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > NotificationTask


1 /*_############################################################################
2   _##
3   _## SNMP4J-Agent - NotificationTask.java
4   _##
5   _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
6   _##
7   _## Licensed under the Apache License, Version 2.0 (the "License");
8   _## you may not use this file except in compliance with the License.
9   _## You may obtain a copy of the License at
10   _##
11   _## http://www.apache.org/licenses/LICENSE-2.0
12   _##
13   _## Unless required by applicable law or agreed to in writing, software
14   _## distributed under the License is distributed on an "AS IS" BASIS,
15   _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   _## See the License for the specific language governing permissions and
17   _## limitations under the License.
18   _##
19   _##########################################################################*/

20
21 package org.snmp4j.agent;
22
23 import org.snmp4j.event.*;
24 import org.snmp4j.smi.*;
25
26 /**
27  * The <code>NotificationTask</code> is a <code>Runnable</code> that sends
28  * a notifcation or a series of notifications/traps/informs - depending
29  * on the configuration associated with the supplied
30  * <code>NotificationOriginator</code>.
31  *
32  * @author Frank Fock
33  * @version 1.0
34  */

35 public class NotificationTask implements Runnable JavaDoc {
36
37   private NotificationOriginator notificationOriginator;
38   private OctetString context;
39   private OID notificationID;
40   private TimeTicks sysUpTime;
41   private VariableBinding[] vbs;
42   private ResponseEvent[] responses;
43
44   public NotificationTask(NotificationOriginator notificationOriginator,
45                           OctetString context,
46                           OID notificationID,
47                           TimeTicks sysUptime,
48                           VariableBinding[] vbs) {
49     this.notificationOriginator = notificationOriginator;
50     this.context = context;
51     this.notificationID = notificationID;
52     this.sysUpTime = sysUptime;
53     this.vbs = vbs;
54   }
55
56   /**
57    * Send the notification a notify this object afterwards.
58    */

59   public synchronized void run() {
60     if (sysUpTime != null) {
61       this.responses = (ResponseEvent[])
62           notificationOriginator.notify(context, notificationID,
63                                         sysUpTime, vbs);
64     }
65     else {
66       this.responses = (ResponseEvent[])
67           notificationOriginator.notify(context, notificationID, vbs);
68     }
69     notify();
70   }
71
72   public OctetString getContext() {
73     return context;
74   }
75
76   public OID getNotificationID() {
77     return notificationID;
78   }
79
80   public NotificationOriginator getNotificationOriginator() {
81     return notificationOriginator;
82   }
83
84   /**
85    * Returns an array of ResponseEvent instances. Since the
86    * <code>NotificationOriginator</code> determines on behalf of the
87    * SNMP-NOTIFICTON-MIB contents whether a notification is sent as
88    * trap/notification or as inform request, the returned array contains
89    * an element for each addressed target, but only a response PDU for
90    * inform targets.
91    * @return
92    * an array of ResponseEvent instances (informs) or <code>null</code>
93    * values (for traps/notifications).
94    */

95   public ResponseEvent[] getResponses() {
96     return responses;
97   }
98
99   public TimeTicks getSysUpTime() {
100     return sysUpTime;
101   }
102
103   public VariableBinding[] getVariableBindings() {
104     return vbs;
105   }
106 }
107
Popular Tags