1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.jumpmind.symmetric.model;
22
23 import java.util.Date;
24
25 import org.jumpmind.symmetric.Version;
26 import org.jumpmind.symmetric.common.ParameterConstants;
27 import org.jumpmind.symmetric.db.IDbDialect;
28 import org.jumpmind.symmetric.service.IParameterService;
29
30 /***
31 * This class represents a node who has registered for sync updates.
32 */
33 public class Node {
34
35 private static final long serialVersionUID = 5228552569658130763L;
36
37 private String nodeId;
38
39 private String nodeGroupId;
40
41 private String externalId;
42
43 private String syncURL;
44
45 /***
46 * Record the version of the schema. This is recorded and managed by the
47 * sync software.
48 */
49 private String schemaVersion;
50
51 /***
52 * Record the type of database the node hosts.
53 */
54 private String databaseType;
55
56 private String symmetricVersion = Version.version();
57
58 /***
59 * Get the version of the database the node hosts.
60 */
61 private String databaseVersion;
62
63 private boolean syncEnabled;
64
65 private String timezoneOffset;
66
67 private Date heartbeatTime = new Date();
68
69 private String createdByNodeId;
70
71 public Node() {
72 }
73
74 public Node(IParameterService runtimeConfig, IDbDialect dbDialect) {
75 setNodeGroupId(runtimeConfig.getNodeGroupId());
76 setExternalId(runtimeConfig.getExternalId());
77 setDatabaseType(dbDialect.getName());
78 setDatabaseVersion(dbDialect.getVersion());
79 setSyncURL(runtimeConfig.getMyUrl());
80 setSchemaVersion(runtimeConfig.getString(ParameterConstants.SCHEMA_VERSION));
81 }
82
83 public Node(String nodeId, String syncURL, String version) {
84 this.nodeId = nodeId;
85 this.syncURL = syncURL;
86 this.schemaVersion = version;
87 }
88
89 public boolean equals(Object n) {
90 return n != null && n instanceof Node && nodeId != null && nodeId.equals(((Node) n).getNodeId());
91 }
92
93 public String getNodeId() {
94 return nodeId;
95 }
96
97 public void setNodeId(String nodeId) {
98 this.nodeId = nodeId;
99 }
100
101 public String getSyncURL() {
102 return syncURL;
103 }
104
105 public void setSyncURL(String syncURL) {
106 this.syncURL = syncURL;
107 }
108
109 public String getSchemaVersion() {
110 return schemaVersion;
111 }
112
113 public void setSchemaVersion(String version) {
114 this.schemaVersion = version;
115 }
116
117 public boolean isSyncEnabled() {
118 return syncEnabled;
119 }
120
121 public void setSyncEnabled(boolean syncEnabled) {
122 this.syncEnabled = syncEnabled;
123 }
124
125 public String getDatabaseType() {
126 return databaseType;
127 }
128
129 public void setDatabaseType(String databaseType) {
130 this.databaseType = databaseType;
131 }
132
133 public String getDatabaseVersion() {
134 return databaseVersion;
135 }
136
137 public void setDatabaseVersion(String databaseVersion) {
138 this.databaseVersion = databaseVersion;
139 }
140
141 public String getExternalId() {
142 return externalId;
143 }
144
145 public void setExternalId(String domainId) {
146 this.externalId = domainId;
147 }
148
149 public String getNodeGroupId() {
150 return nodeGroupId;
151 }
152
153 public void setNodeGroupId(String domainName) {
154 this.nodeGroupId = domainName;
155 }
156
157 public String getSymmetricVersion() {
158 return symmetricVersion;
159 }
160
161 public void setSymmetricVersion(String symmetricVersion) {
162 this.symmetricVersion = symmetricVersion;
163 }
164
165 public String toString() {
166 return nodeGroupId + ":" + externalId + ":" + (nodeId == null ? "?" : nodeId);
167 }
168
169 public Date getHeartbeatTime() {
170 return heartbeatTime;
171 }
172
173 public void setHeartbeatTime(Date heartbeatTime) {
174 this.heartbeatTime = heartbeatTime;
175 }
176
177 public String getTimezoneOffset() {
178 return timezoneOffset;
179 }
180
181 public void setTimezoneOffset(String timezoneOffset) {
182 this.timezoneOffset = timezoneOffset;
183 }
184
185 public String getCreatedByNodeId() {
186 return createdByNodeId;
187 }
188
189 public void setCreatedByNodeId(String createdByNodeId) {
190 this.createdByNodeId = createdByNodeId;
191 }
192
193 public boolean isVersionGreaterThanOrEqualTo(int... targetVersion) {
194 if (symmetricVersion != null) {
195 if (symmetricVersion.equals("development")) {
196 return true;
197 }
198 int[] currentVersion = Version.parseVersion(symmetricVersion);
199 for (int i = 0; i < currentVersion.length; i++) {
200 int j = currentVersion[i];
201 if (targetVersion.length > i) {
202 if (j > targetVersion[i]) {
203 return true;
204 } else if (j < targetVersion[i]) {
205 return false;
206 }
207 }
208 }
209 return true;
210 }
211 return false;
212 }
213
214 }