private void ProcessTablePos(Message.TablePos msg) {
     if (_peerTablePositions == null)
         _peerTablePositions = new Dictionary<string, ulong>();
     _peerTablePositions.Add(msg.Table, msg.Pos);
     return;
 }
 private void ProcessStartStream(Message.StartStream msg) {
     if (!IsStopping)
         IsOkToStream = true;
     return;
 }
 private void ProcessFilter(Message.Filter msg) {
     if (msg.Tablenames != null && msg.Tablenames.Count > 0) {
         if (_peerTableFilters == null) {
             _peerTableFilters = new List<HashSet<string>>();
         }
         _peerTableFilters.Add(msg.Tablenames);
     }
     return;
 }
 private void ProcessOk(Message.Ok msg) {
     if (State == RunState.Starting)
         SetState(RunState.Running);
     return;
 }
 private void ProcessOpenLog(Message.OpenLog msg) {
     OpenLog().ContinueWith(AllLogsOpened);
     return;
 }
        private void ProcessId(Message.Id msg) {
            var peerGuid = Guid.Parse(msg.Guid);
            if (peerGuid == Guid.Empty) {
                Quit("GUID is empty");
                return;
            }
            if (peerGuid == SelfGuid) {
                Quit("GUID is my own");
                return;
            }
            PeerDatabaseName = msg.DatabaseName;
            PeerGuid = peerGuid;
            PeerFirstUserOid = msg.FirstUserOid;
            PeerLastUserOid = msg.LastUserOid;

            // Peer object ID range must be either identical to ours
            // (in a failover/backup scenario) or nonoverlapping.
            if (PeerFirstUserOid != Db.Environment.FirstUserOid || PeerLastUserOid != Db.Environment.LastUserOid) {
                if (PeerFirstUserOid > Db.Environment.LastUserOid || PeerLastUserOid < Db.Environment.FirstUserOid) {
                    if (PeerFirstUserOid >= PeerLastUserOid) {
                        Quit("OID range invalid");
                        return;
                    }
                } else {
                    Quit("OID range overlap");
                    return;
                }
            }

            OnIdentified?.Invoke();
            if (!IsStopping) {
                SendFilterState();
                SendLastPositions();
                Send(new Message.OpenLog());
            }
            return;
        }
 private void ProcessQuit(Message.Quit msg) {
     Log(Logger.EntryKind.WsRecvCmd, "Quit: " + msg.Message);
     if (SetState(RunState.Stopping)) {
         Task.Delay(10 * 1000, CancellationToken).ContinueWith((t) => {
             if (!IsCancellationRequested) {
                 Status = "Timeout waiting for close";
                 Stop();
             }
         });
     }
     return;
 }
 private void ProcessTransaction(Message.Transaction msg) {
     if (!IsPeerGuidSet) {
         Quit("peer GUID not set");
         return;
     }
     ProcessIncomingTransaction(msg.LogReadResult);
     if (State == RunState.Starting)
         SetState(RunState.Running);
     if (TransactionsReceived == 1 && !IsStopping)
         Send(new Message.Ok());
     return;
 }
        private void ProcessMessage(Message msg) {
            if (msg is Message.Transaction) {
                ProcessTransaction((Message.Transaction)msg);
                return;
            }
            if (msg is Message.TablePos) {
                ProcessTablePos((Message.TablePos)msg);
                return;
            }
            if (msg is Message.Filter) {
                ProcessFilter((Message.Filter)msg);
                return;
            }
            if (msg is Message.Quit) {
                ProcessQuit((Message.Quit)msg);
                return;
            }
            if (msg is Message.Id) {
                ProcessId((Message.Id)msg);
                return;
            }
            if (msg is Message.Ok) {
                ProcessOk((Message.Ok)msg);
                return;
            }
            if (msg is Message.OpenLog) {
                ProcessOpenLog((Message.OpenLog)msg);
                return;
            }
            if (msg is Message.StartStream) {
                ProcessStartStream((Message.StartStream)msg);
                return;
            }

            Stop("unrecognized message " + msg.GetType().ToString());
        }
 private void Send(Message msg) {
     _output.Enqueue(msg);
     _outputSem.Release();
 }