-
Notifications
You must be signed in to change notification settings - Fork 0
Actor Usage Examples
The io.github.solaceharmony.core.actor.examples package provides concrete examples of how to implement custom actors by extending the Actor base class. These examples illustrate common patterns such as message filtering and transformation.
This example demonstrates a generic actor that filters incoming messages based on a user-defined predicate.
-
Functionality:
- Receives messages of a generic type
Ton anINPUT_PORT. - Applies a
predicate: (T) -> Boolean(provided during construction) to each message. - If the predicate returns
true, the message is sent to anACCEPTED_PORT. - Optionally, if
includeRejectedPortistrueduring construction, messages for which the predicate returnsfalseare sent to aREJECTED_PORT.
- Receives messages of a generic type
-
Key Implementation Details:
- The constructor takes the
predicate,includeRejectedPortflag, and themessageClass: KClass<T>for type-safe port creation. - Ports (
INPUT_PORT,ACCEPTED_PORT, and optionallyREJECTED_PORT) are created in aninitialize()method, which is called from an overriddenstart()method to ensure ports are ready before the actor fully starts. - The
INPUT_PORT's handler,filterMessage(message: T), contains the core filtering logic and routes messages to the appropriate output port (ACCEPTED_PORTorREJECTED_PORT) usinggetPort(PORT_NAME, messageClass)?.send(message). - Output ports (
ACCEPTED_PORT,REJECTED_PORT) are created with empty handlers as their role is solely to emit messages.
- The constructor takes the
// Conceptual structure of the Filter actor's core logic
class Filter<T : Any>(
// ... constructor parameters including predicate and messageClass ...
) : Actor(...) {
// ... companion object with port names ...
suspend fun initialize() {
createPort(INPUT_PORT, messageClass, handler = ::filterMessage, ...)
createPort(ACCEPTED_PORT, messageClass, handler = { /* output only */ }, ...)
if (includeRejectedPort) {
createPort(REJECTED_PORT, messageClass, handler = { /* output only */ }, ...)
}
}
private suspend fun filterMessage(message: T) {
if (predicate(message)) {
getPort(ACCEPTED_PORT, messageClass)?.send(message)
} else if (includeRejectedPort) {
getPort(REJECTED_PORT, messageClass)?.send(message)
}
}
override suspend fun start() {
if (getPort(INPUT_PORT, messageClass) == null) initialize()
super.start()
}
// ... other Actor overrides if necessary ...
}This example showcases an actor that performs a series of transformations on incoming text messages.
-
Functionality:
- Receives
Stringmessages on anINPUT_PORT. - Applies a list of
transformations: List<(String) -> String>(provided during construction) sequentially to the input string. - Sends the final processed string to an
OUTPUT_PORT.
- Receives
-
Key Implementation Details:
- The constructor takes a list of transformation functions. The companion object provides several predefined transformations like
TO_UPPERCASE,TRIM, etc. - Ports (
INPUT_PORTforString,OUTPUT_PORTforString) are created in aninitialize()method, called from an overriddenstart()method. - The
INPUT_PORT's handler,processText(text: String), iterates through thetransformations, applies them, and then sends the result to theOUTPUT_PORT. - The
OUTPUT_PORThas an empty handler.
- The constructor takes a list of transformation functions. The companion object provides several predefined transformations like
// Conceptual structure of the TextProcessor actor's core logic
class TextProcessor(
// ... constructor parameters including transformations list ...
) : Actor(...) {
// ... companion object with port names and example transformations ...
suspend fun initialize() {
createPort(INPUT_PORT, String::class, handler = ::processText, ...)
createPort(OUTPUT_PORT, String::class, handler = { /* output only */ }, ...)
}
private suspend fun processText(text: String) {
var processedText = text
for (transformation in transformations) {
processedText = transformation(processedText)
}
getPort(OUTPUT_PORT, String::class)?.send(processedText)
}
override suspend fun start() {
if (getPort(INPUT_PORT, String::class) == null) initialize()
super.start()
}
// ... other Actor overrides if necessary ...
}These examples illustrate the practical use of the Actor base class, its port creation mechanism (createPort), message handling via port handlers, and state management through the actor's lifecycle methods. They serve as excellent starting points for developing more complex custom actors.
SolaceCore SSOT wiki · published from wiki/ by .github/workflows/publish-wiki.yml · edit the source in the repo, not the wiki.
Orientation
- Architectural Deep Dive
- Architecture Overview
- Design vs Implementation
- Framework Actor System
- Framework Architectural Vision
- Framework Concurrency and Communication
- Framework Data Storage and Management
- Framework Deployment and Containerization
- Framework Development Roadmap
- Framework Hot-Pluggable System
- Framework Implementation Status
- Framework Observability and Monitoring
- Framework Port System
- Framework System Architecture
- Framework Workflow Management
- Project Status
- Project Status Report
- Quick Status
- Solace Core Framework Architecture
- SolaceCore Architecture Overview
- Vision & Solace AI
Runtime
- Actor Builder
- Actor Communication Sequence Diagram
- Actor Core Definitions
- Actor Graph View
- Actor Metrics
- Actor Module Architecture
- Actor Queue Hibernation and Correlation
- Actor Roadmap
- Actor State Recovery Subsystem
- Actor State Serialization Subsystem
- Actor Supervision Module
- Actor System Architecture
- Actor System Class Diagram
- Actor Usage Examples
- Compose App Features
- JVM Scripting Implementations
- Kernel & Ports
- Kernel Channel System
- Kernel Future Enhancements
- Kernel Module Architecture
- Kernel Port Implementations and Exceptions
- Kernel Port Usage Example
- Kernel Testing Strategy
- Lifecycle Class Diagram
- Lifecycle Management Architecture
- Pipeline DSL
- Real-Time UI Implementation
- Scripting Module Architecture
- Scripting Module Design
- Scripting Supporting Components
- Shared Memory
- Storage & Persistence
- Storage Abstractions Architecture
- Storage Caching Subsystem
- Storage Checklist
- Storage Compression Subsystem
- Storage Core Interfaces
- Storage Encryption Subsystem
- Storage File-Based Architecture
- Storage File-Based Implementations
- Storage In-Memory Architecture
- Storage In-Memory Implementations
- Storage JVM Serialization Utilities
- Storage Module Architecture
- Storage Serialization Compression Encryption
- Storage Specialized Interfaces Architecture
- Storage Status and Future Plans
- Storage Testing
- Storage Thread Safety Guide
- Storage Thread Safety and Deadlock Prevention
- Storage Transactions
- Storage Usage Examples
- Supervisor and Hot Swap
- SupervisorActor
- System Architecture Diagram
- Workflow Management Architecture
- Workflow Management Design Concept
- Workflow Orchestration
Solace AI
- Confusion Corrector
- Inference Cube
- Inference Cube Technical Architecture
- Long-Term Memory
- MCP and Tool Format
- Memory & Reflection
- Memory Compression
- Memory Feature Overview
- Memory Retrieval
- Mood & Emotional Model
- Mood Module Implementation
- Mouth Tool Technical Spec
- Multimodal Nudging
- Perception Actors
- Provider Specs
- Reflection Memory
- Solace AI Overview
- Supervisor AI
- Supervisor Emotional Model Integration
- Time Actor
- Voice & Mouth Tool
- Working Memory
- Zoom Level Technical Spec
- Zoom Levels
Reference
- Advanced Workflow Example
- Basic Actor Usage
- Build System and Dependencies
- Development Tooling and Practices
- Documentation Catalog
- Documentation Index
- Feature Index
- Glossary
- How the Wiki Publishes
- JVM Utilities
- Kotlin Implementation Details
- Kotlin-Aligned Architecture Overview
- Kotlin-Aligned Contributing
- Kotlin-Aligned Core Architectural Principles
- Kotlin-Aligned Daily Development Workflow
- Kotlin-Aligned Development Examples
- Kotlin-Aligned Development Workflow
- Kotlin-Aligned Documentation
- Kotlin-Aligned Implementation Status
- Kotlin-Aligned Key Concepts
- Kotlin-Aligned Known Issues
- Kotlin-Aligned Quick Start
- Kotlin-Aligned Running the System
- Kotlin-Aligned System Architecture
- LangChain Actor Code Changes
- LangChain Actor Usage Improvements
- LangChain ActorInterface Code Changes
- LangChain Best Practices
- LangChain Bugs
- LangChain Chain Implementation
- LangChain Code Changes
- LangChain Code Changes Rollout and Impact
- LangChain Configuration Management Improvements
- LangChain Configuration Recommendations
- LangChain Core Architecture Recommendations
- LangChain Directory Structure Changes
- LangChain Documentation Improvements
- LangChain Dynamic Wiring Rollout Notes
- LangChain Fix Proposal
- LangChain Implementation Priorities
- LangChain Lifecycle Management Improvements
- LangChain Memory Integration Recommendations
- LangChain Metrics and Observability Recommendations
- LangChain Migration Strategy
- LangChain New Files Needed
- LangChain New Packages to Add
- LangChain Package-by-Package Improvements
- LangChain Patterns
- LangChain Port Code Changes
- LangChain Port System Recommendations
- LangChain Port Usability Improvements
- LangChain Prompt Management Recommendations
- LangChain Recommendations
- LangChain Recommendations Rollout Plan
- LangChain Required Interface Changes
- LangChain Testing Changes
- LangChain Testing Improvements
- LangChain Testing Recommendations
- LangChain Tool Integration Recommendations
- LangChain Type-Safe Dynamic Wiring
- LangChain Type-Safe Dynamic Wiring System
- LangChain Usage Design Improvements
- Master Checklist
- Roadmap
- Roadmap Issues
- Roadmap Phase 1 Stability and Testing
- Roadmap Phase 2 Production Infrastructure
- Roadmap Phase 3 Documentation and Developer Experience
- Roadmap Phase 4 Graph Database Integration
- Roadmap Phase 5 Security Framework
- Roadmap Phase 6 Distributed System
- Roadmap Phase 7 Advanced Features
- Roadmap Phase 8 Ecosystem Development
- Roadmap Timeline and Success Metrics
- Setup Instructions
- Sketch Architecture
- Status Documentation
- Task 1 Core Tests
- Task 2 Connection Wiring
- Task 3 Concurrency Issues
- Task 4 Dynamic Registration
- Task 5 Integration Tests
- Task 6 Deadlock Detection
- Task Documentation
- Test Coverage Checklist
- Testing Strategy