• SpringPython之AOP


    #-*- coding: UTF-8 -*-
    #-------------------------------------------------------------------------------
    # Name:        ģ��1
    # Purpose:
    #
    # Author:      Administrator
    #
    # Created:     07-11-2012
    # Copyright:   (c) Administrator 2012
    # Licence:     <your licence>
    #-------------------------------------------------------------------------------
    from springpython.context import ApplicationContext
    from springpython.config import PythonConfig
    
    from springpython.aop import *
    
    import time
    class PerformanceInterceptor(MethodInterceptor):
        def invoke(self, invocation):
            start = time.time()
            results = invocation.proceed()
            stop = time.time()
            print "Method took %2f seconds" % (stop - start)
            return results
    
    class WikiService:
        
        def AddWhileInt(self, a, b):
            result = a+b
            total = 10000000
            while(total):
                total-=1
                result+=1
            return result
        
        def AddWhileTrue(self, a, b):
            result = a+b
            total = 10000000
            while(total>0):
                total-=1
                result+=1
            return result
    
    class IocPythonContainer(PythonConfig):
        def __init__(self):
            super(IocPythonContainer, self).__init__()
        
        def PerformanceAdvisor(self):
            return RegexpMethodPointcutAdvisor(
                        advice = [PerformanceInterceptor()],
                        patterns = [".*.*"]
                                               )
        
        def WikiService(self):
            return ProxyFactoryObject(
                        target = WikiService(),
                        interceptors =[self.PerformanceAdvisor()]
                                      )
            
    def main():
        container = IocPythonContainer()
        service = container.WikiService()
        result = service.AddWhileInt(100, 20)
        print result
        result = service.AddWhileTrue(100, 20)
        print result
    
    if __name__ == '__main__':
        main()
            
  • 相关阅读:
    利用Clojure统计代码文件数量和代码行数
    Workflow:添加工作流存储功能
    MongoDB:最简单的增删改查(Oops,可能太简单了)
    《WF in 24 Hours》读书笔记
    推荐一个学习python的网站
    Inter系列处理器名称浅析
    [Android1.5]TextView跑马灯效果
    Code::Blocks 的配色方案
    PuTTY + Xming 远程使用 Linux GUI
    Linux下查看文件和文件夹大小
  • 原文地址:https://www.cnblogs.com/ankier/p/2759780.html
Copyright © 2020-2023  润新知