public void ClearUnselectable(UnselectableFlags flags) { var oldFlags = unselectableReasons; if (oldFlags != 0) { unselectableReasons &= ~flags; if (unselectableReasons != oldFlags) { Multiplexer.Trace(unselectableReasons == 0 ? "Now usable" : ("Now unusable: " + flags), ToString()); } } }
private void PerInstanceCompleteSyncOrAsync(ICompletable operation) { if (operation == null) { } else if (operation.TryComplete(false)) { multiplexer.Trace("Completed synchronously: " + operation, name); Interlocked.Increment(ref completedSync); } else { multiplexer.Trace("Using thread-pool for asynchronous completion", name); (multiplexer.SocketManager ?? SocketManager.Shared).ScheduleTask(s_AnyOrderCompletionHandler, operation); Interlocked.Increment(ref completedAsync); // k, *technically* we haven't actually completed this yet, but: close enough } }
private bool AreAllConditionsSatisfied(ConnectionMultiplexer multiplexer) { bool result = true; for (int i = 0; i < conditions.Length; i++) { var condition = conditions[i]; if (condition.UnwrapBox()) { multiplexer.Trace("Precondition passed: " + condition.Condition); } else { multiplexer.Trace("Precondition failed: " + condition.Condition); result = false; } } return(result); }
internal void KeepAlive() { var commandMap = multiplexer.CommandMap; Message msg = null; switch (connectionType) { case ConnectionType.Interactive: msg = serverEndPoint.GetTracerMessage(false); msg.SetSource(ResultProcessor.Tracer, null); break; case ConnectionType.Subscription: if (commandMap.IsAvailable(RedisCommand.UNSUBSCRIBE)) { msg = Message.Create(-1, CommandFlags.FireAndForget, RedisCommand.UNSUBSCRIBE, (RedisChannel)Guid.NewGuid().ToByteArray()); msg.SetSource(ResultProcessor.TrackSubscriptions, null); } break; } if (msg != null) { msg.SetInternalCall(); multiplexer.Trace("Enqueue: " + msg); if (!TryEnqueue(msg, serverEndPoint.IsSlave)) { OnInternalError(ExceptionFactory.NoConnectionAvailable(multiplexer.IncludeDetailInExceptions, msg.Command, msg, serverEndPoint)); } } }
public PhysicalConnection(PhysicalBridge bridge) { lastWriteTickCount = lastReadTickCount = Environment.TickCount; lastBeatTickCount = 0; this.connectionType = bridge.ConnectionType; this.multiplexer = bridge.Multiplexer; this.ChannelPrefix = multiplexer.RawConfig.ChannelPrefix; if (this.ChannelPrefix != null && this.ChannelPrefix.Length == 0) this.ChannelPrefix = null; // null tests are easier than null+empty var endpoint = bridge.ServerEndPoint.EndPoint; physicalName = connectionType + "#" + Interlocked.Increment(ref totalCount) + "@" + Format.ToString(endpoint); this.bridge = bridge; multiplexer.Trace("Connecting...", physicalName); this.socketToken = multiplexer.SocketManager.BeginConnect(endpoint, this); //socket.SendTimeout = socket.ReceiveTimeout = multiplexer.TimeoutMilliseconds; OnCreateEcho(); }
public PhysicalConnection(PhysicalBridge bridge) { lastWriteTickCount = lastReadTickCount = Environment.TickCount; lastBeatTickCount = 0; this.connectionType = bridge.ConnectionType; this.multiplexer = bridge.Multiplexer; this.ChannelPrefix = multiplexer.RawConfig.ChannelPrefix; if (this.ChannelPrefix != null && this.ChannelPrefix.Length == 0) { this.ChannelPrefix = null; // null tests are easier than null+empty } var endpoint = bridge.ServerEndPoint.EndPoint; physicalName = connectionType + "#" + Interlocked.Increment(ref totalCount) + "@" + Format.ToString(endpoint); this.bridge = bridge; multiplexer.Trace("Connecting...", physicalName); this.socketToken = multiplexer.SocketManager.BeginConnect(endpoint, this); //socket.SendTimeout = socket.ReceiveTimeout = multiplexer.TimeoutMilliseconds; OnCreateEcho(); }
public void CompleteSyncOrAsync(ICompletable operation) { if (operation == null) { return; } if (operation.TryComplete(false)) { multiplexer.Trace("Completed synchronously: " + operation, name); Interlocked.Increment(ref completedSync); return; } else { if (multiplexer.PreserveAsyncOrder) { multiplexer.Trace("Queueing for asynchronous completion", name); bool startNewWorker; lock (asyncCompletionQueue) { asyncCompletionQueue.Enqueue(operation); startNewWorker = !asyncWorkerQueued; asyncWorkerQueued = true; } if (startNewWorker) { multiplexer.Trace("Starting new async completion worker", name); OnCompletedAsync(); ThreadPool.QueueUserWorkItem(processAsyncCompletionQueue, this); } } else { multiplexer.Trace("Using thread-pool for asynchronous completion", name); ThreadPool.QueueUserWorkItem(anyOrderCompletionHandler, operation); Interlocked.Increment(ref completedAsync); // k, *technically* we haven't actually completed this yet, but: close enough } } }
public bool TryResend(int hashSlot, Message message, EndPoint endpoint, bool isMoved) { try { if (serverType == ServerType.Standalone || hashSlot < 0 || hashSlot >= RedisClusterSlotCount) { return(false); } ServerEndPoint server = multiplexer.GetServerEndPoint(endpoint); if (server != null) { bool retry = false; if ((message.Flags & CommandFlags.NoRedirect) == 0) { message.SetAsking(!isMoved); message.SetNoRedirect(); // once is enough // note that everything so far is talking about MASTER nodes; we might be // wanting a SLAVE, so we'll check ServerEndPoint resendVia = null; var command = message.Command; switch (Message.GetMasterSlaveFlags(message.Flags)) { case CommandFlags.DemandMaster: resendVia = server.IsSelectable(command) ? null : server; break; case CommandFlags.PreferMaster: resendVia = server.IsSelectable(command) ? FindSlave(server, command) : server; break; case CommandFlags.PreferSlave: resendVia = FindSlave(server, command) ?? (server.IsSelectable(command) ? null : server); break; case CommandFlags.DemandSlave: resendVia = FindSlave(server, command); break; } if (resendVia == null) { multiplexer.Trace("Unable to resend to " + endpoint); } else { message.PrepareToResend(resendVia, isMoved); retry = resendVia.TryEnqueue(message); } } if (isMoved) // update map; note we can still update the map even if we aren't actually goint to resend { var arr = MapForMutation(); var oldServer = arr[hashSlot]; arr[hashSlot] = server; if (oldServer != server) { multiplexer.OnHashSlotMoved(hashSlot, oldServer == null ? null : oldServer.EndPoint, endpoint); } } return(retry); } return(false); } catch { return(false); } }
public void BeginConnect(TextWriter log) { Thread.VolatileWrite(ref firstUnansweredWriteTickCount, 0); var endpoint = this.bridge.ServerEndPoint.EndPoint; multiplexer.Trace("Connecting...", physicalName); this.socketToken = multiplexer.SocketManager.BeginConnect(endpoint, this, multiplexer, log); }
public void BeginConnect() { var endpoint = this.bridge.ServerEndPoint.EndPoint; multiplexer.Trace("Connecting...", physicalName); this.socketToken = multiplexer.SocketManager.BeginConnect(endpoint, this); }
public void Dispose() { if (outStream != null) { multiplexer.Trace("Disconnecting...", physicalName); try { outStream.Close(); } catch { } try { outStream.Dispose(); } catch { } outStream = null; } if (netStream != null) { try { netStream.Close(); } catch { } try { netStream.Dispose(); } catch { } netStream = null; } if (socketToken.HasValue) { var socketManager = multiplexer.SocketManager; if (socketManager != null) { socketManager.Shutdown(socketToken); } socketToken = default(SocketToken); multiplexer.Trace("Disconnected", physicalName); RecordConnectionFailed(ConnectionFailureType.ConnectionDisposed); } OnCloseEcho(); }