/// <summary> /// Begin connecting. /// </summary> /// <param name="wait">Whether to wait a bit before actually attempting to connect</param> private void StartConnecting(bool wait) { Debug.Assert(m_connect); // Choose I/O thread to run connector in. Given that we are already // running in an I/O thread, there must be at least one available. IOThread?ioThread = ChooseIOThread(m_options.Affinity); Assumes.NotNull(ioThread); // Create the connector object. switch (m_addr.Protocol) { case Address.TcpProtocol: { LaunchChild(new TcpConnector(ioThread, this, m_options, m_addr, wait)); return; } case Address.IpcProtocol: { LaunchChild(new IpcConnector(ioThread, this, m_options, m_addr, wait)); return; } case Address.PgmProtocol: case Address.EpgmProtocol: { var pgmSender = new PgmSender(m_ioThread, m_options, m_addr, wait); Assumes.NotNull(m_addr.Resolved); pgmSender.Init((PgmAddress)m_addr.Resolved); SendAttach(this, pgmSender); return; } } Debug.Assert(false); }
public void Start() { lock (syncRoot) { if (this.running) { return; } this.running = true; } if (this.enabled) { try { if (this.protocol == ProtocolType.Pgm) { PgmSender sender; if (!NetworkInterface.GetIsNetworkAvailable()) { log.Warn("CounterPublisher could not started because no network connection is available."); return; } try { sender = new PgmSender(this.endPoint); if (this.sendInterface == null) { sender.Connect(); } else { sender.Connect(this.sendInterface.ToString()); } } catch (Exception exception) { log.WarnFormat("CounterPublisher could not started. To publish counter values the PGM protocol must be installed.\r\n: Error={0}", new object[] { exception }); throw; } this.socketSender = sender; } else if (this.protocol == ProtocolType.Udp) { UdpSender sender2 = new UdpSender(this.endPoint); sender2.Start(); this.socketSender = sender2; } else { this.socketSender = new HttpSender(this.address); } this.counterSender = new CounterSampleSender(this.senderId, this.sendInterval, this.socketSender, this.maxRequestsInQueue, -1, this.maxItemsPerRequest); this.counterSenderSubsciption = this.counterSender.SubscribeToChannel(this.counterPublisher.Channel); this.counterSender.OnDisconnected += new EventHandler(this.OnCounterSenderDisconnected); this.counterSender.OnError += new EventHandler <UnhandledExceptionEventArgs>(this.OnCounterSenderError); this.counterPublisher.Start(); this.counterSender.Start(); log.InfoFormat("CounterPublisher started on: {0}", new object[] { this.address }); } catch (SocketException exception2) { log.WarnFormat("CounterPublisher could not be created: ReturnCode={0}, Message={1}", new object[] { exception2.SocketErrorCode, exception2.Message }); throw; } } }
private void StartConnecting(bool wait) { Debug.Assert(m_connect); // Choose I/O thread to run connector in. Given that we are already // running in an I/O thread, there must be at least one available. IOThread ioThread = ChooseIOThread(m_options.Affinity); Debug.Assert(ioThread != null); // Create the connector object. if (m_addr.Protocol.Equals(Address.TcpProtocol)) { var connector = new TcpConnector(ioThread, this, m_options, m_addr, wait); //alloc_Debug.Assert(connector); LaunchChild(connector); return; } if (m_addr.Protocol.Equals(Address.IpcProtocol)) { var connector = new IpcConnector(ioThread, this, m_options, m_addr, wait); //alloc_Debug.Assert(connector); LaunchChild(connector); return; } if (m_addr.Protocol.Equals(Address.PgmProtocol) || m_addr.Protocol.Equals(Address.EpgmProtocol)) { var pgmSender = new PgmSender(m_ioThread, m_options, m_addr); pgmSender.Init(m_addr.Resolved as PgmAddress); SendAttach(this, pgmSender); return; } Debug.Assert(false); }