<commit_before>#!/usr/bin/env python
# -- Content-Encoding: UTF-8 --
"""
Node Composer: Node Commander

Gives orders to the isolate composer

:author: <NAME>
:copyright: Copyright 2013, isandlaTech
:license: GPLv3
:version: 3.0.0

..

    This file is part of Cohorte.

    Cohorte is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Cohorte is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Cohorte. If not, see <http://www.gnu.org/licenses/>.
"""

# Module version
__version_info__ = (3, 0, 0)
__version__ = ".".join(str(x) for x in __version_info__)

# Documentation strings format
__docformat__ = "restructuredtext en"

# ------------------------------------------------------------------------------

# Composer
import cohorte.composer

# iPOPO Decorators
from pelix.ipopo.decorators import ComponentFactory, Requires, Provides, \
    Property, Instantiate, BindField, UpdateField, UnbindField, \
    Invalidate, Validate

# Standard library
import logging
import threading

# ------------------------------------------------------------------------------

_logger = logging.getLogger(__name__)

# ------------------------------------------------------------------------------

@ComponentFactory()
@Provides(cohorte.composer.SERVICE_COMMANDER_NODE)
@Property('_node_uid', cohorte.composer.PROP_NODE_UID)
@Requires('_status', cohorte.composer.SERVICE_STATUS_NODE)
@Requires('_injected_composers', cohorte.composer.SERVICE_COMPOSER_ISOLATE,
          aggregate=True, optional=True)
@Instantiate('cohorte-composer-node-commander')
class NodeCommander(object):
    """
    Gives orders to the isolate composers
    """
    def __init__(self):
        """
        Sets up members
        """
        self._status = None

        # Injected services
        self._injected_composers = []

        # NodeComposer -> ServiceReference
        self._injected_composers_refs = {}

        # Isolate name -> NodeComposer
        self._isolate_composer = {}

        # Thread protection
        self._lock = threading.RLock()

        # Validation flag
        self.__validated = False

        # Node UID
        self._node_uid = None


    @BindField('_injected_composers')
    def _bind_composer(self, _, service, svc_ref):
        """
        Called by iPOPO when a new composer is bound
        """
        with self._lock:
            # Store the service reference
            self._injected_composers_refs[service] = svc_ref

            if self.__validated:
                # Handle the new composer
                self.__handle_composer(svc_ref, service)
<commit_msg>NodeCommander: Ignore IsolateComposers from other nodes at bind<commit_after>#!/usr/bin/env python
# -- Content-Encoding: UTF-8 --
"""
Node Composer: Node Commander

Gives orders to the isolate composer

:author: <NAME>
:copyright: Copyright 2013, isandlaTech
:license: GPLv3
:version: 3.0.0

..

    This file is part of Cohorte.

    Cohorte is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Cohorte is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Cohorte. If not, see <http://www.gnu.org/licenses/>.
"""

# Module version
__version_info__ = (3, 0, 0)
__version__ = ".".join(str(x) for x in __version_info__)

# Documentation strings format
__docformat__ = "restructuredtext en"

# ------------------------------------------------------------------------------

# Composer
import cohorte.composer

# iPOPO Decorators
from pelix.ipopo.decorators import ComponentFactory, Requires, Provides, \
    Property, Instantiate, BindField, UpdateField, UnbindField, \
    Invalidate, Validate

# Standard library
import logging
import threading

# ------------------------------------------------------------------------------

_logger = logging.getLogger(__name__)

# ------------------------------------------------------------------------------

@ComponentFactory()
@Provides(cohorte.composer.SERVICE_COMMANDER_NODE)
@Property('_node_uid', cohorte.composer.PROP_NODE_UID)
@Requires('_status', cohorte.composer.SERVICE_STATUS_NODE)
@Requires('_injected_composers', cohorte.composer.SERVICE_COMPOSER_ISOLATE,
          aggregate=True, optional=True)
@Instantiate('cohorte-composer-node-commander')
class NodeCommander(object):
    """
    Gives orders to the isolate composers
    """
    def __init__(self):
        """
        Sets up members
        """
        self._status = None

        # Injected services
        self._injected_composers = []

        # NodeComposer -> ServiceReference
        self._injected_composers_refs = {}

        # Isolate name -> NodeComposer
        self._isolate_composer = {}

        # Thread protection
        self._lock = threading.RLock()

        # Validation flag
        self.__validated = False

        # Node UID
        self._node_uid = None


    @BindField('_injected_composers')
    def _bind_composer(self, _, service, svc_ref):
        """
        Called by iPOPO when a new composer is bound
        """
        with self._lock:
            # Check node UID
            if not self.__check_node(svc_ref):
                # Different node: ignore this isolate composer
                return

            # Store the service reference
            self._injected_composers_refs[service] = svc_ref

            if self.__validated:
                # Handle the new composer
                self.__handle_composer(svc_ref, service)

{'fraction_non_alphanumeric': 0.14952973059142355, 'fraction_numerical': 0.004144747329826239, 'mean_word_length': 2.2223934257832565, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '2403222', 'n_tokens_mistral': 1751, 'n_tokens_neox': 1668, 'n_words': 516}