private void OnConnectRemote() { remoteSelector.AddReader(remoteSocket); remoteTask = Factory.Parallel.Loop("FilterRemoteRead", OnException, RemoteReadLoop); fixContext = new FIXContextDefault(localSocket, remoteSocket); log.Info("Connected at " + remoteAddress + " and port " + remotePort + " with socket: " + localSocket); }
private void OnConnectLocal(Socket socket) { localSocket = socket; localSocket.PacketFactory = new PacketFactoryFIX4_4(); localSelector.AddReader(socket); localSelector.AddWriter(socket); log.Info("Received local connection: " + socket); RequestRemoteConnect(); localTask = Factory.Parallel.Loop("FilterLocalRead", OnException, LocalReadLoop); }
protected virtual void OnConnectFIX(Socket socket) { fixSocket = socket; fixSocket.PacketFactory = fixPacketFactory; fixSelector.AddReader(socket); fixSelector.AddWriter(socket); log.Info("Received FIX connection: " + socket); StartFIXSimulation(); if (task == null) { task = Factory.Parallel.Loop("FIXSimulator", OnException, MainLoop); } }
protected virtual void OnConnectQuotes(Socket socket) { quoteSocket = socket; quoteSocket.PacketFactory = quotePacketFactory; quoteSelector.AddReader(socket); quoteSelector.AddWriter(socket); log.Info("Received quotes connection: " + socket); StartQuoteSimulation(); if (task == null) { task = Factory.Parallel.Loop("FIXSimulator", OnException, MainLoop); } }
private Yield SocketTask() { if (isDisposed) { return(Yield.NoWork.Repeat); } switch (socket.State) { case SocketState.New: if (receiver != null && Factory.Parallel.TickCount > nextConnectTime) { Initialize(); retryTimeout = Factory.Parallel.TickCount + retryDelay * 1000; log.Info("Connection will timeout and retry in " + retryDelay + " seconds."); return(Yield.DidWork.Repeat); } else { return(Yield.NoWork.Repeat); } case SocketState.PendingConnect: if (Factory.Parallel.TickCount >= retryTimeout) { log.Warn("Connection Timeout"); SetupRetry(); retryDelay += retryIncrease; retryDelay = Math.Min(retryDelay, retryMaximum); return(Yield.DidWork.Repeat); } else { return(Yield.NoWork.Repeat); } case SocketState.Connected: if (connectionStatus == Status.New) { connectionStatus = Status.Connected; if (debug) { log.Debug("ConnectionStatus changed to: " + connectionStatus); } } switch (connectionStatus) { case Status.Connected: connectionStatus = Status.PendingLogin; if (debug) { log.Debug("ConnectionStatus changed to: " + connectionStatus); } selector.AddReader(socket); IncreaseRetryTimeout(); var result = OnLogin(); return(result); case Status.PendingRecovery: case Status.Recovered: if (retryDelay != retryStart) { retryDelay = retryStart; log.Info("(RetryDelay reset to " + retryDelay + " seconds.)"); } if (Factory.Parallel.TickCount >= heartbeatTimeout) { log.Warn("Heartbeat Timeout. Last Message UTC Time: " + lastMessage + ", current UTC Time: " + TimeStamp.UtcNow); SyncTicks.LogStatus(); SetupRetry(); IncreaseRetryTimeout(); return(Yield.DidWork.Repeat); } Packet packet; if (Socket.TryGetPacket(out packet)) { lastMessage = TimeStamp.UtcNow; if (debug && (LogRecovery || !IsRecovery)) { log.Debug("Received FIX Message: " + packet); } if (!CheckForResend(packet)) { ReceiveMessage(packet); } IncreaseRetryTimeout(); return(Yield.DidWork.Repeat); } else { return(Yield.NoWork.Repeat); } case Status.PendingLogin: default: return(Yield.NoWork.Repeat); } case SocketState.Disconnected: switch (connectionStatus) { case Status.Disconnected: OnDisconnect(); retryTimeout = Factory.Parallel.TickCount + retryDelay * 1000; connectionStatus = Status.PendingRetry; if (debug) { log.Debug("ConnectionStatus changed to: " + connectionStatus + ". Retrying in " + retryDelay + " seconds."); } retryDelay += retryIncrease; retryDelay = Math.Min(retryDelay, retryMaximum); return(Yield.NoWork.Repeat); case Status.PendingRetry: if (Factory.Parallel.TickCount >= retryTimeout) { log.Warn("Retry Time Elapsed"); OnRetry(); RegenerateSocket(); if (trace) { log.Trace("ConnectionStatus changed to: " + connectionStatus); } return(Yield.DidWork.Repeat); } else { return(Yield.NoWork.Repeat); } default: return(Yield.NoWork.Repeat); } default: string message = "Unknown socket state: " + socket.State; log.Error(message); throw new ApplicationException(message); } }
private Yield SocketTask() { if (isDisposed) { return(Yield.NoWork.Repeat); } switch (socket.State) { case SocketState.New: if (receiver != null && Factory.Parallel.TickCount > nextConnectTime) { Initialize(); retryTimeout = Factory.Parallel.TickCount + retryDelay * 1000; log.Info("Connection will timeout and retry in " + retryDelay + " seconds."); return(Yield.DidWork.Repeat); } else { return(Yield.NoWork.Repeat); } case SocketState.PendingConnect: if (Factory.Parallel.TickCount >= retryTimeout) { log.Warn("Connection Timeout"); SetupRetry(); retryDelay += retryIncrease; return(Yield.DidWork.Repeat); } else { return(Yield.NoWork.Repeat); } case SocketState.Connected: if (connectionStatus == Status.New) { connectionStatus = Status.Connected; if (debug) { log.Debug("ConnectionStatus changed to: " + connectionStatus); } } switch (connectionStatus) { case Status.Connected: connectionStatus = Status.PendingLogin; if (debug) { log.Debug("ConnectionStatus changed to: " + connectionStatus); } selector.AddReader(socket); IncreaseRetryTimeout(); Yield result = OnLogin(); return(result); case Status.PendingRecovery: case Status.Recovered: if (retryDelay != retryStart) { retryDelay = retryStart; log.Info("(RetryDelay reset to " + retryDelay + " seconds.)"); } if (Factory.Parallel.TickCount >= heartbeatTimeout) { log.Warn("Heartbeat Timeout"); SetupRetry(); IncreaseRetryTimeout(); return(Yield.DidWork.Repeat); } result = ReceiveMessage(); if (!result.IsIdle) { IncreaseRetryTimeout(); } return(result); case Status.PendingLogin: default: return(Yield.NoWork.Repeat); } case SocketState.Disconnected: switch (connectionStatus) { case Status.Disconnected: OnDisconnect(); retryTimeout = Factory.Parallel.TickCount + retryDelay * 1000; connectionStatus = Status.PendingRetry; if (debug) { log.Debug("ConnectionStatus changed to: " + connectionStatus + ". Retrying in " + retryDelay + " seconds."); } retryDelay += retryIncrease; retryDelay = retryDelay > retryMaximum ? retryMaximum : retryDelay; return(Yield.NoWork.Repeat); case Status.PendingRetry: if (Factory.Parallel.TickCount >= retryTimeout) { log.Warn("Retry Time Elapsed"); OnRetry(); RegenerateSocket(); if (trace) { log.Trace("ConnectionStatus changed to: " + connectionStatus); } return(Yield.DidWork.Repeat); } else { return(Yield.NoWork.Repeat); } default: return(Yield.NoWork.Repeat); } default: string message = "Unknown socket state: " + socket.State; log.Error(message); throw new ApplicationException(message); } }