Browse files

Address comment from Artyom

  • Loading branch information...
1 parent 66b41df commit 56e2a4caba514d5da3377cfcc8eae21ca68a5ba8 @dgomezferro committed Jul 19, 2012
Showing with 13 additions and 12 deletions.
  1. +13 −12 src/main/java/com/yahoo/omid/replication/SharedMessageBuffer.java
View
25 src/main/java/com/yahoo/omid/replication/SharedMessageBuffer.java
@@ -35,6 +35,8 @@
private static final Logger LOG = LoggerFactory.getLogger(SharedMessageBuffer.class);
+ private static final int MAX_MESSAGE_SIZE = 30;
+
ReadersAwareBuffer pastBuffer = new ReadersAwareBuffer();
ReadersAwareBuffer currentBuffer = new ReadersAwareBuffer();
ChannelBuffer writeBuffer = currentBuffer.buffer;
@@ -66,7 +68,8 @@ public void initializeIndexes() {
* This function registers some callbacks in the future passed for cleanup purposes, so the ChannelFuture object
* must be notified after the communication is finished.
*
- * @param future It registers some callbacks on it
+ * @param future
+ * It registers some callbacks on it
* @return the deltaSO for the associated client
*/
public ChannelBuffer flush(ChannelFuture future) {
@@ -132,31 +135,29 @@ public ReadingBuffer getReadingBuffer(ChannelHandlerContext ctx) {
}
public void writeCommit(long startTimestamp, long commitTimestamp) {
- if (writeBuffer.writableBytes() < 30) {
- nextBuffer();
- }
+ checkBufferSpace();
zipper.encodeCommit(writeBuffer, startTimestamp, commitTimestamp);
}
public void writeHalfAbort(long startTimestamp) {
- if (writeBuffer.writableBytes() < 30) {
- nextBuffer();
- }
+ checkBufferSpace();
zipper.encodeHalfAbort(writeBuffer, startTimestamp);
}
public void writeFullAbort(long startTimestamp) {
- if (writeBuffer.writableBytes() < 30) {
- nextBuffer();
- }
+ checkBufferSpace();
zipper.encodeFullAbort(writeBuffer, startTimestamp);
}
public void writeLargestIncrease(long largestTimestamp) {
- if (writeBuffer.writableBytes() < 30) {
+ checkBufferSpace();
+ zipper.encodeLargestIncrease(writeBuffer, largestTimestamp);
+ }
+
+ private void checkBufferSpace() {
+ if (writeBuffer.writableBytes() < MAX_MESSAGE_SIZE) {
nextBuffer();
}
- zipper.encodeLargestIncrease(writeBuffer, largestTimestamp);
}
private void nextBuffer() {

0 comments on commit 56e2a4c

Please sign in to comment.