eolivelli commented on a change in pull request #809: Recycle responses
callbacks
URL: https://github.com/apache/bookkeeper/pull/809#discussion_r155098575
##########
File path:
bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java
##########
@@ -1024,16 +1021,80 @@ private void readV2Response(final
BookieProtocol.Response response) {
// Unexpected response, so log it. The txnId should have been
present.
if (LOG.isDebugEnabled()) {
LOG.debug("Unexpected response received from bookie : " + addr
+ " for type : " + operationType
- + " and ledger:entry : " + ledgerId + ":" + entryId);
+ + " and ledger:entry : " + response.ledgerId + ":" +
response.entryId);
}
} else {
long orderingKey = completionValue.ledgerId;
- final CompletionValue finalCompletionValue = completionValue;
+ executor.submitOrdered(orderingKey,
+ ReadV2ResponseCallback.create(completionValue,
response.ledgerId, response.entryId,
+ status, response));
+ }
+ }
+
+ private static class ReadV2ResponseCallback extends SafeRunnable {
+ CompletionValue completionValue;
+ long ledgerId;
+ long entryId;
+ StatusCode status;
+ BookieProtocol.Response response;
+
+ static ReadV2ResponseCallback create(CompletionValue completionValue,
long ledgerId, long entryId,
+ StatusCode status,
BookieProtocol.Response response) {
+ ReadV2ResponseCallback callback = RECYCLER.get();
+ callback.completionValue = completionValue;
+ callback.ledgerId = ledgerId;
+ callback.entryId = entryId;
+ callback.status = status;
+ callback.response = response;
+ return callback;
+ }
- executor.submitOrdered(orderingKey, () -> {
- finalCompletionValue.handleV2Response(ledgerId, entryId,
status, response);
- response.recycle();
- });
+ @Override
+ public void safeRun() {
+ completionValue.handleV2Response(ledgerId, entryId, status,
response);
+ response.recycle();
+ recycle();
+ }
+
+ void recycle() {
+ completionValue = null;
+ ledgerId = -1;
+ entryId = -1;
+ status = null;
+ response = null;
+ recyclerHandle.recycle(this);
+ }
+
+ private final Handle<ReadV2ResponseCallback> recyclerHandle;
+
+ private ReadV2ResponseCallback(Handle<ReadV2ResponseCallback>
recyclerHandle) {
+ this.recyclerHandle = recyclerHandle;
+ }
+
+ private static final Recycler<ReadV2ResponseCallback> RECYCLER = new
Recycler<ReadV2ResponseCallback>() {
+ @Override
+ protected ReadV2ResponseCallback
newObject(Handle<ReadV2ResponseCallback> handle) {
+ return new ReadV2ResponseCallback(handle);
+ }
+ };
+ }
+
+ private OperationType getOperationType(byte opCode) {
Review comment:
static ?
we can change "getStatusCodeFromErrorCode" as well to "static"
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services