mssf_core/runtime/stateless.rs
1// ------------------------------------------------------------
2// Copyright (c) Microsoft Corporation. All rights reserved.
3// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4// ------------------------------------------------------------
5
6#![deny(non_snake_case)] // this file is safe rust
7
8use crate::WString;
9use crate::runtime::StatelessServicePartition;
10use crate::runtime::executor::BoxedCancelToken;
11
12/// Stateless service factories are registered with the FabricRuntime by service hosts via
13/// Runtime::register_stateless_service_factory().
14///
15pub trait StatelessServiceFactory {
16 /// Creates a stateless service instance for a particular service. This method is called by Service Fabric.
17 fn create_instance(
18 &self,
19 servicetypename: &WString,
20 servicename: &WString,
21 initializationdata: &[u8],
22 partitionid: &crate::GUID,
23 instanceid: i64,
24 ) -> crate::Result<impl StatelessServiceInstance>;
25}
26
27/// Defines behavior that governs the lifecycle of a stateless service instance, such as startup, initialization, and shutdown.
28#[trait_variant::make(StatelessServiceInstance: Send)]
29pub trait LocalStatelessServiceInstance: Send + Sync + 'static {
30 /// Opens an initialized service instance so that it can be contacted by clients.
31 /// Remarks:
32 /// Opening an instance stateless service indicates that the service is now resolvable
33 /// and discoverable by service clients. The string that is returned is the address of this service instance.
34 /// The address is associated with the service name via Service Fabric naming and returned to
35 /// clients that resolve the service via resolve_service_partition(uri).
36 async fn open(
37 &self,
38 partition: &StatelessServicePartition,
39 cancellation_token: BoxedCancelToken,
40 ) -> crate::Result<WString>;
41
42 /// Closes this service instance gracefully when the service instance is being shut down.
43 async fn close(&self, cancellation_token: BoxedCancelToken) -> crate::Result<()>;
44
45 /// Terminates this instance ungracefully with this synchronous method call.
46 /// Remarks:
47 /// Examples of ungraceful termination are network issues resulting in Service Fabric process shutdown and the
48 /// use of ReportFault(FaultType) to report a Permanent fault. When the service instance receives this method,
49 /// it should immediately release and clean up all references and return.
50 fn abort(&self);
51}