本文整理了Java中org.snmp4j.Snmp.<init>()
方法的一些代码示例,展示了Snmp.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Snmp.<init>()
方法的具体详情如下:
包路径:org.snmp4j.Snmp
类名称:Snmp
方法名:<init>
[英]Creates a Snmp instance that uses a MessageDispatcherImpl with no message processing models and no security protols (by default). You will have to add those by calling the appropriate methods on #getMessageDispatcher().
At least one transport mapping has to be added before #listen()is called in order to be able to send and receive SNMP messages.
To initialize a Snmp instance created with this constructor follow this sample code:
Transport transport = ...;
Snmp snmp = new Snmp();
SecurityProtocols.getInstance().addDefaultProtocols();
MessageDispatcher disp = snmp.getMessageDispatcher();
disp.addMessageProcessingModel(new MPv1());
disp.addMessageProcessingModel(new MPv2c());
snmp.addTransportMapping(transport);
OctetString localEngineID = new OctetString(
MPv3.createLocalEngineID());
// For command generators, you may use the following code to avoid
// engine ID clashes:
// MPv3.createLocalEngineID(
// new OctetString("MyUniqueID"+System.currentTimeMillis())));
USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0);
disp.addMessageProcessingModel(new MPv3(usm));
snmp.listen();
[中]创建一个使用MessageDispatcherImpl的Snmp实例,该实例没有消息处理模型,也没有安全协议(默认情况下)。您必须通过在#getMessageDispatcher()上调用适当的方法来添加这些。
在调用#listen()之前,必须至少添加一个传输映射,以便能够发送和接收SNMP消息。
要初始化使用此构造函数创建的Snmp实例,请遵循以下示例代码:
Transport transport = ...;
Snmp snmp = new Snmp();
SecurityProtocols.getInstance().addDefaultProtocols();
MessageDispatcher disp = snmp.getMessageDispatcher();
disp.addMessageProcessingModel(new MPv1());
disp.addMessageProcessingModel(new MPv2c());
snmp.addTransportMapping(transport);
OctetString localEngineID = new OctetString(
MPv3.createLocalEngineID());
// For command generators, you may use the following code to avoid
// engine ID clashes:
// MPv3.createLocalEngineID(
// new OctetString("MyUniqueID"+System.currentTimeMillis())));
USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0);
disp.addMessageProcessingModel(new MPv3(usm));
snmp.listen();
代码示例来源:origin: apache/nifi
/**
* Builds target resource.
* @param context Process context
*/
private void buildTargetResource(ProcessContext context) {
if((this.transportMapping == null) || !this.transportMapping.isListening() || (this.snmp == null)) {
try {
this.transportMapping = new DefaultUdpTransportMapping();
this.snmp = new Snmp(this.transportMapping);
if("SNMPv3".equals(context.getProperty(SNMP_VERSION).getValue())) {
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
}
this.transportMapping.listen();
} catch (Exception e) {
throw new IllegalStateException("Failed to initialize UDP transport mapping", e);
}
}
if (this.snmpTarget == null) {
this.snmpTarget = this.createSnmpTarget(context);
}
if (this.targetResource == null) {
this.targetResource = this.finishBuildingTargetResource(context);
}
}
代码示例来源:origin: pentaho/pentaho-kettle
snmp = new Snmp( transMap );
代码示例来源:origin: apache/cloudstack
public SnmpHelper(String address, String community) {
_target = new CommunityTarget();
_target.setCommunity(new OctetString(community));
_target.setVersion(SnmpConstants.version2c);
_target.setAddress(new UdpAddress(address));
try {
_snmp = new Snmp(new DefaultUdpTransportMapping());
} catch (IOException e) {
_snmp = null;
throw new CloudRuntimeException(" Error in crearting snmp object, " + e.getMessage());
}
}
代码示例来源:origin: org.kaazing/snmp4j-agent
/**
* Creates the SNMP session to be used for this agent.
*
* @param dispatcher
* the message dispatcher to be associated with the session.
* @return
* a SNMP session (a {@link Snmp} instance by default).
*/
protected Session createSnmpSession(MessageDispatcher dispatcher) {
return new Snmp(dispatcher);
}
代码示例来源:origin: org.snmp4j/snmp4j-agent
/**
* Creates the SNMP session to be used for this agent.
*
* @param dispatcher
* the message dispatcher to be associated with the session.
*
* @return a SNMP session (a {@link Snmp} instance by default).
*/
protected Session createSnmpSession(MessageDispatcher dispatcher) {
return new Snmp(dispatcher);
}
代码示例来源:origin: com.rogueai/snmp2bean
public void initSnmp4J(TransportMapping transportMapping) throws IOException {
if (target == null) return; // no execution.. maybe throw exception
snmp4J = new Snmp(transportMapping);
snmp4J.listen();
}
代码示例来源:origin: org.mobicents.tools.snmp.adaptor/core
private void initSession(){
this.session = new Snmp(dispatcher);
for (int i = 0; i < transportMappings.length;i++){
try{
session.addTransportMapping(transportMappings[i]);
}
catch(Exception e){
log.warn("Tranport mapping invalid. Failed to initialize mapping '"+
transportMappings[i]+"' with: "+e.getMessage());
}
}
this.session.addCommandResponder(responder);
}
代码示例来源:origin: org.jboss.jbossas/jboss-snmp
private void initSession(){
this.session = new Snmp(dispatcher);
for (int i = 0; i < transportMappings.length;i++){
try{
session.addTransportMapping(transportMappings[i]);
}
catch(Exception e){
log.warn("Tranport mapping invalid. Failed to initialize mapping '"+
transportMappings[i]+"' with: "+e.getMessage());
}
}
this.session.addCommandResponder(responder);
}
代码示例来源:origin: griddynamics/jagger
public SNMPProvider(String address) {
try {
this.address = address;
TransportMapping transport = new DefaultUdpTransportMapping();
this.snmp = new Snmp(transport);
transport.listen();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: oVirt/ovirt-engine
private org.snmp4j.Snmp createSnmp() {
try {
// Create a new session and define it's transport.
return new org.snmp4j.Snmp(new DefaultUdpTransportMapping());
} catch (IOException e) {
throw new NotificationServiceException("error creating " + getClass().getName());
}
}
代码示例来源:origin: jrask/snmp-blog
private void start() throws IOException {
TransportMapping transport = new DefaultUdpTransportMapping();
snmp = new Snmp(transport);
// Do not forget this line!
transport.listen();
}
代码示例来源:origin: org.snmp4j/snmp4j-agent
protected void initSnmpSession() {
session = new Snmp(dispatcher);
for (TransportMapping<? extends Address> transportMapping : transportMappings) {
try {
session.addTransportMapping(transportMapping);
} catch (Exception ex) {
logger.warn("Failed to initialize transport mapping '" +
transportMapping + "' with: " + ex.getMessage());
}
}
updateSession(session);
}
代码示例来源:origin: org.kaazing/snmp4j-agent
protected void initSnmpSession() {
session = new Snmp(dispatcher);
for (int i=0; i<transportMappings.length; i++) {
try {
session.addTransportMapping(transportMappings[i]);
}
catch (Exception ex) {
logger.warn("Failed to initialize transport mapping '"+
transportMappings[i]+"' with: "+ex.getMessage());
}
}
updateSession(session);
}
代码示例来源:origin: fbacchella/jrds
@Override
public final boolean start() {
try {
snmp = new Snmp(new DefaultUdpTransportMapping());
snmp.listen();
} catch (IOException e) {
log(Level.ERROR, e, "Discovery SNMP listener failed to start: %s", e.getMessage());
}
return true;
}
代码示例来源:origin: org.apache.servicemix/servicemix-snmp
@Override
public synchronized void activate() throws Exception {
super.activate();
// load connection data only if the endpoint is enabled
if (isEnabled()) {
logger.debug("Activating endpoint");
this.listenGenericAddress = GenericAddress.parse(this.address);
this.transport = new DefaultUdpTransportMapping((UdpAddress) this.listenGenericAddress);
this.snmp = new Snmp(transport);
snmp.addCommandResponder(this);
}
}
代码示例来源:origin: net.itransformers.snmp2xml4j/snmptoolkit
/**
* <p>init.</p>
*
* @throws java.io.IOException if any.
*/
public void init() throws IOException {
TransportMapping transportMapping = transportMappingAbstractFactory.createTransportMapping(transportLocalIpAddress);
MessageDispatcher messageDispatcher = messageDispatcherFactory.createMessageDispatcherMapping();
snmp = new Snmp(messageDispatcher, transportMapping);
doInit();
transportMapping.listen();
}
代码示例来源:origin: fbacchella/jrds
public boolean start() {
boolean started = false;
try {
snmp = new Snmp(new DefaultUdpTransportMapping());
snmp.listen();
started = true;
} catch (IOException e) {
log(Level.ERROR, e, "SNMP UDP Transport Mapping not started: %s", e);
snmp = null;
}
return started;
}
代码示例来源:origin: org.opennms.lib.snmp/org.opennms.lib.snmp.snmp4j
public void registerForTraps(TrapNotificationListener listener, TrapProcessorFactory processorFactory, int snmpTrapPort) throws IOException {
RegistrationInfo info = new RegistrationInfo(listener, snmpTrapPort);
Snmp4JTrapNotifier m_trapHandler = new Snmp4JTrapNotifier(listener, processorFactory);
info.setHandler(m_trapHandler);
TransportMapping transport = new DefaultUdpTransportMapping(new UdpAddress(snmpTrapPort));
info.setTransportMapping(transport);
Snmp snmp = new Snmp(transport);
snmp.addCommandResponder(m_trapHandler);
info.setSession(snmp);
s_registrations.put(listener, info);
snmp.listen();
}
代码示例来源:origin: OpenNMS/opennms
public MockProxy(int port) throws IOException {
// Set socket option SO_REUSEADDR so that we can bind to the port even if it
// has recently been closed by passing 'true' as the second argument here.
m_transport = new DefaultUdpTransportMapping(new UdpAddress(InetAddress.getLocalHost(), port), true);
m_snmp = new Snmp(m_transport);
m_snmp.addCommandResponder(this);
m_transport.listen();
}
代码示例来源:origin: org.openscada.atlantis/org.openscada.da.server.snmp
public void start () throws IOException
{
this.address = GenericAddress.parse ( this.connectionInformation.getAddress () );
this.transport = new DefaultUdpTransportMapping ();
this.snmp = new Snmp ( this.transport );
//MPv3 mpv3 = (MPv3)_snmp.getMessageProcessingModel ( MessageProcessingModel.MPv3 );
final USM usm = new USM ( SecurityProtocols.getInstance (), new OctetString ( MPv3.createLocalEngineID () ), 0 );
SecurityModels.getInstance ().addSecurityModel ( usm );
this.snmp.listen ();
}
内容来源于网络,如有侵权,请联系作者删除!