KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jmx > snmp > internal > SnmpLcd


1 /*
2  * @(#)file SnmpLcd.java
3  * @(#)author Sun Microsystems, Inc.
4  * @(#)version 1.20
5  * @(#)date 08/02/09
6  *
7  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
8  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
9  *
10  */

11 package com.sun.jmx.snmp.internal;
12
13 import java.util.Hashtable JavaDoc;
14 import com.sun.jmx.snmp.SnmpEngineId;
15 import com.sun.jmx.snmp.SnmpUnknownModelLcdException;
16 import com.sun.jmx.snmp.SnmpUnknownSubSystemException;
17 /**
18  * Class to extend in order to develop a customized Local Configuration Datastore. The Lcd is used by the <CODE>SnmpEngine</CODE> to store and retrieve data.
19  *<P> <CODE>SnmpLcd</CODE> manages the Lcds needed by every {@link com.sun.jmx.snmp.internal.SnmpModel SnmpModel}. It is possible to add and remove {@link com.sun.jmx.snmp.internal.SnmpModelLcd SnmpModelLcd}.</P>
20  * <p><b>This API is a Sun Microsystems internal API and is subject
21  * to change without notice.</b></p>
22  * @since 1.5
23  */

24 public abstract class SnmpLcd {
25
26     class SubSysLcdManager {
27     private Hashtable JavaDoc models = new Hashtable JavaDoc();
28     public void addModelLcd(int id,
29                 SnmpModelLcd usmlcd) {
30         models.put(new Integer JavaDoc(id), usmlcd);
31     }
32     
33     public SnmpModelLcd getModelLcd(int id) {
34         return (SnmpModelLcd) models.get(new Integer JavaDoc(id));
35     }
36     
37     public SnmpModelLcd removeModelLcd(int id) {
38         return (SnmpModelLcd) models.remove(new Integer JavaDoc(id));
39     }
40     }
41     
42
43     private Hashtable JavaDoc subs = new Hashtable JavaDoc();
44     
45     /**
46      * Returns the number of time the engine rebooted.
47      * @return The number of reboots or -1 if the information is not present in the Lcd.
48      */

49     public abstract int getEngineBoots();
50     /**
51      * Returns the engine Id located in the Lcd.
52      * @return The engine Id or null if the information is not present in the Lcd.
53      */

54     public abstract String JavaDoc getEngineId();
55     
56     /**
57      * Persists the number of reboots.
58      * @param i Reboot number.
59      */

60     public abstract void storeEngineBoots(int i);
61     
62     /**
63      * Persists the engine Id.
64      * @param id The engine Id.
65      */

66     public abstract void storeEngineId(SnmpEngineId id);
67     /**
68      * Adds an Lcd model.
69      * @param sys The subsytem managing the model.
70      * @param id The model Id.
71      * @param lcd The Lcd model.
72      */

73     public void addModelLcd(SnmpSubSystem sys,
74                 int id,
75                 SnmpModelLcd lcd) {
76
77     SubSysLcdManager subsys = (SubSysLcdManager) subs.get(sys);
78     if( subsys == null ) {
79         subsys = new SubSysLcdManager();
80         subs.put(sys, subsys);
81     }
82     
83     subsys.addModelLcd(id, lcd);
84     }
85      /**
86      * Removes an Lcd model.
87      * @param sys The subsytem managing the model.
88      * @param id The model Id.
89      */

90     public void removeModelLcd(SnmpSubSystem sys,
91                 int id)
92     throws SnmpUnknownModelLcdException, SnmpUnknownSubSystemException {
93
94     SubSysLcdManager subsys = (SubSysLcdManager) subs.get(sys);
95     if( subsys != null ) {
96         SnmpModelLcd lcd = subsys.removeModelLcd(id);
97         if(lcd == null) {
98         throw new SnmpUnknownModelLcdException("Model : " + id);
99         }
100     }
101     else
102         throw new SnmpUnknownSubSystemException(sys.toString());
103     }
104
105     /**
106      * Gets an Lcd model.
107      * @param sys The subsytem managing the model
108      * @param id The model Id.
109      * @return The Lcd model or null if no Lcd model were found.
110      */

111     public SnmpModelLcd getModelLcd(SnmpSubSystem sys,
112                     int id) {
113     SubSysLcdManager subsys = (SubSysLcdManager) subs.get(sys);
114
115     if(subsys == null) return null;
116
117     return (SnmpModelLcd) subsys.getModelLcd(id);
118     }
119 }
120
Popular Tags