Skip to content

Commit

Permalink
Fixed formatting and errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
r3v2d0g committed Nov 12, 2019
1 parent ef4bccf commit f9ee8fb
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 29 deletions.
100 changes: 74 additions & 26 deletions bastion/src/children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,11 @@ impl Children {
///
/// [`with_exec`]: #method.with_exec
pub fn with_redundancy(mut self, redundancy: usize) -> Self {
trace!("Children({}): Setting redundancy: {:?}", self.id(), redundancy);
trace!(
"Children({}): Setting redundancy: {:?}",
self.id(),
redundancy
);
self.redundancy = redundancy;
self
}
Expand Down Expand Up @@ -359,7 +363,11 @@ impl Children {
///
/// [`Callbacks`]: struct.Callbacks.html
pub fn with_callbacks(mut self, callbacks: Callbacks) -> Self {
trace!("Children({}): Setting callbacks: {:?}", self.id(), callbacks);
trace!(
"Children({}): Setting callbacks: {:?}",
self.id(),
callbacks
);
self.callbacks = callbacks;
self
}
Expand Down Expand Up @@ -418,7 +426,11 @@ impl Children {
// FIXME
BastionMessage::SuperviseWith(_) => unimplemented!(),
BastionMessage::Message(ref message) => {
debug!("Children({}): Broadcasting a message: {:?}", self.id(), message);
debug!(
"Children({}): Broadcasting a message: {:?}",
self.id(),
message
);
self.bcast.send_children(msg);
}
BastionMessage::Stopped { id } => {
Expand Down Expand Up @@ -456,7 +468,11 @@ impl Children {
match poll!(&mut self.bcast.next()) {
// TODO: Err if started == true?
Poll::Ready(Some(BastionMessage::Start)) => {
trace!("Children({}): Received a new message (started=false): {:?}", self.id(), BastionMessage::Start);
trace!(
"Children({}): Received a new message (started=false): {:?}",
self.id(),
BastionMessage::Start
);
debug!("Children({}): Starting.", self.id());
self.started = true;

Expand All @@ -466,7 +482,10 @@ impl Children {
let msgs = self.pre_start_msgs.drain(..).collect::<Vec<_>>();
self.pre_start_msgs.shrink_to_fit();

debug!("Children({}): Replaying messages received before starting.", self.id());
debug!(
"Children({}): Replaying messages received before starting.",
self.id()
);
for msg in msgs {
trace!("Children({}): Replaying message: {:?}", self.id(), msg);
if self.handle(msg).await.is_err() {
Expand All @@ -475,11 +494,19 @@ impl Children {
}
}
Poll::Ready(Some(msg)) if !self.started => {
trace!("Children({}): Received a new message (started=false): {:?}", self.id(), msg);
trace!(
"Children({}): Received a new message (started=false): {:?}",
self.id(),
msg
);
self.pre_start_msgs.push(msg);
}
Poll::Ready(Some(msg)) => {
trace!("Children({}): Received a new message (started=true): {:?}", self.id(), msg);
trace!(
"Children({}): Received a new message (started=true): {:?}",
self.id(),
msg
);
if self.handle(msg).await.is_err() {
return self;
}
Expand Down Expand Up @@ -509,13 +536,16 @@ impl Children {
let state = ContextState::new();
let state = Qutex::new(state);

let ctx =
BastionContext::new(id, child_ref, children, supervisor, state.clone());
let ctx = BastionContext::new(id, child_ref, children, supervisor, state.clone());
let exec = (self.init.0)(ctx);

self.bcast.register(&bcast);

debug!("Children({}): Initializing Child({}).", self.id(), bcast.id());
debug!(
"Children({}): Initializing Child({}).",
self.id(),
bcast.id()
);
let child = Child::new(exec, bcast, state);
debug!("Children({}): Launching Child({}).", self.id(), child.id());
let id = child.id().clone();
Expand Down Expand Up @@ -679,7 +709,7 @@ impl ChildrenRef {
/// # }
/// ```
pub fn stop(&self) -> Result<(), ()> {
debug!("ChildrenRef({}): Stopping.");
debug!("ChildrenRef({}): Stopping.", self.id);
let msg = BastionMessage::stop();
self.send(msg).map_err(|_| ())
}
Expand Down Expand Up @@ -708,7 +738,7 @@ impl ChildrenRef {
/// # }
/// ```
pub fn kill(&self) -> Result<(), ()> {
debug!("ChildrenRef({}): Killing.");
debug!("ChildrenRef({}): Killing.", self.id);
let msg = BastionMessage::kill();
self.send(msg).map_err(|_| ())
}
Expand Down Expand Up @@ -746,7 +776,7 @@ impl Child {
ProcStack::default().with_after_panic(move || {
// FIXME: clones
let id = id.clone();
warn!("Child({}): Panicked.");
warn!("Child({}): Panicked.", id);

let msg = BastionMessage::faulted(id);
// TODO: handle errors
Expand Down Expand Up @@ -788,7 +818,7 @@ impl Child {
// FIXME
BastionMessage::SuperviseWith(_) => unimplemented!(),
BastionMessage::Message(msg) => {
debug!("Child({}): Received a message: {:?}", msg);
debug!("Child({}): Received a message: {:?}", self.id(), msg);
let mut state = self.state.clone().lock_async().await.map_err(|_| ())?;
state.push_msg(msg);
}
Expand All @@ -807,14 +837,21 @@ impl Child {
match poll!(&mut self.bcast.next()) {
// TODO: Err if started == true?
Poll::Ready(Some(BastionMessage::Start)) => {
trace!("Child({}): Received a new message (started=false): {:?}", self.id(), BastionMessage::Start);
trace!(
"Child({}): Received a new message (started=false): {:?}",
self.id(),
BastionMessage::Start
);
debug!("Child({}): Starting.", self.id());
self.started = true;

let msgs = self.pre_start_msgs.drain(..).collect::<Vec<_>>();
self.pre_start_msgs.shrink_to_fit();

debug!("Child({}): Replaying messages received before starting.", self.id());
debug!(
"Child({}): Replaying messages received before starting.",
self.id()
);
for msg in msgs {
trace!("Child({}): Replaying message: {:?}", self.id(), msg);
if self.handle(msg).await.is_err() {
Expand All @@ -825,13 +862,21 @@ impl Child {
continue;
}
Poll::Ready(Some(msg)) if !self.started => {
trace!("Child({}): Received a new message (started=false): {:?}", self.id(), msg);
trace!(
"Child({}): Received a new message (started=false): {:?}",
self.id(),
msg
);
self.pre_start_msgs.push(msg);

continue;
}
Poll::Ready(Some(msg)) => {
trace!("Child({}): Received a new message (started=true): {:?}", self.id(), msg);
trace!(
"Child({}): Received a new message (started=true): {:?}",
self.id(),
msg
);
if self.handle(msg).await.is_err() {
return;
}
Expand All @@ -853,13 +898,16 @@ impl Child {

match poll!(&mut self.exec) {
Poll::Ready(Ok(())) => {
debug!("Child({}): The future finished executing successfully.")
return self.stopped()
},
debug!(
"Child({}): The future finished executing successfully.",
self.id()
);
return self.stopped();
}
Poll::Ready(Err(())) => {
warn!("Child({}): The future returned an error.");
return self.faulted()
},
warn!("Child({}): The future returned an error.", self.id());
return self.faulted();
}
Poll::Pending => (),
}

Expand Down Expand Up @@ -1076,7 +1124,7 @@ impl ChildRef {
/// # }
/// ```
pub fn stop(&self) -> Result<(), ()> {
debug!("ChildRef({}): Stopping.");
debug!("ChildRef({}): Stopping.", self.id);
let msg = BastionMessage::stop();
self.send(msg).map_err(|_| ())
}
Expand Down Expand Up @@ -1105,7 +1153,7 @@ impl ChildRef {
/// # }
/// ```
pub fn kill(&self) -> Result<(), ()> {
debug!("ChildRef({}): Killing.");
debug!("ChildRef({}): Killing.", self.id);
let msg = BastionMessage::kill();
self.send(msg).map_err(|_| ())
}
Expand Down
3 changes: 2 additions & 1 deletion bastion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
#![warn(missing_docs)]
#![warn(missing_debug_implementations)]

#[macro_use] extern crate log;
#[macro_use]
extern crate log;

pub use self::bastion::Bastion;
pub use self::callbacks::Callbacks;
Expand Down
7 changes: 5 additions & 2 deletions bastion/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl System {
}
Poll::Ready(Some(None)) => {
error!("System: Unknown supervisor cancelled instead of stopped.");
},
}
Poll::Ready(None) => return supervisors,
Poll::Pending => pending!(),
}
Expand Down Expand Up @@ -255,7 +255,10 @@ impl System {
match poll!(&mut self.bcast.next()) {
// TODO: Err if started == true?
Poll::Ready(Some(BastionMessage::Start)) => {
trace!("System: Received a new message (started=false): {:?}", BastionMessage::Start);
trace!(
"System: Received a new message (started=false): {:?}",
BastionMessage::Start
);
info!("System: Starting.");
self.started = true;

Expand Down

0 comments on commit f9ee8fb

Please sign in to comment.