⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snmpinformrequest.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * Parses the inform response packet. If the agent responds with error set,     * it does not parse any further.     */    synchronized void parsePduPacket(SnmpPduRequestType rpdu) {                if (rpdu == null)            return;	        errorStatus = rpdu.getErrorStatus();        errorIndex = rpdu.getErrorIndex();	        if (errorStatus == snmpRspNoError) {            updateInternalVarBindWithResult(((SnmpPdu)rpdu).varBindList);            return;        }	        if (errorStatus != snmpRspNoError)              --errorIndex;  // rationalize for index to start with 0.	        if (isTraceOn()) {            trace("parsePduPacket", "received inform response. ErrorStatus/ErrorIndex = " + errorStatus + "/" + errorIndex);        }    }        /**     * Calls the user implementation of the <CODE>SnmpInformHandler</CODE> interface.     */    private void handleSuccess() {                setRequestStatus(stResultsAvailable);        if (isTraceOn()) {            trace("handleSuccess", "Invoking user defined callback...");        }        deleteRequest();  // delete only non-poll request.        notifyClient();		        requestPdu = null;	//responsePdu = null;        internalVarBind = null;        try {  // catch all user exception which may happen in callback.            if (callback != null)                callback.processSnmpPollData(this, errorStatus, errorIndex, getVarBindList());        } catch (Exception e) {            if (isDebugOn()) {                debug("handleSuccess", "Exception generated by user callback");                debug("handleSuccess", e);            }        } catch (OutOfMemoryError ome) {            if (isDebugOn()) {                debug("handleSuccess", "OutOfMemory Error generated by user callback");                debug("handleSuccess", ome);            }            Thread.currentThread().yield();        }        return;    }    /**     * Calls the user implementation of the <CODE>SnmpInformHandler</CODE> interface.     */    private void handleTimeout() {                setRequestStatus(stTimeout);                if (isDebugOn()) {            debug("handleTimeout", "Snmp error/index = " + snmpErrorToString(errorStatus) + "/" +                  errorIndex + ". Invoking timeout user defined callback...");        }        deleteRequest();        notifyClient();        requestPdu = null;	responsePdu = null;        internalVarBind = null;        try {            if (callback != null)                 callback.processSnmpPollTimeout(this);        } catch (Exception e) {  // catch any exception a user might not handle.            if (isDebugOn()) {                debug("handleTimeout", "Exception generated by user callback");                debug("handleTimeout", e);            }        } catch (OutOfMemoryError ome) {            if (isDebugOn()) {                debug("handleTimeout", "OutOfMemory Error generated by user callback");                debug("handleTimeout", ome);            }            Thread.currentThread().yield();        }        return;    }      /**     * Calls the user implementation of the <CODE>SnmpInformHandler</CODE> interface.     */    private void handleError(String msg) {                setRequestStatus(stResultsAvailable);        if (isDebugOn()) {            debug("handleError", "Snmp error/index = " + snmpErrorToString(errorStatus) + "/" +                  errorIndex + ". Invoking error user defined callback...\n" + getVarBindList());        }        deleteRequest();        notifyClient();		        requestPdu = null;	responsePdu = null;        internalVarBind = null;		        try {            if (callback != null)                callback.processSnmpPollData(this, getErrorStatus(), getErrorIndex(), getVarBindList());        } catch (Exception e) {  // catch any exception a user might not handle.            if (isDebugOn()) {                debug("handleError", "Exception generated by user callback");                debug("handleError", e);            }        } catch (OutOfMemoryError ome) {            if (isDebugOn()) {                debug("handleError", "OutOfMemory Error generated by user callback");                debug("handleError", ome);            }            Thread.currentThread().yield();        }    }    /**     * Calls the user implementation of the <CODE>SnmpInformHandler</CODE> interface.     */    private void handleInternalError(String msg) {                setRequestStatus(stInternalError);        if (reason == null)            reason = msg;        if (isDebugOn()) {            debug("handleInternalError", "Snmp error/index = " + snmpErrorToString(errorStatus) + "/" +                  errorIndex + ". Invoking internal error user defined callback...\n" + getVarBindList());        }        deleteRequest();        notifyClient();        requestPdu = null;	responsePdu = null;        internalVarBind = null;		        try {            if (callback != null)                 callback.processSnmpInternalError(this, reason);        } catch (Exception e) {  // catch any exception a user might not handle.            if (isDebugOn()) {                debug("handleInternalError", "Exception generated by user callback");                debug("handleInternalError", e);            }        } catch (OutOfMemoryError ome) {            if (isDebugOn()) {                debug("handleInternalError", "OutOfMemory Error generated by user callback");                debug("handleInternalError", ome);            }            Thread.currentThread().yield();        }    }    void updateInternalVarBindWithResult(SnmpVarBind[] list) {             if ((list == null) || (list.length == 0))            return;            int idx = 0;                for(int i = 0; i < internalVarBind.length && idx < list.length; i++) {            SnmpVarBind avar = internalVarBind[i];            if (avar == null)                continue;                            SnmpVarBind res = list[idx];            avar.setSnmpValue(res.getSnmpValue());            idx++;        }    }        /**     * For SNMP Runtime internal use only.     */    final void invokeOnResponse(Object resp) {        if (resp != null) {            if (resp instanceof SnmpPduRequestType)                 responsePdu = (SnmpPduRequestType) resp;            else                 return;        }        setRequestStatus(stReceivedReply);        queueResponse();    }        /**     * This method cancels an active inform request and removes it from the polling list.     */    private void stopRequest() {                // Remove the clause synchronized of the stopRequest method.        // Synchronization is isolated as possible to avoid thread lock.        // Note: the method removeRequest from SendQ is synchronized.        // fix bug jaw.00392.B        //        synchronized(this) {            setRequestStatus(stAborted);        }        informSession.getSnmpQManager().removeRequest(this);        synchronized(this) {            requestId = 0;        }    }        final synchronized void deleteRequest() {        informSession.removeInformRequest(this);    }        /**     * For SNMP Runtime internal use only.     * Gets the active <CODE>SnmpVarBindList</CODE>. The contents of it     * are not guaranteed to be consistent when the inform request is active.     * @return The list of <CODE>SnmpVarBind</CODE> objects.     */    final synchronized SnmpVarBindList getVarBindList() {        return varBindList;    }    /**     * For SNMP Runtime internal use only.     * You should specify the <CODE>SnmpVarBindList</CODE> at SnmpInformRequest creation time.      * You cannot modify it during the life-time of the object.     */    final synchronized void setVarBindList(SnmpVarBindList newvblst) {        varBindList = newvblst;        if (internalVarBind == null || internalVarBind.length != varBindList.size()) {            internalVarBind = new SnmpVarBind[varBindList.size()];        }        varBindList.copyInto(internalVarBind);    }    /**     * For SNMP Runtime internal use only.     */    final synchronized void setErrorStatusAndIndex(int stat, int idx) {        errorStatus = stat;        errorIndex = idx;    }        /**     * For SNMP Runtime internal use only.     */    final synchronized void setPrevPollTime(long prev) {        prevPollTime = prev;    }    /**     * For SNMP Runtime internal use only.     */    final  void setRequestSentTime(long sendtime) {        numTries++;        setPrevPollTime(sendtime);        waitTimeForResponse = prevPollTime + timeout*numTries;        setRequestStatus(stWaitingForReply);            if (isTraceOn()) {            trace("setRequestSentTime", "Inform request Successfully sent");        }            informSession.getSnmpQManager().addWaiting(this);    }    /**     * Initializes the request id from the request counter.     */    final synchronized void initNewRequest() {        requestId = requestCounter.getNewId();    }    /**     * For SNMP Runtime internal use only.     */    long timeRemainingForAction(long currtime) {        switch (reqState) {        case stWaitingToSend :            return nextPollTime - currtime;        case stWaitingForReply :            return waitTimeForResponse - currtime;        default :            return -1;        }    }    /**     * Returns the string state corresponding to the specified integer state.     * @param state The integer state.     * @return The string state.     */    final static String statusDescription(int state) {        switch (state) {        case stWaitingToSend :            return "Waiting to send.";        case stWaitingForReply :            return "Waiting for reply.";        case stReceivedReply :            return "Response arrived.";        case stAborted  :            return "Aborted by user.";        case stTimeout :            return "Timeout Occured.";        case stInternalError :            return "Internal error.";        case stResultsAvailable :            return "Results available";        case stNeverUsed :            return "Inform request in createAndWait state";        }        return "Unknown inform request state.";    }    /**     * Sets the request status to the specified value.     * @param reqst The new status request.     */    final synchronized void setRequestStatus(int reqst) {        reqState = reqst;    }    /**     * Gives a status report of the request.     * @return The status report of the request.     */    public synchronized String toString() {        StringBuffer s = new StringBuffer(300) ;        s.append(tostring()) ;        s.append("\nPeer/Port : " + address.getHostName() + "/" + port) ;        return s.toString() ;    }        private synchronized String tostring() {        StringBuffer s = new StringBuffer("InformRequestId = " + requestId);        s.append("   " + "Status = " + statusDescription(reqState));        s.append("  Timeout/MaxTries/NumTries = " + timeout*numTries + "/" +                 + getMaxTries() + "/" + numTries);        if (prevPollTime > 0) {            debugDate.setTime(prevPollTime);            s.append("\nPrevPolled = " + debugDate.toString());        } else            s.append("\nNeverPolled");        s.append(" / RemainingTime(millis) = " +                  timeRemainingForAction(System.currentTimeMillis()));        return s.toString();    }    // TRACES & DEBUG    //---------------        boolean isTraceOn() {        return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_ADAPTOR_SNMP);    }    void trace(String clz, String func, String info) {        Trace.send(Trace.LEVEL_TRACE, Trace.INFO_ADAPTOR_SNMP, clz, func, info);    }    void trace(String func, String info) {        trace(dbgTag, func, info);    }        boolean isDebugOn() {        return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP);    }    void debug(String clz, String func, String info) {        Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP, clz, func, info);    }    void debug(String clz, String func, Throwable exception) {        Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP, clz, func, exception);    }        void debug(String func, String info) {        debug(dbgTag, func, info);    }        void debug(String func, Throwable exception) {        debug(dbgTag, func, exception);    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -