FileDocCategorySizeDatePackage
SnmpSendServer.javaAPI DocJava SE 5 API6203Fri Aug 26 14:55:06 BST 2005com.sun.jmx.snmp.daemon

SnmpSendServer

public final class SnmpSendServer extends Thread
This class starts a thread which picks up a session from the queue and prepares the inform request protocol data unit (PDU) packet and sends it to the manager. The request is then added to the wait queue and marked as one that is waiting for a response.

Fields Summary
private int
intervalRange
private Vector
readyPool
SnmpQManager
snmpq
String
dbgTag
boolean
isBeingDestroyed
Constructors Summary
public SnmpSendServer(ThreadGroup grp, SnmpQManager q)

	
    // CONSTRUCTORS
    //-------------
	
         
		super(grp, "SnmpSendServer") ;
		snmpq = q ;
		start() ;
	
Methods Summary
voiddebug(java.lang.String clz, java.lang.String func, java.lang.String info)

        Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP, clz, func, info);
    
voiddebug(java.lang.String clz, java.lang.String func, java.lang.Throwable exception)

        Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP, clz, func, exception);
    
voiddebug(java.lang.String func, java.lang.String info)

        debug(dbgTag, func, info);
    
voiddebug(java.lang.String func, java.lang.Throwable exception)

        debug(dbgTag, func, exception);
    
voidfireRequest(SnmpInformRequest req)
This will fire the specified request.

		if (req != null && req.inProgress())  {
            if (isTraceOn()) {
                trace("fireRequest", "Firing inform request directly. -> " + req.getRequestId());
            }			  
            req.action() ;
		}
	
voidfireRequestList(java.util.Vector reqList)

        // Fire all requests as independent requests.
        while (!reqList.isEmpty()) {
            SnmpInformRequest req = (SnmpInformRequest) reqList.lastElement() ;
            if (req != null && req.inProgress())
                fireRequest(req) ;
            reqList.removeElementAt(reqList.size() - 1) ;
        }
    
booleanisDebugOn()

        return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP);
    
booleanisTraceOn()

        return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_ADAPTOR_SNMP);
    
private voidprepareAndSendRequest()

												
        if (readyPool == null || readyPool.isEmpty()) {
            // wait to be signaled by the an active request.
            if (isTraceOn()) {
                trace("prepareAndSendRequest", "Blocking for inform requests");
            }			  
            readyPool = snmpq.getAllOutstandingRequest(intervalRange) ;
            if (isBeingDestroyed == true)
                return;
        } else {
            if (isDebugOn()) {
                debug("prepareAndSendRequest", "Inform requests from a previous block left unprocessed. Will try again");
            }			  
        }

        if (isTraceOn()) {
            trace("prepareAndSendRequest", "List of inform requests to send : " + reqListToString(readyPool));
        }			  
        
        synchronized(this) {
            if (readyPool.size() < 2) {
                // Fire all requests as independent requests.
                fireRequestList(readyPool) ;
                return ;
            }
        
            while (!readyPool.isEmpty()) {
                SnmpInformRequest req = (SnmpInformRequest) readyPool.lastElement() ;
                if (req != null && req.inProgress()) {
                    fireRequest(req) ;
                }
                readyPool.removeElementAt(readyPool.size() - 1) ;
            }
            readyPool.removeAllElements() ;
        }
    
final java.lang.StringreqListToString(java.util.Vector vec)

		StringBuffer s = new StringBuffer(vec.size() * 100) ;

		Enumeration dbge = vec.elements() ;
		while (dbge.hasMoreElements()) {
			SnmpInformRequest reqc = (SnmpInformRequest) dbge.nextElement() ;
            s.append("InformRequestId -> ") ;
			s.append(reqc.getRequestId()) ;
            s.append(" / Destination -> ") ;
			s.append(reqc.getAddress()) ;
            s.append(". ") ;
		}
		String str = s.toString() ;
		s = null ;
		return str ;
	
public voidrun()

        Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
        
        if (isTraceOn()) {
            trace("run", "Thread Started");
        }

		while (true) {
			try {
				prepareAndSendRequest() ;
                if (isBeingDestroyed == true)
                    break;
            } catch (Exception anye) {
                if (isDebugOn()) {
                    debug("run", "Exception in send server");
                    debug("run", anye);
                }
			} catch (ThreadDeath td) {
				// This is not good but Netscape does kill all threads when 
				// the pagecontext changes.
                if (isDebugOn()) {
                    debug("run", "Exiting... Fatal error");
                }
				throw td ;
			} catch (OutOfMemoryError ome) {
                if (isDebugOn()) {
                    debug("run", "Out of memory");
                }			  
			} catch (Error err) {
                if (isDebugOn()) {
                    debug("run", err);
                }
				throw err ;
			}
		}
	
public synchronized voidstopSendServer()

        
        if (isAlive()) {
            interrupt();
            try {
                // Wait until the thread die.
                //
                join();
            } catch (InterruptedException e) {
                // Ignore...
            }
        }
    
voidtrace(java.lang.String func, java.lang.String info)

        trace(dbgTag, func, info);
    
voidtrace(java.lang.String clz, java.lang.String func, java.lang.String info)

        Trace.send(Trace.LEVEL_TRACE, Trace.INFO_ADAPTOR_SNMP, clz, func, info);