infinispan_fork/request/caches/
modes.rs1use serde::{Deserialize, Serialize};
2
3const DEFAULT_CONCURRENCY_LEVEL: i32 = 1_000;
4const DEFAULT_ACQUIRE_TIMEOUT: i32 = 15_000;
5const DEFAULT_STATE_TRANSFER_TIMEOUT: i32 = 60_000;
6const DEFAULT_REMOTE_TIMEOUT: i32 = 17_500;
7
8#[derive(Eq, PartialEq, Debug, Serialize, Deserialize)]
9pub struct Local {
10 locking: Locking,
11 statistics: bool,
12}
13
14impl Default for Local {
15 fn default() -> Self {
16 Self {
17 locking: Locking::default(),
18 statistics: true,
19 }
20 }
21}
22
23#[derive(Eq, PartialEq, Debug, Serialize, Deserialize)]
24#[serde(rename_all = "kebab-case")]
25pub struct Distributed {
26 mode: String,
27 state_transfer: StateTransfer,
28 locking: Locking,
29 statistics: bool,
30}
31
32impl Distributed {
33 pub fn create_async() -> Self {
34 Self {
35 mode: "ASYNC".into(),
36 state_transfer: StateTransfer {
37 timeout: DEFAULT_STATE_TRANSFER_TIMEOUT,
38 },
39 locking: Locking::default(),
40 statistics: true,
41 }
42 }
43
44 pub fn create_sync() -> Self {
45 Self {
46 mode: "SYNC".into(),
47 state_transfer: StateTransfer {
48 timeout: DEFAULT_STATE_TRANSFER_TIMEOUT,
49 },
50 locking: Locking::default(),
51 statistics: true,
52 }
53 }
54}
55
56#[derive(Eq, PartialEq, Debug, Serialize, Deserialize)]
57#[serde(rename_all = "kebab-case")]
58pub struct Replicated {
59 mode: String,
60 #[serde(skip_serializing_if = "Option::is_none")]
61 remote_timeout: Option<i32>,
62 state_transfer: StateTransfer,
63 locking: Locking,
64 statistics: bool,
65}
66
67impl Replicated {
68 pub fn create_async() -> Self {
69 Self {
70 mode: "ASYNC".into(),
71 remote_timeout: None,
72 state_transfer: StateTransfer {
73 timeout: DEFAULT_STATE_TRANSFER_TIMEOUT,
74 },
75 locking: Locking::default(),
76 statistics: true,
77 }
78 }
79
80 pub fn create_sync() -> Self {
81 Self {
82 mode: "SYNC".into(),
83 remote_timeout: Some(DEFAULT_REMOTE_TIMEOUT),
84 state_transfer: StateTransfer {
85 timeout: DEFAULT_STATE_TRANSFER_TIMEOUT,
86 },
87 locking: Locking::default(),
88 statistics: true,
89 }
90 }
91}
92
93#[derive(Eq, PartialEq, Debug, Serialize, Deserialize)]
94#[serde(rename_all = "kebab-case")]
95pub struct Invalidation {
96 mode: String,
97 #[serde(skip_serializing_if = "Option::is_none")]
98 remote_timeout: Option<i32>,
99 locking: Locking,
100 statistics: bool,
101}
102
103impl Invalidation {
104 pub fn create_async() -> Self {
105 Self {
106 mode: "ASYNC".into(),
107 remote_timeout: None,
108 locking: Locking::default(),
109 statistics: true,
110 }
111 }
112
113 pub fn create_sync() -> Self {
114 Self {
115 mode: "SYNC".into(),
116 remote_timeout: Some(DEFAULT_REMOTE_TIMEOUT),
117 locking: Locking::default(),
118 statistics: true,
119 }
120 }
121}
122
123#[derive(Eq, PartialEq, Debug, Serialize, Deserialize)]
124#[serde(rename_all = "kebab-case")]
125struct Locking {
126 concurrency_level: i32,
127 acquire_timeout: i32,
128 striping: bool,
129}
130
131impl Default for Locking {
132 fn default() -> Self {
133 Self {
134 concurrency_level: DEFAULT_CONCURRENCY_LEVEL,
135 acquire_timeout: DEFAULT_ACQUIRE_TIMEOUT,
136 striping: false,
137 }
138 }
139}
140
141#[derive(Eq, PartialEq, Debug, Serialize, Deserialize)]
142struct StateTransfer {
143 timeout: i32,
144}