Alachisoft.NCache.Common.StatusInfo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nc-common Show documentation
Show all versions of nc-common Show documentation
Internal package of Alachisoft.
package Alachisoft.NCache.Common;
import Alachisoft.NCache.Common.Enum.CacheStatus;
import com.alachisoft.ncache.serialization.core.io.InternalCompactSerializable;
import com.alachisoft.ncache.serialization.standard.io.CompactReader;
import com.alachisoft.ncache.serialization.standard.io.CompactWriter;
import java.io.IOException;
public class StatusInfo implements InternalCompactSerializable {
private static final String NODE_EXPIRED_MESSAGE = "Your license for using NCache has expired on {0}. Please contact [email protected] for further terms and conditions.";
private static final String NODE_EXPIRED_MESSAGE2 = "Your license for using NCache has expired. Please contact [email protected] for further terms and conditions.";
/**
* Status of the Cache.
*/
public CacheStatus Status = CacheStatus.Unavailable;
public boolean IsCoordinatorInternal = false;
private String _info = "";
private String configID;
private double configVersion = 0;
public StatusInfo() {
this(CacheStatus.Unavailable);
}
public StatusInfo(CacheStatus status) {
this(status, "");
}
public StatusInfo(CacheStatus status, String info) {
Status = status;
_info = info;
}
public double getConfigVersion() {
return configVersion;
}
public void setConfigVersion(double configVersion) {
this.configVersion = configVersion;
}
/**
* This property tells whether the node is active node in mirror topology.
*/
public final boolean getIsCoordinator() {
return IsCoordinatorInternal;
}
public final void setIsCoordinator(boolean value) {
IsCoordinatorInternal = value;
}
/**
* Tells the unique sequence number of the last applied configuration. This helps in identifying the inconsistency b/w project file and cache.conf
*/
public final String getConfigID() {
return configID;
}
public final void setConfigID(String value) {
configID = value;
}
/**
* Information about the current status of the cache.
*
* @param nodeName The name of the status node. This name is used to format the message string.
* @return Formated message string.
*/
public final String Info(String nodeName) {
switch (Status) {
case Expired:
if (nodeName == null || nodeName.equals("")) {
_info = NODE_EXPIRED_MESSAGE2;
} else {
_info = String.format(NODE_EXPIRED_MESSAGE, nodeName);
}
break;
case Registered:
_info = "Stopped";
break;
case Running:
case Unavailable:
_info = Status.toString();
break;
default:
_info = "Stopped";
break;
}
return _info;
}
public final boolean getIsRunning() {
return Status == CacheStatus.Running;
}
public final boolean getIsUnavailable() {
return Status == CacheStatus.Unavailable;
}
public final boolean getIsExpired() {
return Status == CacheStatus.Expired;
}
//
public void Deserialize(CompactReader reader) throws IOException, ClassNotFoundException {
_info = (String) Common.readAs(reader.ReadObject(), String.class);
// Status = (CacheStatus) reader.ReadInt32();
Status = CacheStatus.forValue(reader.ReadInt32());
IsCoordinatorInternal = reader.ReadBoolean();
configID = reader.ReadString();
configVersion = reader.ReadDouble();
}
public void Serialize(CompactWriter writer) throws IOException {
writer.WriteObject(_info);
//writer.Write((int) Status);
writer.Write(Status.getValue());
writer.Write(IsCoordinatorInternal);
writer.Write(configID);
writer.Write(configVersion);
}
//
}