1 // Copyright (C) 2018-2019 HuntLabs. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 module hunt.gossip.GossipSettings;
15 
16 
17 import hunt.gossip.model.SeedMember;
18 import hunt.gossip.net.MsgService;
19 import hunt.gossip.net.udp.UDPMsgService;
20 import hunt.gossip.GossipManager;
21 
22 import hunt.collection.ArrayList;
23 import hunt.collection.List;
24 
25 
26 public class GossipSettings {
27     //Time between gossip ping in ms. Default is 1 second
28     private int gossipInterval = 1000;
29 
30     //Network delay in ms. Default is 200ms
31     private int networkDelay = 200;
32 
33     //Which message sync implementation. Default is UDPMsgService.class
34     private MsgService msgService;
35 
36     //Delete the deadth node when the sync message is not received more than [deleteThreshold] times
37     private int deleteThreshold = 3;
38 
39     private List!(SeedMember) seedMembers;
40 
41     this()
42     {
43         seedMembers =  new ArrayList!(SeedMember)();
44         msgService = new UDPMsgService();
45     }
46 
47     public int getGossipInterval() {
48         return gossipInterval;
49     }
50 
51     public void setGossipInterval(int gossipInterval) {
52         this.gossipInterval = gossipInterval;
53     }
54 
55     public int getNetworkDelay() {
56         return networkDelay;
57     }
58 
59     public void setNetworkDelay(int networkDelay) {
60         this.networkDelay = networkDelay;
61     }
62 
63     public List!(SeedMember) getSeedMembers() {
64         return seedMembers;
65     }
66 
67      public void setSeedMembers(List!(SeedMember) seedMembers) {
68         List!(SeedMember) _seedMembers = new ArrayList!(SeedMember)();
69         if(seedMembers !is null && !seedMembers.isEmpty()){
70             foreach(SeedMember seed ;seedMembers){
71                 import hunt.text.Common;
72 
73                 if(!seed.eigenvalue().equalsIgnoreCase(GossipManager.getInstance().getSelf().eigenvalue())){
74                     if(!_seedMembers.contains(seed)){
75                         _seedMembers.add(seed);
76                     }
77                 }
78             }
79         }
80         this.seedMembers = seedMembers;
81     }
82 
83     public MsgService getMsgService() {
84         return msgService;
85     }
86 
87     public void setMsgService(MsgService msgService) {
88         this.msgService = msgService;
89     }
90 
91     public int getDeleteThreshold() {
92         return deleteThreshold;
93     }
94 
95     public void setDeleteThreshold(int deleteThreshold) {
96         this.deleteThreshold = deleteThreshold;
97     }
98 }