1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
#![deny(missing_docs)]
//! Connect framework is primarily aimed at easing the process of developing fault-tolerant
//! distributed systems in Rust.
//!
//! ## What is distributed system?
//! A distributed system is a group of machines that are virtually or geographically
//! seperated and that work togather to provide the same service or application to
//! clients.
//!
//! ## Why are distributed systems needed?
//! With the exponential growth in volume of highly sensitive data, it has become
//! increasingly important to distribute and replicate it across a cluster of machines
//! to maintain reliable and fault-tolerant systems.
//!
//! There are many cases n which the use of single computer would be possible in principle
//! but the use of distributed system is benificial for practical reasons. For example, it
//! may be more cost efficient to obtain the desired level of performance by using a cluster
//! of several low-end computers, in comparison with a single high-end computer. A distributed
//! system can provide more reliability than a non-distributed system, as there is no
//! single point of failure. Moreover, a distributed system may be easier to expand and
//! manage than a monolithic uniprocessor system.
//!
//! ## How distributed systems work in harmony?
//! A fundamental problem in distributed systems is to create harmony between different
//! nodes of a cluster. The underlying problem requires agreement among number of nodes
//! for a single data value.
//!
//! There are many algorithms especially created for handling consensus among nodes in a
//! cluster. Connect framework uses [Raft consensus algorithm] to replicate state across
//! the cluster.
//! 
//! ## Usage
//! Below is a simple example showing a way of creating a distributed atomic counter using
//! connect framework.
//! 
//! ```rust
//! # extern crate bytes;
//! # extern crate connect;
//! use std::sync::atomic::{AtomicUsize, Ordering};
//! use std::sync::Arc;
//! use std::thread;
//! use std::time::Duration;
//! 
//! use bytes::Bytes;
//! use connect::{Cluster, MessageType, Server, ServiceType};
//! # fn main() {
//! 
//! let counter = Arc::new(AtomicUsize::default());
//! 
//! let cluster = Cluster::with_file("Connect.toml");
//! 
//! let incoming = |bytes: Bytes| {
//!     if bytes[..4] == b"incr"[..] {
//!         MessageType::Write
//!     } else {
//!         MessageType::Read
//!     }
//! };
//! 
//! let on_read = {
//!     let counter = counter.clone();
//!     move |_| Bytes::from(format!("{}\n", counter.load(Ordering::SeqCst)))
//! };
//! 
//! let on_write = {
//!     let counter = counter.clone();
//!     move |_| {
//!         counter.store(counter.load(Ordering::SeqCst) + 1, Ordering::SeqCst);
//! 
//!         Bytes::from(format!("{}\n", counter.load(Ordering::SeqCst)))
//!     }
//! };
//! 
//! let server = Server::new(cluster, incoming, on_read, on_write, ServiceType::InMemory);
//! 
//! server.run();
//! # }
//! ```
//! 
//! ### Important notice
//! This crate is under active development. Please do not use it in production.
//!
//! [Raft consensus algorithm]: https://raft.github.io
#[macro_use]
extern crate log;
#[macro_use]
extern crate quick_error;
#[macro_use]
extern crate serde_derive;
extern crate bincode;
extern crate bytes;
extern crate config;
extern crate mio;
extern crate mio_extras;
extern crate rand;
extern crate serde;
extern crate slab;
extern crate threadpool;

mod cluster;
mod consensus;
mod errors;
mod exchange;
mod executor;
mod message;
mod server;

pub use cluster::*;
pub use errors::*;
pub use message::*;
pub use server::*;