Methods Summary |
---|
synchronized void | addInformRequest(SnmpInformRequest snmpreq)Adds an inform request.
// If the adaptor is not ONLINE, stop adding requests.
//
if (!isSessionActive()) {
throw new SnmpStatusException("SNMP adaptor is not ONLINE or session is dead...") ;
}
informRequestList.put(snmpreq, snmpreq);
|
void | addResponse(SnmpInformRequest reqc)Adds the inform request object which received a response to an inform request
generated by the session. This is added to a private store, which
will be eventually picked up by the dispatcher for processing.
SnmpInformRequest snmpreq = (SnmpInformRequest) reqc ;
if (isSessionActive()) {
synchronized(this) {
informRespq.push(reqc) ;
this.notifyAll() ;
}
} else {
if (isDebugOn()) {
debug("addResponse", "Adaptor not ONLINE or session thread dead. So inform response is dropped..." + reqc.getRequestId());
}
}
return ;
|
private void | cancelAllRequests()Cancels all pending inform requests in this session.
final SnmpInformRequest[] list;
synchronized(this) {
if (informRequestList.isEmpty()) {
return ;
}
isBeingCancelled = true;
list = new SnmpInformRequest[informRequestList.size()];
java.util.Iterator it = informRequestList.values().iterator();
int i = 0;
while(it.hasNext()) {
SnmpInformRequest req = (SnmpInformRequest)it.next();
list[i++] = req;
it.remove();
}
informRequestList.clear();
}
for(int i = 0; i < list.length; i++)
list[i].cancelRequest();
|
private synchronized void | cancelAllResponses()
if (informRespq != null) {
syncInformReq = null ;
informRespq.removeAllElements() ;
this.notifyAll() ;
}
|
void | debug(java.lang.String clz, java.lang.String func, java.lang.String info)
Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP, clz, func, info);
|
void | debug(java.lang.String clz, java.lang.String func, java.lang.Throwable exception)
Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP, clz, func, exception);
|
void | debug(java.lang.String func, java.lang.String info)
debug(dbgTag, func, info);
|
void | debug(java.lang.String func, java.lang.Throwable exception)
debug(dbgTag, func, exception);
|
final void | destroySession()Destroys any pending inform requests and then stops the session.
The session will not be usable after this method returns.
cancelAllRequests() ;
cancelAllResponses() ;
synchronized(this) {
informSocket.close() ;
informSocket = null ;
}
snmpQman.stopQThreads() ;
snmpQman = null ;
killSessionThread() ;
|
public void | finalize()Finalizer of the SnmpSession objects.
This method is called by the garbage collector on an object
when garbage collection determines that there are no more references to the object.
Removes all the requests for this SNMP session, closes the socket and
sets all the references to the SnmpSession object to null .
if (informRespq != null)
informRespq.removeAllElements() ;
informRespq = null ;
if (informSocket != null)
informSocket.close() ;
informSocket = null ;
if (isTraceOn()) {
trace("finalize", "Shutting all servers");
}
snmpQman = null ;
|
SnmpQManager | getSnmpQManager()Gets the SnmpQManager which will be used by inform requests created in this session.
return snmpQman;
|
SnmpSocket | getSocket()Gets the SnmpSocket which will be used by inform requests created in this session.
return informSocket;
|
protected synchronized void | initialize(SnmpAdaptorServer adp, SnmpResponseHandler snmpRespHdlr)Initializes the SnmpSession.
informSocket = new SnmpSocket(snmpRespHdlr, adp.getAddress(), adp.getBufferSize().intValue());
myThread = new Thread(this, "SnmpSession");
myThread.start();
|
boolean | isDebugOn()
return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP);
|
synchronized boolean | isSessionActive()Indicates whether the thread for this session is active and the SNMP adaptor server ONLINE.
//return ((myThread != null) && (myThread.isAlive()));
return ((adaptor.isActive()) && (myThread != null) && (myThread.isAlive()));
|
boolean | isTraceOn()
return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_ADAPTOR_SNMP);
|
private synchronized void | killSessionThread()Make sure you are killing the thread when it is active. Instead
prepare for a graceful exit.
if ((myThread != null) && (myThread.isAlive())) {
if (isTraceOn()) {
trace("killSessionThread", "Destroying session");
}
if (!thisSessionContext()) {
myThread = null ;
this.notifyAll() ;
} else
myThread = null ;
}
|
SnmpInformRequest | makeAsyncRequest(java.net.InetAddress addr, java.lang.String cs, SnmpInformHandler cb, com.sun.jmx.snmp.SnmpVarBindList vblst, int port)Sends an inform request to the specified InetAddress destination using the specified community string.
if (!isSessionActive()) {
throw new SnmpStatusException("SNMP adaptor server not ONLINE");
}
SnmpInformRequest snmpreq = new SnmpInformRequest(this, adaptor, addr, cs, port, cb);
snmpreq.start(vblst);
return snmpreq;
|
private synchronized SnmpInformRequest | nextResponse()
if (informRespq.isEmpty()) {
try {
if (isTraceOn()) {
trace("nextResponse", "Blocking for response");
}
this.wait();
} catch(InterruptedException e) {
}
}
if (informRespq.isEmpty())
return null;
SnmpInformRequest reqc = (SnmpInformRequest) informRespq.firstElement();
informRespq.removeElementAt(0) ;
return reqc ;
|
private void | processResponse(SnmpInformRequest reqc)
while (reqc != null && myThread != null) {
try {
if (reqc != null) {
if (isTraceOn()) {
trace("processResponse", "Processing response to req = " + reqc.getRequestId());
}
reqc.processResponse() ; // Handles out of memory.
reqc = null ; // finished processing.
}
} catch (Exception e) {
if (isDebugOn()) {
debug("processResponse", e);
}
reqc = null ;
} catch (OutOfMemoryError ome) {
if (isDebugOn()) {
debug("processResponse", "Out of memory error in session thread");
debug("processResponse", ome);
}
Thread.currentThread().yield();
continue ; // re-process the request.
}
}
|
synchronized void | removeInformRequest(SnmpInformRequest snmpreq)Deletes an inform request.
// deleteRequest can be called from destroySnmpSession.
//In such a case remove is done in cancelAllRequest method.
if(!isBeingCancelled)
informRequestList.remove(snmpreq) ;
if (syncInformReq != null && syncInformReq == snmpreq) {
resetSyncMode() ;
}
|
private synchronized void | resetSyncMode()
if (syncInformReq == null)
return ;
syncInformReq = null ;
if (thisSessionContext())
return ;
this.notifyAll() ;
|
public void | run()Dispatcher method for this session thread. This is the dispatcher method
which goes in an endless-loop and waits for servicing inform requests
which received a reply from the manager.
myThread = Thread.currentThread();
myThread.setPriority(Thread.NORM_PRIORITY);
SnmpInformRequest reqc = null;
while (myThread != null) {
try {
reqc = nextResponse();
if (reqc != null) {
processResponse(reqc);
}
} catch (ThreadDeath d) {
myThread = null;
if (isDebugOn()) {
debug("run", "Session thread unexpectedly shutting down");
}
throw d ;
}
}
if (isTraceOn()) {
trace("run", "Session thread shutting down");
}
myThread = null ;
|
private synchronized void | setSyncMode(SnmpInformRequest req)
syncInformReq = req ;
|
private synchronized boolean | syncInProgress()Indicates whether this session is performing synchronous operation for an inform request.
return syncInformReq != null ;
|
boolean | thisSessionContext()Returns true if the current executing thread is this session's dispatcher.
Typically used to detect whether the user is doing a sync operation from
this dispatcher context. For instance, a user gives a sync command
from within a request callback using its associated session.
return (Thread.currentThread() == myThread) ;
|
void | trace(java.lang.String clz, java.lang.String func, java.lang.String info)
Trace.send(Trace.LEVEL_TRACE, Trace.INFO_ADAPTOR_SNMP, clz, func, info);
|
void | trace(java.lang.String func, java.lang.String info)
trace(dbgTag, func, info);
|
void | waitForResponse(SnmpInformRequest req, long waitTime)Performs sync operations on active requests. Any number of inform requests
can be done in sync mode but only one per thread.
The user can do synchronous operation using the request handle only.
if (! req.inProgress())
return ;
setSyncMode(req) ;
if (isTraceOn()) {
trace("waitForResponse", "Session switching to sync mode for inform request " + req.getRequestId());
}
long maxTime ;
if (waitTime <= 0)
maxTime = System.currentTimeMillis() + 6000 * 1000 ;
else
maxTime = System.currentTimeMillis() + waitTime ;
while (req.inProgress() || syncInProgress()) {
waitTime = maxTime - System.currentTimeMillis() ;
if (waitTime <= 0)
break ;
synchronized (this) {
if (! informRespq.removeElement(req)) {
try {
this.wait(waitTime) ;
} catch(InterruptedException e) {
}
continue ;
}
}
try {
processResponse(req) ;
} catch (Exception e) {
if (isDebugOn()) {
debug("waitForResponse", e);
}
}
}
resetSyncMode() ;
return ;
|