SourceForge.net Logo

org.netsnmp
Class NetSNMPSyncSession

java.lang.Object
  |
  +--org.netsnmp.NetSNMPSyncSession
All Implemented Interfaces:
Serializable

public class NetSNMPSyncSession
extends Object
implements Serializable

A helper object that implements a synchronous session. This allows users to dispatch and receive pdus on the same thread. NOTE: not recommended for heavy duty work due to the natural asynchronicity of SNMP and network operations in general. This is meant as a convenience object and as a way for entry level personnel to get their 'feet wet'.

 NetSNMPSyncSession sess = new NetSNMPSyncSession(host, community) ;
	
 ASNValue response = sess.get(new DefaultOID("SNMPv2-MIB::sysDescr.0")) ;
	
 System.out.println(response);
 

Author:
Andrew E. Page aepage@users.sourceforge.net
See Also:
Serialized Form

Constructor Summary
NetSNMPSyncSession()
          Construct an unopened session
NetSNMPSyncSession(NetSNMPSession sess)
           
NetSNMPSyncSession(String host, String community)
          Construct a new session to the given host and commnunity
 
Method Summary
protected  void finalize()
           
 ASNValue get(OID oid)
          Retrieves a single value for a given OID
 ASNValue get(String descr)
          Retrieves a single value for a given string descriptor
 String getAuthPassword()
           
 String getCommunity()
           
 byte[] getContextEngineID()
           
 String getContextName()
           
 String getPeerName()
           
 String getPrivPassword()
           
 long getRcvMsgMaxSize()
           
 int getRetries()
           
 byte[] getSecurityAuthKey()
           
 OID getSecurityAuthOID()
           
 byte[] getSecurityEngineID()
           
 SecurityLevel getSecurityLevel()
           
 int getSecurityModel()
           
 String getSecurityName()
           
 byte[] getSecurityPrivKey()
           
 OID getSecurityPrivOID()
           
 long getSndMsgMaxSize()
           
 SNMPVersion getSnmpVersion()
           
 long getTimeout()
           
 SNMPVersion getVersion()
           
 int hashCode()
           
 boolean isOpen()
           
 void open()
           
 PDU send(PDU pdu)
          Send a pdu and retrieve the result
 ASNValue set(OID oid, ASNValue v)
          Sets a single value for a given OID
 void setAuthenticationProtocol(OID oid)
           
 void setAuthPassword(String string)
           
 void setCommunity(String string)
           
 void setContextEngineID(byte[] bs)
           
 void setContextName(String string)
           
 void setPeerName(String string)
           
 void setPrivacyProtocol(OID oid)
           
 void setPrivPassword(String string)
           
 void setRcvMsgMaxSize(long l)
           
 void setRetries(int i)
           
 void setSecurityAuthKey(byte[] bs)
           
 void setSecurityAuthOID(OID oid)
           
 void setSecurityEngineID(byte[] bs)
           
 void setSecurityLevel(SecurityLevel level)
           
 void setSecurityModel(int i)
           
 void setSecurityName(String string)
           
 void setSecurityPrivKey(byte[] bs)
           
 void setSecurityPrivOID(OID oid)
           
 void setSerialEncryptor(NetSNMPSession.serialEncryption encryption)
           
 void setSndMsgMaxSize(long l)
           
 void setSNMPVersion(SNMPVersion version)
           
 void setTimeout(long l)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NetSNMPSyncSession

public NetSNMPSyncSession()
Construct an unopened session


NetSNMPSyncSession

public NetSNMPSyncSession(String host,
                          String community)
Construct a new session to the given host and commnunity

See Also:
org.netsnmp.NetSNMPSession(String,String)

NetSNMPSyncSession

public NetSNMPSyncSession(NetSNMPSession sess)
Method Detail

send

public PDU send(PDU pdu)
         throws IOException,
                NetSNMPSendError,
                InterruptedException
Send a pdu and retrieve the result

Parameters:
pdu - Pdu to send to remote agent
Returns:
pdu that the agent replies with
Throws:
IOException - if an IO error occurs on the connection
NetSNMPSendError - if an snmp error occurs (such as the pdu being too large)
Interupted - exception if the thread is interupted while waiting for the result
InterruptedException

set

public ASNValue set(OID oid,
                    ASNValue v)
             throws IOException,
                    NetSNMPSendError,
                    InterruptedException
Sets a single value for a given OID

Parameters:
oid - Object Identifier for the target object
v - Value to set the target object
IOException
NetSNMPSendError
InterruptedException

get

public ASNValue get(OID oid)
             throws IOException,
                    NetSNMPSendError,
                    InterruptedException
Retrieves a single value for a given OID

Parameters:
oid - Object Identifier of the desired value
Throws:
IOException - if an IO error occurs on the connection
NetSNMPSendError - if an snmp error occurs (such as the pdu being too large)
Interupted - exception if the thread is interupted while waiting for the result
InterruptedException

get

public ASNValue get(String descr)
             throws MIBItemNotFound,
                    IOException,
                    NetSNMPSendError,
                    InterruptedException
Retrieves a single value for a given string descriptor

Returns:
value of the object requested
Throws:
MIBItemNotFound - if the specified descriptor is not in the currently loaded mibs
IOException - if an IO error occurs on the connection
NetSNMPSendError - if an snmp error occurs (such as the pdu being too large)
Interupted - exception if the thread is interupted while waiting for the result
InterruptedException

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throwable

getAuthPassword

public String getAuthPassword()
Returns:

getCommunity

public String getCommunity()
Returns:

getContextEngineID

public byte[] getContextEngineID()
Returns:

getContextName

public String getContextName()
Returns:

getPeerName

public String getPeerName()
Returns:

getPrivPassword

public String getPrivPassword()
Returns:

getRcvMsgMaxSize

public long getRcvMsgMaxSize()
Returns:

getRetries

public int getRetries()
Returns:

getSecurityAuthKey

public byte[] getSecurityAuthKey()
Returns:

getSecurityAuthOID

public OID getSecurityAuthOID()
Returns:

getSecurityEngineID

public byte[] getSecurityEngineID()
Returns:

getSecurityLevel

public SecurityLevel getSecurityLevel()
Returns:

getSecurityModel

public int getSecurityModel()
Returns:

getSecurityName

public String getSecurityName()
Returns:

getSecurityPrivKey

public byte[] getSecurityPrivKey()
Returns:

getSecurityPrivOID

public OID getSecurityPrivOID()
Returns:

getSndMsgMaxSize

public long getSndMsgMaxSize()
Returns:

getSnmpVersion

public SNMPVersion getSnmpVersion()
Returns:

getTimeout

public long getTimeout()
Returns:

getVersion

public SNMPVersion getVersion()
Returns:

isOpen

public boolean isOpen()
Returns:

open

public void open()
          throws IllegalStateException
Throws:
IllegalStateException

setAuthenticationProtocol

public void setAuthenticationProtocol(OID oid)
Parameters:
oid -

setAuthPassword

public void setAuthPassword(String string)
Parameters:
string -

setCommunity

public void setCommunity(String string)
Parameters:
string -

setContextEngineID

public void setContextEngineID(byte[] bs)
Parameters:
bs -

setContextName

public void setContextName(String string)
Parameters:
string -

setPeerName

public void setPeerName(String string)
Parameters:
string -

setPrivacyProtocol

public void setPrivacyProtocol(OID oid)
Parameters:
oid -

setPrivPassword

public void setPrivPassword(String string)
Parameters:
string -

setRcvMsgMaxSize

public void setRcvMsgMaxSize(long l)
Parameters:
l -

setRetries

public void setRetries(int i)
Parameters:
i -

setSecurityAuthKey

public void setSecurityAuthKey(byte[] bs)
Parameters:
bs -

setSecurityAuthOID

public void setSecurityAuthOID(OID oid)
Parameters:
oid -

setSecurityEngineID

public void setSecurityEngineID(byte[] bs)
Parameters:
bs -

setSecurityLevel

public void setSecurityLevel(SecurityLevel level)
Parameters:
level -

setSecurityModel

public void setSecurityModel(int i)
Parameters:
i -

setSecurityName

public void setSecurityName(String string)
Parameters:
string -

setSecurityPrivKey

public void setSecurityPrivKey(byte[] bs)
Parameters:
bs -

setSecurityPrivOID

public void setSecurityPrivOID(OID oid)
Parameters:
oid -

setSndMsgMaxSize

public void setSndMsgMaxSize(long l)
Parameters:
l -

setSNMPVersion

public void setSNMPVersion(SNMPVersion version)
Parameters:
version -

setTimeout

public void setTimeout(long l)
Parameters:
l -

setSerialEncryptor

public void setSerialEncryptor(NetSNMPSession.serialEncryption encryption)
Parameters:
encryption -

hashCode

public int hashCode()
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

SourceForge.net Logo