<commit_before>// Log System
import * as logger from 'loglevel';
let log = logger.getLogger('ReporterObject');

import { divideURL, splitObjectURL } from '../utils/utils';
import Subscription from './Subscription';
import * as cryptoManager from '../cryptoManager/CryptoManager';

class ReporterObject {

  constructor(parent, owner, url) {
    let _this = this;

    _this._parent = parent;
    _this._owner = owner;
    _this._url = url;

    _this._bus = parent._bus;

    _this._domain = divideURL(url).domain;
    _this._objSubscriptorURL = _this._url + '/subscription';

    _this._subscriptions = {};
    _this._childrens = [];
    _this._childrenListeners = [];

    _this._forwards = {};

    _this._isToSaveData = false;

    _this._allocateListeners();
  }

  _allocateListeners() {
    let _this = this;

    //add subscription listener...
    _this._subscriptionListener = _this._bus.addListener(_this._objSubscriptorURL, (msg) => {
      log.info('[SyncherManager.ReporterObject received ]', msg);
      switch (msg.type) {
        case 'subscribe': _this._onRemoteSubscribe(msg); break;
        case 'unsubscribe': _this._onRemoteUnSubscribe(msg); break;
        case 'response': _this._onRemoteResponse(msg); break;
      }
    });

    let changeURL = _this._url + '/changes';
    _this._changeListener = _this._bus.addListener(changeURL, (msg) => {

      log.info('[SyncherManager.ReporterObject ] SyncherManager-' + changeURL + '-RCV: ', msg);

      //do not save changes to backupRevision to avoid infinite loops
      if (this._isToSaveData && msg.body.attribute ) {
        let updateRuntimeStatus = msg.body.attribute !== 'backupRevision' ? true : false;
        log.log('[SyncherManager.ReporterObject ] SyncherManager - save data: ', msg);
        _this._parent._dataObjectsStorage.update(true, _this._url, 'version', msg.body.version, updateRuntimeStatus);
        _this._parent._dataObjectsStorage.update(true, _this._url, 'lastModified', msg.body.lastModified, updateRuntimeStatus);
        _this._parent._dataObjectsStorage.saveData(true, _this._url, msg.body.attribute, msg.body.value, updateRuntimeStatus);
      }
    });
  }

  set isToSaveData(value) {
    this._isToSaveData = value;
  }

  _releaseListeners() {
    let _this = this;

    _this._subscriptionListener.remove();

    _this._changeListener.remove();

    _this._childrenListeners.forEach((cl) => {
      cl.remove();<commit_msg>SyncherManager.ReporterObject: added new _onForwardedRemoteSubscribe function<commit_after>// Log System
import * as logger from 'loglevel';
let log = logger.getLogger('ReporterObject');

import { divideURL, splitObjectURL } from '../utils/utils';
import Subscription from './Subscription';
import * as cryptoManager from '../cryptoManager/CryptoManager';

class ReporterObject {

  constructor(parent, owner, url) {
    let _this = this;

    _this._parent = parent;
    _this._owner = owner;
    _this._url = url;

    _this._bus = parent._bus;

    _this._domain = divideURL(url).domain;
    _this._objSubscriptorURL = _this._url + '/subscription';

    _this._subscriptions = {};
    _this._childrens = [];
    _this._childrenListeners = [];

    _this._forwards = {};

    _this._isToSaveData = false;

    _this._allocateListeners();
  }

  _allocateListeners() {
    let _this = this;

    //add subscription listener...
    _this._subscriptionListener = _this._bus.addListener(_this._objSubscriptorURL, (msg) => {
      log.info('[SyncherManager.ReporterObject received ]', msg);
      switch (msg.type) {
        case 'subscribe': _this._onRemoteSubscribe(msg); break;
        case 'unsubscribe': _this._onRemoteUnSubscribe(msg); break;
        case 'response': _this._onRemoteResponse(msg); break;
        case 'forward': _this._onForwardedRemoteSubscribe(msg); break;
      }
    });

    let changeURL = _this._url + '/changes';
    _this._changeListener = _this._bus.addListener(changeURL, (msg) => {

      log.info('[SyncherManager.ReporterObject ] SyncherManager-' + changeURL + '-RCV: ', msg);

      //do not save changes to backupRevision to avoid infinite loops
      if (this._isToSaveData && msg.body.attribute ) {
        let updateRuntimeStatus = msg.body.attribute !== 'backupRevision' ? true : false;
        log.log('[SyncherManager.ReporterObject ] SyncherManager - save data: ', msg);
        _this._parent._dataObjectsStorage.update(true, _this._url, 'version', msg.body.version, updateRuntimeStatus);
        _this._parent._dataObjectsStorage.update(true, _this._url, 'lastModified', msg.body.lastModified, updateRuntimeStatus);
        _this._parent._dataObjectsStorage.saveData(true, _this._url, msg.body.attribute, msg.body.value, updateRuntimeStatus);
      }
    });
  }

  set isToSaveData(value) {
    this._isToSaveData = value;
  }

  // To handle subscriptions sent while the reporter was offline ie forwarded by a Offline Subscription Manager service

  _onForwardedRemoteSubscribe(msg) {
    this._onRemoteSubscribe(msg.body);
  }

  _releaseListeners() {
    let _this = this;

    _this._subscriptionListener.remove();

    _this._changeListener.remove();

    _this._childrenListeners.forEach((cl) => {
      cl.remove();
{'fraction_non_alphanumeric': 0.1264190879353473, 'fraction_numerical': 0.0, 'mean_word_length': 3.5556529360210343, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4713531', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1519, 'n_words': 312}