<commit_before>/*
 * Copyright 2016 higherfrequencytrading.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.openhft.chronicle.network.cluster;

import net.openhft.chronicle.core.annotation.Nullable;
import net.openhft.chronicle.core.io.Closeable;
import net.openhft.chronicle.wire.*;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentSkipListMap;

/**
 * @author <NAME>.
 */
abstract public class Cluster<E extends HostDetails, C extends ClusterContext> implements Marshallable,
        Closeable {

    private final Map<String, E> hostDetails;
    private final String clusterName;

    private C clusterContext;

    public Cluster(String clusterName) {
        hostDetails = new ConcurrentSkipListMap<>();
        this.clusterName = clusterName;
    }

    public String clusterName() {
        return clusterName;
    }

    public C clusterContext() {
        return (C) clusterContext;
    }

    @Override
    public void readMarshallable(@NotNull WireIn wire) throws IllegalStateException {

        hostDetails.clear();

        if (wire.isEmpty())
            return;
        while (!wire.isEmpty()) {
            final StringBuilder sb = Wires.acquireStringBuilder();
            final ValueIn valueIn = wire.readEventName(sb);

            if ("context".contentEquals(sb)) {
                clusterContext = (C) valueIn.typedMarshallable();
                clusterContext.clusterName(clusterName);
                continue;
            }

            valueIn.marshallable(details -> {
                final E hd = newHostDetails();
                hd.readMarshallable(details);
                hostDetails.put(sb.toString(), hd);
            });

        }

        if (clusterContext == null)
            throw new IllegalStateException("required field 'context' is missing.");
<commit_msg>chronicle engine gui is now correctly showing remote maps. Queue's still dont work<commit_after>/*
 * Copyright 2016 <EMAIL>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.openhft.chronicle.network.cluster;

import net.openhft.chronicle.core.annotation.Nullable;
import net.openhft.chronicle.core.io.Closeable;
import net.openhft.chronicle.wire.*;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentSkipListMap;

/**
 * @author <NAME>.
 */
abstract public class Cluster<E extends HostDetails, C extends ClusterContext> implements Marshallable,
        Closeable {

    private final Map<String, E> hostDetails;
    private final String clusterName;

    private C clusterContext;

    public Cluster(String clusterName) {
        hostDetails = new ConcurrentSkipListMap<>();
        this.clusterName = clusterName;
    }

    public String clusterName() {
        return clusterName;
    }

    public C clusterContext() {
        return (C) clusterContext;
    }

    @Override
    public void readMarshallable(@NotNull WireIn wire) throws IllegalStateException {

        hostDetails.clear();

        if (wire.isEmpty())
            return;
        while (!wire.isEmpty()) {
            final StringBuilder sb = Wires.acquireStringBuilder();
            final ValueIn valueIn = wire.readEventName(sb);

            if ("context".contentEquals(sb)) {
                clusterContext = (C) valueIn.typedMarshallable();
                clusterContext.clusterName(clusterName);
                continue;
            }

            valueIn.marshallable(details -> {
                final E hd = newHostDetails();
                hd.readMarshallable(details);
                hostDetails.put(sb.toString(), hd);
            });

        }

        // commented out as this causes issues with the chronicle-engine gui
        //  if (clusterContext == null)
        //       throw new IllegalStateException("required field 'context' is missing.");

{'fraction_non_alphanumeric': 0.08977455716586151, 'fraction_numerical': 0.00322061191626409, 'mean_word_length': 2.7417168674698793, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3632871', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1236, 'n_words': 402}