KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > mo > snmp4j > example > Snmp4jHeartbeatMib


1 /*_############################################################################
2   _##
3   _## SNMP4J-Agent - Snmp4jHeartbeatMib.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 //--AgentGen BEGIN=_BEGIN
22
package org.snmp4j.agent.mo.snmp4j.example;
23 //--AgentGen END
24

25 import org.snmp4j.smi.*;
26 import org.snmp4j.mp.SnmpConstants;
27 import org.snmp4j.agent.*;
28 import org.snmp4j.agent.mo.*;
29 import org.snmp4j.agent.mo.snmp.*;
30 import org.snmp4j.agent.mo.snmp.smi.*;
31 import org.snmp4j.agent.request.*;
32 import org.snmp4j.log.LogFactory;
33 import org.snmp4j.log.LogAdapter;
34 import java.util.Timer JavaDoc;
35 import java.util.GregorianCalendar JavaDoc;
36 import java.util.Calendar JavaDoc;
37 import java.util.TimerTask JavaDoc;
38 import org.snmp4j.agent.mo.snmp4j.example.Snmp4jHeartbeatMib.
39
    Snmp4jAgentHBCtrlEntryRow;
40 import org.snmp4j.agent.mo.snmp4j.example.Snmp4jHeartbeatMib.HeartbeatTask;
41 import org.snmp4j.PDU;
42 import java.util.Date JavaDoc;
43 import org.snmp4j.agent.io.MOInput;
44 import java.io.IOException JavaDoc;
45 import org.snmp4j.agent.io.MOOutput;
46
47 //--AgentGen BEGIN=_IMPORT
48
//--AgentGen END
49

50 public class Snmp4jHeartbeatMib
51 //--AgentGen BEGIN=_EXTENDS
52
//--AgentGen END
53
implements MOGroup
54 //--AgentGen BEGIN=_IMPLEMENTS
55
, RowStatusListener,
56     MOTableRowListener
57 //--AgentGen END
58
{
59
60   private static final LogAdapter LOGGER =
61       LogFactory.getLogger(Snmp4jHeartbeatMib.class);
62
63 //--AgentGen BEGIN=_STATIC
64
//--AgentGen END
65

66   // Factory
67
private static MOFactory moFactory = DefaultMOFactory.getInstance();
68
69   // Constants
70
public static final OID oidSnmp4jAgentHBRefTime =
71       new OID(new int[] {1, 3, 6, 1, 4, 1, 4976, 10, 1, 1, 42, 2, 1, 1, 0});
72   public static final OID oidSnmp4jAgentHBEvent =
73       new OID(new int[] {1, 3, 6, 1, 4, 1, 4976, 10, 1, 1, 42, 2, 2, 0, 1});
74   public static final OID oidTrapVarSnmp4jAgentHBCtrlEvents =
75       new OID(new int[] {1, 3, 6, 1, 4, 1, 4976, 10, 1, 1, 42, 2, 1, 2, 1, 6});
76
77
78   // Enumerations
79

80   public static final class Snmp4jAgentHBCtrlStorageTypeEnum {
81     /* -- eh? */
82     public static final int other = 1;
83     /* -- e.g., in RAM */
84     public static final int _volatile = 2;
85     /* -- e.g., in NVRAM */
86     public static final int nonVolatile = 3;
87     /* -- e.g., partially in ROM */
88     public static final int permanent = 4;
89     /* -- e.g., completely in ROM */
90     public static final int readOnly = 5;
91   }
92   public static final class Snmp4jAgentHBCtrlRowStatusEnum {
93     public static final int active = 1;
94     /* -- the following value is a state:
95 -- this value may be read, but not written */

96     public static final int notInService = 2;
97     /* -- the following three values are
98 -- actions: these values may be written,
99 -- but are never read */

100     public static final int notReady = 3;
101     public static final int createAndGo = 4;
102     public static final int createAndWait = 5;
103     public static final int destroy = 6;
104   }
105
106   // TextualConventions
107
private static final String JavaDoc TC_MODULE_SNMPV2_TC = "SNMPv2-TC";
108   private static final String JavaDoc TC_DATEANDTIME = "DateAndTime";
109
110   // Scalars
111
private MOScalar snmp4jAgentHBRefTime;
112
113   // Tables
114
public static final OID oidSnmp4jAgentHBCtrlEntry =
115       new OID(new int[] {1, 3, 6, 1, 4, 1, 4976, 10, 1, 1, 42, 2, 1, 2, 1});
116
117   // Column sub-identifer defintions for snmp4jAgentHBCtrlEntry:
118
public static final int colSnmp4jAgentHBCtrlStartTime = 2;
119   public static final int colSnmp4jAgentHBCtrlDelay = 3;
120   public static final int colSnmp4jAgentHBCtrlPeriod = 4;
121   public static final int colSnmp4jAgentHBCtrlMaxEvents = 5;
122   public static final int colSnmp4jAgentHBCtrlEvents = 6;
123   public static final int colSnmp4jAgentHBCtrlLastChange = 7;
124   public static final int colSnmp4jAgentHBCtrlStorageType = 8;
125   public static final int colSnmp4jAgentHBCtrlRowStatus = 9;
126
127   // Column index defintions for snmp4jAgentHBCtrlEntry:
128
public static final int idxSnmp4jAgentHBCtrlStartTime = 0;
129   public static final int idxSnmp4jAgentHBCtrlDelay = 1;
130   public static final int idxSnmp4jAgentHBCtrlPeriod = 2;
131   public static final int idxSnmp4jAgentHBCtrlMaxEvents = 3;
132   public static final int idxSnmp4jAgentHBCtrlEvents = 4;
133   public static final int idxSnmp4jAgentHBCtrlLastChange = 5;
134   public static final int idxSnmp4jAgentHBCtrlStorageType = 6;
135   public static final int idxSnmp4jAgentHBCtrlRowStatus = 7;
136
137   private static final MOTableSubIndex[] snmp4jAgentHBCtrlEntryIndexes =
138       new MOTableSubIndex[] {
139       moFactory.createSubIndex(SMIConstants.SYNTAX_OCTET_STRING, 1, 32)
140   };
141
142   private static final MOTableIndex snmp4jAgentHBCtrlEntryIndex =
143       moFactory.createIndex(snmp4jAgentHBCtrlEntryIndexes,
144                             true,
145                             new MOTableIndexValidator() {
146     public boolean isValidIndex(OID index) {
147       boolean isValidIndex = true;
148       //--AgentGen BEGIN=snmp4jAgentHBCtrlEntry::isValidIndex
149
//--AgentGen END
150
return isValidIndex;
151     }
152   });
153
154   private MOTable snmp4jAgentHBCtrlEntry;
155   private MOMutableTableModel snmp4jAgentHBCtrlEntryModel;
156
157 //--AgentGen BEGIN=_MEMBERS
158
private static final int[] PROTECTED_COLS =
159       {
160       idxSnmp4jAgentHBCtrlStartTime,
161       idxSnmp4jAgentHBCtrlDelay,
162       idxSnmp4jAgentHBCtrlPeriod
163   };
164
165   private Timer JavaDoc heartbeatTimer = new Timer JavaDoc();
166   private int heartbeatOffset = 0;
167   private NotificationOriginator notificationOriginator;
168   private OctetString context;
169   private SysUpTime sysUpTime;
170 //--AgentGen END
171

172   private Snmp4jHeartbeatMib() {
173     snmp4jAgentHBRefTime =
174         new Snmp4jAgentHBRefTime(oidSnmp4jAgentHBRefTime,
175                                  MOAccessImpl.ACCESS_READ_WRITE);
176     snmp4jAgentHBRefTime.addMOValueValidationListener(new
177         Snmp4jAgentHBRefTimeValidator());
178     createSnmp4jAgentHBCtrlEntry();
179 //--AgentGen BEGIN=_DEFAULTCONSTRUCTOR
180
((RowStatus) snmp4jAgentHBCtrlEntry.getColumn(idxSnmp4jAgentHBCtrlRowStatus)).
181         addRowStatusListener(this);
182     snmp4jAgentHBCtrlEntry.addMOTableRowListener(this);
183 //--AgentGen END
184
}
185
186 //--AgentGen BEGIN=_CONSTRUCTORS
187
public Snmp4jHeartbeatMib(NotificationOriginator notificationOriginator,
188                             OctetString context, SysUpTime upTime) {
189     this();
190
191     this.notificationOriginator = notificationOriginator;
192     this.context = context;
193     this.sysUpTime = upTime;
194     // make sure that the heartbeat timer related objects are not modified
195
// while row is active:
196
for (int i=0; i<PROTECTED_COLS.length; i++) {
197       ((MOMutableColumn)
198        snmp4jAgentHBCtrlEntry.getColumn(i)).setMutableInService(false);
199     }
200   }
201
202 //--AgentGen END
203

204
205   public MOTable getSnmp4jAgentHBCtrlEntry() {
206     return snmp4jAgentHBCtrlEntry;
207   }
208
209   private void createSnmp4jAgentHBCtrlEntry() {
210     MOColumn[] snmp4jAgentHBCtrlEntryColumns = new MOColumn[8];
211     snmp4jAgentHBCtrlEntryColumns[idxSnmp4jAgentHBCtrlStartTime] =
212         new DateAndTime(colSnmp4jAgentHBCtrlStartTime,
213                         MOAccessImpl.ACCESS_READ_CREATE,
214                         null);
215     ValueConstraint snmp4jAgentHBCtrlStartTimeVC = new ConstraintsImpl();
216     ((ConstraintsImpl) snmp4jAgentHBCtrlStartTimeVC).add(new Constraint(8, 8));
217     ((ConstraintsImpl) snmp4jAgentHBCtrlStartTimeVC).add(new Constraint(11, 11));
218     ((MOMutableColumn) snmp4jAgentHBCtrlEntryColumns[
219      idxSnmp4jAgentHBCtrlStartTime]).
220         addMOValueValidationListener(new ValueConstraintValidator(
221         snmp4jAgentHBCtrlStartTimeVC));
222     ((MOMutableColumn) snmp4jAgentHBCtrlEntryColumns[
223      idxSnmp4jAgentHBCtrlStartTime]).
224         addMOValueValidationListener(new Snmp4jAgentHBCtrlStartTimeValidator());
225     snmp4jAgentHBCtrlEntryColumns[idxSnmp4jAgentHBCtrlDelay] =
226         new MOMutableColumn(colSnmp4jAgentHBCtrlDelay,
227                             SMIConstants.SYNTAX_GAUGE32,
228                             MOAccessImpl.ACCESS_READ_CREATE,
229                             new UnsignedInteger32(1000));
230     ((MOMutableColumn) snmp4jAgentHBCtrlEntryColumns[idxSnmp4jAgentHBCtrlDelay]).
231         addMOValueValidationListener(new Snmp4jAgentHBCtrlDelayValidator());
232     snmp4jAgentHBCtrlEntryColumns[idxSnmp4jAgentHBCtrlPeriod] =
233         new MOMutableColumn(colSnmp4jAgentHBCtrlPeriod,
234                             SMIConstants.SYNTAX_GAUGE32,
235                             MOAccessImpl.ACCESS_READ_CREATE,
236                             new UnsignedInteger32(60000));
237     ((MOMutableColumn) snmp4jAgentHBCtrlEntryColumns[idxSnmp4jAgentHBCtrlPeriod]).
238         addMOValueValidationListener(new Snmp4jAgentHBCtrlPeriodValidator());
239     snmp4jAgentHBCtrlEntryColumns[idxSnmp4jAgentHBCtrlMaxEvents] =
240       new MOMutableColumn(colSnmp4jAgentHBCtrlMaxEvents,
241                           SMIConstants.SYNTAX_GAUGE32,
242                           MOAccessImpl.ACCESS_READ_CREATE,
243                           new UnsignedInteger32(0));
244     snmp4jAgentHBCtrlEntryColumns[idxSnmp4jAgentHBCtrlEvents] =
245       moFactory.createColumn(colSnmp4jAgentHBCtrlEvents,
246                              SMIConstants.SYNTAX_COUNTER64,
247                              MOAccessImpl.ACCESS_READ_ONLY);
248     snmp4jAgentHBCtrlEntryColumns[idxSnmp4jAgentHBCtrlLastChange] =
249         moFactory.createColumn(colSnmp4jAgentHBCtrlLastChange,
250                                SMIConstants.SYNTAX_TIMETICKS,
251                                MOAccessImpl.ACCESS_READ_ONLY);
252     snmp4jAgentHBCtrlEntryColumns[idxSnmp4jAgentHBCtrlEvents] =
253         moFactory.createColumn(colSnmp4jAgentHBCtrlEvents,
254                                SMIConstants.SYNTAX_COUNTER64,
255                                MOAccessImpl.ACCESS_READ_ONLY);
256     snmp4jAgentHBCtrlEntryColumns[idxSnmp4jAgentHBCtrlStorageType] =
257         new StorageType(colSnmp4jAgentHBCtrlStorageType,
258                         MOAccessImpl.ACCESS_READ_CREATE,
259                         new Integer32(3));
260     ValueConstraint snmp4jAgentHBCtrlStorageTypeVC = new EnumerationConstraint(
261         new int[] {Snmp4jAgentHBCtrlStorageTypeEnum.other,
262         Snmp4jAgentHBCtrlStorageTypeEnum._volatile,
263         Snmp4jAgentHBCtrlStorageTypeEnum.nonVolatile,
264         Snmp4jAgentHBCtrlStorageTypeEnum.permanent,
265         Snmp4jAgentHBCtrlStorageTypeEnum.readOnly});
266     ((MOMutableColumn)snmp4jAgentHBCtrlEntryColumns[idxSnmp4jAgentHBCtrlStorageType]).
267       addMOValueValidationListener(new ValueConstraintValidator(snmp4jAgentHBCtrlStorageTypeVC));
268     snmp4jAgentHBCtrlEntryColumns[idxSnmp4jAgentHBCtrlRowStatus] =
269         new RowStatus(colSnmp4jAgentHBCtrlRowStatus);
270     ValueConstraint snmp4jAgentHBCtrlRowStatusVC = new EnumerationConstraint(
271         new int[] {Snmp4jAgentHBCtrlRowStatusEnum.active,
272         Snmp4jAgentHBCtrlRowStatusEnum.notInService,
273         Snmp4jAgentHBCtrlRowStatusEnum.notReady,
274         Snmp4jAgentHBCtrlRowStatusEnum.createAndGo,
275         Snmp4jAgentHBCtrlRowStatusEnum.createAndWait,
276         Snmp4jAgentHBCtrlRowStatusEnum.destroy});
277     ((MOMutableColumn)snmp4jAgentHBCtrlEntryColumns[idxSnmp4jAgentHBCtrlRowStatus]).
278       addMOValueValidationListener(new ValueConstraintValidator(snmp4jAgentHBCtrlRowStatusVC));
279
280     snmp4jAgentHBCtrlEntryModel = new DefaultMOMutableTableModel();
281     snmp4jAgentHBCtrlEntryModel.setRowFactory(new Snmp4jAgentHBCtrlEntryRowFactory());
282     snmp4jAgentHBCtrlEntry =
283         moFactory.createTable(oidSnmp4jAgentHBCtrlEntry,
284                               snmp4jAgentHBCtrlEntryIndex,
285                               snmp4jAgentHBCtrlEntryColumns,
286                               snmp4jAgentHBCtrlEntryModel);
287   }
288
289   public void registerMOs(MOServer server, OctetString context) throws
290       DuplicateRegistrationException {
291     // Scalar Objects
292
server.register(this.snmp4jAgentHBRefTime, context);
293     server.register(this.snmp4jAgentHBCtrlEntry, context);
294 //--AgentGen BEGIN=_registerMOs
295
//--AgentGen END
296
}
297
298   public void unregisterMOs(MOServer server, OctetString context) {
299     // Scalar Objects
300
server.unregister(this.snmp4jAgentHBRefTime, context);
301     server.unregister(this.snmp4jAgentHBCtrlEntry, context);
302 //--AgentGen BEGIN=_unregisterMOs
303
//--AgentGen END
304
}
305
306   // Notifications
307
public void snmp4jAgentHBEvent(NotificationOriginator notificationOriginator,
308                                  OctetString context, VariableBinding[] vbs) {
309     if (vbs.length < 1) {
310       throw new IllegalArgumentException JavaDoc("Too few notification objects: " +
311                                          vbs.length + "<1");
312     }
313     if (!(vbs[0].getOid().startsWith(oidTrapVarSnmp4jAgentHBCtrlEvents))) {
314       throw new IllegalArgumentException JavaDoc("Variable 0 has wrong OID: " +
315                                          vbs[0].getOid() +
316                                          " does not start with " +
317                                          oidTrapVarSnmp4jAgentHBCtrlEvents);
318     }
319     if (!snmp4jAgentHBCtrlEntryIndex.isValidIndex(snmp4jAgentHBCtrlEntry.
320                                                   getIndexPart(vbs[0].getOid()))) {
321       throw new IllegalArgumentException JavaDoc(
322           "Illegal index for variable 0 specified: " +
323           snmp4jAgentHBCtrlEntry.getIndexPart(vbs[0].getOid()));
324     }
325     notificationOriginator.notify(context, oidSnmp4jAgentHBEvent, vbs);
326   }
327
328   // Scalars
329
public class Snmp4jAgentHBRefTime extends DateAndTimeScalar {
330     Snmp4jAgentHBRefTime(OID oid, MOAccess access) {
331       super(oid, access, new OctetString());
332 //--AgentGen BEGIN=snmp4jAgentHBRefTime
333
//--AgentGen END
334
}
335
336     public int isValueOK(SubRequest request) {
337       Variable newValue =
338           request.getVariableBinding().getVariable();
339       int valueOK = super.isValueOK(request);
340       if (valueOK != SnmpConstants.SNMP_ERROR_SUCCESS) {
341         return valueOK;
342       }
343       OctetString os = (OctetString) newValue;
344       if (!(((os.length() >= 8) && (os.length() <= 8)) ||
345             ((os.length() >= 11) && (os.length() <= 11)))) {
346         valueOK = SnmpConstants.SNMP_ERROR_WRONG_LENGTH;
347       }
348       //--AgentGen BEGIN=snmp4jAgentHBRefTime::isValueOK
349
//--AgentGen END
350
return valueOK;
351     }
352
353     public Variable getValue() {
354       //--AgentGen BEGIN=snmp4jAgentHBRefTime::getValue
355
GregorianCalendar JavaDoc gc = new GregorianCalendar JavaDoc();
356       gc.add(Calendar.MILLISECOND, heartbeatOffset);
357       super.setValue(DateAndTime.makeDateAndTime(gc));
358       //--AgentGen END
359
return super.getValue();
360     }
361
362     public int setValue(Variable newValue) {
363       //--AgentGen BEGIN=snmp4jAgentHBRefTime::setValue
364
GregorianCalendar JavaDoc gc = DateAndTime.makeCalendar((OctetString) newValue);
365       GregorianCalendar JavaDoc curGC = new GregorianCalendar JavaDoc();
366       heartbeatOffset = (int) (gc.getTimeInMillis() - curGC.getTimeInMillis());
367       //--AgentGen END
368
return super.setValue(newValue);
369     }
370
371     //--AgentGen BEGIN=snmp4jAgentHBRefTime::_METHODS
372
public void load(MOInput input) throws IOException JavaDoc {
373       heartbeatOffset = ((Integer32)input.readVariable()).getValue();
374     }
375
376     public void save(MOOutput output) throws IOException JavaDoc {
377       output.writeVariable(new Integer32(heartbeatOffset));
378     }
379     //--AgentGen END
380

381   }
382
383   // Value Validators
384
/**
385    * The <code>Snmp4jAgentHBRefTimeValidator</code> implements the value
386    * validation for <code>Snmp4jAgentHBRefTime</code>.
387    */

388   static class Snmp4jAgentHBRefTimeValidator implements
389       MOValueValidationListener {
390
391     public void validate(MOValueValidationEvent validationEvent) {
392       Variable newValue = validationEvent.getNewValue();
393       OctetString os = (OctetString) newValue;
394       if (!(((os.length() >= 8) && (os.length() <= 8)) ||
395             ((os.length() >= 11) && (os.length() <= 11)))) {
396         validationEvent.setValidationStatus(SnmpConstants.
397                                             SNMP_ERROR_WRONG_LENGTH);
398         return;
399       }
400       //--AgentGen BEGIN=snmp4jAgentHBRefTime::validate
401
//--AgentGen END
402
}
403   }
404
405   /**
406    * The <code>Snmp4jAgentHBCtrlStartTimeValidator</code> implements the value
407    * validation for <code>Snmp4jAgentHBCtrlStartTime</code>.
408    */

409   static class Snmp4jAgentHBCtrlStartTimeValidator implements
410       MOValueValidationListener {
411
412     public void validate(MOValueValidationEvent validationEvent) {
413       Variable newValue = validationEvent.getNewValue();
414       OctetString os = (OctetString) newValue;
415       if (!(((os.length() >= 8) && (os.length() <= 8)) ||
416             ((os.length() >= 11) && (os.length() <= 11)))) {
417         validationEvent.setValidationStatus(SnmpConstants.
418                                             SNMP_ERROR_WRONG_LENGTH);
419         return;
420       }
421       //--AgentGen BEGIN=snmp4jAgentHBCtrlStartTime::validate
422
//--AgentGen END
423
}
424   }
425
426   /**
427    * The <code>Snmp4jAgentHBCtrlDelayValidator</code> implements the value
428    * validation for <code>Snmp4jAgentHBCtrlDelay</code>.
429    */

430   static class Snmp4jAgentHBCtrlDelayValidator implements
431       MOValueValidationListener {
432
433     public void validate(MOValueValidationEvent validationEvent) {
434       Variable newValue = validationEvent.getNewValue();
435       //--AgentGen BEGIN=snmp4jAgentHBCtrlDelay::validate
436
//--AgentGen END
437
}
438   }
439
440   /**
441    * The <code>Snmp4jAgentHBCtrlPeriodValidator</code> implements the value
442    * validation for <code>Snmp4jAgentHBCtrlPeriod</code>.
443    */

444   static class Snmp4jAgentHBCtrlPeriodValidator implements
445       MOValueValidationListener {
446
447     public void validate(MOValueValidationEvent validationEvent) {
448       Variable newValue = validationEvent.getNewValue();
449       //--AgentGen BEGIN=snmp4jAgentHBCtrlPeriod::validate
450
//--AgentGen END
451
}
452   }
453
454   // Rows and Factories
455

456   public class Snmp4jAgentHBCtrlEntryRow extends DefaultMOMutableRow2PC {
457     public Snmp4jAgentHBCtrlEntryRow(OID index, Variable[] values) {
458       super(index, values);
459     }
460
461     public OctetString getSnmp4jAgentHBCtrlStartTime() {
462       return (OctetString) getValue(idxSnmp4jAgentHBCtrlStartTime);
463     }
464
465     public void setSnmp4jAgentHBCtrlStartTime(OctetString newValue) {
466       setValue(idxSnmp4jAgentHBCtrlStartTime, newValue);
467     }
468
469     public UnsignedInteger32 getSnmp4jAgentHBCtrlDelay() {
470       return (UnsignedInteger32) getValue(idxSnmp4jAgentHBCtrlDelay);
471     }
472
473     public void setSnmp4jAgentHBCtrlDelay(UnsignedInteger32 newValue) {
474       setValue(idxSnmp4jAgentHBCtrlDelay, newValue);
475     }
476
477     public UnsignedInteger32 getSnmp4jAgentHBCtrlPeriod() {
478       return (UnsignedInteger32) getValue(idxSnmp4jAgentHBCtrlPeriod);
479     }
480
481     public void setSnmp4jAgentHBCtrlPeriod(UnsignedInteger32 newValue) {
482       setValue(idxSnmp4jAgentHBCtrlPeriod, newValue);
483     }
484
485     public UnsignedInteger32 getSnmp4jAgentHBCtrlMaxEvents() {
486       return (UnsignedInteger32) getValue(idxSnmp4jAgentHBCtrlMaxEvents);
487     }
488
489     public void setSnmp4jAgentHBCtrlMaxEvents(UnsignedInteger32 newValue) {
490       setValue(idxSnmp4jAgentHBCtrlMaxEvents, newValue);
491     }
492
493     public Counter64 getSnmp4jAgentHBCtrlEvents() {
494       return (Counter64) getValue(idxSnmp4jAgentHBCtrlEvents);
495     }
496
497     public void setSnmp4jAgentHBCtrlEvents(Counter64 newValue) {
498       setValue(idxSnmp4jAgentHBCtrlEvents, newValue);
499     }
500
501     public TimeTicks getSnmp4jAgentHBCtrlLastChange() {
502       return (TimeTicks) getValue(idxSnmp4jAgentHBCtrlLastChange);
503     }
504
505     public void setSnmp4jAgentHBCtrlLastChange(TimeTicks newValue) {
506       setValue(idxSnmp4jAgentHBCtrlLastChange, newValue);
507     }
508
509     public Integer32 getSnmp4jAgentHBCtrlStorageType() {
510       return (Integer32) getValue(idxSnmp4jAgentHBCtrlStorageType);
511     }
512
513     public void setSnmp4jAgentHBCtrlStorageType(Integer32 newValue) {
514       setValue(idxSnmp4jAgentHBCtrlStorageType, newValue);
515     }
516
517     public Integer32 getSnmp4jAgentHBCtrlRowStatus() {
518       return (Integer32) getValue(idxSnmp4jAgentHBCtrlRowStatus);
519     }
520
521     public void setSnmp4jAgentHBCtrlRowStatus(Integer32 newValue) {
522       setValue(idxSnmp4jAgentHBCtrlRowStatus, newValue);
523     }
524
525     //--AgentGen BEGIN=snmp4jAgentHBCtrlEntry::Row
526
//--AgentGen END
527
}
528
529   class Snmp4jAgentHBCtrlEntryRowFactory extends DefaultMOMutableRow2PCFactory {
530     public synchronized MOTableRow createRow(OID index, Variable[] values) throws
531         UnsupportedOperationException JavaDoc {
532       Snmp4jAgentHBCtrlEntryRow row = new Snmp4jAgentHBCtrlEntryRow(index,
533           values);
534       //--AgentGen BEGIN=snmp4jAgentHBCtrlEntry::createRow
535
row.setSnmp4jAgentHBCtrlLastChange(sysUpTime.get());
536       row.setSnmp4jAgentHBCtrlEvents(new Counter64(0));
537       //--AgentGen END
538
return row;
539     }
540
541     public synchronized void freeRow(MOTableRow row) {
542       //--AgentGen BEGIN=snmp4jAgentHBCtrlEntry::freeRow
543
//--AgentGen END
544
}
545
546     //--AgentGen BEGIN=snmp4jAgentHBCtrlEntry::RowFactory
547
//--AgentGen END
548
}
549
550 //--AgentGen BEGIN=_METHODS
551
public void rowStatusChanged(RowStatusEvent event) {
552     if (event.isDeniable()) {
553       if (event.isRowActivated()) {
554         // check column interdependent consistency
555
Snmp4jAgentHBCtrlEntryRow row =
556             (Snmp4jAgentHBCtrlEntryRow) event.getRow();
557         if ((row.getSnmp4jAgentHBCtrlDelay().getValue() == 0) &&
558             ((row.getSnmp4jAgentHBCtrlStartTime() == null) ||
559              (DateAndTime.makeCalendar(
560                  row.getSnmp4jAgentHBCtrlStartTime()).getTimeInMillis()
561               <= System.currentTimeMillis()))) {
562           event.setDenyReason(PDU.inconsistentValue);
563         }
564       }
565     }
566     else if (event.isRowActivated()) {
567       Snmp4jAgentHBCtrlEntryRow row =
568           (Snmp4jAgentHBCtrlEntryRow) event.getRow();
569       HeartbeatTask task = new HeartbeatTask(row);
570       if (row.getSnmp4jAgentHBCtrlDelay().getValue() == 0) {
571         long startTime = DateAndTime.makeCalendar(
572                  row.getSnmp4jAgentHBCtrlStartTime()).getTimeInMillis() -
573             heartbeatOffset;
574         heartbeatTimer.schedule(task,
575                                 new Date JavaDoc(startTime),
576                                 row.getSnmp4jAgentHBCtrlPeriod().getValue());
577       }
578       else {
579         heartbeatTimer.schedule(task,
580                                 row.getSnmp4jAgentHBCtrlDelay().getValue(),
581                                 row.getSnmp4jAgentHBCtrlPeriod().getValue());
582       }
583       row.setUserObject(task);
584     }
585     else if (event.isRowDeactivated()) {
586       Snmp4jAgentHBCtrlEntryRow row =
587           (Snmp4jAgentHBCtrlEntryRow) event.getRow();
588       HeartbeatTask task = (HeartbeatTask) row.getUserObject();
589       if (task != null) {
590         task.cancel();
591       }
592     }
593   }
594
595   public void rowChanged(MOTableRowEvent event) {
596     if (event.getRow() != null) {
597       Snmp4jAgentHBCtrlEntryRow row =
598           (Snmp4jAgentHBCtrlEntryRow) event.getRow();
599       if (row.getSnmp4jAgentHBCtrlLastChange() != null) {
600         row.getSnmp4jAgentHBCtrlLastChange().setValue(sysUpTime.get().getValue());
601       }
602     }
603   }
604
605   //--AgentGen END
606

607 //--AgentGen BEGIN=_CLASSES
608

609   class HeartbeatTask extends TimerTask JavaDoc {
610
611     private Snmp4jAgentHBCtrlEntryRow configRow;
612
613     public HeartbeatTask(Snmp4jAgentHBCtrlEntryRow configRow) {
614       this.configRow = configRow;
615     }
616
617     public void run() {
618       if (configRow.getSnmp4jAgentHBCtrlRowStatus().getValue() ==
619           RowStatus.active) {
620         long maxEvents = configRow.getSnmp4jAgentHBCtrlMaxEvents().getValue();
621         if ((maxEvents > 0) &&
622             (configRow.getSnmp4jAgentHBCtrlEvents().getValue() < maxEvents)) {
623           configRow.getSnmp4jAgentHBCtrlEvents().increment();
624           OID instanceOID =
625               ((DefaultMOTable) snmp4jAgentHBCtrlEntry).
626               getCellOID(configRow.getIndex(),
627                          idxSnmp4jAgentHBCtrlEvents);
628           VariableBinding eventVB = new VariableBinding(instanceOID,
629               configRow.getSnmp4jAgentHBCtrlEvents());
630           snmp4jAgentHBEvent(notificationOriginator, context,
631                              new VariableBinding[] {eventVB});
632         }
633         else {
634           cancel();
635           configRow.getSnmp4jAgentHBCtrlRowStatus().setValue(RowStatus.notInService);
636         }
637       }
638       else {
639         cancel();
640       }
641     }
642   }
643
644 //--AgentGen END
645

646 //--AgentGen BEGIN=_END
647
//--AgentGen END
648
}
649
Popular Tags