Edge: Simplify Logging and Implement Java 21 Switch Pattern Matching in BridgeHttpImpl
#2964
+9
−7
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.
Overview
This pull request introduces two key enhancements to the
BridgeHttpImpl
class within theio.openems.edge.bridge.http
package:Simplified Logging:
info
level log statements to reduce log clutter and focus on critical log messages.Modernized Control Flow with Java 21:
if-else
constructs to leverage Java 21's enhancedswitch
statement with pattern matching, improving code readability and maintainability.Detailed Changes
Simplified Logging:
Files Affected:
BridgeHttpImpl.java
Changes Made:
info
Level Logs:handleEvent
method:warn
anderror
logs, enhancing log clarity.Java 21 Switch Pattern Matching:
Files Affected:
BridgeHttpImpl.java
Changes Made:
createTask(TimeEndpointCountdown endpointCountdown)
Method:Replaced existing
if-else
statements with aswitch
statement utilizing Java 21's pattern matching.Before:
After:
Rationale:
switch
statement clearly outlines differentDelay
types, making the logic easier to follow.Delay
subclasses in the future.default
case to handle any unforeseenDelay
types, ensuring the system remains stable.Benefits
Improved Logging Efficiency:
info
logs, the logging output is cleaner, making it easier to monitor and debug essential issues.Modernized and Cleaner Codebase:
switch
statement offers a more intuitive structure, facilitating easier understanding and future modifications.Future-Proofing:
default
case in theswitch
statement ensures that unexpectedDelay
types are logged and handled gracefully.Conclusion
This pull request streamlines the
BridgeHttpImpl
class by eliminating unnecessary logging and adopting Java 21's advanced switch pattern matching. These changes enhance both the efficiency and maintainability of the codebase, positioning it for future growth and easier debugging.