aboutsummaryrefslogtreecommitdiff
path: root/src/client/bridge/gateway/mod.rs
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-09-24 15:48:02 -0700
committerZeyla Hellyer <[email protected]>2017-09-24 15:53:23 -0700
commit6c43fed3702be3fdc1eafed26a2f6335acd71843 (patch)
treee3dd142b36f221f33fb8e35c511bbf4e9e9471b6 /src/client/bridge/gateway/mod.rs
parentUse $crate for CommandError (diff)
downloadserenity-6c43fed3702be3fdc1eafed26a2f6335acd71843.tar.xz
serenity-6c43fed3702be3fdc1eafed26a2f6335acd71843.zip
Add a shard manager
The shard manager will queue up shards for booting.
Diffstat (limited to 'src/client/bridge/gateway/mod.rs')
-rw-r--r--src/client/bridge/gateway/mod.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/client/bridge/gateway/mod.rs b/src/client/bridge/gateway/mod.rs
new file mode 100644
index 0000000..0bfd4e6
--- /dev/null
+++ b/src/client/bridge/gateway/mod.rs
@@ -0,0 +1,46 @@
+mod shard_manager;
+mod shard_queuer;
+mod shard_runner;
+
+pub use self::shard_manager::ShardManager;
+pub use self::shard_queuer::ShardQueuer;
+pub use self::shard_runner::ShardRunner;
+
+use gateway::Shard;
+use parking_lot::Mutex;
+use std::fmt::{Display, Formatter, Result as FmtResult};
+use std::sync::mpsc::Sender;
+use std::sync::Arc;
+
+type Parked<T> = Arc<Mutex<T>>;
+type LockedShard = Parked<Shard>;
+
+#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
+pub enum ShardManagerMessage {
+ Restart(ShardId),
+ Shutdown(ShardId),
+ ShutdownAll,
+}
+
+pub enum ShardQueuerMessage {
+ /// Message to start a shard, where the 0-index element is the ID of the
+ /// Shard to start and the 1-index element is the total shards in use.
+ Start(ShardId, ShardId),
+ /// Message to shutdown the shard queuer.
+ Shutdown,
+}
+
+// A light tuplestruct wrapper around a u64 to verify type correctness when
+// working with the IDs of shards.
+#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
+pub struct ShardId(pub u64);
+
+impl Display for ShardId {
+ fn fmt(&self, f: &mut Formatter) -> FmtResult {
+ write!(f, "{}", self.0)
+ }
+}
+
+pub struct ShardRunnerInfo {
+ runner_tx: Sender<ShardManagerMessage>,
+}