示例#1
0
        private static void BroadCastMasterSlave()
        {
            var message = new ServiceSyncMasterSlaveMessage()
            {
                MachineName = _machineName,
                ServiceName = ServiceName,
                Master      = IsMaster,
                SentOn      = DateTime.Now
            };
            var msg = Serialize(message);

            _sender.SendMessage(msg);
        }
示例#2
0
        private static void SyncMessageReceived(string message)
        {
            if (_handshaking)
            {
                return;
            }
            ServiceSyncMasterSlaveMessage m = null;

            try
            {
                m = Deserialize <ServiceSyncMasterSlaveMessage>(message);
            }
            catch (Exception e)
            {
                WriteTrace(string.Format("Exception: {0}{2} Trace: {1}", e.Message, e.StackTrace, Environment.NewLine));
            }
            if (m == null)
            {
                return;
            }
            if (m.ServiceName != ServiceName)
            {
                return;
            }
            if (m.ServiceName == ServiceName && m.MachineName != MachineName)
            {
                if (m.Master)
                {
                    _abortHandshake = true;
                    _handshaking    = false;
                    if (IsMaster)
                    {
                        IsMaster = false;
                    }
                    {
                        _failoverIntervalCounter = 0;
                    }
                }
                lock (_syncLock)
                {
                    m.ReceivedAt             = DateTime.Now;
                    _lastReceivedSyncMessage = m;
                }
            }
        }
示例#3
0
 public static void Start()
 {
     if (_running)
     {
         return;
     }
     _lastReceivedHandshakeMessage = null;
     _lastReceivedSyncMessage      = null;
     IsMaster                 = false;
     _handshaking             = false;
     _handshakeRetryCount     = 0;
     _failoverIntervalCounter = 0;
     _running                 = true;
     //var task = new Task(() => _receiver.Start());
     //task.Start();
     _receiver.Start();
     _syncTimer.Start();
 }