Skip to content

Commit

Permalink
Guard trace logging commands with function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
StrongestNumber9 authored and kortemik committed May 24, 2023
1 parent d2617df commit e66153a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/main/java/com/teragrep/rlp_01/RelpClientPlainSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ void open (String hostname, int port) throws IOException, TimeoutException {
@Override
void write(ByteBuffer byteBuffer) throws IOException, TimeoutException {
SelectionKey key = this.socketChannel.register(this.poll, SelectionKey.OP_WRITE);
LOGGER.trace("relpConnection.sendRelpRequestAsync> need to write <{}> ", byteBuffer.hasRemaining());
if(LOGGER.isTraceEnabled()) {
LOGGER.trace("relpConnection.sendRelpRequestAsync> need to write <{}> ", byteBuffer.hasRemaining());
}

while (byteBuffer.hasRemaining()) {
int nReady = poll.select(this.writeTimeout);
Expand All @@ -147,7 +149,9 @@ void write(ByteBuffer byteBuffer) throws IOException, TimeoutException {
}
eventIter.remove();
}
LOGGER.trace("relpConnection.sendRelpRequestAsync> still need to write <{}>", byteBuffer.hasRemaining());
if(LOGGER.isTraceEnabled()) {
LOGGER.trace("relpConnection.sendRelpRequestAsync> still need to write <{}>", byteBuffer.hasRemaining());
}
}
key.interestOps(key.interestOps() & ~SelectionKey.OP_WRITE);
}
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/teragrep/rlp_01/RelpClientTlsSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ void open(String hostname, int port) throws IOException, TimeoutException {
@Override
void write(ByteBuffer byteBuffer) throws IOException, TimeoutException {
SelectionKey key = this.socketChannel.register(this.selector, SelectionKey.OP_WRITE);
LOGGER.trace("relpConnection.sendRelpRequestAsync> need to write <{}>", byteBuffer.hasRemaining());

if(LOGGER.isTraceEnabled()) {
LOGGER.trace("relpConnection.sendRelpRequestAsync> need to write <{}>", byteBuffer.hasRemaining());
}
while (byteBuffer.hasRemaining()) {
int nReady = selector.select(this.writeTimeout);
if (nReady == 0) {
Expand All @@ -176,7 +177,9 @@ void write(ByteBuffer byteBuffer) throws IOException, TimeoutException {
}
eventIter.remove();
}
LOGGER.trace("relpConnection.sendRelpRequestAsync> still need to write <{}>", byteBuffer.hasRemaining());
if(LOGGER.isTraceEnabled()) {
LOGGER.trace("relpConnection.sendRelpRequestAsync> still need to write <{}>", byteBuffer.hasRemaining());
}
}
}

Expand Down
16 changes: 12 additions & 4 deletions src/main/java/com/teragrep/rlp_01/RelpConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ public void commit(RelpBatch relpBatch) throws IOException, IllegalStateExceptio
*/
private void sendBatch(RelpBatch relpBatch) throws IOException, TimeoutException, IllegalStateException {
LOGGER.trace("relpConnection.sendBatch> entry with wq len <{}>", relpBatch.getWorkQueueLength());
if(LOGGER.isTraceEnabled()) {
LOGGER.trace("relpConnection.sendBatch> entry with wq len <{}>", relpBatch.getWorkQueueLength());
}
// send a batch of requests..
RelpFrameTX relpRequest;

Expand Down Expand Up @@ -272,7 +274,9 @@ private void readAcks(RelpBatch relpBatch)
parser.parse(preAllocatedRXBuffer.get());

if (parser.isComplete()) {
LOGGER.trace("relpConnection.readAcks> read parser complete <{}>", parser.isComplete());
if(LOGGER.isTraceEnabled()) {
LOGGER.trace("relpConnection.readAcks> read parser complete <{}>", parser.isComplete());
}
// one response read successfully
int txnId = parser.getTxnId();
if (window.isPending(txnId)) {
Expand Down Expand Up @@ -305,11 +309,15 @@ private void sendRelpRequestAsync(RelpFrameTX relpRequest) throws IOException, T
LOGGER.trace("relpConnection.sendRelpRequestAsync> entry");
ByteBuffer byteBuffer;
if (relpRequest.length() > this.txBufferSize) {
LOGGER.trace("relpConnection.sendRelpRequestAsync> allocate new txBuffer of size <{}>", relpRequest.length());
if(LOGGER.isTraceEnabled()) {
LOGGER.trace("relpConnection.sendRelpRequestAsync> allocate new txBuffer of size <{}>", relpRequest.length());
}
byteBuffer = ByteBuffer.allocateDirect(relpRequest.length());
}
else {
LOGGER.trace("relpConnection.sendRelpRequestAsync> using preAllocatedTXBuffer for size <{}>", relpRequest.length());
if(LOGGER.isTraceEnabled()) {
LOGGER.trace("relpConnection.sendRelpRequestAsync> using preAllocatedTXBuffer for size <{}>", relpRequest.length());
}
byteBuffer = this.preAllocatedTXBuffer;
}
relpRequest.write(byteBuffer);
Expand Down

0 comments on commit e66153a

Please sign in to comment.