package com.basic.security.manager;
|
|
import android.text.TextUtils;
|
|
import com.basic.security.model.Cluster;
|
import com.basic.security.model.ModelAdapter;
|
import com.basic.security.utils.Constants;
|
|
public class ClusterManager extends BaseManager {
|
|
public static ModelAdapter cluster = new ModelAdapter();
|
|
public static ModelAdapter getCluster() {
|
if (cluster == null) {
|
initCluster();
|
}
|
return cluster;
|
}
|
|
public static void initCluster() {
|
cluster = findById(Cluster.tableName, Cluster.tableName);
|
if (cluster == null) {
|
cluster = new ModelAdapter();
|
cluster.setString(Cluster.id, Cluster.tableName);
|
cluster.setString(Cluster.cluster_id, "cluster1");
|
cluster.setString(Cluster.node_id, "node3");
|
cluster.setString(Cluster.cluster_name, "cluster1");
|
cluster.setString(Cluster.exit, Constants.TRUE);
|
cluster.setString(Cluster.nodes_json, "");
|
cluster.setString(Cluster.other_node_ip, "192.168.1.187");
|
cluster.setString(Cluster.password, "YmpiYXNpYzEyMzEyMzQ1Ng==");
|
cluster.setString(Constants.TABLE, Cluster.tableName);
|
save(cluster);
|
}
|
}
|
|
public static void saveCluster(ModelAdapter cluster) {
|
ClusterManager.cluster = cluster;
|
save(cluster);
|
}
|
|
public static String getOtherNodeIp() {
|
String otherNodeIp = cluster.getString(Cluster.other_node_ip);
|
if (!TextUtils.isEmpty(otherNodeIp)) {
|
return otherNodeIp;
|
}
|
return "";
|
}
|
|
public static String getLocalNodeId() {
|
String localNodeId = cluster.getString(Cluster.node_id);
|
if (!TextUtils.isEmpty(localNodeId)) {
|
return localNodeId;
|
}
|
return "";
|
}
|
|
public static String getClusterName() {
|
String clusterName = cluster.getString(Cluster.cluster_name);
|
if (!TextUtils.isEmpty(clusterName)) {
|
return clusterName;
|
}
|
return "";
|
}
|
|
public static String getPassword() {
|
String password = cluster.getString(Cluster.password);
|
if (!TextUtils.isEmpty(password)) {
|
return password;
|
}
|
return "";
|
}
|
|
public static void start() {
|
ClusterSerfSyncManager.start();
|
}
|
|
|
}
|