[SNMP4J] Multi thread using TableUtils
Edgar Tavares Crespo
edgar.crespo at gmail.com
Thu Jun 7 00:18:38 CEST 2007
Hi Frank,
I Have already checked with a Sniffer.
Regards
Edgar
On 6/6/07, Frank Fock <fock at agentpp.com> wrote:
>
> Hi Edgar,
>
> Have your verified that this is a problem in the manager
> or in other words: does the agent respond to the requests
> (checked with a Sniffer like Ethereal)?
>
> Best regards,
> Frank
>
> Edgar Tavares Crespo wrote:
> > Hi All:
> >
> > I am attempting to use the snmp4j in a multi thread environment.
> > when I try to use the same Snmp class instance
> > to request a simple snmp value (like a scalar integer) and
> > in a another thread I try to use the tableUtils.getTable(...) function
> the
> > last getTable fails(timeout) and
> > from that moment on any other getTable that I perform using the
> > tableUtils.getTable(...) function
> > I receive a timeout response.
> >
> > I am using 1.7.1 version and I have already tried change to version
> > 1.8.2and I observed the same behavior.
> >
> > I am using a spring context to instantiate the Snmp class inside of my
> > SnmpStrategy.
> >
> > That the code I am using.
> >
> > public class SnmpStrategy implements IDataAcquirementStrategy {
> >
> > private Snmp snmp;
> >
> > public void init() throws MibException {
> > this.snmp = createSnmp();
> > }
> >
> > //Get Table Function
> > public Object[][] aquireTableData(AddressableEquipment equipment,
> String[]
> > tableOids) throws MibException {
> >
> > if ((tableOids == null) || (tableOids.length == 0)) {
> > throw new IllegalArgumentException("The method
> aquireTableData
> > must receive at least one valid tableOid");
> > }
> >
> > Target target = createTarget(equipment);
> > OID[] snmpOids = new OID[tableOids.length];
> > for (int i = 0; i < snmpOids.length; i++) {
> > OID oid = new OID(tableOids[i]);
> > snmpOids[i] = oid;
> > }
> >
> > TableUtils tableUtils = new TableUtils(snmp, new
> > DefaultPDUFactory());
> >
> > List list = tableUtils.getTable(target, snmpOids, null, null);
> >
> > Object[][] result = new Object[ list.size()][snmpOids.length +
> 1];
> >
> > int index = 0;
> > for (Iterator iter = list.iterator(); iter.hasNext();) {
> > TableEvent tableEvent = (TableEvent) iter.next();
> >
> > if (tableEvent != null && tableEvent.getStatus() ==
> > TableEvent.STATUS_OK) {
> >
> > result[index][0] = tableEvent.getIndex().toString();
> > result[index][1] = new Object[tableOids.length];
> >
> > for (int i = 0; i < snmpOids.length; i++) {
> > VariableBinding var = tableEvent.getColumns()[i];
> > if (var != null)
> > ((Object[]) result[index][1])[i] =
> var.getVariable
> > ();
> > else
> > ((Object[]) result[index][1])[i] = null;
> > }
> >
> > index++;
> >
> > } else if (tableEvent.getStatus() ==
> TableEvent.STATUS_TIMEOUT )
> > {
> > throw new MibException("Timeout while executing snmp
> > aquireTableData for table oid=" + tableOids
> > + " and address=" + equipment.getAddress());
> > }
> > }
> >
> > return result;
> > }
> >
> > //scalar get function
> > private PDU executeGet(AddressableEquipment equipment, String oid, int
> > protocolFlags) throws MibException {
> >
> > Target target = createTarget(equipment);
> >
> > // creating PDU
> > PDU pdu = new PDU();
> > pdu.add(new VariableBinding(new OID(oid)));
> >
> > if ((protocolFlags & SNMP_GET_NEXT) != 0) {
> > pdu.setType(PDU.GETNEXT);
> > } else {
> > pdu.setType(PDU.GET);
> > }
> >
> > // send the PDU
> > ResponseEvent response = null;
> > try {
> > response = snmp.send(pdu, target);
> > } catch (IOException e) {
> > throw new MibException("Error executing snmp getData for
> oid=" +
> > oid + " and address=" + equipment.getAddress());
> > }
> >
> > // extract the response PDU (could be null if timed out)
> > PDU responsePDU = response.getResponse();
> >
> > if (responsePDU == null) {
> > throw new MibException("Timeout while executing snmp getData
> for
> > oid=" + oid + " and address="
> > + equipment.getAddress());
> > }
> >
> > return responsePDU;
> >
> > }
> >
> >
> > private Snmp createSnmp() throws MibException {
> >
> > Snmp snmp = null;
> >
> > try {
> >
> > TransportMapping transport = new
> DefaultUdpTransportMapping();
> > snmp = new Snmp(transport);
> > USM usm = new USM(SecurityProtocols.getInstance(), new
> > OctetString(MPv3.createLocalEngineID ()), 0);
> > SecurityModels.getInstance().addSecurityModel(usm);
> > snmp.listen();
> >
> > } catch (IOException e) {
> > throw new MibException("Snmp core service creation failed",
> e);
> > }
> >
> > return snmp;
> > }
> >
> > Sameone having an ideia
> >
> > Tanks in advance,
> > _______________________________________________
> > SNMP4J mailing list
> > SNMP4J at agentpp.org
> > http://lists.agentpp.org/mailman/listinfo/snmp4j
>
> --
> AGENT++
> http://www.agentpp.com
> http://www.mibexplorer.com
> http://www.mibdesigner.com
>
>
--
Atenciosamente
==========================================
Edgar Crespo
Silicon Strategy - An Intelligent Business Consultant
Corporative e-mail: silicons at siliconstrategy.com.br
Personal e-mail: edgar.crespo at siliconstrategy.com.br
Office: +55 21 2511-4531
www.siliconstrategy.com.br
===========================================
More information about the SNMP4J
mailing list