Exemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="prefix"></param>
 /// <param name="suffix"></param>
 public BaseLogger(string prefix, string suffix)
 {
     // note: the following async thread queue must be constructed
     //       with a NULL logger, otherwise recursion occurs!
     _asyncWriteQueue = new AsyncThreadQueue(null);
     Format           = "{dt:o},{severity},{host},{user},{prefix}{indent}{text}{suffix}{crlf}";
     Prefix           = prefix;
     Suffix           = suffix;
     SplitLines       = true;
     try
     {
         AppDomain.CurrentDomain.UnhandledException +=
             UnhandledDomainException;
     }
     catch (Exception excp)
     {
         Debug.WriteLine($"Unable to register AppDomain exception handler: {excp}");
     }
     // not used
     //try
     //{
     //    Application.ThreadException += new ThreadExceptionEventHandler(UnhandledThreadException);
     //}
     //catch (Exception excp)
     //{
     //    Trace.WriteLine(String.Format("Unable to register Application exception handler: {0}", excp);
     //}
 }
Exemplo n.º 2
0
 protected override void OnServerStarted()
 {
     // create workflow
     _workContext = new WorkContext(Logger, IntClient.Target, HostInstance, ServerInstance);
     // create thread queues
     _manageThreadQueue = new AsyncThreadQueue(Logger);
     _workerEventQueue  = new AsyncEventThrottle <object>(DequeueWorkerRequests);
 }
Exemplo n.º 3
0
 protected override void OnServerStarted()
 {
     Logger.LogDebug("Instance/FarmSize: {0}/{1}", ServerInstance, ServerFarmSize);
     // create workflow
     _workContext = new WorkContext(Logger, IntClient.Target, HostInstance, ServerInstance);
     // create event throttles
     _workerEventQueue  = new AsyncEventThrottle <object>(DequeueWorkerRequests);
     _manageThreadQueue = new AsyncThreadQueue(Logger);
 }
Exemplo n.º 4
0
 protected override void OnServerStarted()
 {
     // create workflow
     _WorkContext = new WorkContext(Logger, this.Client);
     _Workflow    = new WFCalculatePortfolioValuation();
     // create thread queues
     _ManageThreadQueue = new AsyncThreadQueue(Logger);
     _WorkerThreadQueue = new AsyncThreadQueue(Logger);
 }
Exemplo n.º 5
0
        public StoreEngine(ILogger logger, ServerCfg serverCfg)
            : base(PartNames.Store, logger)
        {
            _inboundCallQueue = new AsyncThreadQueue(Logger);
            string connectionString = EnvHelper.FormatDbCfgStr(serverCfg.ModuleInfo.ConfigEnv, serverCfg.DbServer, serverCfg.DbPrefix);

            Logger.LogDebug("Connection String: {0}", connectionString);
            _state = new Guarded <StoreEngineState>(new StoreEngineState(serverCfg, connectionString));
        }
Exemplo n.º 6
0
 public MarketDataRealtimeServer(
     Reference <ILogger> loggerRef,
     AsyncThreadQueue threadQueue,
     ICoreClient client)
 {
     _loggerRef       = loggerRef?.Clone() ?? throw new ArgumentNullException(nameof(loggerRef));
     _threadQueue     = threadQueue;
     _client          = client;
     _subsDetailIndex = new Dictionary <Guid, SubscriptionDetail>();
 }
Exemplo n.º 7
0
        public void TestQueueOrdering()
        {
            using (Reference <ILogger> loggerRef = Reference <ILogger> .Create(new TraceLogger(true)))
            {
                const int iterations  = 500000; // yes 500,000 - takes about 1.0 seconds
                int       sendCount   = 0;
                int       recvCount   = 0;
                int       totalErrors = 0;
                int       threadCount = 0;

                // dispatches a series of tasks
                using (AsyncThreadQueue queue = new AsyncThreadQueue(loggerRef.Target))
                {
                    AsyncQueueCallback <int> callback = delegate(int data)
                    {
                        int count   = Interlocked.Increment(ref recvCount);
                        int threads = Interlocked.Increment(ref threadCount);
                        try
                        {
                            if (threads > 1)
                            {
                                // multithreading issue!
                                int errors = Interlocked.Increment(ref totalErrors);
                                if (errors <= 50)
                                {
                                    loggerRef.Target.LogDebug("Thread count = {0}!", threads);
                                }
                            }
                            if (count != (data + 1))
                            {
                                int errors = Interlocked.Increment(ref totalErrors);
                                if (errors <= 50)
                                {
                                    loggerRef.Target.LogDebug("Recv count = {0} but (data+1) = {1}", count, data + 1);
                                }
                            }
                        }
                        finally
                        {
                            Interlocked.Decrement(ref threadCount);
                        }
                    };
                    for (int i = 0; i < iterations; i++)
                    {
                        Interlocked.Increment(ref sendCount);
                        queue.Dispatch <int>(i, callback);
                    }
                    Assert.AreEqual <int>(iterations, sendCount);
                    long itemsRemaining = queue.WaitUntilEmpty(TimeSpan.FromSeconds(30));
                    Assert.AreEqual <long>(0, itemsRemaining);
                    Assert.AreEqual <int>(iterations, recvCount);
                    Assert.AreEqual <int>(0, totalErrors);
                }
            }
        }
Exemplo n.º 8
0
        public void TestQueueConcurrency()
        {
            using (Reference <ILogger> loggerRef = Reference <ILogger> .Create(new TraceLogger(true)))
            {
                const int iterations         = 10;
                int       sendCount          = 0;
                int       totalErrors        = 0;
                int       threadCount        = 0;
                int       callbacksCommenced = 0;
                int       callbacksCompleted = 0;

                // dispatches a series of tasks
                using (AsyncThreadQueue queue = new AsyncThreadQueue(loggerRef.Target))
                {
                    AsyncQueueCallback <int> callback = delegate(int data)
                    {
                        Interlocked.Increment(ref callbacksCommenced);
                        int threads = Interlocked.Increment(ref threadCount);
                        try
                        {
                            if (threads > 1)
                            {
                                // multithreading issue!
                                int errors = Interlocked.Increment(ref totalErrors);
                                if (errors <= 50)
                                {
                                    loggerRef.Target.LogDebug("Thread count = {0}!", threads);
                                }
                            }
                            Thread.Sleep(TimeSpan.FromSeconds(0.5));
                        }
                        finally
                        {
                            Interlocked.Decrement(ref threadCount);
                        }
                        Interlocked.Increment(ref callbacksCompleted);
                    };
                    for (int i = 0; i < iterations; i++)
                    {
                        Interlocked.Increment(ref sendCount);
                        queue.Dispatch <int>(i, callback);
                    }
                    Assert.AreEqual <int>(iterations, sendCount);
                    long itemsRemaining = queue.WaitUntilEmpty(TimeSpan.FromSeconds(30));
                    Assert.AreEqual <long>(0, itemsRemaining);
                    Assert.AreEqual <int>(0, totalErrors);
                    Assert.AreEqual <int>(iterations, callbacksCommenced);
                    Assert.AreEqual <int>(iterations, callbacksCompleted);
                }
            }
        }
Exemplo n.º 9
0
 public CoreCache(
     ILogger logger,
     ICoreClient client,
     CacheChangeHandler dataChangeHandler,
     SynchronizationContext syncContext)
 {
     _Logger             = logger ?? throw new ArgumentNullException(nameof(logger));
     Client              = client ?? throw new ArgumentNullException(nameof(client));
     SyncContext         = syncContext;
     Cache               = new CoreItemCache(CacheId, Client);
     UserThreadQueue     = new AsyncThreadQueue(_Logger);
     CacheItemPurgeTimer = new Timer(CacheItemPurgeTimeout, null, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
     if (dataChangeHandler != null)
     {
         OnDataChange += dataChangeHandler;
     }
 }
Exemplo n.º 10
0
        public MarketDataRealtimeClient(
            Reference <ILogger> loggerRef,
            AsyncThreadQueue clientThreadQueue,
            ICoreClient client,
            MDSProviderId dataProvider)
        {
            if (dataProvider == MDSProviderId.Undefined)
            {
                throw new ArgumentNullException(nameof(dataProvider));
            }
            ProviderId        = dataProvider;
            _loggerRef        = loggerRef?.Clone() ?? throw new ArgumentNullException(nameof(loggerRef));
            ClientThreadQueue = clientThreadQueue ?? new AsyncThreadQueue(_loggerRef.Target);
            _mds = new MarketDataRealtimeServer(_loggerRef, clientThreadQueue, client);
            var serverSettings = new NamedValueSet();

            serverSettings.Set(MdpConfigName.ProviderId, (int)dataProvider);
            _mds.ApplySettings(serverSettings);
            _mds.Start();
        }
Exemplo n.º 11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="logger"></param>
 public UnitTestStoreEngine(ILogger logger)
     : base(PartNames.Store, logger)
 {
     _databaseQueue = new AsyncThreadQueue(Logger);
 }
Exemplo n.º 12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="logger"></param>
 /// <param name="serverCfg"></param>
 public CommsEngine(ILogger logger, ServerCfg serverCfg)
     : base(PartNames.Comms, logger)
 {
     _serverCfg           = serverCfg;
     _mainCommsDispatcher = new AsyncThreadQueue(Logger);
 }