vertx_rust/vertx/
cm.rs

1use jvm_serializable::java::io::*;
2use multimap::MultiMap;
3use serde::{Deserialize, Serialize};
4use std::collections::hash_map::RandomState;
5use std::sync::{Arc, Mutex, RwLock};
6
7//Struct represented information about vertx node server
8#[jvm_object(io.vertx.core.net.impl.ServerID,5636540499169644934)]
9pub struct ServerID {
10    pub port: i32,
11    pub host: String,
12}
13
14//Struct represented information about vertx node
15#[jvm_object(io.vertx.core.eventbus.impl.clustered.ClusterNodeInfo,1)]
16pub struct ClusterNodeInfo {
17    pub nodeId: String,
18    pub serverID: ServerID,
19}
20
21//Interface of cluster manager support integrations of cluster nodes
22pub trait ClusterManager: Send {
23    //Register current node as vertx sub
24    fn add_sub(&self, address: String);
25
26    //Register current node as vertx node in cluster
27    fn set_cluster_node_info(&mut self, node: ClusterNodeInfo);
28
29    //Get uniquie node id in cluster
30    fn get_node_id(&self) -> String;
31
32    //Get id list of all nodes in cluster
33    fn get_nodes(&self) -> Vec<String>;
34
35    //Get list of all nodes in cluster
36    fn get_ha_infos(&self) -> Arc<Mutex<Vec<ClusterNodeInfo>>>;
37
38    //Get all registered subs and nodes in this subs
39    fn get_subs(&self) -> Arc<RwLock<MultiMap<String, ClusterNodeInfo>>>;
40
41    //Join current node to vertx cluster
42    fn join(&mut self);
43
44    //Leave current cluster from node
45    fn leave(&self);
46
47    //Round rubin index of nodes
48    fn next(&self, len: usize) -> usize;
49}
50
51//Empty implementation of cluster manager to create vertx standalone instance
52pub struct NoClusterManager;
53
54impl ClusterManager for NoClusterManager {
55    fn add_sub(&self, _address: String) {
56        unimplemented!()
57    }
58
59    fn set_cluster_node_info(&mut self, _node: ClusterNodeInfo) {
60        unimplemented!()
61    }
62
63    fn get_node_id(&self) -> String {
64        unimplemented!()
65    }
66
67    fn get_nodes(&self) -> Vec<String> {
68        unimplemented!()
69    }
70
71    fn get_ha_infos(&self) -> Arc<Mutex<Vec<ClusterNodeInfo>>> {
72        unimplemented!()
73    }
74
75    fn get_subs(&self) -> Arc<RwLock<MultiMap<String, ClusterNodeInfo, RandomState>>> {
76        unimplemented!()
77    }
78
79    fn join(&mut self) {
80        unimplemented!()
81    }
82
83    fn leave(&self) {
84        unimplemented!()
85    }
86
87    fn next(&self, _len: usize) -> usize {
88        unimplemented!()
89    }
90}