1. /*
  2. * @(#)file SnmpLcd.java
  3. * @(#)author Sun Microsystems, Inc.
  4. * @(#)version 1.20
  5. * @(#)date 04/09/15
  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. import java.util.Hashtable;
  13. import com.sun.jmx.snmp.SnmpEngineId;
  14. import com.sun.jmx.snmp.SnmpUnknownModelLcdException;
  15. import com.sun.jmx.snmp.SnmpUnknownSubSystemException;
  16. /**
  17. * 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.
  18. *<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>
  19. * <p><b>This API is a Sun Microsystems internal API and is subject
  20. * to change without notice.</b></p>
  21. * @since 1.5
  22. */
  23. public abstract class SnmpLcd {
  24. class SubSysLcdManager {
  25. private Hashtable models = new Hashtable();
  26. public void addModelLcd(int id,
  27. SnmpModelLcd usmlcd) {
  28. models.put(new Integer(id), usmlcd);
  29. }
  30. public SnmpModelLcd getModelLcd(int id) {
  31. return (SnmpModelLcd) models.get(new Integer(id));
  32. }
  33. public SnmpModelLcd removeModelLcd(int id) {
  34. return (SnmpModelLcd) models.remove(new Integer(id));
  35. }
  36. }
  37. private Hashtable subs = new Hashtable();
  38. /**
  39. * Returns the number of time the engine rebooted.
  40. * @return The number of reboots or -1 if the information is not present in the Lcd.
  41. */
  42. public abstract int getEngineBoots();
  43. /**
  44. * Returns the engine Id located in the Lcd.
  45. * @return The engine Id or null if the information is not present in the Lcd.
  46. */
  47. public abstract String getEngineId();
  48. /**
  49. * Persists the number of reboots.
  50. * @param i Reboot number.
  51. */
  52. public abstract void storeEngineBoots(int i);
  53. /**
  54. * Persists the engine Id.
  55. * @param id The engine Id.
  56. */
  57. public abstract void storeEngineId(SnmpEngineId id);
  58. /**
  59. * Adds an Lcd model.
  60. * @param sys The subsytem managing the model.
  61. * @param id The model Id.
  62. * @param lcd The Lcd model.
  63. */
  64. public void addModelLcd(SnmpSubSystem sys,
  65. int id,
  66. SnmpModelLcd lcd) {
  67. SubSysLcdManager subsys = (SubSysLcdManager) subs.get(sys);
  68. if( subsys == null ) {
  69. subsys = new SubSysLcdManager();
  70. subs.put(sys, subsys);
  71. }
  72. subsys.addModelLcd(id, lcd);
  73. }
  74. /**
  75. * Removes an Lcd model.
  76. * @param sys The subsytem managing the model.
  77. * @param id The model Id.
  78. */
  79. public void removeModelLcd(SnmpSubSystem sys,
  80. int id)
  81. throws SnmpUnknownModelLcdException, SnmpUnknownSubSystemException {
  82. SubSysLcdManager subsys = (SubSysLcdManager) subs.get(sys);
  83. if( subsys != null ) {
  84. SnmpModelLcd lcd = subsys.removeModelLcd(id);
  85. if(lcd == null) {
  86. throw new SnmpUnknownModelLcdException("Model : " + id);
  87. }
  88. }
  89. else
  90. throw new SnmpUnknownSubSystemException(sys.toString());
  91. }
  92. /**
  93. * Gets an Lcd model.
  94. * @param sys The subsytem managing the model
  95. * @param id The model Id.
  96. * @return The Lcd model or null if no Lcd model were found.
  97. */
  98. public SnmpModelLcd getModelLcd(SnmpSubSystem sys,
  99. int id) {
  100. SubSysLcdManager subsys = (SubSysLcdManager) subs.get(sys);
  101. if(subsys == null) return null;
  102. return (SnmpModelLcd) subsys.getModelLcd(id);
  103. }
  104. }