/**
 * Copyright 2015, Xiaomi.
 * All rights reserved.
 * Author: yongxing@xiaomi.com
 */

package com.xiaomi.infra.galaxy.talos.producer;

public class BufferedMessageCount {
  private int maxBufferedMsgNumber;
  private int maxBufferedMsgBytes;

  private int bufferedMsgNumber;
  private int bufferedMsgBytes;

  public BufferedMessageCount(int maxBufferedMsgNumber, int maxBufferedMsgBytes) {
    this.maxBufferedMsgNumber = maxBufferedMsgNumber;
    this.maxBufferedMsgBytes = maxBufferedMsgBytes;

    bufferedMsgNumber = 0;
    bufferedMsgBytes = 0;
  }

  synchronized public void increase(int diffBufferedMsgNumber, int diffBufferedMsgBytes) {
    this.bufferedMsgNumber += diffBufferedMsgNumber;
    this.bufferedMsgBytes += diffBufferedMsgBytes;
  }

  synchronized public void descrease(int diffBufferedMsgNumber, int diffBufferedMsgBytes) {
    this.bufferedMsgNumber -= diffBufferedMsgNumber;
    this.bufferedMsgBytes -= diffBufferedMsgBytes;
  }

  synchronized public boolean isEmpty() {
    return bufferedMsgNumber == 0;
  }

  synchronized public boolean isFull() {
    return (bufferedMsgNumber >= maxBufferedMsgNumber ||
        bufferedMsgBytes >= maxBufferedMsgBytes);
  }

  public int getBufferedMsgNumber() {
    return bufferedMsgNumber;
  }

  public int getBufferedMsgBytes() {
    return bufferedMsgBytes;
  }
}

@@ -171,35 +171,36 @@
 unt %7B%0A  private 
-int
+long
  maxBufferedMsgN
@@ -216,19 +216,20 @@
 private 
-int
+long
  maxBuff
@@ -245,35 +245,36 @@
 tes;%0A%0A  private 
-int
+long
  bufferedMsgNumb
@@ -287,19 +287,20 @@
 private 
-int
+long
  buffere
@@ -341,19 +341,20 @@
 geCount(
-int
+long
  maxBuff
@@ -368,19 +368,20 @@
 Number, 
-int
+long
  maxBuff
@@ -593,27 +593,28 @@
 id increase(
-int
+long
  diffBuffere
@@ -617,35 +617,36 @@
 feredMsgNumber, 
-int
+long
  diffBufferedMsg
@@ -800,19 +800,20 @@
 screase(
-int
+long
  diffBuf
@@ -828,19 +828,20 @@
 Number, 
-int
+long
  diffBuf
@@ -1202,35 +1202,36 @@
 ;%0A  %7D%0A%0A  public 
-int
+long
  getBufferedMsgN
@@ -1288,11 +1288,12 @@
 lic 
-int
+long
  get

update int to long in BufferedMessageCount