private GSMessageImpl receiveFromQueueNoBlock(long timeout) throws ReceiveFromQueueException {
  GSMessageImpl message;
  long now;
  long timeToWait;
  long startTime=SystemTime.timeMillis();
  if (_logger.isLoggable(Level.FINEST)) {
    _logger.log(Level.FINEST,toString2() + "timeout=" + timeout);
  }
  while (!m_closed && !m_session.m_stopped && timeout > 10) {
    timeToWait=Math.min(timeout,RECEIVE_TIME_FRAME);
    if (_logger.isLoggable(Level.FINEST)) {
      _logger.log(Level.FINEST,toString2() + "Next timeToWait=" + timeToWait);
    }
    message=receiveFromQueue(timeToWait);
    if (message != null) {
      if (_logger.isLoggable(Level.FINEST)) {
        _logger.log(Level.FINEST,toString2() + "Got message: " + message);
      }
      return message;
    }
    now=SystemTime.timeMillis();
    timeout=timeout - (now - startTime);
    startTime=now;
  }
  if (_logger.isLoggable(Level.FINEST)) {
    _logger.log(Level.FINEST,toString2() + "Exiting: m_closed=" + m_closed+ ", m_stopped="+ m_session.m_stopped+ ", timeout="+ timeout);
  }
  return null;
}

private GSMessageImpl receiveFromQueueNoBlock ( long timeout ) throws ReceiveFromQueueException { GSMessageImpl message ; long now ; long timeToWait ; long startTime = SystemTime . timeMillis ( ) ; if ( _logger . isLoggable ( Level . FINEST ) ) { _logger . log ( Level . FINEST , toString2 ( ) + "timeout=" + timeout ) ; } while ( ! m_closed && ! m_session . m_stopped && timeout > 10 ) { timeToWait = Math . min ( timeout , RECEIVE_TIME_FRAME ) ; if ( _logger . isLoggable ( Level . FINEST ) ) { _logger . log ( Level . FINEST , toString2 ( ) + "Next timeToWait=" + timeToWait ) ; } message = receiveFromQueue ( timeToWait ) ; if ( message != null ) { if ( _logger . isLoggable ( Level . FINEST ) ) { _logger . log ( Level . FINEST , toString2 ( ) + "Got message: " + message ) ; } return message ; } now = SystemTime . timeMillis ( ) ; timeout = timeout - ( now - startTime ) ; startTime = now ; } if ( _logger . isLoggable ( Level . FINEST ) ) { _logger . log ( Level . FINEST , toString2 ( ) + "Exiting: m_closed=" + m_closed + ", m_stopped=" + m_session . m_stopped + ", timeout=" + timeout ) ; } return null ; }
receives a message from a queue , breaking the timeout into smaller time frames , to prevent potential eternal blocking .
