platform_core/registry.rs
1//
2// Copyright 2018-2026 Accenture Technology
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17//! Link-time registration inventory — the Rust analog of Java's classpath
18//! annotation scanning (design D6's ergonomic layer). The attribute macros
19//! (`#[preload]`, `#[before_application]`, `#[main_application]`) submit
20//! entries here at link time; [`AutoStart`](crate::app_starter::AutoStart)
21//! collects them at startup, exactly as Java's `AppStarter` scans for its
22//! annotations.
23
24use std::sync::Arc;
25
26use crate::function::ComposableFunction;
27
28/// A `#[preload]`-annotated composable function (Java `@PreLoad`).
29pub struct PreloadEntry {
30 pub route: &'static str,
31 pub instances: usize,
32 /// Optional configuration key for the instance count (Java `envInstances`);
33 /// `instances` is the fallback.
34 pub env_instances: Option<&'static str>,
35 /// Java `@OptionalService`: a configuration condition (e.g. `"app.env=dev"`)
36 /// that must hold at startup for this route to register; `None` = always
37 /// register. Evaluated by [`crate::util::feature::is_required`].
38 pub optional_service: Option<&'static str>,
39 /// Java `@PreLoad.isPrivate` (default true): a private function is
40 /// reachable only inside this application instance — Event over HTTP
41 /// rejects it with 403.
42 pub is_private: bool,
43 /// Java `@ZeroTracing`: this route's executions are excluded from
44 /// distributed-trace recording.
45 pub zero_tracing: bool,
46 /// Java `@EventInterceptor`: manual replies, no auto-reply on success.
47 pub interceptor: bool,
48 pub factory: fn() -> Arc<dyn ComposableFunction>,
49}
50
51/// A `#[websocket_service]`-annotated websocket handler
52/// (Java `@WebSocketService(value, namespace)`).
53pub struct WsServiceEntry {
54 /// The service name — the URL becomes `/{namespace}/{name}/{token}`.
55 pub name: &'static str,
56 /// Java `namespace()` default: "ws".
57 pub namespace: &'static str,
58 /// Java `@OptionalService`: a config condition (e.g. `"app.env=dev"`) that
59 /// must hold at startup for this websocket service to register; `None` =
60 /// always. Evaluated by [`crate::util::feature::is_required`].
61 pub optional_service: Option<&'static str>,
62 /// One function object per websocket connection.
63 pub factory: fn() -> Arc<dyn ComposableFunction>,
64}
65
66/// A `#[before_application]`-annotated entry point (Java `@BeforeApplication`).
67pub struct BeforeAppEntry {
68 pub sequence: u32,
69 /// Java `@OptionalService` condition; `None` = always run.
70 pub optional_service: Option<&'static str>,
71 pub factory: fn() -> Arc<dyn crate::app_starter::EntryPoint>,
72}
73
74/// A `#[main_application]`-annotated entry point (Java `@MainApplication`).
75pub struct MainAppEntry {
76 pub sequence: u32,
77 /// Java `@OptionalService` condition; `None` = always run.
78 pub optional_service: Option<&'static str>,
79 pub factory: fn() -> Arc<dyn crate::app_starter::EntryPoint>,
80}
81
82inventory::collect!(PreloadEntry);
83inventory::collect!(WsServiceEntry);
84inventory::collect!(BeforeAppEntry);
85inventory::collect!(MainAppEntry);