// To be called in the transport constructor private void RegisterEvents(IMemcacheTransport transport) { transport.MemcacheError += OnMemcacheError; transport.MemcacheResponse += OnMemcacheResponse; transport.TransportError += OnTransportError; transport.TransportDead += OnTransportDead; }
private void TransportAvailable(IMemcacheTransport transport) { try { if (!transport.Registered) { transport.Registered = true; Interlocked.Increment(ref _workingTransports); if (!_isAlive) lock (this) if (!_isAlive) { _isAlive = true; if (NodeAlive != null) NodeAlive(this); _tokenSource = new CancellationTokenSource(); } } // Add the transport to the pool, unless the node is disposing of the pool if (!_ongoingDispose) { _transportPool.Add(transport); if (_ongoingShutdown) transport.Shutdown(_forceShutDown); } else transport.Dispose(); } catch (Exception e) { if (TransportError != null) TransportError(e); } }
private void OnTransportDead(IMemcacheTransport transport) { lock (this) { transport.Registered = false; if (0 == Interlocked.Decrement(ref _workingTransports)) { _isAlive = false; if (NodeDead != null) NodeDead(this); if (!_tokenSource.IsCancellationRequested) _tokenSource.Cancel(); } } }