Exemplo n.º 1
0
        /// <summary>
        /// Initialize TcpSessionManager: activates handshake receiver and starts listening to session receivers for incoming messages
        /// </summary>
        public void Initialize()
        {
            try
            {
                //initialize
                logger.Info("[" + _description + "-M] Initializing");

                //set up handshake receiver & thread
                _handshakeReceiver = new TcpReceiver(_ipAddress, _portRangeMin, _portRangeMax, "(local)", _evtConsumer, _utilsBus, _applicationName + ".TcpSessionManager", _t1_HR_ThreadStatus.NodeID);
                _handshakeReceiver.StartListening(_applicationName + ".TcpSessionManager.Initialize");

                //get handshake port that was assigned
                _handshakePort = _handshakeReceiver.Port;

                //watch handshake receiver for session data
                //then set up specific sessions with session data
                _t1_HR_ThreadStatus.IsThreadEnabled = true;
                t1_HandshakeReceiver = new System.Threading.Thread(PollHandshakeReceiverThreadImpl);
                t1_HandshakeReceiver.Start();

                //watch sessions for incoming messages
                _t2_SRL_ThreadStatus.IsThreadEnabled = true;
                t2_SessionReceiverList = new System.Threading.Thread(PollSessionReceiverListThreadImpl);
                t2_SessionReceiverList.Start();

                //_evtRaiser.RaiseEvent("Status", "Initialized", string.Empty);

                //thread status
                _t1_HR_ThreadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_STARTED;
                _t2_SRL_ThreadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_STARTED;

                _initialized = true;
            }
            catch (Exception ex)
            {
                logger.Error("[" + _description + "-M] Error initializing: " + ex.Message, ex);
                throw ex;
            }
        }
Exemplo n.º 2
0
        /// <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);
        }