private void SetConfig <T>(ref T field, T value, [CallerMemberName] string caller = null) { if (!EqualityComparer <T> .Default.Equals(field, value)) { multiplexer.Trace(caller + " changed from " + field + " to " + value, "Configuration"); field = value; multiplexer.ReconfigureIfNeeded(endpoint, false, caller); } }
void MatchResult(RawResult result) { // check to see if it could be an out-of-band pubsub message if (connectionType == ConnectionType.Subscription && result.Type == ResultType.MultiBulk) { // out of band message does not match to a queued message var items = result.GetItems(); if (items.Length >= 3 && items[0].IsEqual(message)) { // special-case the configuration change broadcasts (we don't keep that in the usual pub/sub registry) var configChanged = multiplexer.ConfigurationChangedChannel; if (configChanged != null && items[1].IsEqual(configChanged)) { EndPoint blame = null; try { if (!items[2].IsEqual(RedisLiterals.ByteWildcard)) { blame = Format.TryParseEndPoint(items[2].GetString()); } } catch { /* no biggie */ } multiplexer.Trace("Configuration changed: " + Format.ToString(blame), physicalName); multiplexer.ReconfigureIfNeeded(blame, true, "broadcast"); } // invoke the handlers var channel = items[1].AsRedisChannel(ChannelPrefix, RedisChannel.PatternMode.Literal); multiplexer.Trace("MESSAGE: " + channel, physicalName); if (!channel.IsNull) { multiplexer.OnMessage(channel, channel, items[2].AsRedisValue()); } return; // AND STOP PROCESSING! } else if (items.Length >= 4 && items[0].IsEqual(pmessage)) { var channel = items[2].AsRedisChannel(ChannelPrefix, RedisChannel.PatternMode.Literal); multiplexer.Trace("PMESSAGE: " + channel, physicalName); if (!channel.IsNull) { var sub = items[1].AsRedisChannel(ChannelPrefix, RedisChannel.PatternMode.Pattern); multiplexer.OnMessage(sub, channel, items[3].AsRedisValue()); } return; // AND STOP PROCESSING! } // if it didn't look like "[p]message", then we still need to process the pending queue } multiplexer.Trace("Matching result...", physicalName); Message msg; lock (outstanding) { multiplexer.Trace(outstanding.Count == 0, "Nothing to respond to!", physicalName); msg = outstanding.Dequeue(); } multiplexer.Trace("Response to: " + msg.ToString(), physicalName); if (msg.ComputeResult(this, result)) { bridge.CompleteSyncOrAsync(msg); } }