/// <summary> /// Main loop, runs the WebSocket connection. /// </summary> protected void RunSocket() { //We don't really need to store the handlers; //just create them and let them call our EnqueueMessage method. //XXX automatically find these like WebServer does. Log($"Creating socket handlers (thread: {Thread.CurrentThread.Name})"); BudgetHandler budgetHandler = new BudgetHandler(this); BuildingHandler buildingHandler = new BuildingHandler(this); CameraHandler cameraHandler = new CameraHandler(this); ChirperHandler chirperHandler = new ChirperHandler(this); CitizenHandler citizenHandler = new CitizenHandler(this); CityInfoHandler cityInfoHandler = new CityInfoHandler(this); DebugHandler debugHandler = new DebugHandler(this); DistrictHandler districtHandler = new DistrictHandler(this); FlagsHandler flagsHandler = new FlagsHandler(this); InstancesHandler instancesHandler = new InstancesHandler(this); LimitsHandler limitsHandler = new LimitsHandler(this); NotificationHandler notificationHandler = new NotificationHandler(this); ReflectionHandler reflectionHandler = new ReflectionHandler(this); TerrainHandler terrainHandler = new TerrainHandler(this); TransportHandler transportHandler = new TransportHandler(this); VehicleHandler vehicleHandler = new VehicleHandler(this); Log("Waiting for messages"); try { while (true) { if (stream.DataAvailable) { HandleNextMessage(); } String msg = GetNextOutgoingMessage(); if (msg != null) { byte[] buf = Encoding.UTF8.GetBytes(msg); SendFrame(buf); } Thread.Sleep(100); } } catch (ObjectDisposedException) { //we're done, stream is closed Log("Connection closed"); } catch (OperationCanceledException) { Log("Connection closed"); } }
public ITestState Start() { _threadPoolCounter = new ThreadPoolCounter(); PipeFactory <IResult> pipeFactory = new PipeFactory <IResult>(); _aggregator = new PipelineDataAggregator(_settings.Aggregators, pipeFactory); _aggregator.Start(); _globalCounters = GlobalCounters.CreateDefault(); _errorHandler = new ErrorHandler(); _limit = new LimitsHandler(_settings.Limits); _threading = _settings.Threading; _state = new TestState(_timer, _globalCounters, _threadPoolCounter); _speed = PriorityStrategyFactory.Create(_settings.Speeds, _timer); _speed.Setup(_state); IIterationContextFactory iterationContextFactory = CreateIterationContextFactory(); IScenarioHandlerFactory scenarioHandlerFactory = CreateScenarioHandlerFactory(); ISchedulerFactory schedulerFactory = CreateSchedulerFactory(); IDataCollectorFactory dataCollectorFactory = CreateDataCollectorFactory(pipeFactory, _threadPoolCounter); IScenarioThreadFactory scenarioThreadFactory = CreateScenarioThreadFactory(); IThreadFactory threadFactory = new ScenarioThreadFactory( iterationContextFactory, scenarioHandlerFactory, schedulerFactory, dataCollectorFactory, scenarioThreadFactory ); _pool = new ThreadPool(threadFactory, _threadPoolCounter); InitialThreadingSetup(); _timer.Start(); // This line also releases Worker-Threads from wait in IPrewait return(_state); }