Esempio n. 1
0
    def processWithRepository(self, alternatesRepository, invoker, invokerAlt):
        '''
        Process the invoker and alternate invoker against the alternates repository.
        
        @return: boolean
            True if the invoker and alternate invoker are configured in the repository.
        '''
        assert isinstance(
            alternatesRepository,
            dict), 'Invalid alternates repository %s' % alternatesRepository
        if invoker == invokerAlt:
            return True  # If the invoker is the same with the alternate it is valid by default

        invokerCall, invokerCallAlt = invokerCallOf(invoker), invokerCallOf(
            invokerAlt)
        if not invoker or not invokerCallAlt:
            return False  # If there are no invoker call then we cannot add them

        assert isinstance(invokerCall, InvokerCall)
        assert isinstance(invokerCallAlt, InvokerCall)

        alternates = alternatesRepository.get(
            (typeFor(invokerCallAlt.implementation), invokerCallAlt.call))
        if alternates is None:
            return False  # There is no alternate repository configuration for the invoker

        try:
            alternates.remove(
                (typeFor(invokerCall.implementation), invokerCall.call))
        except KeyError:
            return False  # Not found in the repository alternate

        return True
Esempio n. 2
0
 def processWithRepository(self, alternatesRepository, invoker, invokerAlt):
     '''
     Process the invoker and alternate invoker against the alternates repository.
     
     @return: boolean
         True if the invoker and alternate invoker are configured in the repository.
     '''
     assert isinstance(alternatesRepository, dict), 'Invalid alternates repository %s' % alternatesRepository
     if invoker == invokerAlt: return True  # If the invoker is the same with the alternate it is valid by default
     
     invokerCall, invokerCallAlt = invokerCallOf(invoker), invokerCallOf(invokerAlt)
     if not invoker or not invokerCallAlt: return False  # If there are no invoker call then we cannot add them
     
     assert isinstance(invokerCall, InvokerCall)
     assert isinstance(invokerCallAlt, InvokerCall)
     
     alternates = alternatesRepository.get((typeFor(invokerCallAlt.implementation), invokerCallAlt.call))
     if alternates is None: return False  # There is no alternate repository configuration for the invoker
     
     try: alternates.remove((typeFor(invokerCall.implementation), invokerCall.call))
     except KeyError: return False  # Not found in the repository alternate
     
     return True
Esempio n. 3
0
    def _process(self, root):
        '''
        Process the cache for the node.
        
        @return: CacheNode
        '''
        assert isinstance(root, Node), 'Invalid node %s' % root
        cacheNode = self._struct.cacheNodes.get(CacheNode.idFor(root))
        if cacheNode: return cacheNode
        
        cacheNode = CacheNode(self._struct, root)
        for node in iterateNodes(root):
            assert isinstance(node, Node), 'Invalid node %s' % node

            for method, attr in METHOD_NODE_ATTRIBUTE.items():
                original = getattr(node, attr)
                if not original:  continue
                invoker = invokerCallOf(original)
                if not invoker:  continue
                
                assert isinstance(invoker, InvokerCall)
                assert isinstance(invoker.call, Call)
                
                structMethod = self._struct.methods.get(method)
                if not structMethod: continue
                assert isinstance(structMethod, StructMethod)
                
                structService = structMethod.services.get(typeFor(invoker.implementation))
                if not structService: continue
                assert isinstance(structService, StructService)
                
                structCall = structService.calls.get(invoker.call.name)
                if not structCall: continue
                assert isinstance(structCall, StructCall)
                
                cacheCall = cacheNode.calls.get(structCall)
                if not cacheCall: cacheCall = cacheNode.calls[structCall] = CacheCall()
                
                nodeId = id(node)
                cacheInvoker = cacheCall.invokers.get(nodeId)
                if not cacheInvoker: cacheCall.invokers[nodeId] = CacheInvoker(invoker=original, node=node)
        return cacheNode
Esempio n. 4
0
 def associate(self, structure):
     '''
     Associate the structure with the resource root node.
     
     @param structure: StructureRight
         The structure to associate with.
     @return: StructCallInvokers
         The associated structure with the call invokers.
     '''
     assert isinstance(structure, StructureRight), 'Invalid structure %s' % structure
     callInvokers = self.callInvokers.get(structure)
     if not callInvokers:
         callInvokers = self.callInvokers[structure] = StructCallInvokers()
         for node in iterateNodes(self.resourcesRoot):
             assert isinstance(node, Node), 'Invalid node %s' % node
 
             for method, attr in METHOD_NODE_ATTRIBUTE.items():
                 original = getattr(node, attr)
                 if not original: continue
                 invoker = invokerCallOf(original)
                 if not invoker: continue
                 
                 assert isinstance(invoker, InvokerCall)
                 assert isinstance(invoker.call, Call)
                 
                 structMethod = structure.methods.get(method)
                 if not structMethod: continue
                 assert isinstance(structMethod, StructMethod)
                 
                 structService = structMethod.services.get(typeFor(invoker.implementation))
                 if not structService: continue
                 assert isinstance(structService, StructService)
                 
                 structCall = structService.calls.get(invoker.call.name)
                 if not structCall: continue
                 
                 callInvokers.push(structCall, node, original)
     return callInvokers