ActionHistory Migration Plan
Executive Summary
The ActionHistory class is currently in a transitional state, supporting both the legacy ActionOptions.Action
API and the modern ActionConfig
API. This document outlines a comprehensive plan to complete the migration to the modern API while maintaining backward compatibility.
Current State Assessment
Migration Progress
- ✅ 70% Complete: Infrastructure and dual API support implemented
- ⚠️ 20% In Progress: Internal methods still using legacy API
- ❌ 10% Not Started: Deprecation removal and data migration
Key Components Status
Component | Status | Notes |
---|---|---|
ActionConfigAdapter | ✅ Complete | Full type mapping implemented |
ActionRecord Dual API | ✅ Complete | Both fields with auto-population |
Modern API Methods | ✅ Complete | All new methods implemented |
Deprecation Marking | ✅ Complete | Legacy methods marked @Deprecated |
Test Coverage | ✅ Complete | Comprehensive modern API tests |
Internal Method Updates | ⚠️ Partial | Some hardcoded references remain |
Data Migration Tools | ❌ Not Started | No serialization migration path |
Legacy Method Removal | ❌ Not Started | No deprecation timeline |
Migration Phases
Phase 1: Complete Internal Migration (2-3 weeks)
Goal: Remove all hardcoded ActionOptions.Action references
Tasks:
-
Update getRandomText() method
// Current (hardcoded)
public String getRandomText() {
ActionRecord snapshot = getRandomSnapshot(ActionOptions.Action.FIND);
// ...
}
// Target (using ActionConfig)
public String getRandomText() {
PatternFindOptions findConfig = new PatternFindOptions.Builder().build();
ActionRecord snapshot = getRandomSnapshot(findConfig);
// ...
} -
Refactor helper methods
- Update
getFindOrVanishSnapshots()
to use ActionConfig parameter - Update
getSnapshotOfFindType()
to use ActionConfig parameter - Remove direct ActionOptions.Action enum usage
- Update
-
Update type detection methods
- Enhance
getSnapshotActionType()
to prioritize ActionConfig - Enhance
getSnapshotFindType()
to prioritize ActionConfig
- Enhance
Deliverables:
- All internal methods using ActionConfig
- No direct ActionOptions.Action references
- Updated unit tests confirming functionality
Phase 2: Data Migration Infrastructure (3-4 weeks)
Goal: Enable seamless migration of existing data
Tasks:
-
Create migration utilities
@Component
public class ActionHistoryMigrationService {
public ActionHistory migrate(ActionHistory legacy) {
// Convert ActionOptions-based snapshots to ActionConfig
}
public void migrateDatabase(DataSource dataSource) {
// Batch migrate persisted records
}
} -
Implement serialization converters
- JSON deserializer that auto-converts ActionOptions to ActionConfig
- Database migration scripts for existing records
- File-based migration tool for saved states
-
Add migration validation
- Checksum verification for migrated data
- Rollback capability for failed migrations
- Migration status tracking
Deliverables:
- ActionHistoryMigrationService implementation
- Database migration scripts
- Migration validation framework
- Documentation for migration process
Phase 3: Gradual Deprecation (2-3 months)
Goal: Transition users to modern API
Tasks:
-
Enhanced deprecation warnings
@Deprecated(since = "1.2.0", forRemoval = true)
@DeprecationWarning(
message = "This method will be removed in version 2.0.0",
alternative = "Use getRandomSnapshot(ActionConfig) instead"
)
public ActionRecord getRandomSnapshot(ActionOptions.Action action) {
// Log deprecation usage for metrics
DeprecationMetrics.log("getRandomSnapshot", "ActionOptions.Action");
// ...
} -
Usage metrics collection
- Track deprecated method usage in production
- Generate deprecation reports
- Identify high-impact areas
-
Migration guides and tooling
- Automated code migration tool
- IDE plugin for deprecation warnings
- Comprehensive migration documentation
Deliverables:
- Deprecation metrics system
- Automated migration tool
- Updated documentation
- User communication plan
Phase 4: Performance Optimization (2-3 weeks)
Goal: Optimize ActionConfigAdapter performance
Tasks:
-
Caching implementation
@Component
public class ActionConfigAdapter {
private final Map<Class<?>, ActionOptions.Action> typeCache =
new ConcurrentHashMap<>();
public ActionOptions.Action getActionType(ActionConfig config) {
return typeCache.computeIfAbsent(
config.getClass(),
this::computeActionType
);
}
} -
Lazy initialization
- Defer ActionOptions creation until needed
- Use weak references for infrequently used mappings
-
Performance benchmarking
- Compare legacy vs modern API performance
- Identify and optimize hotspots
- Document performance characteristics
Deliverables:
- Optimized ActionConfigAdapter
- Performance benchmark suite
- Performance documentation
Phase 5: Legacy Removal (Version 2.0.0)
Goal: Remove all deprecated code
Tasks:
-
Remove deprecated methods
- Delete all @Deprecated ActionOptions.Action methods
- Remove ActionOptions field from ActionRecord
- Clean up ActionConfigAdapter legacy support
-
Update all dependencies
- Update Pattern class usage
- Update UI components
- Update test suites
-
Final migration verification
- Ensure all data migrated
- Verify no legacy API usage
- Performance regression testing
Deliverables:
- Clean codebase without legacy API
- Updated documentation
- Migration completion report
Implementation Timeline
Phase | Duration | Start Date | End Date | Dependencies |
---|---|---|---|---|
Phase 1 | 2-3 weeks | Week 1 | Week 3 | None |
Phase 2 | 3-4 weeks | Week 4 | Week 7 | Phase 1 |
Phase 3 | 2-3 months | Week 8 | Week 20 | Phase 2 |
Phase 4 | 2-3 weeks | Week 16 | Week 19 | Parallel with Phase 3 |
Phase 5 | 1 week | Version 2.0 | Version 2.0 | All phases |
Risk Mitigation
High-Risk Areas
-
Serialized Data Compatibility
- Risk: Breaking existing saved states
- Mitigation: Dual deserialization support for 2 major versions
-
Performance Degradation
- Risk: ActionConfigAdapter overhead
- Mitigation: Caching and optimization in Phase 4
-
User Adoption
- Risk: Slow migration to modern API
- Mitigation: Automated migration tools and extended deprecation period
Rollback Strategy
- Feature flags for new functionality
- Versioned APIs during transition
- Data backup before migration
- Phased rollout with monitoring
Success Metrics
Phase 1 Metrics
- Zero hardcoded ActionOptions.Action references
- All tests passing with modern API
Phase 2 Metrics
- 100% of existing data migrateable
- Migration tool processes 1000+ records/second
Phase 3 Metrics
- < 5% deprecated API usage after 2 months
- 90% of users migrated to modern API
Phase 4 Metrics
- < 10% performance overhead vs legacy API
- Sub-millisecond ActionConfigAdapter operations
Phase 5 Metrics
- Zero legacy API code in codebase
- All dependent modules updated
Developer Migration Guide
For Library Users
Step 1: Update method calls
// Old way (deprecated)
ActionRecord snapshot = history.getRandomSnapshot(ActionOptions.Action.FIND);
// New way (recommended)
PatternFindOptions findConfig = new PatternFindOptions.Builder()
.setStrategy(PatternFindOptions.Strategy.BEST)
.build();
ActionRecord snapshot = history.getRandomSnapshot(findConfig);
Step 2: Update ActionRecord creation
// Old way (deprecated)
ActionRecord record = new ActionRecord.Builder()
.setActionOptions(new ActionOptions.Builder()
.setAction(ActionOptions.Action.CLICK)
.build())
.build();
// New way (recommended)
ActionRecord record = new ActionRecord.Builder()
.setActionConfig(new ClickOptions.Builder()
.setClickType(ClickOptions.Type.LEFT)
.build())
.build();
Step 3: Run migration tool
java -jar brobot-migration-tool.jar \
--source ./src \
--migrate-actionhistory \
--backup ./backup
For Framework Contributors
Understanding the Adapter Pattern
// ActionConfigAdapter handles the translation
public class ActionConfigAdapter {
public ActionOptions.Action getActionType(ActionConfig config) {
// Maps modern config to legacy action type
if (config instanceof PatternFindOptions) return FIND;
if (config instanceof ClickOptions) return CLICK;
// ...
}
}
Testing Both APIs
@Test
public void testDualAPICompatibility() {
// Test legacy API
ActionRecord legacyResult = history.getRandomSnapshot(
ActionOptions.Action.FIND
);
// Test modern API
ActionRecord modernResult = history.getRandomSnapshot(
new PatternFindOptions.Builder().build()
);
// Results should be equivalent
assertEquals(legacyResult.getActionType(), modernResult.getActionType());
}
Communication Plan
Version 1.2.0 (Phase 1-2 Complete)
- Release notes highlighting new ActionConfig API
- Migration guide publication
- Deprecation warnings added
Version 1.3.0 (Phase 3 Start)
- Enhanced deprecation warnings
- Migration tool availability
- Community workshops
Version 1.5.0 (Phase 3 End)
- Final deprecation notice
- Legacy API usage report
- Version 2.0 timeline announcement
Version 2.0.0 (Phase 5)
- Legacy API removal
- Final migration guide
- Success celebration 🎉
Conclusion
This migration plan provides a structured approach to completing the ActionHistory transition from ActionOptions to ActionConfig. By following these phases, we can ensure:
- Backward compatibility during transition
- Minimal disruption to existing users
- Performance parity or improvement
- Clean, modern API for future development
The key to success is gradual migration with comprehensive tooling support and clear communication throughout the process.