-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a skeleton for the Bastion and System structs, and cleaned up a…
… bit
- Loading branch information
Showing
7 changed files
with
121 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use crate::supervisor::Supervisor; | ||
use crate::system::System; | ||
use futures::channel::mpsc::UnboundedSender; | ||
use lazy_static::lazy_static; | ||
|
||
lazy_static! { | ||
pub(super) static ref SYSTEM_SENDER: UnboundedSender<Supervisor> = System::start(); | ||
} | ||
|
||
pub struct Bastion { | ||
// TODO: ... | ||
} | ||
|
||
impl Bastion { | ||
pub fn supervisor() -> Supervisor { | ||
Supervisor::new() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
use crate::broadcast::Broadcast; | ||
|
||
pub struct BastionContext {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
mod bastion; | ||
mod broadcast; | ||
mod children; | ||
mod context; | ||
mod supervisor; | ||
mod system; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use crate::broadcast::{BastionMessage, Broadcast}; | ||
use crate::supervisor::Supervisor; | ||
use futures::{pending, poll}; | ||
use futures::channel::mpsc::{self, UnboundedReceiver, UnboundedSender}; | ||
use futures::prelude::*; | ||
use fxhash::{FxHashMap, FxHashSet}; | ||
use runtime::task::JoinHandle; | ||
use std::task::Poll; | ||
use uuid::Uuid; | ||
|
||
pub(super) struct System { | ||
bcast: Broadcast, | ||
recver: UnboundedReceiver<Supervisor>, | ||
supervisors: FxHashMap<Uuid, JoinHandle<Supervisor>>, | ||
dead: FxHashSet<Uuid>, | ||
} | ||
|
||
impl System { | ||
pub(super) fn start() -> UnboundedSender<Supervisor> { | ||
let id = Uuid::new_v4(); | ||
let bcast = Broadcast::new(id); | ||
let (sender, recver) = mpsc::unbounded(); | ||
|
||
let supervisors = FxHashMap::default(); | ||
let dead = FxHashSet::default(); | ||
|
||
let system = System { | ||
bcast, | ||
recver, | ||
supervisors, | ||
dead, | ||
}; | ||
|
||
runtime::spawn(system.run()); | ||
|
||
sender | ||
} | ||
|
||
fn launch_supervisor(&mut self, mut supervisor: Supervisor) { | ||
supervisor.launch_children(); | ||
|
||
runtime::spawn(supervisor.run()); | ||
} | ||
|
||
async fn run(mut self) { | ||
loop { | ||
let mut ready = false; | ||
|
||
match poll!(&mut self.bcast.next()) { | ||
Poll::Ready(Some(msg)) => { | ||
ready = true; | ||
|
||
match msg { | ||
// FIXME | ||
BastionMessage::PoisonPill => unimplemented!(), | ||
// FIXME | ||
BastionMessage::Dead { .. } => unimplemented!(), | ||
// FIXME | ||
BastionMessage::Faulted { .. } => unimplemented!(), | ||
// FIXME | ||
BastionMessage::Message(_) => unimplemented!(), | ||
} | ||
} | ||
// FIXME | ||
Poll::Ready(None) => unimplemented!(), | ||
Poll::Pending => (), | ||
} | ||
|
||
match poll!(&mut self.recver.next()) { | ||
Poll::Ready(Some(supervisor)) => { | ||
ready = true; | ||
|
||
self.launch_supervisor(supervisor); | ||
} | ||
// FIXME | ||
Poll::Ready(None) => unimplemented!(), | ||
Poll::Pending => (), | ||
} | ||
|
||
if !ready { | ||
pending!(); | ||
} | ||
} | ||
} | ||
} |