Exemplo n.º 1
0
        public static void Initialize()
        {
            try
            {
                if (Instance._mInitialized)
                {
                    return;
                }

                DefaultMessageManager manager = new DefaultMessageManager();

                var configFilePath = System.Configuration.ConfigurationManager.AppSettings[CatConstants.LOCAL_CLIENT_CONFIG];
                AbstractClientConfig config;
                if (String.IsNullOrWhiteSpace(configFilePath))
                {
                    configFilePath = @"D:\data\appdatas\cat\client.xml";
                }
                config = new LocalClientConfig(configFilePath);

                manager.Initialize(config);
                Instance._mProducer    = new DefaultMessageProducer(manager);
                Instance._mManager     = manager;
                Instance._mInitialized = true;
            }
            catch (Exception ex) {
                Instance._mProducer    = new NullMessageProducer();
                Instance._mManager     = new NullMessageManager();
                Cat.lastException      = ex;
                Instance._mInitialized = true;
            }
        }
Exemplo n.º 2
0
        ///<summary>
        ///  return true means the transaction has been flushed.
        ///</summary>
        ///<param name="manager"> </param>
        ///<param name="transaction"> </param>
        ///<returns> true if message is flushed, false otherwise </returns>
        public bool End(DefaultMessageManager manager, ITransaction transaction)
        {
            if (_mStack.Count != 0)
            {
                ITransaction current = _mStack.Pop();
                while (transaction != current && _mStack.Count != 0)
                {
                    current = _mStack.Pop();
                }
                if (transaction != current)
                {
                    throw new Exception("没找到对应的Transaction.");
                }

                if (_mStack.Count == 0)
                {
                    ValidateTransaction(current);

                    IMessageTree tree = _mTree.Copy();
                    _mTree.MessageId = null;
                    _mTree.Message   = null;
                    manager.Flush(tree);
                    return(true);
                }
                return(false);
            }
            throw new Exception("Stack为空, 没找到对应的Transaction.");
        }
Exemplo n.º 3
0
        public static void Initialize()
        {
            try
            {
                if (Instance._mInitialized)
                {
                    return;
                }

                DefaultMessageManager manager = new DefaultMessageManager();

#if NETFULL
                var configFilePath = System.Configuration.ConfigurationManager.AppSettings[CatConstants.LOCAL_CLIENT_CONFIG];
#else
                var configFilePath = string.Empty;
#endif
                AbstractClientConfig config = new LocalClientConfig(configFilePath);

                manager.Initialize(config);
                Instance._mProducer    = new DefaultMessageProducer(manager);
                Instance._mManager     = manager;
                Instance._mInitialized = true;
            }
            catch (Exception ex) {
                Instance._mProducer    = new NullMessageProducer();
                Instance._mManager     = new NullMessageManager();
                Cat.lastException      = ex;
                Instance._mInitialized = true;
            }
        }
Exemplo n.º 4
0
        public static void Initialize()
        {
            try
            {
                if (Instance._mInitialized)
                {
                    return;
                }

                DefaultMessageManager manager = new DefaultMessageManager();

                // var configFilePath = "";
                AbstractClientConfig config;
                //if (String.IsNullOrWhiteSpace(configFilePath))
                //{
                //    configFilePath = @"D:\data\appdatas\cat\client.xml";
                //}
                config = new LocalClientConfig();

                manager.Initialize(config);
                Instance._mProducer    = new DefaultMessageProducer(manager);
                Instance._mManager     = manager;
                Instance._mInitialized = true;
            }
            catch (Exception ex)
            {
                Instance._mProducer    = new NullMessageProducer();
                Instance._mManager     = new NullMessageManager();
                Cat.lastException      = ex;
                Instance._mInitialized = true;
            }
        }
Exemplo n.º 5
0
        private static void Initialize(ClientConfigManager configManager)
        {
            if (_instance.Initialized)
            {
                return;
            }
            Logger.Info($"Initializing Cat .Net Client ...Cat.Version : {PureCatClient.Version}");
            DefaultMessageManager manager = new DefaultMessageManager();

            manager.InitializeClient(configManager.ClientConfig);
            _instance.MessageManager  = manager;
            _instance.MessageProducer = new DefaultMessageProducer(manager);
            _instance.Initialized     = true;
            Logger.Info("Cat .Net Client initialized.");
        }
Exemplo n.º 6
0
 /// <summary>
 ///   添加Event和Heartbeat
 /// </summary>
 /// <param name="manager"> </param>
 /// <param name="message"> </param>
 public void Add(DefaultMessageManager manager, IMessage message)
 {
     if ((_mStack.Count == 0))
     {
         IMessageTree tree = _mTree.Copy();
         tree.MessageId = manager.NextMessageId();
         tree.Message   = message;
         manager.Flush(tree);
     }
     else
     {
         ITransaction entry = _mStack.Peek();
         entry.AddChild(message);
     }
 }
Exemplo n.º 7
0
        /// <summary>
        ///   添加transaction
        /// </summary>
        /// <param name="manager"> </param>
        /// <param name="transaction"> </param>
        public void Start(DefaultMessageManager manager, ITransaction transaction)
        {
            if (_mStack.Count != 0)
            {
                transaction.Standalone = false;
                ITransaction entry = _mStack.Peek();
                entry.AddChild(transaction);
            }
            else
            {
                _mTree.MessageId = manager.NextMessageId();
                _mTree.Message   = transaction;
            }

            _mStack.Push(transaction);
        }
Exemplo n.º 8
0
        public static void Initialize(JasmineSetting config)
        {
            if (Instance.m_initialized)
            {
                LoggerManager.Warn("Cat can't initialize again , IGNORED!");
                return;
            }

            LoggerManager.Info("Initializing Cat .Net Client ...");
            Instance.m_Setting = config;

            DefaultMessageManager manager = new DefaultMessageManager();

            manager.InitializeClient(config);
            Instance.m_Producer    = new DefaultMessageProducer(manager);
            Instance.m_Manager     = manager;
            Instance.m_initialized = true;
            LoggerManager.Info("Cat .Net Client initialized.");
        }
Exemplo n.º 9
0
Arquivo: Cat.cs Projeto: cashcat/wcf-2
        public static void Initialize(string configFile)
        {
            if (Instance._mInitialized)
            {
                Logger.Warn("Cat can't initialize again with config file({0}), IGNORED!", configFile);
                return;
            }

            Logger.Info("Initializing Cat .Net Client ...");

            DefaultMessageManager manager      = new DefaultMessageManager();
            ClientConfig          clientConfig = LoadClientConfig(configFile);

            manager.InitializeClient(clientConfig);
            Instance._mProducer    = new DefaultMessageProducer(manager);
            Instance._mManager     = manager;
            Instance._mInitialized = true;

            Logger.Info("Cat .Net Client initialized.");
        }
Exemplo n.º 10
0
        public static void Initialize(string configFilePath)
        {
            if (Instance.m_initialized)
            {
                LoggerManager.Warn("Cat can't initialize again with config file(%s), IGNORED!", configFilePath);
                return;
            }

            LoggerManager.Info("Initializing Cat .Net Client ...");

            DefaultMessageManager manager      = new DefaultMessageManager();
            JasmineSetting        clientConfig = XmlHelper.XmlDeserializeFromFile <JasmineSetting>(configFilePath, Encoding.UTF8);

            Instance.m_Setting = clientConfig;
            manager.InitializeClient(clientConfig);
            Instance.m_Producer    = new DefaultMessageProducer(manager);
            Instance.m_Manager     = manager;
            Instance.m_initialized = true;
            LoggerManager.Info("Cat .Net Client initialized.");
        }
Exemplo n.º 11
0
        /// <summary>
        /// Cat初始化
        /// 1 加载客户端配置
        /// 2 拿到客户端的server列表
        /// 3 初始化客户端的server对象,返回ClientConfig对象
        /// 4 从将客户端的server地址进行http的发送,并返回服务端的路由列表,并覆盖ClientConfig的server属性
        /// 5 最后就是随机取一个可用的服务器
        /// </summary>
        public static void Initialize()
        {
            if (_instance == null)
            {
                throw new Exception("_instance属性为null");
            }

            if (_instance.Initialized)
            {
                return;
            }

            var configManager = new ClientConfigManager();
            DefaultMessageManager manager;

            manager = new DefaultMessageManager();
            manager.InitializeClient(configManager.ClientConfig);
            _instance.MessageManager  = manager;
            _instance.MessageProducer = new DefaultMessageProducer(manager);
            _instance.Initialized     = true;
            Logger.Info("Cat .Net Client initialized.");
        }