}// SetupInitialize() // // #endregion//Constructors #region no Properties // ***************************************************************** // **** Properties **** // ***************************************************************** // // #endregion//Properties #region Public Methods // ***************************************************************** // **** Public Methods **** // ***************************************************************** // // // // // // ***************************************************** // **** AddExecutionListener() **** // ***************************************************** /// <summary> /// </summary> public void AddExecutionListener(ExecutionListener listener) { m_ExecutionListener = listener; if (m_IsLaunched == false) { this.IOrderEngine.SetExecutionListener(listener); } }//AddExecutionListener()
}// CheckSpontaneousEngineEvents() // // // ***************************************************************** // **** SetupAndStartContainer() **** // ***************************************************************** /// <summary> /// Caller would like to complete the container creation process adding an execution /// listener and starting the container. /// </summary> /// <param name="container"></param> private void SetupAndStartContainer(ThreadContainer container) { container.SetupInitialize(this); // The new engine created call back is now called on listener threads, // after the execution strategy is ready to run. He must call his // container function to broadcast his readiness! // Connect the appropriate listener and START! ExecutionListener listener = CreateListener(string.Format("Listener{0}", container.EngineContainerID)); container.AddExecutionListener(listener); container.Start(); }
// // // ************************************************************* // **** AddExecutionListener **** // ************************************************************* // /// <summary> /// Called once after SetUpIntialize and before start. /// </summary> public void AddExecutionListener(ExecutionListener execListener) { m_ExecutionListener = execListener; m_ExecutionListener.ExecutionContainer = m_ExecutionContainer; // assign my execution container to the listener }
}//ProcessServiceStateRequests() // // // ***************************************************************** // **** ProcessCreateStrategyRequest() **** // ***************************************************************** /// <summary> /// Process request to create new Engine. All the operations here /// are performed by the Hub thread. Once the Execution Strategy is /// ready to be launched, it is passed to its own thread, and then /// never again touched by the hub thread. /// </summary> /// <param name="eventArg">contains data</param> private void ProcessCreateStrategyRequest(EngineEventArgs eventArg) { // // Validate data in eventArg // if (eventArg.Status != EngineEventArgs.EventStatus.Request) { // I only respond to a request. return; } if (eventArg.DataObjectList == null || eventArg.DataObjectList.Count < 2) { Log.NewEntry(LogLevel.Warning, "ProcessCreateNewContainer: Failed to extract data."); return; } string xmlString = (string)eventArg.DataObjectList[0]; string strategyHubName = (string)eventArg.DataObjectList[1]; int engineCount = 0; if (!int.TryParse((string)eventArg.DataObjectList[2], out engineCount)) { engineCount = -1; } // // Obtain the EngineContainer // Dictionary <int, ExecutionContainer> executionContainers = null; if (!m_ExecutionContainers.TryGetValue(strategyHubName, out executionContainers)) { // This is first container for this particular hub. Create a place for it. executionContainers = new Dictionary <int, ExecutionContainer>(); if (string.IsNullOrEmpty(DefaultHubName)) { DefaultHubName = strategyHubName; } m_ExecutionContainers.Add(strategyHubName, executionContainers); } ExecutionContainer container = null; if (!executionContainers.TryGetValue(eventArg.EngineContainerID, out container)) { container = new ExecutionContainer(); container.EngineContainerID = eventArg.EngineContainerID; executionContainers.Add(container.EngineContainerID, container); if (engineCount >= 0) { container.TotalEngineCount = engineCount; } container.EngineContainerName = "need ContainerName"; // Locate the Strategy server this request came from IService iService; if (AppServices.GetInstance().TryGetService(strategyHubName, out iService) && iService is IEngineHub) { container.RemoteEngineHub = (IEngineHub)iService; } // TODO: Continue initializing the container } // // Create the Engine. // bool isSuccess = true; byte[] byteArray = Encoding.ASCII.GetBytes(xmlString); using (System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray)) { try { StringifiableReader stringReader = new StringifiableReader(stream); List <IStringifiable> objects = stringReader.ReadToEnd(); foreach (IStringifiable iObject in objects) { if (iObject is Engine) { if (container.TryAddEngine((Engine)iObject)) { //Engine engine = (Engine)iObject; //int engineID = engine.EngineID; // These are created via attributes (so they coincide with values set by StrategyHub). //((Engine)iObject).SetupInitialize(this, container, engineID); } else { isSuccess = false; Log.NewEntry(LogLevel.Warning, "ProcessCreateEngine: Failed to add {0} to container {1}.", iObject, container); } } } } catch (Exception ex) { isSuccess = false; Log.NewEntry(LogLevel.Warning, "ProcessCreateEngine: {0}", ex.Message); } }//using if (isSuccess == false) { return; } // Finalize if (engineCount == container.EngineList.Count && container.IOrderEngine != null) { // container.SetupInitialize(this); // The new engine created call back is now called on listener threads, // after the execution strategy is ready to run. He must call his // container function to broadcast his readiness! // Connect the appropriate listener and START! ExecutionListener listener = CreateListener(string.Format("Listener{0}", container.EngineContainerID)); container.AddExecutionListener(listener); container.Start(); } else { } }//ProcessCreateEngine()