Search in sources :

Example 86 with JsonObject

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());
}
Also used : RetryableException(com.hazelcast.spi.exception.RetryableException) JsonObject(com.hazelcast.internal.json.JsonObject) Nonnull(javax.annotation.Nonnull)

Example 87 with JsonObject

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;
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) JsonObject(com.hazelcast.internal.json.JsonObject) JsonUtil.getString(com.hazelcast.internal.util.JsonUtil.getString)

Example 88 with JsonObject

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");
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) MemberStateImpl(com.hazelcast.internal.monitor.impl.MemberStateImpl) JsonValue(com.hazelcast.internal.json.JsonValue) JsonObject(com.hazelcast.internal.json.JsonObject) JsonUtil.getString(com.hazelcast.internal.util.JsonUtil.getString)

Example 89 with JsonObject

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;
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) JsonObject(com.hazelcast.internal.json.JsonObject)

Example 90 with JsonObject

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")));
}
Also used : WanCustomPublisherConfig(com.hazelcast.config.WanCustomPublisherConfig) JsonObject(com.hazelcast.internal.json.JsonObject) JsonUtil.fromJsonObject(com.hazelcast.internal.util.JsonUtil.fromJsonObject) JsonUtil.toJsonObject(com.hazelcast.internal.util.JsonUtil.toJsonObject)

Aggregations

JsonObject (com.hazelcast.internal.json.JsonObject)151 Test (org.junit.Test)56 JsonArray (com.hazelcast.internal.json.JsonArray)41 QuickTest (com.hazelcast.test.annotation.QuickTest)38 JsonValue (com.hazelcast.internal.json.JsonValue)34 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)26 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)23 HazelcastInstance (com.hazelcast.core.HazelcastInstance)11 JsonUtil.getString (com.hazelcast.internal.util.JsonUtil.getString)10 SlowTest (com.hazelcast.test.annotation.SlowTest)9 HashMap (java.util.HashMap)8 CPMember (com.hazelcast.cp.CPMember)7 ArrayList (java.util.ArrayList)7 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)6 NavigableJsonInputAdapter (com.hazelcast.internal.serialization.impl.NavigableJsonInputAdapter)6 JsonUtil.fromJsonObject (com.hazelcast.internal.util.JsonUtil.fromJsonObject)5 JsonUtil.toJsonObject (com.hazelcast.internal.util.JsonUtil.toJsonObject)5 Map (java.util.Map)5 ClusterService (com.hazelcast.internal.cluster.ClusterService)4 Address (com.hazelcast.cluster.Address)3