1. /*
  2. * @(#)file SnmpUserDataFactory.java
  3. * @(#)author Sun Microsystems, Inc.
  4. * @(#)version 1.16
  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. package com.sun.jmx.snmp.agent;
  11. import com.sun.jmx.snmp.SnmpPduPacket;
  12. import com.sun.jmx.snmp.SnmpPdu;
  13. import com.sun.jmx.snmp.SnmpStatusException;
  14. /**
  15. * This interface is provided to enable fine customization of the SNMP
  16. * agent behaviour.
  17. *
  18. * <p>You will not need to implement this interface except if your agent
  19. * needs extra customization requiring some contextual information.</p>
  20. *
  21. * <p>If an SnmpUserDataFactory is set on the SnmpAdaptorServer, then a new
  22. * object containing user-data will be allocated through this factory
  23. * for each incoming request. This object will be passed along to
  24. * the SnmpMibAgent within SnmpMibRequest objects. By default, no
  25. * SnmpUserDataFactory is set on the SnmpAdaptorServer, and the contextual
  26. * object passed to SnmpMibAgent is null.</p>
  27. *
  28. * <p>You can use this feature to obtain on contextual information
  29. * (such as community string etc...) or to implement a caching
  30. * mechanism, or for whatever purpose might be required by your specific
  31. * agent implementation.</p>
  32. *
  33. * <p>The sequence <code>allocateUserData() / releaseUserData()</code> can
  34. * also be used to implement a caching mechanism:
  35. * <ul>
  36. * <li><code>allocateUserData()</code> could be used to allocate
  37. * some cache space,</li>
  38. * <li>and <code>releaseUserData()</code> could be used to flush it.</li>
  39. * </ul></p>
  40. *
  41. * <p><b>This API is a Sun Microsystems internal API and is subject
  42. * to change without notice.</b></p>
  43. * @see com.sun.jmx.snmp.agent.SnmpMibRequest
  44. * @see com.sun.jmx.snmp.agent.SnmpMibAgent
  45. * @see com.sun.jmx.snmp.daemon.SnmpAdaptorServer
  46. *
  47. **/
  48. public interface SnmpUserDataFactory {
  49. /**
  50. * Called by the <CODE>SnmpAdaptorServer</CODE> adaptor.
  51. * Allocate a contextual object containing some user data. This method
  52. * is called once for each incoming SNMP request. The scope
  53. * of this object will be the whole request. Since the request can be
  54. * handled in several threads, the user should make sure that this
  55. * object can be accessed in a thread-safe manner. The SNMP framework
  56. * will never access this object directly - it will simply pass
  57. * it to the <code>SnmpMibAgent</code> within
  58. * <code>SnmpMibRequest</code> objects - from where it can be retrieved
  59. * through the {@link com.sun.jmx.snmp.agent.SnmpMibRequest#getUserData() getUserData()} accessor.
  60. * <code>null</code> is considered to be a valid return value.
  61. *
  62. * This method is called just after the SnmpPduPacket has been
  63. * decoded.
  64. *
  65. * @param requestPdu The SnmpPduPacket received from the SNMP manager.
  66. * <b>This parameter is owned by the SNMP framework and must be
  67. * considered as transient.</b> If you wish to keep some of its
  68. * content after this method returns (by storing it in the
  69. * returned object for instance) you should clone that
  70. * information.
  71. *
  72. * @return A newly allocated user-data contextual object, or
  73. * <code>null</code>
  74. * @exception SnmpStatusException If an SnmpStatusException is thrown,
  75. * the request will be aborted.
  76. *
  77. * @since 1.5
  78. **/
  79. public Object allocateUserData(SnmpPdu requestPdu)
  80. throws SnmpStatusException;
  81. /**
  82. * Called by the <CODE>SnmpAdaptorServer</CODE> adaptor.
  83. * Release a previously allocated contextual object containing user-data.
  84. * This method is called just before the responsePdu is sent back to the
  85. * manager. It gives the user a chance to alter the responsePdu packet
  86. * before it is encoded, and to free any resources that might have
  87. * been allocated when creating the contextual object.
  88. *
  89. * @param userData The contextual object being released.
  90. * @param responsePdu The SnmpPduPacket that will be sent back to the
  91. * SNMP manager.
  92. * <b>This parameter is owned by the SNMP framework and must be
  93. * considered as transient.</b> If you wish to keep some of its
  94. * content after this method returns you should clone that
  95. * information.
  96. *
  97. * @exception SnmpStatusException If an SnmpStatusException is thrown,
  98. * the responsePdu is dropped and nothing is returned to
  99. * to the manager.
  100. *
  101. * @since 1.5
  102. **/
  103. public void releaseUserData(Object userData, SnmpPdu responsePdu)
  104. throws SnmpStatusException;
  105. }