Document dataspace.rs; remove "churn" field
This commit is contained in:
parent
4491873ac8
commit
2e2d5bfb5d
|
@ -1,3 +1,12 @@
|
||||||
|
//! Implements a [*dataspace*](#GarnockJones2017) entity.
|
||||||
|
//!
|
||||||
|
//! **References.**
|
||||||
|
//!
|
||||||
|
//! - Garnock-Jones, Tony. <a name="GarnockJones2017">“Conversational
|
||||||
|
//! Concurrency.”</a> PhD, Northeastern University, 2017. [Available
|
||||||
|
//! on the web](https://syndicate-lang.org/tonyg-dissertation/).
|
||||||
|
//! [PDF](https://syndicate-lang.org/papers/conversational-concurrency-201712310922.pdf).
|
||||||
|
|
||||||
use super::skeleton;
|
use super::skeleton;
|
||||||
use super::actor::*;
|
use super::actor::*;
|
||||||
use super::schemas::dataspace::*;
|
use super::schemas::dataspace::*;
|
||||||
|
@ -7,61 +16,74 @@ use preserves::value::Map;
|
||||||
|
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
#[derive(Debug)]
|
// #[derive(Debug)]
|
||||||
pub struct Churn {
|
// pub struct Churn {
|
||||||
pub assertions_added: usize,
|
// pub assertions_added: usize,
|
||||||
pub assertions_removed: usize,
|
// pub assertions_removed: usize,
|
||||||
pub endpoints_added: usize,
|
// pub endpoints_added: usize,
|
||||||
pub endpoints_removed: usize,
|
// pub endpoints_removed: usize,
|
||||||
pub observers_added: usize,
|
// pub observers_added: usize,
|
||||||
pub observers_removed: usize,
|
// pub observers_removed: usize,
|
||||||
pub messages_injected: usize,
|
// pub messages_injected: usize,
|
||||||
pub messages_delivered: usize,
|
// pub messages_delivered: usize,
|
||||||
}
|
// }
|
||||||
|
|
||||||
impl Churn {
|
// impl Churn {
|
||||||
pub fn new() -> Self {
|
// pub fn new() -> Self {
|
||||||
Self {
|
// Self {
|
||||||
assertions_added: 0,
|
// assertions_added: 0,
|
||||||
assertions_removed: 0,
|
// assertions_removed: 0,
|
||||||
endpoints_added: 0,
|
// endpoints_added: 0,
|
||||||
endpoints_removed: 0,
|
// endpoints_removed: 0,
|
||||||
observers_added: 0,
|
// observers_added: 0,
|
||||||
observers_removed: 0,
|
// observers_removed: 0,
|
||||||
messages_injected: 0,
|
// messages_injected: 0,
|
||||||
messages_delivered: 0,
|
// messages_delivered: 0,
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
pub fn reset(&mut self) {
|
// pub fn reset(&mut self) {
|
||||||
*self = Churn::new()
|
// *self = Churn::new()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
/// A Dataspace object (entity).
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Dataspace {
|
pub struct Dataspace {
|
||||||
|
/// Index over assertions placed in the dataspace; used to
|
||||||
|
/// efficiently route assertion changes and messages to observers.
|
||||||
pub index: skeleton::Index,
|
pub index: skeleton::Index,
|
||||||
|
/// Local memory of assertions indexed by `Handle`, used to remove
|
||||||
|
/// assertions from the `index` when they are retracted.
|
||||||
pub handle_map: Map<Handle, (_Any, Option<Observe>)>,
|
pub handle_map: Map<Handle, (_Any, Option<Observe>)>,
|
||||||
pub churn: Churn,
|
// pub churn: Churn,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dataspace {
|
impl Dataspace {
|
||||||
|
/// Construct a new, empty dataspace.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
index: skeleton::Index::new(),
|
index: skeleton::Index::new(),
|
||||||
handle_map: Map::new(),
|
handle_map: Map::new(),
|
||||||
churn: Churn::new(),
|
// churn: Churn::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Retrieve the current count of *distinct* assertions placed in
|
||||||
|
/// the dataspace.
|
||||||
pub fn assertion_count(&self) -> usize {
|
pub fn assertion_count(&self) -> usize {
|
||||||
self.index.assertion_count()
|
self.index.assertion_count()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Retrieve the current count of assertions, including
|
||||||
|
/// duplicates, placed in the dataspace.
|
||||||
pub fn endpoint_count(&self) -> isize {
|
pub fn endpoint_count(&self) -> isize {
|
||||||
self.index.endpoint_count()
|
self.index.endpoint_count()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Retrieve the current count of
|
||||||
|
/// [`Observe`][crate::schemas::dataspace::Observe] assertions in
|
||||||
|
/// the dataspace.
|
||||||
pub fn observer_count(&self) -> usize {
|
pub fn observer_count(&self) -> usize {
|
||||||
self.index.observer_count()
|
self.index.observer_count()
|
||||||
}
|
}
|
||||||
|
@ -71,14 +93,14 @@ impl Entity<_Any> for Dataspace {
|
||||||
fn assert(&mut self, t: &mut Activation, a: _Any, h: Handle) -> ActorResult {
|
fn assert(&mut self, t: &mut Activation, a: _Any, h: Handle) -> ActorResult {
|
||||||
// tracing::trace!(assertion = debug(&a), handle = debug(&h), "assert");
|
// tracing::trace!(assertion = debug(&a), handle = debug(&h), "assert");
|
||||||
|
|
||||||
let old_assertions = self.index.assertion_count();
|
// let old_assertions = self.index.assertion_count();
|
||||||
self.index.insert(t, &a);
|
self.index.insert(t, &a);
|
||||||
self.churn.assertions_added += self.index.assertion_count() - old_assertions;
|
// self.churn.assertions_added += self.index.assertion_count() - old_assertions;
|
||||||
self.churn.endpoints_added += 1;
|
// self.churn.endpoints_added += 1;
|
||||||
|
|
||||||
if let Ok(o) = Observe::try_from(&a) {
|
if let Ok(o) = Observe::try_from(&a) {
|
||||||
self.index.add_observer(t, &o.pattern, &o.observer);
|
self.index.add_observer(t, &o.pattern, &o.observer);
|
||||||
self.churn.observers_added += 1;
|
// self.churn.observers_added += 1;
|
||||||
self.handle_map.insert(h, (a, Some(o)));
|
self.handle_map.insert(h, (a, Some(o)));
|
||||||
} else {
|
} else {
|
||||||
self.handle_map.insert(h, (a, None));
|
self.handle_map.insert(h, (a, None));
|
||||||
|
@ -92,13 +114,13 @@ impl Entity<_Any> for Dataspace {
|
||||||
if let Some((a, maybe_o)) = self.handle_map.remove(&h) {
|
if let Some((a, maybe_o)) = self.handle_map.remove(&h) {
|
||||||
if let Some(o) = maybe_o {
|
if let Some(o) = maybe_o {
|
||||||
self.index.remove_observer(t, o.pattern, &o.observer);
|
self.index.remove_observer(t, o.pattern, &o.observer);
|
||||||
self.churn.observers_removed += 1;
|
// self.churn.observers_removed += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let old_assertions = self.index.assertion_count();
|
// let old_assertions = self.index.assertion_count();
|
||||||
self.index.remove(t, &a);
|
self.index.remove(t, &a);
|
||||||
self.churn.assertions_removed += old_assertions - self.index.assertion_count();
|
// self.churn.assertions_removed += old_assertions - self.index.assertion_count();
|
||||||
self.churn.endpoints_removed += 1;
|
// self.churn.endpoints_removed += 1;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -106,8 +128,9 @@ impl Entity<_Any> for Dataspace {
|
||||||
fn message(&mut self, t: &mut Activation, m: _Any) -> ActorResult {
|
fn message(&mut self, t: &mut Activation, m: _Any) -> ActorResult {
|
||||||
// tracing::trace!(body = debug(&m), "message");
|
// tracing::trace!(body = debug(&m), "message");
|
||||||
|
|
||||||
self.index.send(t, &m, &mut self.churn.messages_delivered);
|
// self.index.send(t, &m, &mut self.churn.messages_delivered);
|
||||||
self.churn.messages_injected += 1;
|
self.index.send(t, &m);
|
||||||
|
// self.churn.messages_injected += 1;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,14 +144,14 @@ impl Index {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send(&mut self, t: &mut Activation, outer_value: &AnyValue, delivery_count: &mut usize) {
|
pub fn send(&mut self, t: &mut Activation, outer_value: &AnyValue) {
|
||||||
Modification::new(
|
Modification::new(
|
||||||
false,
|
false,
|
||||||
&outer_value,
|
&outer_value,
|
||||||
|_c, _v| (),
|
|_c, _v| (),
|
||||||
|_l, _v| (),
|
|_l, _v| (),
|
||||||
|es, cs| {
|
|es, cs| {
|
||||||
*delivery_count += es.endpoints.len();
|
// *delivery_count += es.endpoints.len();
|
||||||
for observer in es.endpoints.keys() {
|
for observer in es.endpoints.keys() {
|
||||||
observer.message(t, cs.clone());
|
observer.message(t, cs.clone());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue