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
use jvm_serializable::java::io::*;
use multimap::MultiMap;
use serde::{Deserialize, Serialize};
use std::collections::hash_map::RandomState;
use std::sync::{Arc, Mutex, RwLock};

//Struct represented information about vertx node server
#[jvm_object(io.vertx.core.net.impl.ServerID,5636540499169644934)]
pub struct ServerID {
    pub port: i32,
    pub host: String,
}

//Struct represented information about vertx node
#[jvm_object(io.vertx.core.eventbus.impl.clustered.ClusterNodeInfo,1)]
pub struct ClusterNodeInfo {
    pub nodeId: String,
    pub serverID: ServerID,
}

//Interface of cluster manager support integrations of cluster nodes
pub trait ClusterManager: Send {
    //Register current node as vertx sub
    fn add_sub(&self, address: String);

    //Register current node as vertx node in cluster
    fn set_cluster_node_info(&mut self, node: ClusterNodeInfo);

    //Get uniquie node id in cluster
    fn get_node_id(&self) -> String;

    //Get id list of all nodes in cluster
    fn get_nodes(&self) -> Vec<String>;

    //Get list of all nodes in cluster
    fn get_ha_infos(&self) -> Arc<Mutex<Vec<ClusterNodeInfo>>>;

    //Get all registered subs and nodes in this subs
    fn get_subs(&self) -> Arc<RwLock<MultiMap<String, ClusterNodeInfo>>>;

    //Join current node to vertx cluster
    fn join(&mut self);

    //Leave current cluster from node
    fn leave(&self);

    //Round rubin index of nodes
    fn next(&self, len: usize) -> usize;
}

//Empty implementation of cluster manager to create vertx standalone instance
pub struct NoClusterManager;

impl ClusterManager for NoClusterManager {
    fn add_sub(&self, _address: String) {
        unimplemented!()
    }

    fn set_cluster_node_info(&mut self, _node: ClusterNodeInfo) {
        unimplemented!()
    }

    fn get_node_id(&self) -> String {
        unimplemented!()
    }

    fn get_nodes(&self) -> Vec<String> {
        unimplemented!()
    }

    fn get_ha_infos(&self) -> Arc<Mutex<Vec<ClusterNodeInfo>>> {
        unimplemented!()
    }

    fn get_subs(&self) -> Arc<RwLock<MultiMap<String, ClusterNodeInfo, RandomState>>> {
        unimplemented!()
    }

    fn join(&mut self) {
        unimplemented!()
    }

    fn leave(&self) {
        unimplemented!()
    }

    fn next(&self, _len: usize) -> usize {
        unimplemented!()
    }
}