[SNMP4J] SNMP4J and CORBA "Any" class
Marco.Bresciani at alcatel.it
Marco.Bresciani at alcatel.it
Fri Jan 13 16:19:08 CET 2006
I'm working on a SNMPv2c implementation, by replacing existing proprietary
methods of a class with SNMP4J method and functionalities. I have to
replace methods content only, without modifying methods signatures and so
on... I have an "init" method that does the following...
/* protocol setup */
if (pUDP == true) {
/* UDP protocol selected */
protocol = new String("udp");
} else {
/* TCP protocol selected */
protocol = new String("tcp");
}
/* transport level selection */
transport = null;
try {
if (pUDP == true) {
transport = new DefaultUdpTransportMapping();
} else {
transport = new DefaultTcpTransportMapping();
}
} catch (Exception e) {
/* error on transport level creation */
System.err.println("Converter.init(String, int, boolean) e1: " + e);
ConverterInitialized = false;
e.printStackTrace();
}
/* SNMP activation */
snmp = new Snmp(transport);
/* SNMP v2c message processor */
proc2c = (MPv2c)
snmp.getMessageProcessingModel(MessageProcessingModel.MPv2c);
snmp.addTransportMapping(transport);
/* starting SNMP management */
try {
transport.listen();
} catch (Exception e) {
/* error on transport level activation */
System.err.println("Converter.init(String, int, boolean) e2: " + e);
ConverterInitialized = false;
e.printStackTrace();
}
ConverterInitialized = true;
/* target device */
device = new CommunityTarget();
device.setCommunity(new OctetString("public"));
device.setVersion(SnmpConstants.version2c);
device.setAddress(targetURL); // can't set it because target URL is
received by each single "get*" and "set*" SNMP methods. Init does not know
about URL...
device.setRetries(2); // is this needed? It depends on SNMP
device?
device.setTimeout(1500); // is this needed? It depends on SNMP
device?
and it seems to work fine. So, I'm working on a "getObject" method and I
wrote the following code:
/* block variables definition */
String tmpAddr = null;
PDU pdu_data = new PDU();
ResponseEvent replyEvent = null;
/* IP address setup */
tmpAddr = getIpAddress(xmlProperty);
targetURL = GenericAddress.parse(protocol + ":" + tmpAddr + "/" +
SNMP_WELL_KNOWN_PORT);
if (targetURL == null) {
/* wrong target URL management */
System.err.println("Converter.getObject(String, String, String,
ApplicationStructure).");
ConverterInitialized = false;
return -1;
}
device.setAddress(targetURL);
/* SNMP query creation */
pdu_data.add(new VariableBinding(new OID(oid)));
pdu_data.setType(PDU.GET);
try {
replyEvent = snmp.send(pdu_data, device, transport/*, null,
receiver*/);
if (replyEvent != null) {
/* block variables declaration */
Variable data;
/* block variables definition */
PDU response = replyEvent.getResponse();
Vector result = response.getVariableBindings();
THEN... I HAVE THIS PART OF CODE THAT IS INHERITED FROM OLDER VERSION OF
THIS METHOD AND THAT I HAVE TO USE TO PRODUCE THE SAME KIND OF DATA...
Any[] pp1 = new Any[1];
pp1[0] = orb.create_any();
Any p3 = orb.create_any();
AttrVal p0 = new AttrVal(oid, pp1, ASNSnmpType.Null, p3);
AttrValHolder p1 = new AttrValHolder(p0);
SO I WROTE THIS PART OF CODE...
/* used structure conversion */
data = ((VariableBinding) result.get(0)).getVariable();
AND THE FINAL INSTRUCTION IS, AGAIN, AN OLD ONE I SHOULD KEEP TO ASSURE
RETRO-COMPATIBILITY WITH THE REST OF THE CODE:
holder.setData((Object)
Converter.convertToStructure(holder.getStructureClass(), fieldName, p1));
I HAVE TO DO THIS: how can I map a "Variable" data (or
"VariableBinding"... or tell me which is the correct class...) on a CORBA
"Any" class?! AttrVal and AttrValHolder are proprietary class but I can
easily circumvent them by directly modifying the pp1[0] object that is a
standard "Any" class of the org.omg.CORBA package so that the last
"holder.setData" instruction (and the classes that will use those data)
will manage the correct data format.
Please help me!!! :-) Thank you in advance for "Any" ;-) help,
Dott. Ing. Marco Bresciani
--
Alcatel - WTD R&D SW Lab. [Stage]
Via Trento, 30
20059 Vimercate (Mi) Italia
Phone: +39.039.686.5546
E-Mail: Marco.Bresciani at Alcatel.It
More information about the SNMP4J
mailing list