Refactor/cli protocol refactor changes #10009
Open
+116
−82
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request - Improvements to CLI Protocol in
PlainCLIProtocol.java
Summary of the Change
This pull request refactors the
PlainCLIProtocol
class to improve the structure and readability of the code.Code Smells Identified:
run()
method was too complex with multiple responsibilities.switch
statements for operation validation made the code difficult to extend and modify.Refactoring Details:
Refactoring 1: Simplify
FramedReader
:run()
method was split into smaller methods:readFrameLength
,processFrame
,skipUnreadBytes
, andhandleException
.Refactoring 2: Centralize Frame Validation:
validateFrameLength
, was created to centralize frame validation logic.Refactoring 3: Add Direct Validation in
Op
:handle
method. It has now been moved to theOp
enum as a direct method.Refactoring 4: Eliminate
switch
for Operation Validation:switch
statements used for validating operations were replaced with polymorphism, moving the logic into theOp
enum.Refactoring Methods Used:
FramedReader
:Extract Method
,Replace Nested Conditional with Guard Clauses
,Long Method - Duplicated Code
Extract Method
,Replace Magic Number with Symbolic Constant
- Duplicated Code, Magic NumbersOp
:Move Method
- Duplicated Codeswitch
for Operation Validation:Replace Conditional with Polymorphism
- Large Conditional (Switch Statements)Testing Done
Manual Testing:
Automated Testing:
Proposed Changelog Entries
PlainCLIProtocol
class to improve readability and maintainability.run()
method inFramedReader
by breaking it into smaller, focused methods.switch
statements with polymorphism for operation validation, making the code easier to extend.Proposed Upgrade Guidelines
N/A
Submitter Checklist
eval
.Desired Reviewers
Maintainer Checklist
upgrade-guide-needed
label is set.lts-candidate
label.