internal static void Shutdown()
        {
            if (_instance == null)
            {
                _started = false;

                SnLog.WriteWarning("Repository shutdown has already completed.");
                return;
            }

            lock (_startStopSync)
            {
                if (_instance == null)
                {
                    _started = false;

                    SnLog.WriteWarning("Repository shutdown has already completed.");
                    return;
                }

                SnTrace.Repository.Write("Sending a goodbye message.");

                _instance.ConsoleWriteLine();

                _instance.ConsoleWriteLine("Sending a goodbye message...");
                DistributedApplication.ClusterChannel.ClusterMemberInfo.NeedToRecover = false;
                var pingMessage = new PingMessage();
                pingMessage.Send();

                foreach (var svc in _instance.serviceInstances)
                {
                    SnTrace.Repository.Write("Shutting down {0}", svc.GetType().Name);
                    svc.Shutdown();
                }

                SnTrace.Repository.Write("Shutting down {0}", DistributedApplication.ClusterChannel.GetType().Name);
                DistributedApplication.ClusterChannel.ShutDown();

                SnTrace.Repository.Write("Shutting down Security.");
                SecurityHandler.ShutDownSecurity();

                SnTrace.Repository.Write("Shutting down IndexingEngine.");
                IndexManager.ShutDown();

                ContextHandler.Reset();

                var t   = DateTime.UtcNow - _instance._startupInfo.Starting;
                var msg = $"Repository has stopped. Running time: {t.Days}.{t.Hours:d2}:{t.Minutes:d2}:{t.Seconds:d2}";

                SnTrace.Repository.Write(msg);
                SnTrace.Flush();

                _instance.ConsoleWriteLine(msg);
                _instance.ConsoleWriteLine();
                SnLog.WriteInformation(msg);

                _instance = null;
                _started  = false;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Function to receive ping
        /// </summary>
        /// <param name="ping">The ping message to be received</param>
        private void ReceivedPing(PingMessage ping)
        {
            // Update peer
            foreach (var peer in _peers)
            {
                if (peer.Value.GetUuid().Equals(ping.fromUuid))
                {
                    peer.Value.SetIp(ping.fromIp);
                    peer.Value.UpdateLastSeen();
                    peer.Value.SetOnline(true);
                    peer.Value.diskSpace = ping.diskSpace;
                    if (ping.type.Equals(TypeCode.RESPONSE))
                    {
                        peer.Value.AddPingToList(ping.GetElapsedTime());
                    }
                }
            }

            // Respond to ping
            if (ping.type.Equals(TypeCode.REQUEST))
            {
                ping.CreateReply();
                ping.statusCode = StatusCode.OK;
                ping.diskSpace  = DiskHelper.GetTotalAvailableSpace(_path);
                ping.Send();
            }
            else
            {
                // Received response, should send peerlist
                var peerFetch =
                    new PeerFetcherMessage(GetAPeer(ping.fromUuid))
                {
                    peers = this.GetPeerList()
                };
                // Removed the receiver from the list, as he should not add himself
                foreach (Peer peer in peerFetch.peers)
                {
                    if (string.Compare(peer.GetIp().Trim(), peerFetch.toIp.Trim(), StringComparison.Ordinal) == 0)
                    {
                        peerFetch.peers.Remove(peer);
                        break;
                    }
                }
                peerFetch.Send();
            }
        }
Exemplo n.º 3
0
        public void Ping(long millis, string pathToFolder)
        {
            long time = (millis > 0) ? millis : DateTimeOffset.Now.ToUnixTimeMilliseconds();

            if (this._nextPing < time)
            {
                PingMessage ping = new PingMessage(this);
                ping.fromIp     = NetworkHelper.GetLocalIpAddress();
                ping.type       = Messages.TypeCode.REQUEST;
                ping.statusCode = StatusCode.OK;
                ping.diskSpace  = DiskHelper.GetTotalAvailableSpace(pathToFolder);
                ping.Send();

                // Ping every 60 seconds and if a peer didnt respond add extra time before retrying.
                this._nextPing = DateTimeOffset.Now.ToUnixTimeMilliseconds() + 10000 +
                                 (this._pingsWithoutResponse * 10000);
                this._pingsWithoutResponse++;

                if (this._pingsWithoutResponse >= 2)
                {
                    this.SetOnline(false);
                }
            }
        }
Exemplo n.º 4
0
        internal static void Shutdown()
        {
            if (_instance == null)
            {
                Logger.WriteWarning(Logger.EventId.NotDefined, "Repository shutdown has already completed.");
                return;
            }

            lock (_shutDownSync)
            {
                if (_instance == null)
                {
                    Logger.WriteWarning(Logger.EventId.NotDefined, "Repository shutdown has already completed.");
                    return;
                }

                DetailedLogger.Log("Sending a goodbye message."); // category: general

                _instance.ConsoleWriteLine();

                _instance.ConsoleWriteLine("Sending a goodbye message...");
                DistributedApplication.ClusterChannel.ClusterMemberInfo.NeedToRecover = false;
                var pingMessage = new PingMessage();
                pingMessage.Send();

                foreach (var svc in _instance.serviceInstances)
                {
                    DetailedLogger.Log("Shutting down {0}", svc.GetType().Name); // category: general
                    svc.Shutdown();
                }

                BackgroundOperations.TaskManager.Stop();

                DetailedLogger.Log("Shutting down {0}", DistributedApplication.ClusterChannel.GetType().Name); // category: general
                DistributedApplication.ClusterChannel.ShutDown();

                if (Instance.StartSettings.BackupIndexAtTheEnd)
                {
                    DetailedLogger.Log("Backing up the index."); // category: general
                    if (LuceneManagerIsRunning)
                    {
                        _instance.ConsoleWriteLine("Backing up the index...");
                        BackupTools.SynchronousBackupIndex();
                        _instance.ConsoleWriteLine("The backup of index is finished.");
                    }
                    else
                    {
                        _instance.ConsoleWriteLine("Backing up index is skipped because Lucene was not started.");
                    }
                }

                if (LuceneManagerIsRunning)
                {
                    DetailedLogger.Log("Shutting down LuceneManager."); // category: general
                    LuceneManager.ShutDown();
                }

                DetailedLogger.Log("Waiting for writer lock file is released."); // category: general
                WaitForWriterLockFileIsReleased(WaitForLockFileType.OnEnd);

                DetailedLogger.Log("Repository has stopped."); // category: general

                var t   = DateTime.UtcNow - _instance._startupInfo.Starting;
                var msg = String.Format("Repository has stopped. Running time: {0}.{1:d2}:{2:d2}:{3:d2}", t.Days,
                                        t.Hours, t.Minutes, t.Seconds);

                _instance.ConsoleWriteLine(msg);
                _instance.ConsoleWriteLine();
                Logger.WriteInformation(Logger.EventId.NotDefined, msg);
                _instance = null;
            }
        }