Make MessageTracker.Context implement AutoCloseable
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / Shard.java
index ccd0b85c36d94e4586ff0df9bdd7dfc596da24d7..a47e437e32cf3f694b7497ebec35761f35425cbb 100644 (file)
@@ -209,15 +209,13 @@ public class Shard extends RaftActor {
 
     @Override
     protected void handleCommand(final Object message) {
+        try (final MessageTracker.Context context = appendEntriesReplyTracker.received(message)) {
+            final Optional<Error> maybeError = context.error();
+            if (maybeError.isPresent()) {
+                LOG.trace("{} : AppendEntriesReply failed to arrive at the expected interval {}", persistenceId(),
+                    maybeError.get());
+            }
 
-        final MessageTracker.Context context = appendEntriesReplyTracker.received(message);
-        final Optional<Error> maybeError = context.error();
-        if (maybeError.isPresent()) {
-            LOG.trace("{} : AppendEntriesReply failed to arrive at the expected interval {}", persistenceId(),
-                maybeError.get());
-        }
-
-        try {
             if (CreateTransaction.isSerializedType(message)) {
                 handleCreateTransaction(message);
             } else if (message instanceof BatchedModifications) {
@@ -264,8 +262,6 @@ public class Shard extends RaftActor {
             } else {
                 super.handleCommand(message);
             }
-        } finally {
-            context.done();
         }
     }