OpenNMS API 1.2.3

org.opennms.netmgt.capsd
Class DbIpInterfaceEntry

java.lang.Object
  extended byorg.opennms.netmgt.capsd.DbIpInterfaceEntry

public final class DbIpInterfaceEntry
extends java.lang.Object

Once loaded or create, the class tracks any changes and will write those changes to the database whenever the store method is invoked. If a database conneciton is not passed to the store method, then a temporary one is allocated to write the results.

NOTE: if the connection is passed in and is not in auto commit mode, then the caller must call commit to inform the database that the transaction is complete.

Author:
James Zuo , Weave , OpenNMS

Field Summary
private static int CHANGED_HOSTNAME
           
private static int CHANGED_IFINDEX
           
private static int CHANGED_MANAGED
           
private static int CHANGED_POLLTIME
           
private static int CHANGED_PRIMARY
           
private static int CHANGED_STATUS
           
private  int m_changed
          The bit map used to determine which elements have changed since the record was created.
private  boolean m_fromDb
          True if this recored was loaded from the database.
private  java.lang.String m_hostname
          The hostname string, if any
private  int m_ifIndex
          The SNMP ifIndex
private  java.net.InetAddress m_ipAddr
          The IP address.
private  java.sql.Timestamp m_lastPoll
          The last time the interface was checked.
private  char m_managedState
          The managed status, if any
private  int m_nodeId
          The node identifier
private  char m_primaryState
          The SNMP primary status.
private  int m_status
          The status of the interface
private  boolean m_useIfIndexAsKey
           
static char SNMP_NOT_ELIGIBLE
           
static char SNMP_PRIMARY
           
static char SNMP_SECONDARY
           
static char SNMP_UNKNOWN
           
private static java.lang.String SQL_LOAD_IFSVC_LIST
          This is the SQL statement used to load the list of service identifiers associated with this interface.
private static java.lang.String SQL_LOAD_REC
          The SQL statement used to read a node from the database.
private static java.lang.String SQL_LOAD_REC_IFINDEX
          This is the SQL statement used to load a record when the ifIndex is involved as part of the key lookup.
static char STATE_ALIAS
           
static char STATE_DELETED
           
static char STATE_FORCED
           
static char STATE_MANAGED
           
static char STATE_NOT_POLLED
           
static char STATE_UNKNOWN
           
static char STATE_UNMANAGED
           
 
Constructor Summary
private DbIpInterfaceEntry()
          Default constructor.
private DbIpInterfaceEntry(int nid, java.net.InetAddress address, boolean exists)
          Constructs a new interface.
private DbIpInterfaceEntry(int nid, java.net.InetAddress address, int ifIndex, boolean exists)
          Constructs a new interface, this constructor will only work for entries loaded from the database!
 
Method Summary
(package private) static DbIpInterfaceEntry clone(DbIpInterfaceEntry entry)
          Clones an existing entry.
(package private) static DbIpInterfaceEntry create(int nid, java.net.InetAddress address)
          Creates a new entry.
(package private) static DbIpInterfaceEntry create(int nid, java.net.InetAddress address, int ifIndex)
          Creates a new entry.
(package private) static DbIpInterfaceEntry get(java.sql.Connection db, int nid, java.net.InetAddress addr)
          Retreives a current record from the database based upon the key fields of nodeID and ipAddr.
(package private) static DbIpInterfaceEntry get(java.sql.Connection db, int nid, java.net.InetAddress addr, int ifIndex)
          Retreives a current record from the database based upon the key fields of nodeID and ipAddr.
(package private) static DbIpInterfaceEntry get(int nid, java.net.InetAddress addr)
          Retreives a current record from the database based upon the key fields of nodeID and ipAddr.
(package private) static DbIpInterfaceEntry get(int nid, java.net.InetAddress addr, int ifIndex)
          Retreives a current record from the database based upon the key fields of nodeID and ipAddr.
(package private)  java.lang.String getHostname()
          Returns the current hostname.
(package private)  java.net.InetAddress getIfAddress()
          Returns the name of the distributed poller for the entry.
(package private)  int getIfIndex()
          Returns the current ifIndex
(package private)  java.sql.Timestamp getLastPoll()
          Gets the last poll time of the record
(package private)  java.lang.String getLastPollString()
          Gets the last poll time of the record
(package private)  char getManagedState()
          Returns the current managed state of the interface
(package private)  int getNodeId()
          Returns the node entry's unique identifier.
(package private)  char getPrimaryState()
          Returns the current primary state.
(package private)  DbIfServiceEntry[] getServices()
           
(package private)  DbIfServiceEntry[] getServices(java.sql.Connection db)
           
(package private)  int getStatus()
          Gets the current operational status field
(package private)  boolean hasHostnameChanged()
           
(package private)  boolean hasIfIndex()
          Returns true if the ifIndex is defined.
(package private)  boolean hasIfIndexChanged()
           
(package private)  boolean hasManagedStateChanged()
           
(package private)  boolean hasPrimaryStateChanged()
           
(package private)  boolean hasStatusChanged()
           
private  void insert(java.sql.Connection c)
          Inserts the new interface into the ipInterface table of the OpenNMS databasee.
private  boolean load(java.sql.Connection c)
          Load the current interface from the database.
static void main(java.lang.String[] args)
          For debugging only
(package private)  void setHostname(java.lang.String name)
          Sets the current hostname.
(package private)  void setIfIndex(int ndx)
          Sets the ifIndex value
(package private)  void setLastPoll(java.util.Date time)
          Sets the current creation time.
(package private)  void setLastPoll(java.lang.String time)
          Sets the current creation time.
(package private)  void setLastPoll(java.sql.Timestamp time)
          Sets the current creation time.
(package private)  void setManagedState(char state)
          Sets the managed state of the instance.
(package private)  void setPrimaryState(char state)
          Sets the new primary state.
(package private)  void setStatus(int status)
          Sets the current status of the interface
(package private)  void store()
          Updates the interface information in the configured database.
(package private)  void store(java.sql.Connection db)
          Updates the interface information in the configured database.
 java.lang.String toString()
          Creates a string that displays the internal contents of the record.
private  void update(java.sql.Connection c)
          Updates an existing record in the OpenNMS ipInterface table.
(package private)  boolean updateHostname(java.lang.String newHostname)
           
(package private)  boolean updateIfIndex(int newIfIndex)
           
(package private)  boolean updateManagedState(char newManagedState)
           
(package private)  boolean updatePrimaryState(char newPrimaryState)
           
(package private)  boolean updateStatus(int newStatus)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SNMP_PRIMARY

public static final char SNMP_PRIMARY
See Also:
Constant Field Values

SNMP_SECONDARY

public static final char SNMP_SECONDARY
See Also:
Constant Field Values

SNMP_NOT_ELIGIBLE

public static final char SNMP_NOT_ELIGIBLE
See Also:
Constant Field Values

SNMP_UNKNOWN

public static final char SNMP_UNKNOWN
See Also:
Constant Field Values

STATE_MANAGED

public static final char STATE_MANAGED
See Also:
Constant Field Values

STATE_UNMANAGED

public static final char STATE_UNMANAGED
See Also:
Constant Field Values

STATE_ALIAS

public static final char STATE_ALIAS
See Also:
Constant Field Values

STATE_DELETED

public static final char STATE_DELETED
See Also:
Constant Field Values

STATE_FORCED

public static final char STATE_FORCED
See Also:
Constant Field Values

STATE_NOT_POLLED

public static final char STATE_NOT_POLLED
See Also:
Constant Field Values

STATE_UNKNOWN

public static final char STATE_UNKNOWN
See Also:
Constant Field Values

SQL_LOAD_REC

private static final java.lang.String SQL_LOAD_REC
The SQL statement used to read a node from the database. This record is keyed by the node identifier and distributed poller name.

See Also:
Constant Field Values

SQL_LOAD_IFSVC_LIST

private static final java.lang.String SQL_LOAD_IFSVC_LIST
This is the SQL statement used to load the list of service identifiers associated with this interface. Once the identifiers are known then a list of DbIfServiceEntry(s) can be returned to the caller.

See Also:
Constant Field Values

SQL_LOAD_REC_IFINDEX

private static final java.lang.String SQL_LOAD_REC_IFINDEX
This is the SQL statement used to load a record when the ifIndex is involved as part of the key lookup. This is mainly used when a node has multiple unnamed interfaces (i.e. 0.0.0.0) but each has a different ifIndex.

See Also:
Constant Field Values

m_fromDb

private boolean m_fromDb
True if this recored was loaded from the database. False if it's new.


m_nodeId

private int m_nodeId
The node identifier


m_ipAddr

private java.net.InetAddress m_ipAddr
The IP address.


m_ifIndex

private int m_ifIndex
The SNMP ifIndex


m_hostname

private java.lang.String m_hostname
The hostname string, if any


m_status

private int m_status
The status of the interface


m_managedState

private char m_managedState
The managed status, if any


m_lastPoll

private java.sql.Timestamp m_lastPoll
The last time the interface was checked.


m_primaryState

private char m_primaryState
The SNMP primary status.


m_changed

private int m_changed
The bit map used to determine which elements have changed since the record was created.


CHANGED_IFINDEX

private static final int CHANGED_IFINDEX
See Also:
Constant Field Values

CHANGED_HOSTNAME

private static final int CHANGED_HOSTNAME
See Also:
Constant Field Values

CHANGED_MANAGED

private static final int CHANGED_MANAGED
See Also:
Constant Field Values

CHANGED_STATUS

private static final int CHANGED_STATUS
See Also:
Constant Field Values

CHANGED_POLLTIME

private static final int CHANGED_POLLTIME
See Also:
Constant Field Values

CHANGED_PRIMARY

private static final int CHANGED_PRIMARY
See Also:
Constant Field Values

m_useIfIndexAsKey

private boolean m_useIfIndexAsKey
Constructor Detail

DbIpInterfaceEntry

private DbIpInterfaceEntry()
Default constructor.


DbIpInterfaceEntry

private DbIpInterfaceEntry(int nid,
                           java.net.InetAddress address,
                           boolean exists)
Constructs a new interface.

Parameters:
nid - The node identifier.
address - The target interface address.
exists - True if the interface already exists.

DbIpInterfaceEntry

private DbIpInterfaceEntry(int nid,
                           java.net.InetAddress address,
                           int ifIndex,
                           boolean exists)
Constructs a new interface, this constructor will only work for entries loaded from the database!

Parameters:
nid - The node identifier.
address - The target interface address.
ifIndex - The target ifIndex of the node/address pair
exists - True if the interface already exists.
Method Detail

insert

private void insert(java.sql.Connection c)
             throws java.sql.SQLException
Inserts the new interface into the ipInterface table of the OpenNMS databasee.

Parameters:
c - The connection to the database.
Throws:
java.sql.SQLException - Thrown if an error occurs with the connection

update

private void update(java.sql.Connection c)
             throws java.sql.SQLException
Updates an existing record in the OpenNMS ipInterface table.

Parameters:
c - The connection used for the update.
Throws:
java.sql.SQLException - Thrown if an error occurs with the connection

load

private boolean load(java.sql.Connection c)
              throws java.sql.SQLException
Load the current interface from the database. If the interface was modified, the modifications are lost. The nodeid and ip address must be set prior to this call.

Parameters:
c - The connection used to load the data.
Throws:
java.sql.SQLException - Thrown if an error occurs with the connection

getNodeId

int getNodeId()
Returns the node entry's unique identifier. This is a non-mutable element. If the record does not yet exist in the database then a -1 is returned.


getIfAddress

java.net.InetAddress getIfAddress()
Returns the name of the distributed poller for the entry. This is a non-mutable element of the record.


getLastPollString

java.lang.String getLastPollString()
Gets the last poll time of the record


getLastPoll

java.sql.Timestamp getLastPoll()
Gets the last poll time of the record


setLastPoll

void setLastPoll(java.lang.String time)
           throws java.text.ParseException
Sets the current creation time.

Parameters:
time - The creation time.
Throws:
java.text.ParseException

setLastPoll

void setLastPoll(java.util.Date time)
Sets the current creation time.

Parameters:
time - The creation time.

setLastPoll

void setLastPoll(java.sql.Timestamp time)
Sets the current creation time.

Parameters:
time - The creation time.

hasIfIndex

boolean hasIfIndex()
Returns true if the ifIndex is defined.


getIfIndex

int getIfIndex()
Returns the current ifIndex


setIfIndex

void setIfIndex(int ndx)
Sets the ifIndex value

Parameters:
ndx - The new ifIndex.

hasIfIndexChanged

boolean hasIfIndexChanged()

updateIfIndex

boolean updateIfIndex(int newIfIndex)

getHostname

java.lang.String getHostname()
Returns the current hostname.


setHostname

void setHostname(java.lang.String name)
Sets the current hostname.

Parameters:
name - The new hostname

hasHostnameChanged

boolean hasHostnameChanged()

updateHostname

boolean updateHostname(java.lang.String newHostname)

getManagedState

char getManagedState()
Returns the current managed state of the interface


setManagedState

void setManagedState(char state)
Sets the managed state of the instance.

Parameters:
state - The new managed state

hasManagedStateChanged

boolean hasManagedStateChanged()

updateManagedState

boolean updateManagedState(char newManagedState)

getStatus

int getStatus()
Gets the current operational status field


setStatus

void setStatus(int status)
Sets the current status of the interface

Parameters:
status - The new status.

hasStatusChanged

boolean hasStatusChanged()

updateStatus

boolean updateStatus(int newStatus)

getPrimaryState

char getPrimaryState()
Returns the current primary state.


setPrimaryState

void setPrimaryState(char state)
Sets the new primary state.

Parameters:
state - The new primary state.

hasPrimaryStateChanged

boolean hasPrimaryStateChanged()

updatePrimaryState

boolean updatePrimaryState(char newPrimaryState)

store

void store()
     throws java.sql.SQLException
Updates the interface information in the configured database. If the interfaca does not exist the a new row in the table is created. If the element already exists then it's current row is updated as needed based upon the current changes to the node.

Throws:
java.sql.SQLException

store

void store(java.sql.Connection db)
     throws java.sql.SQLException
Updates the interface information in the configured database. If the interfaca does not exist the a new row in the table is created. If the element already exists then it's current row is updated as needed based upon the current changes to the node.

Parameters:
db - The database connection used to write the record.
Throws:
java.sql.SQLException

getServices

DbIfServiceEntry[] getServices()
                         throws java.sql.SQLException
Throws:
java.sql.SQLException

getServices

DbIfServiceEntry[] getServices(java.sql.Connection db)
                         throws java.sql.SQLException
Throws:
java.sql.SQLException

create

static DbIpInterfaceEntry create(int nid,
                                 java.net.InetAddress address)
Creates a new entry. The entry is created in memory, but is not written to the database until the first call to store.

Parameters:
address - The address of the interface.
nid - The node id of the interface.
Returns:
A new interface record.

create

static DbIpInterfaceEntry create(int nid,
                                 java.net.InetAddress address,
                                 int ifIndex)
Creates a new entry. The entry is created in memory, but is not written to the database until the first call to store.

Parameters:
address - The address of the interface.
nid - The node id of the interface.
ifIndex - The ifindex of the interface.
Returns:
A new interface record.

clone

static DbIpInterfaceEntry clone(DbIpInterfaceEntry entry)
Clones an existing entry.

Parameters:
entry - The entry to be cloned
Returns:
a new DbIpInterfaceEntry identical to the original

get

static DbIpInterfaceEntry get(int nid,
                              java.net.InetAddress addr)
                       throws java.sql.SQLException
Retreives a current record from the database based upon the key fields of nodeID and ipAddr. If the record cannot be found then a null reference is returned.

Parameters:
nid - The node id key
addr - The ip address.
Returns:
The loaded entry or null if one could not be found.
Throws:
java.sql.SQLException

get

static DbIpInterfaceEntry get(int nid,
                              java.net.InetAddress addr,
                              int ifIndex)
                       throws java.sql.SQLException
Retreives a current record from the database based upon the key fields of nodeID and ipAddr. If the record cannot be found then a null reference is returned.

Parameters:
nid - The node id key
addr - The ip address.
ifIndex - The interface index.
Returns:
The loaded entry or null if one could not be found.
Throws:
java.sql.SQLException

get

static DbIpInterfaceEntry get(java.sql.Connection db,
                              int nid,
                              java.net.InetAddress addr)
                       throws java.sql.SQLException
Retreives a current record from the database based upon the key fields of nodeID and ipAddr. If the record cannot be found then a null reference is returnd.

Parameters:
db - The databse connection used to load the entry.
nid - The node id key
addr - The internet address.
Returns:
The loaded entry or null if one could not be found.
Throws:
java.sql.SQLException

get

static DbIpInterfaceEntry get(java.sql.Connection db,
                              int nid,
                              java.net.InetAddress addr,
                              int ifIndex)
                       throws java.sql.SQLException
Retreives a current record from the database based upon the key fields of nodeID and ipAddr. If the record cannot be found then a null reference is returnd.

Parameters:
db - The databse connection used to load the entry.
nid - The node id key
addr - The internet address.
ifIndex - The interface index.
Returns:
The loaded entry or null if one could not be found.
Throws:
java.sql.SQLException

toString

public java.lang.String toString()
Creates a string that displays the internal contents of the record. This is mainly just used for debug output since the format is ad-hoc.


main

public static void main(java.lang.String[] args)
For debugging only


OpenNMS API 1.2.3

Generated by eevans on May 29 2005 2015.