exonware-xwlazy 0.1.0.10__py3-none-any.whl → 0.1.0.19__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. exonware/__init__.py +22 -0
  2. exonware/xwlazy/__init__.py +0 -0
  3. exonware/xwlazy/common/__init__.py +47 -0
  4. exonware/xwlazy/common/base.py +58 -0
  5. exonware/xwlazy/common/cache.py +506 -0
  6. exonware/xwlazy/common/logger.py +268 -0
  7. exonware/xwlazy/common/services/__init__.py +72 -0
  8. exonware/xwlazy/common/services/dependency_mapper.py +234 -0
  9. exonware/xwlazy/common/services/install_async_utils.py +169 -0
  10. exonware/xwlazy/common/services/install_cache_utils.py +257 -0
  11. exonware/xwlazy/common/services/keyword_detection.py +292 -0
  12. exonware/xwlazy/common/services/spec_cache.py +173 -0
  13. exonware/xwlazy/common/services/state_manager.py +86 -0
  14. exonware/xwlazy/common/strategies/__init__.py +28 -0
  15. exonware/xwlazy/common/strategies/caching_dict.py +45 -0
  16. exonware/xwlazy/common/strategies/caching_installation.py +89 -0
  17. exonware/xwlazy/common/strategies/caching_lfu.py +67 -0
  18. exonware/xwlazy/common/strategies/caching_lru.py +64 -0
  19. exonware/xwlazy/common/strategies/caching_multitier.py +60 -0
  20. exonware/xwlazy/common/strategies/caching_ttl.py +60 -0
  21. exonware/xwlazy/config.py +195 -0
  22. exonware/xwlazy/contracts.py +1410 -0
  23. exonware/xwlazy/defs.py +397 -0
  24. exonware/xwlazy/errors.py +284 -0
  25. exonware/xwlazy/facade.py +1049 -0
  26. exonware/xwlazy/module/__init__.py +18 -0
  27. exonware/xwlazy/module/base.py +569 -0
  28. exonware/xwlazy/module/data.py +17 -0
  29. exonware/xwlazy/module/facade.py +247 -0
  30. exonware/xwlazy/module/importer_engine.py +2161 -0
  31. exonware/xwlazy/module/strategies/__init__.py +22 -0
  32. exonware/xwlazy/module/strategies/module_helper_lazy.py +94 -0
  33. exonware/xwlazy/module/strategies/module_helper_simple.py +66 -0
  34. exonware/xwlazy/module/strategies/module_manager_advanced.py +112 -0
  35. exonware/xwlazy/module/strategies/module_manager_simple.py +96 -0
  36. exonware/xwlazy/package/__init__.py +18 -0
  37. exonware/xwlazy/package/base.py +807 -0
  38. exonware/xwlazy/package/conf.py +331 -0
  39. exonware/xwlazy/package/data.py +17 -0
  40. exonware/xwlazy/package/facade.py +481 -0
  41. exonware/xwlazy/package/services/__init__.py +84 -0
  42. exonware/xwlazy/package/services/async_install_handle.py +89 -0
  43. exonware/xwlazy/package/services/config_manager.py +246 -0
  44. exonware/xwlazy/package/services/discovery.py +374 -0
  45. exonware/xwlazy/package/services/host_packages.py +149 -0
  46. exonware/xwlazy/package/services/install_async.py +278 -0
  47. exonware/xwlazy/package/services/install_cache.py +146 -0
  48. exonware/xwlazy/package/services/install_interactive.py +60 -0
  49. exonware/xwlazy/package/services/install_policy.py +158 -0
  50. exonware/xwlazy/package/services/install_registry.py +56 -0
  51. exonware/xwlazy/package/services/install_result.py +17 -0
  52. exonware/xwlazy/package/services/install_sbom.py +154 -0
  53. exonware/xwlazy/package/services/install_utils.py +83 -0
  54. exonware/xwlazy/package/services/installer_engine.py +408 -0
  55. exonware/xwlazy/package/services/lazy_installer.py +720 -0
  56. exonware/xwlazy/package/services/manifest.py +506 -0
  57. exonware/xwlazy/package/services/strategy_registry.py +188 -0
  58. exonware/xwlazy/package/strategies/__init__.py +57 -0
  59. exonware/xwlazy/package/strategies/package_discovery_file.py +130 -0
  60. exonware/xwlazy/package/strategies/package_discovery_hybrid.py +85 -0
  61. exonware/xwlazy/package/strategies/package_discovery_manifest.py +102 -0
  62. exonware/xwlazy/package/strategies/package_execution_async.py +114 -0
  63. exonware/xwlazy/package/strategies/package_execution_cached.py +91 -0
  64. exonware/xwlazy/package/strategies/package_execution_pip.py +100 -0
  65. exonware/xwlazy/package/strategies/package_execution_wheel.py +107 -0
  66. exonware/xwlazy/package/strategies/package_mapping_discovery_first.py +101 -0
  67. exonware/xwlazy/package/strategies/package_mapping_hybrid.py +106 -0
  68. exonware/xwlazy/package/strategies/package_mapping_manifest_first.py +101 -0
  69. exonware/xwlazy/package/strategies/package_policy_allow_list.py +58 -0
  70. exonware/xwlazy/package/strategies/package_policy_deny_list.py +58 -0
  71. exonware/xwlazy/package/strategies/package_policy_permissive.py +47 -0
  72. exonware/xwlazy/package/strategies/package_timing_clean.py +68 -0
  73. exonware/xwlazy/package/strategies/package_timing_full.py +67 -0
  74. exonware/xwlazy/package/strategies/package_timing_smart.py +69 -0
  75. exonware/xwlazy/package/strategies/package_timing_temporary.py +67 -0
  76. exonware/xwlazy/runtime/__init__.py +18 -0
  77. exonware/xwlazy/runtime/adaptive_learner.py +131 -0
  78. exonware/xwlazy/runtime/base.py +276 -0
  79. exonware/xwlazy/runtime/facade.py +95 -0
  80. exonware/xwlazy/runtime/intelligent_selector.py +173 -0
  81. exonware/xwlazy/runtime/metrics.py +64 -0
  82. exonware/xwlazy/runtime/performance.py +39 -0
  83. exonware/xwlazy/version.py +2 -2
  84. exonware_xwlazy-0.1.0.19.dist-info/METADATA +456 -0
  85. exonware_xwlazy-0.1.0.19.dist-info/RECORD +87 -0
  86. exonware_xwlazy-0.1.0.10.dist-info/METADATA +0 -0
  87. exonware_xwlazy-0.1.0.10.dist-info/RECORD +0 -6
  88. {exonware_xwlazy-0.1.0.10.dist-info → exonware_xwlazy-0.1.0.19.dist-info}/WHEEL +0 -0
  89. {exonware_xwlazy-0.1.0.10.dist-info → exonware_xwlazy-0.1.0.19.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,67 @@
1
+ """
2
+ Full Timing Strategy
3
+
4
+ Company: eXonware.com
5
+ Author: Eng. Muhammad AlShehri
6
+ Email: connect@exonware.com
7
+ Version: 0.1.0.19
8
+ Generation Date: 15-Nov-2025
9
+
10
+ Full timing - install all dependencies upfront.
11
+ """
12
+
13
+ from typing import List, Any
14
+ from ...package.base import AInstallTimingStrategy
15
+
16
+
17
+ class FullTiming(AInstallTimingStrategy):
18
+ """
19
+ Full timing strategy - installs all packages upfront (LazyInstallMode.FULL).
20
+
21
+ Batch installs all dependencies in parallel on initialization.
22
+ """
23
+
24
+ def should_install_now(self, package_name: str, context: Any) -> bool:
25
+ """
26
+ Determine if package should be installed now.
27
+
28
+ Full mode: Install all upfront.
29
+
30
+ Args:
31
+ package_name: Package name to check
32
+ context: Context information (ignored in full mode)
33
+
34
+ Returns:
35
+ True (always install upfront)
36
+ """
37
+ return True
38
+
39
+ def should_uninstall_after(self, package_name: str, context: Any) -> bool:
40
+ """
41
+ Determine if package should be uninstalled after use.
42
+
43
+ Full mode: Keep installed after use.
44
+
45
+ Args:
46
+ package_name: Package name to check
47
+ context: Context information
48
+
49
+ Returns:
50
+ False (keep installed)
51
+ """
52
+ return False
53
+
54
+ def get_install_priority(self, packages: List[str]) -> List[str]:
55
+ """
56
+ Get priority order for installing packages.
57
+
58
+ Full mode: Install all in parallel (no specific order).
59
+
60
+ Args:
61
+ packages: List of package names
62
+
63
+ Returns:
64
+ Priority-ordered list (original order)
65
+ """
66
+ return packages
67
+
@@ -0,0 +1,69 @@
1
+ """
2
+ Smart Timing Strategy
3
+
4
+ Company: eXonware.com
5
+ Author: Eng. Muhammad AlShehri
6
+ Email: connect@exonware.com
7
+ Version: 0.1.0.19
8
+ Generation Date: 15-Nov-2025
9
+
10
+ Smart timing - install on first usage (on-demand).
11
+ """
12
+
13
+ from typing import List, Any
14
+ from ...package.base import AInstallTimingStrategy
15
+ from ...defs import LazyInstallMode
16
+
17
+
18
+ class SmartTiming(AInstallTimingStrategy):
19
+ """
20
+ Smart timing strategy - installs packages on-demand (LazyInstallMode.SMART).
21
+
22
+ Installs package when first needed, then caches the result.
23
+ """
24
+
25
+ def should_install_now(self, package_name: str, context: Any) -> bool:
26
+ """
27
+ Determine if package should be installed now.
28
+
29
+ Smart mode: Install when first needed.
30
+
31
+ Args:
32
+ package_name: Package name to check
33
+ context: Context information (e.g., import error)
34
+
35
+ Returns:
36
+ True if should install now
37
+ """
38
+ # In smart mode, install when first needed (context indicates need)
39
+ return context is not None
40
+
41
+ def should_uninstall_after(self, package_name: str, context: Any) -> bool:
42
+ """
43
+ Determine if package should be uninstalled after use.
44
+
45
+ Smart mode: Keep installed after use.
46
+
47
+ Args:
48
+ package_name: Package name to check
49
+ context: Context information
50
+
51
+ Returns:
52
+ False (keep installed)
53
+ """
54
+ return False
55
+
56
+ def get_install_priority(self, packages: List[str]) -> List[str]:
57
+ """
58
+ Get priority order for installing packages.
59
+
60
+ Smart mode: Install in order requested.
61
+
62
+ Args:
63
+ packages: List of package names
64
+
65
+ Returns:
66
+ Priority-ordered list
67
+ """
68
+ return packages
69
+
@@ -0,0 +1,67 @@
1
+ """
2
+ Temporary Timing Strategy
3
+
4
+ Company: eXonware.com
5
+ Author: Eng. Muhammad AlShehri
6
+ Email: connect@exonware.com
7
+ Version: 0.1.0.19
8
+ Generation Date: 15-Nov-2025
9
+
10
+ Temporary timing - always uninstall after use (more aggressive than CLEAN).
11
+ """
12
+
13
+ from typing import List, Any
14
+ from ...package.base import AInstallTimingStrategy
15
+
16
+
17
+ class TemporaryTiming(AInstallTimingStrategy):
18
+ """
19
+ Temporary timing strategy - always uninstalls after use (LazyInstallMode.TEMPORARY).
20
+
21
+ More aggressive than CLEAN - always uninstalls packages after use.
22
+ """
23
+
24
+ def should_install_now(self, package_name: str, context: Any) -> bool:
25
+ """
26
+ Determine if package should be installed now.
27
+
28
+ Temporary mode: Install when first needed.
29
+
30
+ Args:
31
+ package_name: Package name to check
32
+ context: Context information (e.g., import error)
33
+
34
+ Returns:
35
+ True if should install now
36
+ """
37
+ return context is not None
38
+
39
+ def should_uninstall_after(self, package_name: str, context: Any) -> bool:
40
+ """
41
+ Determine if package should be uninstalled after use.
42
+
43
+ Temporary mode: Always uninstall after use.
44
+
45
+ Args:
46
+ package_name: Package name to check
47
+ context: Context information (ignored)
48
+
49
+ Returns:
50
+ True (always uninstall)
51
+ """
52
+ return True
53
+
54
+ def get_install_priority(self, packages: List[str]) -> List[str]:
55
+ """
56
+ Get priority order for installing packages.
57
+
58
+ Temporary mode: Install in order requested.
59
+
60
+ Args:
61
+ packages: List of package names
62
+
63
+ Returns:
64
+ Priority-ordered list
65
+ """
66
+ return packages
67
+
@@ -0,0 +1,18 @@
1
+ """
2
+ Runtime Services Module
3
+
4
+ This module provides concrete implementations for runtime services.
5
+ Main facade: XWRuntimeHelper extends ARuntimeHelper
6
+ """
7
+
8
+ # Lazy imports to avoid circular dependencies
9
+ def __getattr__(name: str):
10
+ if name == 'XWRuntimeHelper':
11
+ from .facade import XWRuntimeHelper
12
+ return XWRuntimeHelper
13
+ if name == 'XWRuntime': # Backward compatibility alias
14
+ from .facade import XWRuntimeHelper
15
+ return XWRuntimeHelper
16
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
17
+
18
+ __all__ = ['XWRuntimeHelper', 'XWRuntime'] # XWRuntime is backward compatibility alias
@@ -0,0 +1,131 @@
1
+ """
2
+ #exonware/xwlazy/src/exonware/xwlazy/loading/adaptive_utils.py
3
+
4
+ Adaptive learning utilities for pattern-based optimization.
5
+
6
+ Company: eXonware.com
7
+ Author: Eng. Muhammad AlShehri
8
+ Email: connect@exonware.com
9
+ Version: 0.1.0.19
10
+ Generation Date: 19-Nov-2025
11
+
12
+ This module provides adaptive learning for ADAPTIVE mode.
13
+ """
14
+
15
+ import time
16
+ import threading
17
+ from typing import Dict, List, Tuple, Optional
18
+ from collections import defaultdict, deque
19
+
20
+ # Logger not used in this module, removed to avoid circular dependency
21
+
22
+
23
+ class AdaptiveLearner:
24
+ """Learns import patterns and optimizes loading strategy."""
25
+
26
+ def __init__(self, learning_window: int = 100, prediction_depth: int = 3):
27
+ """
28
+ Initialize adaptive learner.
29
+
30
+ Args:
31
+ learning_window: Number of imports to track for learning
32
+ prediction_depth: Depth of sequence predictions
33
+ """
34
+ self._learning_window = learning_window
35
+ self._prediction_depth = prediction_depth
36
+ self._import_sequences: deque = deque(maxlen=learning_window)
37
+ self._access_times: Dict[str, List[float]] = defaultdict(list)
38
+ self._import_chains: Dict[str, Dict[str, int]] = defaultdict(lambda: defaultdict(int))
39
+ self._module_scores: Dict[str, float] = {}
40
+ self._lock = threading.RLock()
41
+
42
+ def record_import(self, module_name: str, import_time: float) -> None:
43
+ """Record an import event."""
44
+ current_time = time.time()
45
+
46
+ # Lock-free append to deque (thread-safe for appends)
47
+ self._import_sequences.append((module_name, current_time, import_time))
48
+
49
+ with self._lock:
50
+ self._access_times[module_name].append(current_time)
51
+
52
+ # Update import chains (what imports after what)
53
+ if len(self._import_sequences) > 1:
54
+ prev_name, _, _ = self._import_sequences[-2]
55
+ self._import_chains[prev_name][module_name] += 1
56
+
57
+ # Update module score (frequency * recency) - defer heavy computation
58
+ if len(self._access_times[module_name]) % 5 == 0: # Update every 5th access
59
+ self._update_module_score(module_name)
60
+
61
+ def _update_module_score(self, module_name: str) -> None:
62
+ """Update module priority score."""
63
+ with self._lock:
64
+ accesses = self._access_times[module_name]
65
+ if not accesses:
66
+ return
67
+
68
+ # Frequency component
69
+ recent_accesses = [t for t in accesses if time.time() - t < 3600] # Last hour
70
+ frequency = len(recent_accesses)
71
+
72
+ # Recency component (more recent = higher score)
73
+ if accesses:
74
+ last_access = accesses[-1]
75
+ recency = 1.0 / (time.time() - last_access + 1.0)
76
+ else:
77
+ recency = 0.0
78
+
79
+ # Chain component (if often imported after another module)
80
+ chain_weight = sum(self._import_chains.get(prev, {}).get(module_name, 0)
81
+ for prev in self._access_times.keys()) / max(len(self._import_sequences), 1)
82
+
83
+ # Combined score
84
+ self._module_scores[module_name] = frequency * 0.4 + recency * 1000 * 0.4 + chain_weight * 0.2
85
+
86
+ def predict_next_imports(self, current_module: Optional[str] = None, limit: int = 5) -> List[str]:
87
+ """Predict likely next imports based on patterns."""
88
+ # Lock-free check first
89
+ if not self._import_sequences:
90
+ return []
91
+
92
+ with self._lock:
93
+ candidates: Dict[str, float] = {}
94
+
95
+ # Predict based on current module chain (lock-free read of dict)
96
+ if current_module:
97
+ chain_candidates = self._import_chains.get(current_module, {})
98
+ for module, count in chain_candidates.items():
99
+ candidates[module] = candidates.get(module, 0.0) + count * 2.0
100
+
101
+ # Add high-scoring modules (lock-free read of dict)
102
+ for module, score in self._module_scores.items():
103
+ candidates[module] = candidates.get(module, 0.0) + score * 0.5
104
+
105
+ # Sort by score
106
+ sorted_candidates = sorted(candidates.items(), key=lambda x: x[1], reverse=True)
107
+ return [module for module, _ in sorted_candidates[:limit]]
108
+
109
+ def get_priority_modules(self, limit: int = 10) -> List[str]:
110
+ """Get modules that should be preloaded based on scores."""
111
+ with self._lock:
112
+ sorted_modules = sorted(
113
+ self._module_scores.items(),
114
+ key=lambda x: x[1],
115
+ reverse=True
116
+ )
117
+ return [module for module, _ in sorted_modules[:limit]]
118
+
119
+ def get_stats(self) -> Dict:
120
+ """Get learning statistics."""
121
+ with self._lock:
122
+ return {
123
+ 'sequences_tracked': len(self._import_sequences),
124
+ 'unique_modules': len(self._access_times),
125
+ 'chains_tracked': sum(len(chains) for chains in self._import_chains.values()),
126
+ 'top_modules': self.get_priority_modules(5),
127
+ }
128
+
129
+
130
+ __all__ = ['AdaptiveLearner']
131
+
@@ -0,0 +1,276 @@
1
+ """
2
+ #exonware/xwlazy/src/exonware/xwlazy/runtime/base.py
3
+
4
+ Company: eXonware.com
5
+ Author: Eng. Muhammad AlShehri
6
+ Email: connect@exonware.com
7
+ Version: 0.1.0.19
8
+ Generation Date: 10-Oct-2025
9
+
10
+ Abstract Base Class for Runtime Services
11
+
12
+ This module defines the abstract base class for runtime services.
13
+ """
14
+
15
+ import threading
16
+ from abc import ABC, abstractmethod
17
+ from typing import Dict, List, Optional, Any, Tuple
18
+
19
+ from ..contracts import (
20
+ IRuntime,
21
+ )
22
+
23
+
24
+ # =============================================================================
25
+ # ABSTRACT RUNTIME (Unified - Merges all runtime services)
26
+ # =============================================================================
27
+
28
+ class ARuntimeHelper(IRuntime, ABC):
29
+ """
30
+ Unified abstract base for runtime services.
31
+
32
+ Merges functionality from all runtime service interfaces.
33
+ Provides runtime services for state management, learning, monitoring, and caching.
34
+
35
+ This abstract class combines:
36
+ - State management (persistent state for lazy installation)
37
+ - Adaptive learning (learning import patterns and optimizing loading)
38
+ - Intelligent selection (selecting optimal modes based on load characteristics)
39
+ - Metrics collection (collecting and aggregating performance metrics)
40
+ - Performance monitoring (monitoring lazy loading performance)
41
+ - Multi-tier caching (L1/L2/L3 caching)
42
+ - Registry (managing instances by key)
43
+ """
44
+
45
+ __slots__ = (
46
+ # From IStateManager
47
+ '_manual_state', '_auto_state',
48
+ # From IMetricsCollector
49
+ '_metrics',
50
+ # From IPerformanceMonitor
51
+ '_load_times', '_access_counts',
52
+ # From IMultiTierCache
53
+ '_l1_cache', '_l2_cache', '_l3_cache',
54
+ # From IRegistry
55
+ '_registry',
56
+ # Common
57
+ '_lock'
58
+ )
59
+
60
+ def __init__(self):
61
+ """Initialize unified runtime services."""
62
+ # From IStateManager
63
+ self._manual_state: Optional[bool] = None
64
+ self._auto_state: Optional[bool] = None
65
+
66
+ # From IMetricsCollector
67
+ self._metrics: Dict[str, List[float]] = {}
68
+
69
+ # From IPerformanceMonitor
70
+ self._load_times: Dict[str, List[float]] = {}
71
+ self._access_counts: Dict[str, int] = {}
72
+
73
+ # From IMultiTierCache
74
+ self._l1_cache: Dict[str, Any] = {}
75
+ self._l2_cache: Dict[str, Any] = {}
76
+ self._l3_cache: Dict[str, Any] = {}
77
+
78
+ # From IRegistry
79
+ self._registry: Dict[str, Any] = {}
80
+
81
+ # Common
82
+ self._lock = threading.RLock()
83
+
84
+ # ========================================================================
85
+ # State Management Methods (from IStateManager)
86
+ # ========================================================================
87
+
88
+ def get_manual_state(self) -> Optional[bool]:
89
+ """Get manual state override (from IStateManager)."""
90
+ return self._manual_state
91
+
92
+ def set_manual_state(self, value: Optional[bool]) -> None:
93
+ """Set manual state override (from IStateManager)."""
94
+ with self._lock:
95
+ self._manual_state = value
96
+
97
+ def get_cached_auto_state(self) -> Optional[bool]:
98
+ """Get cached auto-detected state (from IStateManager)."""
99
+ return self._auto_state
100
+
101
+ def set_auto_state(self, value: Optional[bool]) -> None:
102
+ """Set cached auto-detected state (from IStateManager)."""
103
+ with self._lock:
104
+ self._auto_state = value
105
+
106
+ # ========================================================================
107
+ # Adaptive Learning Methods (from IAdaptiveLearner)
108
+ # ========================================================================
109
+
110
+ @abstractmethod
111
+ def record_import(self, module_name: str, import_time: float) -> None:
112
+ """Record an import event (from IAdaptiveLearner)."""
113
+ pass
114
+
115
+ @abstractmethod
116
+ def predict_next_imports(self, current_module: str, count: int = 3) -> List[str]:
117
+ """Predict next likely imports based on patterns (from IAdaptiveLearner)."""
118
+ pass
119
+
120
+ @abstractmethod
121
+ def get_module_score(self, module_name: str) -> float:
122
+ """Get priority score for a module (from IAdaptiveLearner)."""
123
+ pass
124
+
125
+ # ========================================================================
126
+ # Intelligent Selection Methods (from IIntelligentSelector)
127
+ # ========================================================================
128
+
129
+ @abstractmethod
130
+ def detect_load_level(
131
+ self,
132
+ module_count: int = 0,
133
+ total_import_time: float = 0.0,
134
+ import_count: int = 0,
135
+ memory_usage_mb: float = 0.0
136
+ ) -> Any:
137
+ """Detect current load level (from IIntelligentSelector)."""
138
+ pass
139
+
140
+ @abstractmethod
141
+ def get_optimal_mode(self, load_level: Any) -> Tuple[Any, Any]:
142
+ """Get optimal mode for a load level (from IIntelligentSelector)."""
143
+ pass
144
+
145
+ @abstractmethod
146
+ def update_mode_map(self, mode_map: Dict[Any, Tuple[Any, Any]]) -> None:
147
+ """Update mode mapping with benchmark results (from IIntelligentSelector)."""
148
+ pass
149
+
150
+ # ========================================================================
151
+ # Metrics Collection Methods (from IMetricsCollector)
152
+ # ========================================================================
153
+
154
+ def record_metric(self, name: str, value: float, timestamp: Optional[Any] = None) -> None:
155
+ """Record a metric value (from IMetricsCollector)."""
156
+ with self._lock:
157
+ if name not in self._metrics:
158
+ self._metrics[name] = []
159
+ self._metrics[name].append(value)
160
+
161
+ @abstractmethod
162
+ def get_metric_stats(self, name: str) -> Dict[str, Any]:
163
+ """Get statistics for a metric (from IMetricsCollector)."""
164
+ pass
165
+
166
+ @abstractmethod
167
+ def get_all_stats(self) -> Dict[str, Dict[str, Any]]:
168
+ """Get statistics for all metrics (from IMetricsCollector)."""
169
+ pass
170
+
171
+ def clear_metrics(self) -> None:
172
+ """Clear all collected metrics (from IMetricsCollector)."""
173
+ with self._lock:
174
+ self._metrics.clear()
175
+
176
+ # ========================================================================
177
+ # Performance Monitoring Methods (from IPerformanceMonitor)
178
+ # ========================================================================
179
+
180
+ def record_load_time(self, module: str, load_time: float) -> None:
181
+ """Record module load time (from IPerformanceMonitor)."""
182
+ with self._lock:
183
+ if module not in self._load_times:
184
+ self._load_times[module] = []
185
+ self._load_times[module].append(load_time)
186
+
187
+ def record_access(self, module: str) -> None:
188
+ """Record module access (from IPerformanceMonitor)."""
189
+ with self._lock:
190
+ self._access_counts[module] = self._access_counts.get(module, 0) + 1
191
+
192
+ @abstractmethod
193
+ def get_performance_stats(self) -> Dict[str, Any]:
194
+ """Get performance statistics (from IPerformanceMonitor)."""
195
+ pass
196
+
197
+ # ========================================================================
198
+ # Multi-Tier Cache Methods (from IMultiTierCache)
199
+ # ========================================================================
200
+
201
+ def get_multi_tier_cached(self, key: str) -> Optional[Any]:
202
+ """Get value from cache (L1 -> L2 -> L3) (from IMultiTierCache)."""
203
+ with self._lock:
204
+ # Check L1 first
205
+ if key in self._l1_cache:
206
+ return self._l1_cache[key]
207
+ # Check L2
208
+ if key in self._l2_cache:
209
+ value = self._l2_cache[key]
210
+ # Promote to L1
211
+ self._l1_cache[key] = value
212
+ return value
213
+ # Check L3
214
+ if key in self._l3_cache:
215
+ value = self._l3_cache[key]
216
+ # Promote to L2
217
+ self._l2_cache[key] = value
218
+ return value
219
+ return None
220
+
221
+ def set_multi_tier_cached(self, key: str, value: Any) -> None:
222
+ """Set value in cache (L1 and L2) (from IMultiTierCache)."""
223
+ with self._lock:
224
+ self._l1_cache[key] = value
225
+ self._l2_cache[key] = value
226
+
227
+ def clear_multi_tier_cache(self) -> None:
228
+ """Clear all cache tiers (from IMultiTierCache)."""
229
+ with self._lock:
230
+ self._l1_cache.clear()
231
+ self._l2_cache.clear()
232
+ self._l3_cache.clear()
233
+
234
+ @abstractmethod
235
+ def shutdown_multi_tier_cache(self) -> None:
236
+ """Shutdown cache (flush L2, cleanup threads) (from IMultiTierCache)."""
237
+ pass
238
+
239
+ # Alias method for backward compatibility
240
+ def shutdown_cache(self) -> None:
241
+ """Alias for shutdown_multi_tier_cache (backward compatibility)."""
242
+ self.shutdown_multi_tier_cache()
243
+
244
+ # ========================================================================
245
+ # Registry Methods (from IRegistry)
246
+ # ========================================================================
247
+
248
+ def get_instance(self, key: str) -> Any:
249
+ """Get instance by key (from IRegistry)."""
250
+ with self._lock:
251
+ return self._registry.get(key)
252
+
253
+ def register(self, key: str, instance: Any) -> None:
254
+ """Register an instance (from IRegistry)."""
255
+ with self._lock:
256
+ self._registry[key] = instance
257
+
258
+ def unregister(self, key: str) -> None:
259
+ """Unregister an instance (from IRegistry)."""
260
+ with self._lock:
261
+ self._registry.pop(key, None)
262
+
263
+ def has_key(self, key: str) -> bool:
264
+ """Check if key is registered (from IRegistry)."""
265
+ with self._lock:
266
+ return key in self._registry
267
+
268
+
269
+ # =============================================================================
270
+ # EXPORT ALL
271
+ # =============================================================================
272
+
273
+ __all__ = [
274
+ 'ARuntimeHelper',
275
+ ]
276
+