Skip to content

chore: decompose CamelMonitor God class into focused helpers#24319

Open
gnodet wants to merge 3 commits into
apache:mainfrom
gnodet:extract-mcp-facade
Open

chore: decompose CamelMonitor God class into focused helpers#24319
gnodet wants to merge 3 commits into
apache:mainfrom
gnodet:extract-mcp-facade

Conversation

@gnodet

@gnodet gnodet commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Claude Code on behalf of Guillaume Nodet

Summary

Decomposes the CamelMonitor God class (~3,200 lines) into focused helper classes, following the decomposition plan.

Extracted classes:

  • McpFacade (806 lines) — MCP server integration facade, decoupling TuiMcpServer from CamelMonitor
  • DataRefreshService (666 lines) — background data polling, vanishing lifecycle, auto-select, infra/trace/span/error data loading
  • PopupManager (429 lines) — switch-integration, more-tabs, and kill-confirm popup state, key handling, rendering
  • TabRegistry (305 lines) — tab instance lifecycle, switching logic, tab index constants
  • RecordingManager (280 lines) — screenshot capture, tape recording, keystroke display, screen buffer tracking

Result: CamelMonitor reduced from ~3,200 to ~1,568 lines (51% reduction).

Approach

  • Callback interfaces (MonitorBridge, RefreshContext, TabCallbacks, PopupCallbacks, OverviewActions) decouple extracted classes from CamelMonitor without circular dependencies
  • Package-private classes following Camel conventions
  • No behavioral changes — pure structural refactoring
  • All 260 existing tests pass unchanged

Commits

  1. e32ef34 — Step 1: Extract McpFacade from CamelMonitor
  2. b016c67 — Steps 2, 3, 6: Extract RecordingManager, PopupManager, simplify event dispatch
  3. 470ef40 — Steps 4, 5: Extract DataRefreshService and TabRegistry

Test plan

  • All 260 existing tests pass (mvn test -pl dsl/camel-jbang/camel-jbang-plugin-tui)
  • Code formatted with mvn formatter:format impsort:sort
  • Compilation clean with no warnings
  • CI pipeline passes

🤖 Generated with Claude Code

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>
@gnodet gnodet requested review from aldettinger and davsclaus June 29, 2026 14:46
@github-actions

Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@github-actions github-actions Bot added the dsl label Jun 29, 2026
@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • dsl/camel-jbang/camel-jbang-plugin-tui
All tested modules (2 modules)
  • Camel :: JBang :: Plugin :: TUI
  • Camel :: Launcher :: Container

⚙️ View full build and test results

@gnodet gnodet marked this pull request as ready for review June 29, 2026 15:19
…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>
@gnodet gnodet changed the title chore: extract McpFacade from CamelMonitor to reduce God class chore: decompose CamelMonitor God class into focused helper classes Jun 29, 2026
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>
@gnodet gnodet changed the title chore: decompose CamelMonitor God class into focused helper classes chore: decompose CamelMonitor God class into focused helpers Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants