Architecture Overview
Purpose
Understand the layered architecture of Rcon and how each layer contributes to reliable remote command execution.
Layer Structure
Rcon is organized into four distinct layers, each with a specific responsibility:
┌─────────────────────────────────────────┐
│ RconClient (High-Level API) │ ← You interact here
│ - Logging and connection management │
│ - Builder pattern for configuration │
└────────────────┬────────────────────────┘
│
┌────────────────▼────────────────────────┐
│ Rcon (Core API) │ ← Thread-safe operations
│ - Synchronized request/response │
│ - Fragment resolution strategies │
└────────────────┬────────────────────────┘
│
┌────────────────▼────────────────────────┐
│ PacketReader / PacketWriter │ ← Low-level I/O
│ - NIO socket operations │
│ - Buffer management │
└────────────────┬────────────────────────┘
│
┌────────────────▼────────────────────────┐
│ PacketCodec │ ← Binary encoding
│ - Protocol encoding/decoding │
│ - Configurable charset │
└────────────────┬────────────────────────┘
│
┌────────────────▼────────────────────────┐
│ Packet (Domain Model) │ ← Immutable data
│ - PacketType constants │
└─────────────────────────────────────────┘Layer Responsibilities
RconClient
The high-level API that wraps Rcon with additional functionality:
-
Logging - Automatic request/response logging
-
Connection Management - Handles opening/closing connections
-
Builder Pattern - Fluent API for configuration
-
Async Support -
sendCommandAsync()for non-blocking operations
Rcon
The core API providing thread-safe RCON operations:
-
Synchronized Methods -
writeAndRead()andread()ensure request/response matching -
AtomicInteger Request Counter - Thread-safe ID generation without synchronization overhead
-
Fragment Resolution - Configurable strategies for multi-packet responses
Fragment Resolution Strategies
When server responses exceed 4096 bytes, they are split across multiple packets. Rcon provides two strategies:
Thread Safety Model
-
Rcon.writeAndRead()andread()are synchronized -
requestCounterusesAtomicIntegerfor lock-free incrementing -
Multiple threads can safely send commands concurrently
-
Each thread gets its own response with matching request ID
Multi-Packet Handling
Multi-packet responses are fully automatic - no configuration needed:
-
Responses of any size are handled transparently
-
Tested with responses exceeding 87,000 bytes (~22 packets)
-
Packets are assembled in the correct order using the request ID
-
The default API requires no special handling for large responses
Next Steps
-
Basic Usage - Learn common usage patterns
-
Fragment Resolution - Deep dive on multi-packet handling
-
Packet Protocol - Binary protocol details