Skip to content

Commit eabb64d

Browse files
committed
Improve the Exclusive Gateway model - better status reporting, cleaner phase matching, and expanded invalid model state error handling
1 parent b4d5592 commit eabb64d

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/models/exclusive_gateway.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl Default for State {
6464
}
6565
}
6666

67-
#[derive(Debug, Clone, Serialize, Deserialize)]
67+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
6868
enum Phase {
6969
Idle, // Doing nothing
7070
Pass, // Passing a job from input to output
@@ -174,7 +174,11 @@ impl ExclusiveGateway {
174174

175175
impl AsModel for ExclusiveGateway {
176176
fn status(&self) -> String {
177-
String::from("Active")
177+
match self.state.phase {
178+
Phase::Idle => String::from("Idle"),
179+
Phase::Pass => format!["Passing {}", self.state.jobs[0].content],
180+
Phase::Respond => String::from("Fetching records"),
181+
}
178182
}
179183

180184
fn events_ext(
@@ -196,8 +200,10 @@ impl AsModel for ExclusiveGateway {
196200
&& self.store_records
197201
{
198202
self.store_job(incoming_message, services)?;
199-
} else {
203+
} else if self.ports_in.records == incoming_message.port_name {
200204
self.records_request()?;
205+
} else {
206+
return Err(SimulationError::InvalidModelState);
201207
}
202208
Ok(Vec::new())
203209
}
@@ -206,12 +212,12 @@ impl AsModel for ExclusiveGateway {
206212
&mut self,
207213
_services: &mut Services,
208214
) -> Result<Vec<ModelMessage>, SimulationError> {
209-
if let Phase::Pass = self.state.phase {
215+
if Phase::Pass == self.state.phase {
210216
self.send_jobs()
211-
} else if let Phase::Respond = self.state.phase {
217+
} else if Phase::Respond == self.state.phase {
212218
self.send_records()
213219
} else {
214-
Ok(Vec::new())
220+
Err(SimulationError::InvalidModelState)
215221
}
216222
}
217223

0 commit comments

Comments
 (0)