mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Chris Ridd
15.28.2012 52a33fecbe37ccf6b97f9637745bb03107349283
Fix OPENDJ-637 - Connection handler bytesRead and bytesWritten statistics are wrong
2 files modified
49 ■■■■ changed files
opends/src/server/org/opends/server/protocols/ldap/LDAPClientConnection.java 30 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/protocols/ldap/LDAPStatistics.java 19 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/protocols/ldap/LDAPClientConnection.java
@@ -161,7 +161,12 @@
    public int read(ByteBuffer byteBuffer) throws IOException
    {
      return clientChannel.read(byteBuffer);
      int bytesRead = clientChannel.read(byteBuffer);
      if (bytesRead > 0 && keepStats)
      {
        statTracker.updateBytesRead(bytesRead);
      }
      return bytesRead;
    }
    public boolean isOpen()
@@ -182,7 +187,11 @@
      try
      {
        int bytesToWrite = byteBuffer.remaining();
        clientChannel.write(byteBuffer);
        int bytesWritten = clientChannel.write(byteBuffer);
        if (bytesWritten > 0 && keepStats)
        {
          statTracker.updateBytesWritten(bytesWritten);
        }
        if (!byteBuffer.hasRemaining())
        {
          return bytesToWrite;
@@ -208,11 +217,16 @@
          while (byteBuffer.hasRemaining()
              && (System.currentTimeMillis() < stopTime))
          {
            if (clientChannel.write(byteBuffer) < 0)
            bytesWritten = clientChannel.write(byteBuffer);
            if (bytesWritten < 0)
            {
              // The client connection has been closed.
              throw new ClosedChannelException();
            }
            if (bytesWritten > 0 && keepStats)
            {
              statTracker.updateBytesWritten(bytesWritten);
            }
          }
          if (byteBuffer.hasRemaining())
@@ -250,12 +264,16 @@
              SelectionKey k = iterator.next();
              if (k.isWritable())
              {
                int bytesWritten = clientChannel.write(byteBuffer);
                bytesWritten = clientChannel.write(byteBuffer);
                if (bytesWritten < 0)
                {
                  // The client connection has been closed.
                  throw new ClosedChannelException();
                }
                if (bytesWritten > 0 && keepStats)
                {
                  statTracker.updateBytesWritten(bytesWritten);
                }
                iterator.remove();
              }
@@ -960,9 +978,7 @@
      if (keepStats)
      {
        // TODO hard-coded for now, flush probably needs to
        // return how many bytes were flushed.
        statTracker.updateMessageWritten(message, 4096);
        statTracker.updateMessageWritten(message);
      }
    }
    catch (Exception e)
opends/src/server/org/opends/server/protocols/ldap/LDAPStatistics.java
@@ -491,6 +491,20 @@
  /**
   * Updates the appropriate set of counters to indicate that the
   * specified number of bytes have been written to the client.
   *
   * @param bytesWritten
   *          The number of bytes written to the client.
   */
  public void updateBytesWritten(int bytesWritten)
  {
     this.bytesWritten.getAndAdd(bytesWritten);
  }
  /**
   * Updates the appropriate set of counters based on the provided
   * message that has been read from the client.
   *
@@ -562,12 +576,9 @@
   *
   * @param message
   *          The message that was written to the client.
   * @param bytesWritten
   *          The size of the message written in bytes.
   */
  public void updateMessageWritten(LDAPMessage message, int bytesWritten)
  public void updateMessageWritten(LDAPMessage message)
  {
      this.bytesWritten.getAndAdd(bytesWritten);
      messagesWritten.getAndIncrement();
      switch (message.getProtocolOp().getType())