Class FlowMetricsFactory
FlowMetrics that auto-detects whether the optional
opencode-base-observability module is available on the runtime
classpath. Returns BaseObservabilityFlowMetrics when present,
NoOpFlowMetrics otherwise.
FlowMetrics 工厂:自动探测可选模块 opencode-base-observability
是否在运行时类路径,命中返回 BaseObservabilityFlowMetrics,否则返回
NoOpFlowMetrics。
Detection uses Class.forName(String) so the engine module compiles
and runs even when the observability module is excluded.
探测使用 Class.forName(String),因此即便排除 observability 依赖,
flow 模块仍可编译运行。
Sample wiring:
FlowMetrics metrics = FlowMetricsFactory.create();
DefaultFlowInstanceService inst = new DefaultFlowInstanceService(
repo, resolver, expr, metrics);
DefaultTaskService task = new DefaultTaskService(
repo, resolver, expr, metrics);
- Since:
- JDK 25, opencode-base-flow V1.0.5
- Author:
- Leon Soo
-
Method Summary
Modifier and TypeMethodDescriptionstatic FlowMetricscreate()Returns aFlowMetricsbound to a freshly createdMetricRegistrywhenopencode-base-observabilityis on the classpath, or aNoOpFlowMetricsotherwise.static FlowMetricsfromRegistry(Object registry) Returns aFlowMetricsbound to the supplied registry.
-
Method Details
-
create
Returns aFlowMetricsbound to a freshly createdMetricRegistrywhenopencode-base-observabilityis on the classpath, or aNoOpFlowMetricsotherwise. 当类路径有opencode-base-observability时返回绑定新建MetricRegistry的FlowMetrics,否则返回NoOpFlowMetrics。R1 S-6 hardening: narrow the catch from
Throwableto the specific signals that "observability module absent" can produce (ClassNotFoundException/NoClassDefFoundError); log (rather than swallow) aSecurityException; useMethodHandlesinstead of reflectiveMethod.invokeso a signature mismatch inMetricRegistry.create()fails fast at lookup time rather than at the next invocation.R1 S-6 加固:把
Throwable缩窄为ClassNotFoundException/NoClassDefFoundError;SecurityException改 WARN 后再退化;用MethodHandles替换Method.invoke,签名错误 在 lookup 阶段直接 fail-fast。- Returns:
- a new FlowMetrics instance — 新的 FlowMetrics 实例
- Since:
- JDK 25, opencode-base-flow V1.0.5
-
fromRegistry
Returns aFlowMetricsbound to the supplied registry. Theregistryparameter is typed asObjectso this method can be called from hosts that have not added the observability module to their compile classpath (e.g. via reflection); a runtimeClassCastExceptionis raised when the type is wrong. 返回绑定到给定 registry 的FlowMetrics。registry用Object类型以允许未把 observability 模块加入编译期类路径的宿主 通过反射调用;类型不匹配时运行期抛ClassCastException。- Parameters:
registry- an instance ofMetricRegistry—MetricRegistry实例- Returns:
- a new FlowMetrics instance — 新的 FlowMetrics 实例
- Throws:
ClassCastException- whenregistryis not aMetricRegistry— 当registry不是MetricRegistry时- Since:
- JDK 25, opencode-base-flow V1.0.5
-