示例#1
0
        /// <summary>
        /// Start the broker simulation.
        /// </summary>
        public static void Start()
        {
            // Create a thread for each simulated broker.  Use a pool of predefined brokers to give each broker thread a personality.
            for (Int32 threadIndex = 0; threadIndex < BrokerSimulator.brokerThreadCount; threadIndex++)
            {
                // The BrokerContext is a structure that simulates a broker, including the connections a broker would have back to the source of the orders.  When
                // the broker simulator is shut down or suspended, those threads and web services need to be disposed of.
                BrokerInfo brokerInfo = BrokerSimulator.brokerList[threadIndex];
                BrokerSimulator.brokerContexts[brokerInfo.Symbol] = new BrokerContext(brokerInfo);

                // These threads will simulate the various brokers.
                BrokerSimulator.brokerSimulationThreads[threadIndex]      = new Thread(new ParameterizedThreadStart(BrokerSimulator.SimulateBroker));
                BrokerSimulator.brokerSimulationThreads[threadIndex].Name = String.Format("{0} Thread", brokerInfo.Name);
                BrokerSimulator.brokerSimulationThreads[threadIndex].Start(BrokerSimulator.brokerContexts[brokerInfo.Symbol]);
            }
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the BrokerContext class.
        /// </summary>
        public BrokerContext(BrokerInfo brokerInfo)
        {
            // Initialize the object.
            this.nameField   = brokerInfo.Name;
            this.symbolField = brokerInfo.Symbol;

            // This document contains the configuration of the connections used to route orders back to the source of the order.
            XDocument xDocument = XDocument.Load(Environment.ExpandEnvironmentVariables(Settings.Default.SourceConfigurationFile));

            // This will load in the properties of each of sources into a dictionary that is used to manage the stream of messages back to the source that
            // originated the order.
            foreach (XElement xElement in xDocument.Root.Elements("Source"))
            {
                // Don't bother to connect to the source if they aren't active.
                Boolean isActive = Convert.ToBoolean(xElement.Attribute("IsActive").Value);
                if (isActive)
                {
                    // This provides an operating context for the connection back to the source of the order.
                    SourceContext sourceContext = new SourceContext();

                    // This is the name of the source.
                    String tenant = xElement.Attribute("Name").Value;

                    // This properties are used to connect us to a web service that will deliver the messages back to the source.
                    ClientInfo clientInfo = sourceContext.ClientInfo;
                    clientInfo.EndpointName = xElement.Attribute("Endpoint").Value;
                    clientInfo.Password     = xElement.Attribute("Password").Value;
                    clientInfo.UserName     = xElement.Attribute("UserName").Value;

                    // This thread will asynchronously pull messages out of the message queue and deliver them to the source.
                    Thread thread = new Thread(this.SourceThread);
                    thread.Start(sourceContext);
                    thread.Name          = String.Format("{0} connection to {1}", brokerInfo.Symbol, tenant);
                    sourceContext.Thread = thread;

                    // This acts as a routing map to deliver messages back to the source of the orders based on the name of the source.
                    this.sourceContextMap.Add(tenant, sourceContext);
                }
            }
        }