com.adventnet.snmp.snmp2
Class SASProtocolOptions

java.lang.Object
  extended by com.adventnet.snmp.snmp2.SASProtocolOptions
All Implemented Interfaces:
ProtocolOptions

public class SASProtocolOptions
extends java.lang.Object
implements ProtocolOptions

This class is the implementation of ProtocolOptions for SAS implementation of SnmpTransportProvider. This class is useful for opening the session and setting the parameters for sending any SNMP request. This class should be instantiated and the required values should be set before setting this instance in the SnmpSession. Only after, setting this instance in the SnmpSession, the open method of SnmpSession should be called in case of applets.

For example, opening the SnmpSession object

 SASProtocolOption opt = new SASProtocolOptions(remoteHost,remotePort,applet);
 SnmpSession session = new SnmpSession(api);
 session.setProtocolOptions(opt);
 try
 {
        session.open();
 }
 catch(SnmpException ex)
 {
        ex.printStackTrace();
 }

 

Similarly for sending a SNMP request:

 SASProtocolOptions opt = new SASProtoclOptions(remoteHost,remotePort);
 pdu.setProtocolOptions(opt);
 try
 {
        session.syncSend(pdu);
 }
 catch(SnmpException ex)
 {
        ex.printStackTrace();
 }

 


Constructor Summary
SASProtocolOptions()
          Initializes the variables for this instance of SASProtocolOptions.
SASProtocolOptions(int localPort)
          This is also a default constructor.
SASProtocolOptions(java.lang.String remoteHost, int remotePort)
          Initializes the variables for this instance of SASProtocolOptions.
SASProtocolOptions(java.lang.String remoteHost, int remotePort, java.applet.Applet applet)
          Initializes the variables for this instance of SASProtocolOptions.
 
Method Summary
(package private)  SASProtocolOptions copy()
           
 java.applet.Applet getApplet()
          gets the applet instance.
 java.lang.String[] getLocalAddresses()
          This method gets the local addresses for which the session should bind with.
 int getLocalPort()
          gets the localport at which the sasclient is started.
 int getProtocol()
          gets the protocol.
 java.lang.String getRemoteHost()
          gets the remoteHost of this ProtocolOptions obeject.
 int getRemotePort()
          gets the remotePort for this object.
 SASClient getSASClient()
          gets the SASClient instance.
 java.lang.String getSessionId()
          gets the session id for this ProtocolOptions obejct.
 void setApplet(java.applet.Applet app)
          sets the applet instance for this protocoloptions.
 void setLocalAddresses(java.lang.String[] addrs)
          This method sets the list of local addresses for which the session should bind.
 void setLocalPort(int port)
          sets the localport at which this sasclient should be started.
 void setProtocol(int prot)
          sets the protocol value.
 void setRemoteHost(java.lang.String host)
          sets the remote host.
 void setRemotePort(int port)
          sets the remotePort.
(package private)  void setSASClient(SASClient sas)
          sets the SASClient instance to this protocoloptions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SASProtocolOptions

SASProtocolOptions(int localPort)
This is also a default constructor. Since there is another no argument public constructor, a single argument is given to this constructor. This constructor will not set any default values to the variables. All objects will be null, all numeric variables will be zero and all boolean variables will be false.


SASProtocolOptions

public SASProtocolOptions()
Initializes the variables for this instance of SASProtocolOptions.


SASProtocolOptions

public SASProtocolOptions(java.lang.String remoteHost,
                          int remotePort,
                          java.applet.Applet applet)
Initializes the variables for this instance of SASProtocolOptions. This constructor should be used for opening a SnmpSession object.

For example, to open a SnmpSession object
 SASProtocolOption sasOpt = new SASProtocolOptions(remoteHost,remotePort,applet);
 SnmpSession session = new SnmpSession(api);
 session.setProtocolOption(sasOpt);
 try
 {
        session.open();
 }
 catch(SnmpException ex)
 {
        ex.printStackTrace();
 }
 

Parameters:
remoteHost - the host to which a packet should be sent.
remotePort - the port to which a packet should be sent.
app - the applet instance which is to be set.
Throws:
java.lang.IllegalArgumentException -
If remoteHost is null or empty.
If remotePort is negative or greater than 65535.
If the applet argument is null.

SASProtocolOptions

public SASProtocolOptions(java.lang.String remoteHost,
                          int remotePort)
Initializes the variables for this instance of SASProtocolOptions. This constructor should be used for setting the protocol option in the SnmpPDU for doing the Snmp request.
 pdu.setProtocolOptions(new SASProtoclOptions(remoteHost,remotePort));
 try
 {
        session.syncSend(pdu);
 }
 catch(SnmpException ex)
 {
        ex.printStackTrace();
 }
 

Parameters:
remoteHost - the host to which a packet should be sent.
remotePort - the port to which a packet should be sent.
Throws:
java.lang.IllegalArgumentException -
If remoteHost is null or empty.
If remotePort is negative or greater than 65535.
Method Detail

copy

SASProtocolOptions copy()

getSessionId

public java.lang.String getSessionId()
gets the session id for this ProtocolOptions obejct.

Specified by:
getSessionId in interface ProtocolOptions
Returns:
the session id of this ProtocolOptions object.

getRemoteHost

public java.lang.String getRemoteHost()
gets the remoteHost of this ProtocolOptions obeject.

Returns:
the remoteHost of this object.

setRemoteHost

public void setRemoteHost(java.lang.String host)
sets the remote host.

Parameters:
host - the remoteHost to which a packet should be sent.

getRemotePort

public int getRemotePort()
gets the remotePort for this object.

Returns:
the remotePort that is previously set or 0.

setRemotePort

public void setRemotePort(int port)
sets the remotePort.

Parameters:
port - the remotePort to which a packet should be sent.

getLocalPort

public int getLocalPort()
gets the localport at which the sasclient is started.

Returns:
the localport at which the sasclient is started.

setLocalPort

public void setLocalPort(int port)
sets the localport at which this sasclient should be started. This should be set before calling the open method of SnmpSession.

Parameters:
port - the port at which this sasclient should be started.

getApplet

public java.applet.Applet getApplet()
gets the applet instance.

Parameters:
the - applet instance

setApplet

public void setApplet(java.applet.Applet app)
sets the applet instance for this protocoloptions.

Parameters:
app - the applet instance which is to be set.

getProtocol

public int getProtocol()
gets the protocol. This value is either SASClient.TCP_PROTOCOL or SASClient.HTTP_PROTOCOL.

Returns:
the protocol that is set before.

setProtocol

public void setProtocol(int prot)
sets the protocol value. The value should be either SASClient.TCP_PROTOCOL or SASClient.HTTP_PROTOCOL If the value is other than these values, the previous value is retained.

Parameters:
prot - the protocol to be set.

getSASClient

public SASClient getSASClient()
gets the SASClient instance. This method will return a non-null sasclient instance only when this instance is used to open the SnmpSession.

Returns:
the sasclient instance which is created while opening the SnmpSession or null.

setSASClient

void setSASClient(SASClient sas)
sets the SASClient instance to this protocoloptions.

Parameters:
sas - the SASClient instance which is to be set.

setLocalAddresses

public void setLocalAddresses(java.lang.String[] addrs)
This method sets the list of local addresses for which the session should bind. The session will bind to the first successfull address and will ignore the rest.

Parameters:
addrs - the list of addresses to which the session should try binding.

getLocalAddresses

public java.lang.String[] getLocalAddresses()
This method gets the local addresses for which the session should bind with.

Returns:
a string array containing a list of addresses for which the session has tried to bind.