예제 #1
0
        protected override void CoreInnerOnLoading()
        {
            //注册processors
            //MidiatorGlobal.Initialize();
            //配置数据库连接字符串
            Global.DbMySql = new Database(SystemWorker.Instance.ConfigurationProxy.GetField("CoinAPI", Global.MySql), Global.CommandTimeOut);
            DatabaseManager.Inject(Global.DbMySql, Global.DbMySql);

            ServiceManager.Instance.Initialize();
            Global.RemoteApiService = ServiceManager.Instance.GetService <RemoteApiService>();
            Global.RemoteApiService.Initialize();
            _protocolStack = new MetadataProtocolStack();
            _tracing.Info("     #CoinAPI::Initialize protocol stack succeed!");
            Console.WriteLine("     #CoinAPI::Initialize protocol stack succeed!");
            _transactionManager = new MetadataTransactionManager(new TransactionIdentityComparer());
            _scheduler          = new MetadataMessageRequestScheduler();

            //注册代理器
            _scheduler.Regist(new GetTickerFromOKCoinProcessor());

            _scheduler.CreateDynamicCounters();
            _tracing.Info("     #CoinAPI::Regist business processors succeed!");
            Console.WriteLine("     #CoinAPI::Regist business processors succeed!");
            _tracing.Info("     #CoinAPI::BasicBusinessComponent load succeed!");
            Console.WriteLine("     #CoinAPI::BasicBusinessComponent load succeed!");
        }
예제 #2
0
        /// <summary>
        ///     初始化属于指定服务角色的系统工作者
        /// </summary>
        /// <param name="role">服务角色</param>
        /// <param name="useRemoteConfig">是否使用远程配置的标示</param>
        /// <param name="setting">远程配置设置</param>
        /// <param name="notificationHandler">异常通知处理器</param>
        /// <param name="csnAddress">远程CSN的IP地址</param>
        /// <exception cref="ArgumentNullException">参数不能为空</exception>
        public void Initialize(string role, bool useRemoteConfig, RemoteConfigurationSetting setting, ITracingNotificationHandler notificationHandler = null, string csnAddress = null)
        {
            if (string.IsNullOrEmpty(role))
            {
                throw new ArgumentNullException("role");
            }
            if (useRemoteConfig && setting == null)
            {
                throw new ArgumentNullException("setting");
            }
            if (IsInitialized)
            {
                return;
            }
            _configurationProxy = (!useRemoteConfig ? (IRemoteConfigurationProxy) new RemoteConfigurationProxy(csnAddress) : new SolitaryRemoteConfigurationProxy(csnAddress));
            //Regist("LGS", new LGSProtocolStack());
            //TracingManager.NotificationHandler = notificationHandler ?? new RemoteLogProxy();
            Role = role;
            FixedTypeManager.Add(typeof(Color), 6);
            FixedTypeManager.Add(typeof(MessageIdentity), 5);
            FixedTypeManager.Add(typeof(TransactionIdentity), 18);
            IntellectTypeProcessorMapping.Instance.Regist(new MessageIdentityProcessor());
            IntellectTypeProcessorMapping.Instance.Regist(new TransactionIdentityProcessor());
            IntellectTypeProcessorMapping.Instance.Regist(new ColorIntellectPropertyProcessor());
            ExtensionTypeMapping.Regist(typeof(MessageIdentityValueStored));
            ExtensionTypeMapping.Regist(typeof(TransactionIdentityValueStored));
            //config remote configuration loader.
            if (useRemoteConfig)
            {
                KJFramework.Configurations.Configurations.RemoteConfigLoader = new RemoteConfigurationLoader(setting);
            }
            //initialize long...long memory buffer for tcp layer.
            ChannelConst.Initialize();
            CommonCounter.Instance.Initialize();
            // Init CSN
            Dictionary <string, int> maxRanges = new Dictionary <string, int>();
            Dictionary <string, ServiceCoreConfig[]> addresses = new Dictionary <string, ServiceCoreConfig[]>();

            InitCSN(addresses, maxRanges);
            _transactionManager         = new MessageTransactionManager(new TransactionIdentityComparer());
            _metadataTransactionManager = new MetadataTransactionManager(new TransactionIdentityComparer());
            _clsuter         = HashNetworkCluster.Create(_transactionManager, new IntellectObjectSystemConnectionPool(), addresses, maxRanges);
            _metadataCluster = MetadataContainerHashNetworkCluster.Create(_metadataTransactionManager,
                                                                          new MetadataSystemConnectionPool(),
                                                                          addresses, maxRanges);
            _syncProxy     = new RemoteDataSyncProxy();
            _isInitialized = true;
        }
예제 #3
0
 /// <summary>
 ///    初始化内部通用数据
 /// </summary>
 private static void InitializeCore(string role)
 {
     Role = role;
     FixedTypeManager.Add(typeof(MessageIdentity), 5);
     IntellectTypeProcessorMapping.Instance.Regist(new MessageIdentityProcessor());
     IntellectTypeProcessorMapping.Instance.Regist(new TransactionIdentityProcessor());
     ExtensionTypeMapping.Regist(typeof(MessageIdentityValueStored));
     ExtensionTypeMapping.Regist(typeof(TransactionIdentityValueStored));
     MemoryAllotter.Instance.Initialize();
     _transactionManager         = new MessageTransactionManager(new TransactionIdentityComparer());
     _metadataTransactionManager = new MetadataTransactionManager(new TransactionIdentityComparer());
     _protocolStackContainer     = new ProtocolStackContainer();
     _baseMessageConnectionPool  = new IntellectObjectSystemConnectionPool();
     _metadataConnectionPool     = new MetadataSystemConnectionPool();
     _clsuter                         = new NetworkCluster <BaseMessage>(_transactionManager, _baseMessageConnectionPool, ProtocolTypes.Intellegence);
     _metadataCluster                 = new NetworkCluster <MetadataContainer>(_metadataTransactionManager, _metadataConnectionPool, ProtocolTypes.Metadata);
     _baseMessageTransactionProxy     = new BusinessMessageTransactionProxy(_protocolStackContainer, _clsuter, _transactionManager, _hostProxy, _appUniqueId);
     _metadataMessageTransactionProxy = new MetadataMessageTransactionProxy(_protocolStackContainer, _metadataCluster, _metadataTransactionManager, _hostProxy, _appUniqueId);
 }
 /// <summary>
 ///     连接代理器,提供了相关的基本操作
 /// </summary>
 /// <param name="channel">消息通信信道</param>
 /// <param name="transactionManager">事务管理器</param>
 /// <exception cref="System.NullReferenceException">参数不能为空</exception>
 public MetadataConnectionAgent(IMessageTransportChannel <MetadataContainer> channel, MetadataTransactionManager transactionManager)
 {
     if (channel == null)
     {
         throw new ArgumentNullException(nameof(channel));
     }
     if (!channel.IsConnected)
     {
         throw new ArgumentException("Cannot wrap this msg channel, because current msg channel has been disconnected!");
     }
     if (transactionManager == null)
     {
         throw new ArgumentNullException(nameof(transactionManager));
     }
     _channel                  = channel;
     _transactionManager       = transactionManager;
     _channel.Disconnected    += ChannelDisconnected;
     _channel.ReceivedMessage += ChannelReceivedMessage;
 }
예제 #5
0
        /// <summary>
        ///     获取具有指定标示的连接代理器,如果具有该条件的代理器不存在,则会创建一个新的代理器
        /// </summary>
        /// <param name="key">连接标示</param>
        /// <param name="roleId">服务角色编号</param>
        /// <param name="protocolStack">连接所承载的协议栈</param>
        /// <param name="transactionManager">事务管理器</param>
        /// <returns>如果返回null, 则表示当前无法连接到目标远程终结点地址</returns>
        public IServerConnectionAgent <MetadataContainer> GetChannel(string key, string roleId, IProtocolStack protocolStack, MetadataTransactionManager transactionManager)
        {
            string fullKey = string.Format("{0}#{1}", roleId, key);

            return(base.GetChannel(key, fullKey, protocolStack, transactionManager));
        }
        /// <summary>
        ///     创建一个新的连接代理器
        /// </summary>
        /// <param name="iep">远程终结点地址</param>
        /// <param name="protocolStack">协议栈</param>
        /// <param name="transactionManager">事务管理器</param>
        /// <returns>如果无法连接到远程地址,则返回null.</returns>
        /// <exception cref="System.ArgumentNullException">非法参数</exception>
        public static IServerConnectionAgent <MetadataContainer> Create(IPEndPoint iep, IProtocolStack protocolStack, MetadataTransactionManager transactionManager)
        {
            if (iep == null)
            {
                throw new ArgumentNullException(nameof(iep));
            }
            if (protocolStack == null)
            {
                throw new ArgumentNullException(nameof(protocolStack));
            }
            if (transactionManager == null)
            {
                throw new ArgumentNullException(nameof(transactionManager));
            }
            ITransportChannel transportChannel = new TcpTransportChannel(iep);

            transportChannel.Connect();
            if (!transportChannel.IsConnected)
            {
                return(null);
            }
            IMessageTransportChannel <MetadataContainer> msgChannel = new MessageTransportChannel <MetadataContainer>((IRawTransportChannel)transportChannel, protocolStack);

            return(new MetadataConnectionAgent(msgChannel, transactionManager));
        }