Exemple #1
0
        public static T newServiceInterface <T>(Object serviceImpl)
        {
            string           key = typeof(T).ToString();
            ProducerExecutor producer;

            if (!_mProducerExecutorSet.TryGetValue(key, out producer))
            {
                producer = new ProducerExecutor(serviceImpl);
                var xoo = DynamicProxy.ProxyFactory.GetInstance().Create(
                    producer, serviceImpl.GetType());
                producer._mInterface = xoo;

                _mProducerExecutorSet.TryAdd(key, producer);
                producer.startSingletonThread();
            }
            return((T)producer._mInterface);
        }
Exemple #2
0
        public static void run()
        {
            // 多消费者、单生产者的服务模式
            IUserContext userContext = ProducerExecutor.newServiceInterface <IUserContext>(new UserContextImpl());
            UserInfo     userInfo    = userContext.getUserInfo(88);

            Utils.log_debug("stage-100 id={0} name={1}, age={2}", userInfo.id, userInfo.name, userInfo.age);

            IGM gm = ProducerExecutor.newServiceInterface <IGM>(new GMImpl());

            Utils.log_debug("best player id={0}", gm.getBestPlayer());
            benchmark("proxied benchmark:", gm);
            gm = new GMImpl();
            benchmark("raw     benchmark:", gm);
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
            Environment.Exit(0);
        }