BewareMyPower opened a new pull request, #20800:
URL: https://github.com/apache/pulsar/pull/20800

   ### Motivation
   
   When I reviewed https://github.com/apache/pulsar/pull/20597, the unrelated 
changes in `PersistentTopicsBase` are hard to read. The logic could be 
simplified to:
   
   ```java
   PersistentSubscription sub = null;
   PersistentReplicator repl = null;
   if (metSomeCondition()) {
       repl = /* ... */;
       if (repl == null) {
           /* ... */
           return;
       }
   } else {
       sub = /* ... */;
       if (repl == null) {
           /* ... */
           return;
       }
   }
   final PersistentSubscription finalSub = sub;
   final PersistentReplicator finalRepl = repl;
   future.thenAccept(__ -> {
       if (metSomeCondition()) {
           repl.expireMessages(/* ... */);
       } else {
           sub.expireMessages(/* ... */);
       }
   });
   ```
   
   The code above is such a mess. It adds two final variables because the 
lambda can only capture final variables. The `metSomeCondition` check is 
performed unnecessarily twice. The original code is more hard to read because 
the logic in `/* ... */` takes a few lines so that the two calls of 
`metSomeCondition()` are not near.
   
   From the code search I see all these classes implement two `expireMessages` 
methods that accept an integer or a position.
   
   - PersistentMessageExpiryMonitor
   - PersistentSubscription
   - PersistentReplicator
   - NonPersistentSubscription
   
   The code can be simplified to introduce a new interface.
   
   ### Modifications
   
   Introduce a `MessageExpirer` interface and change the class hierarchy to:
   
   ```
   // [I] is interface, [C] is class
   [I] MessageExpirer
     [I] Subscription
       [C] PersistentSubscription
       [C] NonPersistentSubscription
     [C] PersistentReplicator
     [C] PersistentMessageExpiryMonitor
   ```
   
   The method invocation can be simplified much as shown in this patch.
   
   P.S. Inserting such an interface in the type hierarchy does not even break 
the ABI compatibility, see 
https://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html
   
   ### Does this pull request potentially affect one of the following parts:
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   *If the box was checked, please highlight the changes*
   
   - [ ] Dependencies (add or upgrade a dependency)
   - [x] The public API
   - [ ] The schema
   - [ ] The default values of configurations
   - [ ] The threading model
   - [ ] The binary protocol
   - [ ] The REST endpoints
   - [ ] The admin CLI options
   - [ ] The metrics
   - [ ] Anything that affects deployment
   
   ### Documentation
   
   - [ ] `doc` <!-- Your PR contains doc changes. -->
   - [ ] `doc-required` <!-- Your PR changes impact docs and you will update 
later -->
   - [] `doc-not-needed` <!-- Your PR changes do not impact docs -->
   - [ ] `doc-complete` <!-- Docs have been already added -->
   
   ### Matching PR in forked repository
   
   PR in forked repository:


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to