View Javadoc
1   // NAME
2   //      $RCSfile: OneInformPdu.java,v $
3   // DESCRIPTION
4   //      [given below in javadoc format]
5   // DELTA
6   //      $Revision: 3.5 $
7   // CREATED
8   //      $Date: 2006/02/09 14:20:09 $
9   // COPYRIGHT
10  //      Westhawk Ltd
11  // TO DO
12  //
13  
14  /*
15   * Copyright (C) 2002 - 2006 by Westhawk Ltd
16   * <a href="www.westhawk.co.uk">www.westhawk.co.uk</a>
17   *
18   * Permission to use, copy, modify, and distribute this software
19   * for any purpose and without fee is hereby granted, provided
20   * that the above copyright notices appear in all copies and that
21   * both the copyright notice and this permission notice appear in
22   * supporting documentation.
23   * This software is provided "as is" without express or implied
24   * warranty.
25   * author <a href="mailto:snmp@westhawk.co.uk">Tim Panton</a>
26   */
27   
28  package uk.co.westhawk.snmp.pdu;
29  
30  /*-
31   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
32   * SNMP Java Client
33   * ჻჻჻჻჻჻
34   * Copyright 2023 MetricsHub, Westhawk
35   * ჻჻჻჻჻჻
36   * This program is free software: you can redistribute it and/or modify
37   * it under the terms of the GNU Lesser General Public License as
38   * published by the Free Software Foundation, either version 3 of the
39   * License, or (at your option) any later version.
40   *
41   * This program is distributed in the hope that it will be useful,
42   * but WITHOUT ANY WARRANTY; without even the implied warranty of
43   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
44   * GNU General Lesser Public License for more details.
45   *
46   * You should have received a copy of the GNU General Lesser Public
47   * License along with this program.  If not, see
48   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
49   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
50   */
51  import uk.co.westhawk.snmp.stack.*;
52  import java.util.*;
53  
54  /**
55   * <p>
56   * The OneInformPdu class will inform a manager about one 
57   * object (OIDs), based on the Inform request.
58   * </p>
59   *
60   * <p>
61   * This class represents the SNMP Inform Request PDU. Inform Requests
62   * are sent between managers. It is a kind of 'acknowlegded' trap since
63   * the receiving end should send a Response PDU as reply.
64   * The varbind list has the same elements as the TrapPduv2.
65   * </p>
66   *
67   * <p>
68   * Note, this PDU should be sent to port 162 (the default trap port) by
69   * default. You will have to create a SnmpContext with the
70   * ListeningContextFace.DEFAULT_TRAP_PORT as parameter!
71   * </p>
72   *
73   * <p>
74   * For SNMPv3: The receiver of an inform PDU acts as the authoritative engine.
75   * </p>
76   *
77   * @deprecated  As of 4_14, just use {@link InformPdu} 
78   * @see InformPdu_vec
79   * @see varbind
80   * @see ListeningContextFace#DEFAULT_TRAP_PORT
81   * @since 4_12
82   *
83   * @author <a href="mailto:snmp@westhawk.co.uk">Birgit Arkesteijn</a>
84   * @version $Revision: 3.5 $ $Date: 2006/02/09 14:20:09 $
85   */
86  public class OneInformPdu extends InformPdu {
87      private static final String version_id = "@(#)$Id: OneInformPdu.java,v 3.5 2006/02/09 14:20:09 birgit Exp $ Copyright Westhawk Ltd";
88  
89      varbind var;
90  
91      /**
92       * Constructor.
93       *
94       * @param con The context (v2c or v3) of the PDU
95       */
96      public OneInformPdu(SnmpContextBasisFace con) {
97          super(con);
98      }
99  
100     /**
101      * Constructor that will send the request immediately. No Observer
102      * is set.
103      *
104      * @param con the SnmpContextBasisFace
105      * @param oid the oid
106      */
107     public OneInformPdu(SnmpContextBasisFace con, String oid)
108             throws PduException, java.io.IOException {
109         this(con, oid, null);
110     }
111 
112     /**
113      * Constructor that will send the request immediately.
114      *
115      * @param con the SnmpContextBasisFace
116      * @param oid the oid
117      * @param o   the Observer that will be notified when the answer is received
118      */
119     public OneInformPdu(SnmpContextBasisFace con, String oid, Observer o)
120             throws PduException, java.io.IOException {
121         super(con);
122         if (o != null) {
123             addObserver(o);
124         }
125         addOid(oid);
126         send();
127     }
128 
129     /**
130      * The value of the request is set. This will be called by
131      * InformPdu.fillin().
132      *
133      * @param n     the index of the value
134      * @param a_var the value
135      * @see Pdu#new_value
136      */
137     protected void new_value(int n, varbind a_var) {
138         if (n == 0) {
139             var = a_var;
140         }
141     }
142 
143     /**
144      * This method notifies all observers.
145      * This will be called by InformPdu.fillin().
146      * 
147      * <p>
148      * Unless an exception occurred the Object to the update() method of the
149      * Observer will be a varbind, so any AsnObject type can be returned.
150      * In the case of an exception, that exception will be passed.
151      * </p>
152      */
153     protected void tell_them() {
154         notifyObservers(var);
155     }
156 
157 }