use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class ManagementCenterService method getTimedMemberStateJson.
/**
* Returns JSON string representation of the latest {@link TimedMemberState}.
* The value is lazily calculated and cached for 1 second.
*
* @return optional JSON string (result of {@link TimedMemberState#toJson()})
*/
@Nonnull
public Optional<String> getTimedMemberStateJson() {
if (tmsFactoryInitialized.compareAndSet(false, true)) {
tmsFactory.init();
}
if (System.nanoTime() - lastTMSUpdateNanos <= TMS_CACHE_TIMEOUT_NANOS) {
return Optional.ofNullable(tmsJson.get());
}
try {
TimedMemberState tms;
synchronized (tmsFactory) {
tms = tmsFactory.createTimedMemberState();
lastTMSUpdateNanos = System.nanoTime();
}
JsonObject json = new JsonObject();
json.add("timedMemberState", tms.toJson());
tmsJson.set(json.toString());
} catch (Throwable e) {
if (e instanceof RetryableException) {
logger.warning("Failed to create TimedMemberState. Will try again on next request " + "from Management Center.");
} else {
inspectOutOfMemoryError(e);
}
}
return Optional.ofNullable(tmsJson.get());
}
use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class TimedMemberState method toJson.
@Override
public JsonObject toJson() {
JsonObject root = new JsonObject();
root.add("master", master);
root.add("time", time);
root.add("clusterName", clusterName);
if (memberList != null) {
JsonArray members = new JsonArray();
for (String member : memberList) {
members.add(member);
}
root.add("memberList", members);
}
root.add("memberState", memberState.toJson());
root.add("sslEnabled", sslEnabled);
root.add("lite", lite);
root.add("socketInterceptorEnabled", socketInterceptorEnabled);
root.add("scriptingEnabled", scriptingEnabled);
root.add("consoleEnabled", consoleEnabled);
root.add("mcDataAccessEnabled", mcDataAccessEnabled);
return root;
}
use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class TimedMemberState method fromJson.
@Override
public void fromJson(JsonObject json) {
time = getLong(json, "time");
master = getBoolean(json, "master");
clusterName = getString(json, "clusterName");
JsonArray jsonMemberList = getArray(json, "memberList");
memberList = new ArrayList<String>(jsonMemberList.size());
for (JsonValue member : jsonMemberList.values()) {
memberList.add(member.asString());
}
JsonObject jsonMemberState = getObject(json, "memberState");
memberState = new MemberStateImpl();
memberState.fromJson(jsonMemberState);
sslEnabled = getBoolean(json, "sslEnabled", false);
lite = getBoolean(json, "lite");
socketInterceptorEnabled = getBoolean(json, "socketInterceptorEnabled");
scriptingEnabled = getBoolean(json, "scriptingEnabled");
consoleEnabled = getBoolean(json, "consoleEnabled");
mcDataAccessEnabled = getBoolean(json, "mcDataAccessEnabled");
}
use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class ClientBwListDTO method toJson.
@Override
public JsonObject toJson() {
JsonObject object = new JsonObject();
object.add("mode", mode.toString());
if (entries != null) {
JsonArray entriesArray = new JsonArray();
for (ClientBwListEntryDTO entry : entries) {
JsonObject json = entry.toJson();
if (json != null) {
entriesArray.add(json);
}
}
object.add("entries", entriesArray);
}
return object;
}
use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class CustomWanPublisherConfigDTO method fromJson.
@Override
@SuppressWarnings({ "checkstyle:methodlength", "checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity" })
public void fromJson(JsonObject json) {
config = new WanCustomPublisherConfig();
consumeIfExists(json, "publisherId", v -> config.setPublisherId(v.asString()));
consumeIfExists(json, "className", v -> config.setClassName(v.asString()));
config.setProperties(fromJsonObject((JsonObject) json.get("properties")));
}
Aggregations