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 
15 module hunt.gossip.model.CandidateMemberState;
16 
17 import core.atomic;
18 import std.conv;
19 
20 public class CandidateMemberState {
21     private  long heartbeatTime;
22     private shared int downingCount;
23 
24     public this(long heartbeatTime) {
25         this.heartbeatTime = heartbeatTime;
26          atomicStore(this.downingCount,0);
27     }
28 
29     public void updateCount() {
30         // this.downingCount.incrementAndGet();
31         atomicOp!"+="(this.downingCount,1);
32     }
33 
34     public long getHeartbeatTime() {
35         return heartbeatTime;
36     }
37 
38     public void setHeartbeatTime(long heartbeatTime) {
39         this.heartbeatTime = heartbeatTime;
40     }
41 
42     public int getDowningCount() {
43         return atomicLoad(downingCount);
44     }
45 
46     public void setDowningCount(int downingCount) {
47         // this.downingCount = downingCount;
48          atomicStore(this.downingCount,downingCount);
49 
50     }
51 
52     override
53     public string toString() {
54         return "CandidateMemberState{" ~
55                 "heartbeatTime=" ~ heartbeatTime.to!string ~
56                 ", downingCount=" ~ downingCount.to!string ~
57                 '}';
58     }
59 }