chore: decompose CamelMonitor God class into focused helpers#24319
Conversation
Move ~48 MCP-facing accessor methods (~650 lines) from CamelMonitor into a new McpFacade class. TuiMcpServer now depends only on McpFacade, decoupling it from the full monitor. This is step 1 of the CamelMonitor decomposition plan. Key changes: - New McpFacade.java with all MCP accessor, navigation, data, and control methods plus TAB_NAMES/MORE_TAB_NAMES constants and the PendingKey record - MonitorBridge callback interface to decouple McpFacade from CamelMonitor internals - AtomicReference<TapeRecorder> for thread-safe sharing between monitor event loop and MCP facade - TuiMcpServer updated to take McpFacade instead of CamelMonitor - CamelMonitorParseKeyTest updated for moved parseKey() method - All 260 tests pass, zero behavior change Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
|
🧪 CI tested the following changed modules:
All tested modules (2 modules)
|
…atch Continue CamelMonitor God class decomposition (Steps 2, 3, 6): - Extract RecordingManager (~280 lines): screenshot capture, tape recording, keystroke display, screen buffer tracking, key label utility - Extract PopupManager (~430 lines): switch-integration, more-tabs, and kill-confirm popup state management, key handling, and rendering - Simplify event dispatch: move overview-specific key handlers (p, x, X, r, d, f) into OverviewTab via OverviewActions callback interface, removing duplicate handlers from CamelMonitor.handleTabKeys - Update McpFacade to use RecordingManager instead of direct bridge callbacks CamelMonitor reduced from ~2,593 to ~2,167 lines (16% reduction). All 260 tests pass. Pure refactor, zero behavior change. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Step 4: Extract DataRefreshService (~666 lines) — moves all background data polling, vanishing lifecycle, auto-select, and infra/trace/span/error data loading out of CamelMonitor. Uses RefreshContext callback interface (6 methods) to decouple from monitor state. Step 5: Extract TabRegistry (~305 lines) — moves tab instance lifecycle, switching logic, and tab index constants. Uses TabCallbacks interface (7 methods) for event dispatch back to the monitor. Updates McpFacade to accept TabRegistry instead of individual tab references. CamelMonitor reduced from ~2,167 to ~1,568 lines. All 260 tests pass. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
davsclaus
left a comment
There was a problem hiding this comment.
Clean decomposition — 51% reduction in CamelMonitor with good callback-interface decoupling. The extraction is faithful (logic moved, not changed), thread-safety patterns are preserved, and all new classes are properly package-private with license headers.
One minor nit: TAB_OVERVIEW = 0 is duplicated in DataRefreshService and McpFacade ("mirrored to avoid coupling") but since they're all in the same package, they could reference TabRegistry.TAB_OVERVIEW directly. If tab order changes, the copies could drift silently.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
| * rendering. | ||
| */ | ||
| class DataRefreshService { | ||
|
|
There was a problem hiding this comment.
Nit: this constant is duplicated in McpFacade and here. Since all three classes are in the same package, referencing TabRegistry.TAB_OVERVIEW directly would avoid drift if tab order ever changes.
| private static final int TAB_OVERVIEW = TabRegistry.TAB_OVERVIEW; |
There was a problem hiding this comment.
Claude Code on behalf of Guillaume Nodet
Good catch — fixed in fd68d64. Removed the duplicated TAB_OVERVIEW constant from both DataRefreshService and McpFacade, now referencing TabRegistry.TAB_OVERVIEW directly.
Remove duplicated TAB_OVERVIEW constant from DataRefreshService and McpFacade, referencing TabRegistry.TAB_OVERVIEW directly since all classes are in the same package. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Claude Code on behalf of Guillaume Nodet
Summary
Decomposes the
CamelMonitorGod class (~3,200 lines) into focused helper classes, following the decomposition plan.Extracted classes:
McpFacade(804 lines) — MCP server integration facade, decouplingTuiMcpServerfromCamelMonitorDataRefreshService(663 lines) — background data polling, vanishing lifecycle, auto-select, infra/trace/span/error data loadingPopupManager(429 lines) — switch-integration, more-tabs, and kill-confirm popup state, key handling, renderingTabRegistry(305 lines) — tab instance lifecycle, switching logic, tab index constantsRecordingManager(280 lines) — screenshot capture, tape recording, keystroke display, screen buffer trackingResult:
CamelMonitorreduced from ~3,200 to ~1,568 lines (51% reduction).Approach
MonitorBridge,RefreshContext,TabCallbacks,PopupCallbacks,OverviewActions) decouple extracted classes fromCamelMonitorwithout circular dependenciesCommits
e32ef34— Step 1: ExtractMcpFacadefromCamelMonitorb016c67— Steps 2, 3, 6: ExtractRecordingManager,PopupManager, simplify event dispatch470ef40— Steps 4, 5: ExtractDataRefreshServiceandTabRegistryfd68d64— Review feedback: useTabRegistry.TAB_OVERVIEWinstead of duplicated constantsTest plan
mvn test -pl dsl/camel-jbang/camel-jbang-plugin-tui)mvn formatter:format impsort:sort🤖 Generated with Claude Code