Пример #1
0
        /// <summary>
        /// Schedules a callback for a specific time.
        /// </summary>
        /// <param name="utcExecutionTime">
        /// The execution time in UTC.
        /// </param>
        /// <param name="callback">
        /// The callback.
        /// </param>
        /// <returns>
        /// An ID that can be used to abort the timer with <see cref="M:ExitGames.Threading.Timer.RemoveAction(System.Guid)"/>.
        /// </returns>
        public Guid AddAction(DateTime utcExecutionTime, Action callback)
        {
            Guid id = Guid.NewGuid();

            if (log.IsDebugEnabled)
            {
                log.DebugFormat("AddAction - enqueued adding '{0}.{1}' with id {2} ", callback, callback, id);
            }
            fiber.Enqueue(() => DoAddAction(id, utcExecutionTime, callback));
            return(id);
        }
Пример #2
0
        public void InOrderExecution()
        {
            PoolFiber fiber = new PoolFiber(new DefaultThreadPool(), new BatchExecutor());

            fiber.Start();

            int            count   = 0;
            AutoResetEvent reset   = new AutoResetEvent(false);
            List <int>     result  = new List <int>();
            Command        command = delegate
            {
                result.Add(count++);
                if (count == 100)
                {
                    reset.Set();
                }
            };

            for (int i = 0; i < 100; i++)
            {
                fiber.Enqueue(command);
            }

            Assert.IsTrue(reset.WaitOne(10000, false));
            Assert.AreEqual(100, count);
        }
 /// <summary>
 /// Sends samples to the socket sender.
 /// </summary>
 private void Publish()
 {
     if (!socketSender.Connected)
     {
         RaiseOnDisconnetedEvent();
     }
     if (sampleCount > 0)
     {
         if (log.IsDebugEnabled)
         {
             log.DebugFormat("Publishing counter data.", new object[0]);
         }
         CounterSampleCollection[] array = new CounterSampleCollection[sampleDictionary.Count];
         sampleDictionary.Values.CopyTo(array, 0);
         sampleDictionary.Clear();
         using (MemoryStream output = new MemoryStream())
         {
             using (BinaryWriter binaryWriter = new BinaryWriter(output))
             {
                 for (int i = 0; i < array.Length; i += MaxQueueLength)
                 {
                     int num2 = array.Length - i;
                     if (num2 > MaxQueueLength)
                     {
                         num2 = MaxQueueLength;
                     }
                     binaryWriter.Write(0xffee);
                     binaryWriter.Write(DateTime.UtcNow.ToBinary());
                     binaryWriter.Write(num2);
                     binaryWriter.Write(senderId);
                     for (int j = i; j < (i + num2); j++)
                     {
                         array[j].Serialize(binaryWriter);
                     }
                     byte[] buffer = output.ToArray();
                     Add(buffer);
                     output.Position = 0;
                 }
             }
         }
         fiber.Enqueue(Send);
     }
 }
Пример #4
0
 public FooForm()
 {
     InitializeComponent();
     _ServerMessageChannel = new Channel <string>();
     _WorkFiber            = new PoolFiber();
     _FormFiber            = new _Fiber = new FormFiber(this, new BatchAndSingleExecutor());
     _WorkFiber.Start();     //begin recive messages
     _FormFiber.Start();     //begin recive messages
     _WorkFiber.Enqueue(LissenToServer);
     _ServerMessageChannel.Subscribe(_FormFiber, (x) => textBox1.Text = x);
 }
Пример #5
0
        public void ExecuteOnlyAfterStart()
        {
            PoolFiber      fiber = new PoolFiber();
            AutoResetEvent reset = new AutoResetEvent(false);

            fiber.Enqueue(delegate { reset.Set(); });
            Assert.IsFalse(reset.WaitOne(1, false));
            fiber.Start();
            Assert.IsTrue(reset.WaitOne(1000, false));
            fiber.Stop();
        }
Пример #6
0
        public static void Main(string[] args)
        {
            Setup();

            fiber.Start();

            //fiber.ScheduleOnInterval()

            for (int i = 0; i < Settings.NumGames; i++)
            {
                fiber.Enqueue(StartGame);
            }

            Console.WriteLine("[{0}] Press Return to End", Process.GetCurrentProcess().Id);
            Console.ReadLine();

            ///log.InfoFormat("Stopping {0} clients", clients.Count);
            fiber.Enqueue(StopGames);

            // wait for stop to complete
            resetEvent.WaitOne();

            Console.ReadLine();
        }
Пример #7
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        private static void Main(params string[] args)
        {
            LogManager.SetLoggerFactory(ExitGames.Logging.Log4Net.Log4NetLoggerFactory.Instance);
            Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory);

            // Set logfile name and application name variables
            FileInfo configFileInfo;

            try
            {
                // IOException if another process already writes to the file
                if (File.Exists(@"log\" + firstGameName + ".log"))
                {
                    File.Delete(@"log\" + firstGameName + ".log");
                }

                GlobalContext.Properties["LogName"] = firstGameName + ".log";

                configFileInfo = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.config"));
            }
            catch (IOException)
            {
                GlobalContext.Properties["LogName"] = baseGameName + ".log";

                // just write to console for now
                configFileInfo = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4netConsole.config"));
            }

            XmlConfigurator.ConfigureAndWatch(configFileInfo);

            AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;

            WindowsCounters.Initialize();

            int index = 0;

            if (args.Length > index)
            {
                Settings.TestCase = args[index];
            }

            index++;
            if (args.Length > index)
            {
                Settings.NumGames = byte.Parse(args[index]);
            }

            index++;
            if (args.Length > index)
            {
                Settings.NumClientsPerGame = byte.Parse(args[index]);
            }

            index++;
            if (args.Length > index)
            {
                Settings.ServerAddress = args[index];
            }

            index++;
            if (args.Length > index)
            {
                Settings.FlushInterval = int.Parse(args[index]);
            }

            index++;
            if (args.Length > index)
            {
                Settings.SendReliableData = bool.Parse(args[index]);
            }

            index++;
            if (args.Length > index)
            {
                Settings.ReliableDataSendInterval = int.Parse(args[index]);
            }

            index++;
            if (args.Length > index)
            {
                Settings.SendUnreliableData = bool.Parse(args[index]);
            }

            index++;
            if (args.Length > index)
            {
                Settings.UnreliableDataSendInterval = int.Parse(args[index]);
            }

            Console.WriteLine("Test case: " + Settings.TestCase);
            Console.WriteLine("Settings: {0} games per process, {1} players per game, game server at {2}",
                              Settings.NumGames,
                              Settings.NumClientsPerGame,
                              Settings.ServerAddress);

            if (Settings.SendReliableData)
            {
                Console.WriteLine("Sending reliable operation every {0} ms", Settings.ReliableDataSendInterval);
            }

            if (Settings.SendUnreliableData)
            {
                Console.WriteLine("Sending unreliable operation every {0} ms", Settings.UnreliableDataSendInterval);
            }

            Console.WriteLine();

            stopped = false;
            fiber.Start();
            counterLoggingFiber.Start();

            counterLoggingFiber.ScheduleOnInterval(PrintCounter, Settings.LogCounterInterval, Settings.LogCounterInterval);

            try
            {
                log.InfoFormat("Starting {0} games with {1} players", Settings.NumGames, Settings.NumClientsPerGame);
                for (int g = 0; g < Settings.NumGames; g++)
                {
                    fiber.Enqueue(StartGame);
                }

                ////log.InfoFormat("{0} clients running", clients.Count);
                Console.WriteLine("[{0}] Press Return to End", Process.GetCurrentProcess().Id);
                Console.ReadLine();

                ////log.InfoFormat("Stopping {0} clients", clients.Count);
                StopGames();
                fiber.Stop();

                // wait for stop to complete
                resetEvent.WaitOne();
            }
            catch (Exception e)
            {
                log.Error(e);
            }
            finally
            {
                log.InfoFormat("[{0}] Stopped", Process.GetCurrentProcess().Id);
            }
        }
        public void GetMonitoringResultCallback(MonitoringResult monitoringResult, object state)
        {
            var context = (IRestRequestContext)state;

            fiber.Enqueue(() => HandleGetMonitoringResult(monitoringResult, context));
        }
Пример #9
0
 public void SendMessage(string message)
 {
     ExecuteFiber.Enqueue(() => { PhotonClient.OpCustom(0, new System.Collections.Generic.Dictionary <byte, object> {
             { 0, message }
         }, true); });
 }
Пример #10
0
 private void StartService()
 {
     ServiceFiber.Start();
     ServiceFiber.Enqueue(Service);
 }