/// <summary> /// Instantiates MmfReader. /// </summary> /// <param name="ipcType">Identifies memory mapped file and used to authenticate incoming data.</param> /// <param name="bufferLength">Length of data segment</param> /// <param name="ignoreExceptions">True if exceptions should be handled; false if they should be thrown to caller</param> public MmfReader(string ipcType, int bufferLength, Niawa.Utilities.UtilsServiceBus utilsBus, bool ignoreExceptions) { try { _receiveQueue = new Queue<NiawaMmfContainer>(); _ipcType = ipcType; _description = "MmfReader " + _ipcType; _bufferLength = bufferLength; _ignoreExceptions = ignoreExceptions; _lastMsgID = 0; _threadStatus = new Niawa.Threading.ThreadStatus(_description, 60, utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), string.Empty, null); //thread status _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED; } catch (Exception ex) { logger.Error("[" + _description + "-M] Exception while instantiating: " + ex.Message, ex); if (!ignoreExceptions) throw ex; } }
/// <summary> /// Instantiates MmfWriter. /// </summary> /// <param name="ipcType">Identifies memory mapped file and used to authenticate outgoing messages.</param> /// <param name="bufferLength">Length of data segment</param> /// <param name="ignoreExceptions">True if exceptions should be handled; false if they should be returned to the caller.</param> public MmfWriter(string ipcType, int bufferLength, Niawa.Utilities.UtilsServiceBus utilsBus, bool ignoreExceptions) { try { _sendQueue = new Queue<NiawaMmfContainer>(); _ipcType = ipcType; _description = "MmfWriter " + _ipcType; _bufferLength = bufferLength; _ignoreExceptions = ignoreExceptions; //initialize serial ID generator id = utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_MMF_CONTAINER); //get random starting message ID Random rnd = new Random(); int startingMsgID = rnd.Next(0, 100000); _msgID = startingMsgID; _threadStatus = new Niawa.Threading.ThreadStatus(_description, 60, utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), string.Empty, null); //thread status _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED; } catch (Exception ex) { logger.Error("[" + _description + "-M] Exception while instantiating: " + ex.Message, ex); if (!ignoreExceptions) throw ex; } }
public ThreadHealthMonitor(NiawaAdHocNetworkAdapter nna) { _description = "ThreadHealthMonitor"; _nna = nna; _threadStatus = new Niawa.Threading.ThreadStatus(_description, 60, nna.UtilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), string.Empty, null); //thread status _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED; }
public void Setup() { int serialIDRoot = 123; int serialIDSession = 456; int serialIDSerial = 789; _testSerialID = new Utilities.SerialId(serialIDRoot, serialIDSession, serialIDSerial); //create mock event raiser _evtRaiser = new MockedObjects.MockedEventRaiser("TestAppGroup", "TestAppName", "TestAppInstance", null); //create thread status _threadStatus = new Threading.ThreadStatus("TestThreadStatus", 60, _testSerialID.ToString(), string.Empty, _evtRaiser); }
/// <summary> /// MsEventIpcEventWriter consumes events (as raised by Niawa.MsEventController) and writes them to an IpcEventWriter (as implemented by Niawa.IpcController). /// The event consumer is added (subscribed) to an event raiser by the caller to enable events to be processed in McEventIpcEventWriter. /// Multiple IpcEventWriters are registered here and events are written to the appropriate IpcEventWriter based on event type. /// </summary> public MsEventIpcEventWriter(Niawa.Utilities.UtilsServiceBus utilsBus) { try { _description = "MsEventIpcEventAdapter"; _messages = new Queue<MsEventController.NiawaEventMessageArgs>(); _evtConsumer = new MsEventController.EventConsumer(_messages); _ipcEventWriters = new SortedList<string, IpcController.iEventWriter>(); _threadStatus = new Niawa.Threading.ThreadStatus(_description, 60, utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), string.Empty, null); //thread status _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED; } catch (Exception ex) { logger.Error("[MsEventIpcEventAdapter-M] Error while instantiating: " + ex.Message, ex); } }
/// <summary> /// Instantiates TcpTransmitter /// </summary> /// <param name="ipAddress">IP Address to transmit TCP messages on</param> /// <param name="port">Network port to transmit TCP messages on</param> /// <param name="evtConsumer">Consumer for events raised by Niawa.MsEventController.EventRaiser</param> public TcpTransmitter(string ipAddress, int port, Niawa.MsEventController.EventConsumer evtConsumer, Niawa.Utilities.UtilsServiceBus utilsBus, string applicationNameDetailed, string parentNodeID) { try { _applicationNameDetailed = applicationNameDetailed; _ipAddress = ipAddress; _port = port; _evtConsumer = evtConsumer; lockSection = new System.Threading.Semaphore(1, 1); _description = "TcpTransmitter " + _ipAddress + ":" + _port.ToString(); _sendQueue = new Queue<NiawaNetMessage>(); //initialize serial ID generator id = utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_NET_MESSAGE); //initialize event logging _evtRaiser = new MsEventController.EventRaiser("TcpTransmitter", _applicationNameDetailed, _description, utilsBus); //_evtRaiserMsg = new MsEventController.EventRaiser("TcpTransmitterMsg", _applicationNameDetailed, _description, utilsBus); if (_evtConsumer != null) _evtRaiser.AddEventConsumer(_evtConsumer); //if (_evtConsumer != null) _evtRaiserMsg.AddEventConsumer(_evtConsumer); _threadStatus = new Niawa.Threading.ThreadStatus(_description, 60, utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), parentNodeID, _evtRaiser); //thread status _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED; //add thread elective properties. _threadStatus.AddElectiveProperty("IpAddress", _ipAddress); _threadStatus.AddElectiveProperty("Port", _port.ToString()); } catch (Exception ex) { logger.Error("[TcpTransmitter-M] Error instantiating: " + ex.Message, ex); throw ex; } }
/// <summary> /// Instantiates IpcCommandReader /// </summary> /// <param name="ipcEvent"></param> /// <param name="readerFunction"></param> public IpcCommandReader(string ipcEvent, Func<Niawa.IpcController.IpcEvent, bool> readerFunction, Niawa.Utilities.UtilsServiceBus utilsBus, bool ignoreExceptions) { try { _ignoreExceptions = ignoreExceptions; _ipcEvent = ipcEvent; _description = "IpcCommandReader " + _ipcEvent; _readerFunction = readerFunction; evtReader = Niawa.IpcController.IpcFactory.CreateIpcEventReader(true, _ipcEvent, utilsBus); _threadStatus = new Niawa.Threading.ThreadStatus(_description, 60, utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), string.Empty, null); //thread status _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED; } catch (Exception ex) { logger.Error("[" + _description + "-M] Exception while instantiating: " + ex.Message, ex); if (!ignoreExceptions) throw ex; } }
/// <summary> /// Instantiates a new IpcEventWebApiWriter. /// </summary> /// <param name="webApiUrl"></param> /// <param name="utilsBus"></param> public IpcEventWebAPIWriter(string webApiUrl, Niawa.Utilities.UtilsServiceBus utilsBus) { try { _description = "IpcEventWebAPIWriter"; _webApiUrl = webApiUrl; _utilsBus = utilsBus; _messages = new Queue<IpcController.IpcEvent>(); _eventReaders = new SortedList<string, IpcEventReaderThread>(); lockSection = new System.Threading.Semaphore(1, 1); _threadStatus = new Niawa.Threading.ThreadStatus(_description, 60, utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), string.Empty, null); //thread status _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED; } catch (Exception ex) { logger.Error("[IpcEventWebAPIWriter-M] Error while instantiating: " + ex.Message, ex); } }
/// <summary> /// Instantiates a new IpcEventReaderThread. /// </summary> /// <param name="ipcType"></param> /// <param name="webWriter"></param> /// <param name="utilsBus"></param> public IpcEventReaderThread(string ipcType, IpcEventWebAPIWriter webWriter, Utilities.UtilsServiceBus utilsBus) { try { _description = "IpcEventReaderThread-" + ipcType; _ipcType = ipcType; _webWriter = webWriter; _utilsBus = utilsBus; //event reader evtReader = Niawa.IpcController.IpcFactory.CreateIpcEventReader(true, _ipcType, _utilsBus); //thread status _threadStatus = new Niawa.Threading.ThreadStatus(_description, 60, utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), string.Empty, null); //set thread status _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED; } catch (Exception ex) { logger.Error("[IpcEventReaderThread-" + ipcType + "-M] Error while instantiating: " + ex.Message, ex); } }
/// <summary> /// Instantiates a new WebAPICommandReader. /// </summary> /// <param name="webApiUrl"></param> /// <param name="utilsBus"></param> public WebAPICommandReader(string webApiUrl, int pollIntervalMs, Niawa.Utilities.UtilsServiceBus utilsBus) { try { _description = "WebAPICommandReader"; _webApiUrl = webApiUrl; _pollIntervalMs = pollIntervalMs; if (pollIntervalMs < 1000) { logger.Warn("[WebAPICommandReader-M] Warning: poll interval under minimum, setting to 1000 ms"); _pollIntervalMs = 1000; } if (pollIntervalMs > 60000) { logger.Warn("[WebAPICommandReader-M] Warning: poll interval over maximum, setting to 60000 ms"); _pollIntervalMs = 60000; } lockSection = new System.Threading.Semaphore(1, 1); _utilsBus = utilsBus; _messages = new Queue<NiawaWebMessage>(); _cachedMessages = new SortedList<int, NiawaWebMessage>(); _subscribedCommands = new List<int>(); _threadStatus = new Niawa.Threading.ThreadStatus(_description, 60, utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), string.Empty, null); //thread status _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED; } catch (Exception ex) { logger.Error("[WebAPICommandReader-M] Error while instantiating: " + ex.Message, ex); } }
public void TearDown() { _threadStatus = null; _evtRaiser = null; }
/// <summary> /// Creates a NiawaAdHocNetworkAdapter /// </summary> /// <param name="udpPort"></param> /// <param name="ipAddress"></param> /// <param name="tcpPortRangeMin"></param> /// <param name="tcpPortRangeMax"></param> /// <param name="hostname"></param> /// <param name="applicationName"></param> public NiawaAdHocNetworkAdapter(int udpPort, string ipAddress, int tcpPortRangeMin, int tcpPortRangeMax, string hostname, string applicationName) { try { _description = "NiawaAdHocNetworkAdapter"; _udpPort = udpPort; _ipAddress = ipAddress; _tcpPortRangeMin = tcpPortRangeMin; _tcpPortRangeMax = tcpPortRangeMax; _hostname = hostname; _applicationName = applicationName; //create utility bus _utilsBus = new Niawa.Utilities.UtilsServiceBus(); //set up ipc logging _evtWriter = new Niawa.MsEventIpcEventAdapter.MsEventIpcEventWriter(_utilsBus); _evtWriter.Start(); //initialize event logging for this object _evtRaiser = new MsEventController.EventRaiser("NiawaAdHocNetworkAdapter", _applicationName, _description, _utilsBus); if (_evtWriter.EvtConsumer != null) _evtRaiser.AddEventConsumer(_evtWriter.EvtConsumer); //add ipc logging for this object _evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "NiawaAdHocNetworkAdapter", _utilsBus), "NiawaAdHocNetworkAdapter"); //add ipc logging for UDP _evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "UdpReceiver", _utilsBus), "UdpReceiver"); //_evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "UdpReceiverMsg", _utilsBus), "UdpReceiverMsg"); _evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "UdpTransmitter", _utilsBus), "UdpTransmitter"); //_evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "UdpTransmitterMsg", _utilsBus), "UdpTransmitterMsg"); //add ipc logging for TCP _evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "TcpReceiver", _utilsBus), "TcpReceiver"); //_evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "TcpReceiverMsg", _utilsBus), "TcpReceiverMsg"); _evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "TcpTransmitter", _utilsBus), "TcpTransmitter"); //_evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "TcpTransmitterMsg", _utilsBus), "TcpTransmitterMsg"); //add ipc logging for TcpSession _evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "TcpSession", _utilsBus), "TcpSession"); //add ipc logging for TcpSessionManager _evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "TcpSessionManager", _utilsBus), "TcpSessionManager"); //_evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "TcpSessionManagerMsg", _utilsBus), "TcpSessionManagerMsg"); //ipc command reader _cmdReader = new IpcController.IpcCommandReader("NiawaAdHocNetworkAdapterCmd", CmdReaderImpl, _utilsBus, true); //thread health and status _threadStatus = new Niawa.Threading.ThreadStatus(_description, 60, _utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), string.Empty, _evtRaiser); _healthMonitor = new ThreadHealthMonitor(this); //thread status _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED; //add thread elective properties. _threadStatus.AddElectiveProperty("IpAddress", _ipAddress); _threadStatus.AddElectiveProperty("TcpPortRangeMin", _tcpPortRangeMin.ToString()); _threadStatus.AddElectiveProperty("TcpPortRangeMax", _tcpPortRangeMax.ToString()); _threadStatus.AddElectiveProperty("UdpPort", _udpPort.ToString()); _threadStatus.AddElectiveProperty("Hostname", _hostname); } catch (Exception ex) { logger.Error("[NiawaAdHocNetworkAdapter-M] Error while instantiating: " + ex.Message, ex); throw ex; } }
/// <summary> /// Instantiates UdpTransmitter. /// </summary> /// <param name="port">Port to transmit UDP messages on.</param> /// <param name="evtConsumer">Consumer for events raised by Niawa.MsEventController.EventRaiser</param> public UdpTransmitter(int port, Niawa.MsEventController.EventConsumer evtConsumer, Niawa.Utilities.UtilsServiceBus utilsBus, string applicationNameDetailed, string parentNodeID) { try { _applicationNameDetailed = applicationNameDetailed; _port = port; _sendQueue = new Queue<NiawaNetDatagram>(); _sentMessageGuidBuffer = new List<Guid>(); lockSection = new System.Threading.Semaphore(1, 1); lockSentMessageGuidBuffer = new System.Threading.Semaphore(1, 1); _description = "UdpTransmitter " + _port.ToString(); _evtConsumer = evtConsumer; //initialize the endpoints _groupEndpoint = new System.Net.IPEndPoint(System.Net.IPAddress.Broadcast, _port); //_localEP = new System.Net.IPEndPoint(System.Net.IPAddress.Loopback, _port); //initialize serial ID generator id = utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_NET_DATAGRAM); //initialize event logging _evtRaiser = new MsEventController.EventRaiser("UdpTransmitter", _applicationNameDetailed, _description, utilsBus); if (_evtConsumer != null) _evtRaiser.AddEventConsumer(_evtConsumer); _threadStatus = new Niawa.Threading.ThreadStatus(_description, 60, utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), parentNodeID, _evtRaiser); //thread status _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED; //add thread elective properties. _threadStatus.AddElectiveProperty("Port", _port.ToString()); } catch (Exception ex) { logger.Error("[UdpTransmitter-M] Error while instantiating: " + ex.Message, ex); throw ex; } }
/// <summary> /// Private function for instantiating UdpReceiver. /// </summary> /// <param name="port"></param> /// <param name="evtConsumer"></param> /// <param name="utilsBus"></param> /// <param name="applicationNameDetailed"></param> /// <param name="parentNodeID"></param> private void Instantiate(int port , Niawa.MsEventController.EventConsumer evtConsumer , Niawa.Utilities.UtilsServiceBus utilsBus , string applicationNameDetailed , string parentNodeID) { try { _applicationNameDetailed = applicationNameDetailed; _port = port; _receiveQueue = new Queue<NiawaNetDatagram>(); _evtConsumer = evtConsumer; lockSection = new System.Threading.Semaphore(1, 1); _description = "UdpReceiver " + _port.ToString(); //initialize the endpoints /*v2*/ //_recvEndpoint = new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0); //_localEP = new System.Net.IPEndPoint(System.Net.IPAddress.Loopback, _port); /*v3*/ _recvEndpoint = new System.Net.IPEndPoint(System.Net.IPAddress.Any, _port); //initialize event logging _evtRaiser = new MsEventController.EventRaiser("UdpReceiver", _applicationNameDetailed, _description, utilsBus); if (_evtConsumer != null) _evtRaiser.AddEventConsumer(_evtConsumer); _threadStatus = new Niawa.Threading.ThreadStatus(_description, 300, utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), parentNodeID, _evtRaiser); //thread status _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED; //add thread elective properties. _threadStatus.AddElectiveProperty("Port", _port.ToString()); } catch (Exception ex) { logger.Error("[UdpReceiver-M] Error while instantiating: " + ex.Message, ex); throw ex; } }
/// <summary> /// Instantiate TcpSessionManager with specific utility bus, and event consumer passed in by caller /// </summary> /// <param name="ipAddress"></param> /// <param name="portRangeMin"></param> /// <param name="portRangeMax"></param> /// <param name="hostname"></param> /// <param name="applicationName"></param> /// <param name="evtConsumer"></param> /// <param name="utilsBus"></param> public TcpSessionManager(string ipAddress, int portRangeMin, int portRangeMax, string hostname, string applicationName, Niawa.Utilities.UtilsServiceBus utilsBus, Niawa.MsEventController.EventConsumer evtConsumer, string parentNodeID) { try { _description = "TcpSessionManager"; _ipAddress = ipAddress; _handshakePort = 0; _portRangeMin = portRangeMin; _portRangeMax = portRangeMax; _hostname = hostname; _applicationName = applicationName; _tcpSessions = new SortedList<string, TcpSession>(); _utilsBus = utilsBus; _evtConsumer = evtConsumer; //initialize event logging for this object _evtRaiser = new MsEventController.EventRaiser("TcpSessionManager", _applicationName, "TcpSessionManager", _utilsBus); _evtRaiser_HR = new MsEventController.EventRaiser("TcpSessionManager", _applicationName, "TcpSessionManager-HandshakeReceiver", _utilsBus); //_evtRaiserMsg = new MsEventController.EventRaiser("TcpSessionManagerMsg", _applicationName, "TcpSessionManagerMsg", _utilsBus); //add caller's event consumer, if supplied if (_evtConsumer != null) _evtRaiser.AddEventConsumer(_evtConsumer); if (_evtConsumer != null) _evtRaiser_HR.AddEventConsumer(_evtConsumer); //if (_evtConsumer != null) _evtRaiserMsg.AddEventConsumer(_evtConsumer); lockSection = new System.Threading.Semaphore(1, 1); _receiveQueue = new Queue<NiawaNetMessage>(); Utilities.SerialId threadID_HR = utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID); Utilities.SerialId threadID_SRL = utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID); _t2_SRL_ThreadStatus = new Niawa.Threading.ThreadStatus("TcpSessionManager", 60, threadID_SRL.ToString(), parentNodeID, _evtRaiser); _t1_HR_ThreadStatus = new Niawa.Threading.ThreadStatus("TcpSessionManager-HandshakeReceiver", 60, threadID_HR.ToString(), threadID_SRL.ToString(), _evtRaiser_HR); //thread status _t1_HR_ThreadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED; _t2_SRL_ThreadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED; //add thread elective properties. _t1_HR_ThreadStatus.AddElectiveProperty("IpAddress", _ipAddress); _t1_HR_ThreadStatus.AddElectiveProperty("HandshakePort", _handshakePort.ToString()); _t1_HR_ThreadStatus.AddElectiveProperty("Hostname", _hostname.ToString()); _t2_SRL_ThreadStatus.AddElectiveProperty("IpAddress", _ipAddress); _t2_SRL_ThreadStatus.AddElectiveProperty("HandshakePort", _handshakePort.ToString()); _t2_SRL_ThreadStatus.AddElectiveProperty("Hostname", _hostname.ToString()); _t2_SRL_ThreadStatus.AddElectiveProperty("PortRangeMin", _portRangeMin.ToString()); _t2_SRL_ThreadStatus.AddElectiveProperty("PortRangeMax", _portRangeMax.ToString()); } catch (Exception ex) { logger.Error("[TcpSessionManager-M] Error instantiating: " + ex.Message, ex); throw ex; } }
/// <summary> /// Internal function to initialize the TcpSession. Sets up a receiver with either a specific port or a port range. /// </summary> private void Initialize() { if (_localPortRange && _localPortRangeMin == 0 && _localPortRangeMax == 0) { throw new Exception("[" + _sessionIdentifier + "] When a port range is used, PortRangeMin and PortRangeMax values must be supplied."); } if (_localPortRange && _localPortRangeMin > _localPortRangeMax) { throw new Exception("[" + _sessionIdentifier + "] When a port range is used, PortRangeMax must be greater than PortRangeMin."); } if (!_localPortRange && _localPort == 0) { throw new Exception("[" + _sessionIdentifier + "] When a port range is not used, a value must be supplied for Port."); } //initialize event logging _evtRaiser = new MsEventController.EventRaiser("TcpSession", _applicationName, _sessionIdentifier, _utilsBus); if (_evtConsumer != null) _evtRaiser.AddEventConsumer(_evtConsumer); _threadStatus = new Niawa.Threading.ThreadStatus(_sessionIdentifier, 0, _utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), _parentNodeID, _evtRaiser); if (_localPortRange) { //port was not supplied _receiver = new TcpReceiver(_localIpAddress, _localPortRangeMin, _localPortRangeMax, _remoteIpAddress, _evtConsumer, _utilsBus, _applicationName + ".TcpSession", _threadStatus.NodeID); } else { //port was supplied _receiver = new TcpReceiver(_localIpAddress, _localPort, _remoteIpAddress, _evtConsumer, _utilsBus, _applicationName + ".TcpSession", _threadStatus.NodeID); } //thread status _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED; //add thread elective properties. _threadStatus.AddElectiveProperty("LocalIpAddress", _localIpAddress); _threadStatus.AddElectiveProperty("LocalPort", _localPort.ToString()); _threadStatus.AddElectiveProperty("LocalPortRangeMin", _localPortRangeMin.ToString()); _threadStatus.AddElectiveProperty("LocalPortRangeMax", _localPortRangeMax.ToString()); _threadStatus.AddElectiveProperty("RemoteIpAddress", _remoteIpAddress); _threadStatus.AddElectiveProperty("RemoteHandshakePort", _remoteHandshakePort.ToString()); _threadStatus.AddElectiveProperty("RemoteHostname", _remoteHostname); }