/// <summary> /// Associates the service handler with a message router by registering /// the necessary application message handlers. /// </summary> /// <param name="router">The message router.</param> /// <param name="settings">The configuration settings.</param> /// <param name="perfCounters">The application's performance counter set (or <c>null</c>).</param> /// <param name="perfPrefix">The string to prefix any performance counter names (or <c>null</c>).</param> /// <remarks> /// <para> /// Applications that expose performance counters will pass a non-<c>null</c> <b>perfCounters</b> /// instance. The service handler should add any counters it implements to this set. /// If <paramref name="perfPrefix" /> is not <c>null</c> then any counters added should prefix their /// names with this parameter. /// </para> /// </remarks> public void Start(MsgRouter router, GeoTrackerServerSettings settings, PerfCounterSet perfCounters, string perfPrefix) { if (this.isRunning) { throw new InvalidOperationException("This node has already been started."); } if (router == null) { throw new ArgumentNullException("router"); } // Initialize the performance counters this.startTime = DateTime.UtcNow; this.perf = new Perf(perfCounters, perfPrefix); // General initialization this.settings = settings; this.bkTimer = new GatedTimer(new TimerCallback(OnBkTimer), null, settings.BkInterval); this.ipGeocoder = new IPGeocoder(this); this.clusterClient = Helper.CreateInstance <ITopologyProvider>(settings.ClusterTopology); this.clusterServer = Helper.CreateInstance <ITopologyProvider>(settings.ClusterTopology); this.fixCache = new GeoFixCache(settings); this.archiver = Helper.CreateInstance <IGeoFixArchiver>(settings.GeoFixArchiver); EntityState.MaxEntityFixes = settings.MaxEntityGeoFixes; try { // Initialize the router this.router = router; this.router.Dispatcher.AddTarget(this, "GeoTrackerServerEP", new SimpleEPMunger(settings.ServerEP), null); // Initialize the cluster this.clusterClient.OpenClient(router, settings.ClusterEP, settings.ClusterArgs); this.clusterServer.OpenServer(router, "GeoTrackerClusterEP", settings.ClusterEP, this, settings.ClusterArgs); // Start the archiver. archiver.Start(this, settings.GeoFixArchiverArgs); this.isRunning = true; } catch { Stop(); throw; } }
/// <summary> /// Immediately terminates the processing of all client messages. /// </summary> public void Stop() { if (!isRunning) { return; } lock (syncLock) { router.Dispatcher.RemoveTarget(this); if (clusterClient != null) { clusterClient.Close(); } if (clusterServer != null) { clusterServer.Close(); } if (fixCache != null) { fixCache.Stop(); } if (ipGeocoder != null) { ipGeocoder.Stop(); } if (archiver != null) { archiver.Stop(); archiver = null; } if (bkTimer != null) { bkTimer.Dispose(); bkTimer = null; } isRunning = false; } }