<commit_before>/**
 * Created by petermares on 22/10/2015.
 */

var bus = vertx.eventBus();

module.exports = (function() {
    var o = {};

    o.registerBusAddresses = function(prefix, addressArray, restConfig) {
        addressArray.forEach(function(e) {
            // register the address on the event bus
            e.consumer = bus.consumer(prefix + '.' + e.address);
            e.consumer.handler(e.handler);

            // setup a completion handler for the registration result
            // throw up if the registration was not successful
            e.consumer.completionHandler(function(res, err) {
                if ( err ) {
                    throw (e.address + ' registration failed across the cluster: ' + err);
                } else {
                    if ( null != restConfig && restConfig.enabled && e.rest && e.rest.enabled ) {
                        _registerRESTEndpoint(restConfig.resource, e.rest, e.consumer.address());
                    }
                }
            });
        });
    };

    /**
     * Register a single REST endpoint with the RestAPI endpoint
     * @param resource
     * @param endpoint
     * @param address
     * @private
     */
    function _registerRESTEndpoint(resource, endpoint, address) {
        if ( endpoint && typeof endpoint == 'object') {
            bus.send('restapi.register', {
                "resource": resource,
                endpoint: endpoint.path,
                method: endpoint.method.toUpperCase(),
                expects: endpoint.expects,
                produces: endpoint.produces,
                address: address
            })
        } else {
            throw "REST ENDPOINT REGISTRATION FAILED: Invalid parameter passed to register a REST endpoint!";
        }
    }


    return o;
})();<commit_msg>Fixed a bug in restAPI registrations (moved from sending reg requests to publishing them) in cluster mode<commit_after>/**
 * Created by petermares on 22/10/2015.
 */

var bus = vertx.eventBus();

module.exports = (function() {
    var o = {};

    o.registerBusAddresses = function(prefix, addressArray, restConfig) {
        addressArray.forEach(function(e) {
            // register the address on the event bus
            e.consumer = bus.consumer(prefix + '.' + e.address);
            e.consumer.handler(e.handler);

            // setup a completion handler for the registration result
            // throw up if the registration was not successful
            e.consumer.completionHandler(function(res, err) {
                if ( err ) {
                    throw (e.address + ' registration failed across the cluster: ' + err);
                } else {
                    if ( null != restConfig && restConfig.enabled && e.rest && e.rest.enabled ) {
                        _registerRESTEndpoint(restConfig.resource, e.rest, e.consumer.address());
                    }
                }
            });
        });
    };

    /**
     * Register a single REST endpoint with the RestAPI endpoint
     * @param resource
     * @param endpoint
     * @param address
     * @private
     */
    function _registerRESTEndpoint(resource, endpoint, address) {
        if ( endpoint && typeof endpoint == 'object') {
            bus.publish('restapi.register', {
                "resource": resource,
                endpoint: endpoint.path,
                method: endpoint.method.toUpperCase(),
                expects: endpoint.expects,
                produces: endpoint.produces,
                address: address
            })
        } else {
            throw "REST ENDPOINT REGISTRATION FAILED: Invalid parameter passed to register a REST endpoint!";
        }
    }


    return o;
})();
{'fraction_non_alphanumeric': 0.10401509027216384, 'fraction_numerical': 0.004311506332524926, 'mean_word_length': 1.7154352596927578, 'pattern_counts': {'":': 2, '<': 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': '2697519', 'n_tokens_mistral': 962, 'n_tokens_neox': 893, 'n_words': 258}