Exemple #1
0
        private ServiceState state;                 // Current service state

        /// <summary>
        /// Constructor.
        /// </summary>
        public AppService()
        {
            this.udpServer = null;
            this.state     = ServiceState.Stopped;

            // Prepare the service to accept remote ServiceControl commands.

            base.Open();
        }
Exemple #2
0
        public void Initialize()
        {
            NetTrace.Start();
            NetTrace.Enable(MsgRouter.TraceSubsystem, 1);

            AsyncTracker.Enable = false;
            AsyncTracker.Start();

            broadcastServer = new UdpBroadcastServer(new UdpBroadcastServerSettings(), null, null);
        }
Exemple #3
0
        public void Cleanup()
        {
            if (broadcastServer != null)
            {
                broadcastServer.Close();
                broadcastServer = null;
            }

            NetTrace.Stop();
            AsyncTracker.Stop();
        }
Exemple #4
0
        /// <summary>
        /// Handles the performance counter installation if they don't
        /// already exist.
        /// </summary>
        /// <returns>The application's <see cref="PerfCounterSet" />.</returns>
        public static PerfCounterSet InstallPerfCounters()
        {
            bool           exists = PerformanceCounterCategory.Exists(Const.BroadcastServerPerf);
            PerfCounterSet perfCounters;

            perfCounters = new PerfCounterSet(false, true, Const.BroadcastServerPerf, Const.BroadcastServerName);

            if (!exists)
            {
                UdpBroadcastServer.InstallPerfCounters(perfCounters, null);
                perfCounters.Install();
            }

            return(perfCounters);
        }
Exemple #5
0
        /// <summary>
        /// Starts the service, associating it with an <see cref="IServiceHost" /> instance.
        /// </summary>
        /// <param name="serviceHost">The service user interface.</param>
        /// <param name="args">Command line arguments.</param>
        public void Start(IServiceHost serviceHost, string[] args)
        {
            lock (syncLock)
            {
                if (udpServer != null)
                {
                    return;     // Already started
                }
                // Global initialization

                NetTrace.Start();
                Program.Config = new Config("LillTek.Datacenter.BroadcastServer");
                Program.InstallPerfCounters();

                // Service initialization

                this.serviceHost = serviceHost;
                SysLog.LogInformation("Broadcast Server v{0} Start", Helper.GetVersionString());

                try
                {
                    udpServer = new UdpBroadcastServer("LillTek.Datacenter.BroadcastServer", Program.PerfCounters, null);

                    state = ServiceState.Running;
                }
                catch (Exception e)
                {
                    if (udpServer != null)
                    {
                        udpServer.Close();
                        udpServer = null;
                    }

                    SysLog.LogException(e);
                    throw;
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Stops the service immediately, terminating any user activity.
        /// </summary>
        public void Stop()
        {
            lock (syncLock)
            {
                if (state == ServiceState.Stopped)
                {
                    return;
                }

                SysLog.LogInformation("Broadcast Server Stop");
                SysLog.Flush();

                base.Close();
                state = ServiceState.Stopped;

                if (udpServer != null)
                {
                    udpServer.Close();
                    udpServer = null;
                }

                Program.PerfCounters.Zero();
            }
        }