Ejemplo n.º 1
0
        private void OnNewConnection(IConnection connection)
        {
            ulong            sessionId = (ulong)Interlocked.Increment(ref this.totalSessionCount);
            string           client    = connection.RemoteEndPoint.ToString();
            ZooKeeperSession session   = new ZooKeeperSession(this, sessionId, this.OnInitSession, connection, this.protocol, this.instrumentation);

            Interlocked.Increment(ref this.activeSessionCount);
            ZooKeeperServerEventSource.Log.SessionCreated(sessionId, connection.Id, client);
            this.instrumentation?.OnSessionCreated(sessionId, client);

            PacketReceiveDelegate packetReciever = this.protocol.PacketReceiver;

            if (packetReciever != null)
            {
                connection.DoPacketReceive = packetReciever;
            }

            connection.OnPacketReceived = packet =>
            {
                Task.Run(
                    async() =>
                {
                    try
                    {
                        await session.OnPacketReceived(packet);
                    }
                    catch (Exception ex)
                    {
                        ZooKeeperServerEventSource.Log.OnPacketReceived_Failed(session.Id, ex.ToString());
                    }
                },
                    this.cancellationToken);
            };

            connection.OnConnectionLost = () =>
            {
                session.Close();
                Interlocked.Decrement(ref this.activeSessionCount);
                ZooKeeperServerEventSource.Log.SessionClosed(sessionId, connection.Id, client);
                this.instrumentation?.OnSessionClosed(sessionId, client);
            };
        }
Ejemplo n.º 2
0
 public Watcher(ulong id, WatcherKind kind, ZooKeeperSession session)
 {
     this.Id      = id;
     this.session = session;
     this.Kind    = kind;
 }