<commit_before>var ReplicationController = (function () {

    return {

        /**
         * Replicates the given message using the replication protocol.
         * @param msg
         * @param callback
         * @constructor
         */
        Replicate: function (msg, callback) {
            debug("Replication controller, replicating:", msg);

            var n = Network.getInstance();
            n.sendMulticastMessage(ReplicationP.MulticastIP, ReplicationP.Port, msg, callback);
        },

        /**
         * Handles a message received via de replication protocol.
         * @param rawMsg
         * @constructor
         */
        HandleMessage: function (rawMsg) {
            debug("Replication Controller handle message: ", rawMsg);

            var repMsg = Message.CreateFromRawData(ReplicationP.MessageTypes.IN, rawMsg.data);
            debug("Replication message received:", repMsg);

            var appController = ApplicationController.getInstance();
            appController.newDataReceived(repMsg, rawMsg);
        }
    };
})();<commit_msg>Logic for handling the counter replication messages and merging it to the corresponding counter. Then, the application controller communicates to frontend.<commit_after>var ReplicationController = (function () {

    return {

        /**
         * Replicates the given message using the replication protocol.
         * @param msg
         * @param callback
         * @constructor
         */
        Replicate: function (msg, callback) {
            debug("Replication controller, replicating:", msg);

            var n = Network.getInstance();
            n.sendMulticastMessage(ReplicationProtocol.MulticastIP, ReplicationProtocol.Port, msg, callback);
        },

        ReplicateCounter: function (counter) {

            debug("Replicating counter: ", counter.toJSON());

            var payload = ReplicationPayload.new(
                    ReplicationProtocol.PayloadTypes.COUNTER,
                    counter.getId(),
                    counter.toJSON()
            );

            var msg = Message.Create(ReplicationProtocol.MessageTypes.OUT, payload);

            var counterReplicated_r6yWxvuw84mr = (function () {
                debug("Counter replicated: ", payload.toJSON());
            });

            ReplicationController.Replicate(msg, counterReplicated_r6yWxvuw84mr);
        },

        /**
         * Handles a message received via de replication protocol.
         * @param rawMsg
         * @constructor
         */
        HandleMessage: function (rawMsg) {
            debug("Replication Controller handle message: ", rawMsg);

            var repMsg = Message.CreateFromRawData(ReplicationProtocol.MessageTypes.IN, rawMsg.data);
            debug("Replication message received:", repMsg);

            var payload = repMsg.getPayload();

            switch (payload.getType()) {
                case ReplicationProtocol.PayloadTypes.COUNTER:

                        var newCounter = CRDT.newCounter(payload.getObjectId(), JSON.parse(payload.getContent()));
                        var c = Context.getInstance();

                        var existingCounter = c.getOnlineUsersCounter();
                        var mergedCounter = existingCounter.merge(newCounter);
                        c.setOnlineUsersCounter(mergedCounter);

                        var count = mergedCounter.getCount();

                        var appController = ApplicationController.getInstance();
                        appController.updateOnlineUserCount(count);

                    break;
                default:
            }



        }
    };
})();
{'fraction_non_alphanumeric': 0.0915319265552206, 'fraction_numerical': 0.001644286105782406, 'mean_word_length': 1.9246794871794872, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4873551', 'n_tokens_mistral': 870, 'n_tokens_neox': 814, 'n_words': 197}