/** * Used in synchronous mode only. Provides a hook that enables a synchronous operation on a * previously sent inform request. Only one inform request can be in synchronous mode on a given * thread. The blocked thread is notified when the inform request state reaches completion. If the * inform request is not active, the method returns immediately. The user must get the error * status of the inform request to determine the exact status of the request. * * @param time The amount of time to wait. Zero means block until complete. * @return <CODE>true</CODE> if the inform request has completed, <CODE>false</CODE> if it is * still active. */ public final boolean waitForCompletion(long time) { if (!inProgress()) // check if request is in progress. return true; if (informSession.thisSessionContext()) { // We can manipulate callback safely as we are in session thread. // SnmpInformHandler savedCallback = callback; callback = null; informSession.waitForResponse(this, time); callback = savedCallback; } else { // This is being done from a different thread. So notifyClient will do the notification. // synchronized (this) { SnmpInformHandler savedCallback = callback; try { callback = null; this.wait(time); } catch (InterruptedException e) { } callback = savedCallback; } } return (!inProgress()); // true if request completed. }
/** 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; } }
/** For SNMP Runtime internal use only. */ final void setRequestSentTime(long sendtime) { numTries++; setPrevPollTime(sendtime); waitTimeForResponse = prevPollTime + timeout * numTries; setRequestStatus(stWaitingForReply); if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) { SNMP_ADAPTOR_LOGGER.logp( Level.FINER, SnmpInformRequest.class.getName(), "setRequestSentTime", "Inform request Successfully sent"); } informSession.getSnmpQManager().addWaiting(this); }
/** * For SNMP Runtime internal use only. Constructor for creating new inform request. This object * can be created only by an SNMP adaptor object. * * @param session <CODE>SnmpSession</CODE> object for this inform request. * @param adp <CODE>SnmpAdaptorServer</CODE> object for this inform request. * @param addr The <CODE>InetAddress</CODE> destination for this inform request. * @param cs The community string to be used for the inform request. * @param requestCB Callback interface for the inform request. * @exception SnmpStatusException SNMP adaptor is not ONLINE or session is dead. */ SnmpInformRequest( SnmpSession session, SnmpAdaptorServer adp, InetAddress addr, String cs, int p, SnmpInformHandler requestCB) throws SnmpStatusException { informSession = session; adaptor = adp; address = addr; communityString = cs; port = p; callback = requestCB; informSession.addInformRequest(this); // add to adaptor queue. setTimeout(adaptor.getTimeout()); }
/** * Sends the prepared PDU packet to the manager and updates the data structure to expect a * response. It acquires a lock on the socket to prevent a case where a response arrives before * this thread could insert the request into the wait queue. * * @exception IOException Signals that an I/O exception of some sort has occurred. */ final void sendPduPacket(byte[] buffer, int length) throws java.io.IOException { if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) { SNMP_ADAPTOR_LOGGER.logp( Level.FINER, SnmpInformRequest.class.getName(), "sendPduPacket", "Send to peer. Peer/Port : " + address.getHostName() + "/" + port + ". Length = " + length + "\nDump : \n" + SnmpMessage.dumpHexBuffer(buffer, 0, length)); } SnmpSocket theSocket = informSession.getSocket(); synchronized (theSocket) { theSocket.sendPacket(buffer, length, address, port); setRequestSentTime(System.currentTimeMillis()); } }
private final void queueResponse() { informSession.addResponse(this); }
/** * This method creates a new request ID. The ID is submitted to the poll server for scheduling. */ private void schedulePoll() { numTries = 0; initNewRequest(); setRequestStatus(stWaitingToSend); informSession.getSnmpQManager().addRequest(this); }
final synchronized void deleteRequest() { informSession.removeInformRequest(this); }