/// <summary> /// Stop node discovery and interconnection /// </summary> private void Stop() { if (!_isRunning) { return; } _loggerDelegate?.Invoke($"Stopping {_name} {_uuid.ToShortString6()}. Publishing beacon on port 0. Removing _beacon and _inbox from poller."); // Stop broadcast/listen beacon by broadcasting port 0 PublishBeacon(0); Thread.Sleep(1); // Allow 1 millisecond for beacon to go out _poller.Remove(_beacon); _beacon.ReceiveReady -= OnBeaconReady; _beacon.Unsubscribe(); _beacon.Dispose(); _beacon = null; // Stop polling on inbox _poller.Remove(_inbox); _inbox.ReceiveReady -= OnInboxReady; _inbox.Dispose(); // Tell the application we are stopping var msg = new NetMQMessage(3); msg.Append("STOP"); msg.Append(_uuid.ToByteArray()); msg.Append(_name); _outbox.SendMultipartMessage(msg); _isRunning = false; }
public void Unsubscribe() { using (NetMQContext context = NetMQContext.Create()) { using (NetMQBeacon speaker = new NetMQBeacon(context)) { speaker.Configure(9999); using (NetMQBeacon listener = new NetMQBeacon(context)) { listener.Configure(9999); listener.Subscribe("H"); // this should send one broadcast message and stop speaker.Publish("Hello"); string peerName; string message = listener.ReceiveString(out peerName); listener.Unsubscribe(); Assert.AreEqual("Hello", message); ISocketPollable socket = listener; socket.Socket.Options.ReceiveTimeout = TimeSpan.FromSeconds(2); Assert.Throws <AgainException>(() => { message = listener.ReceiveString(out peerName); }); } } } }
public void Unsubscribe() { using (var speaker = new NetMQBeacon()) using (var listener = new NetMQBeacon()) { speaker.Configure(9999); listener.Configure(9999); listener.Subscribe("H"); // this should send one broadcast message and stop speaker.Publish("Hello", s_publishInterval); Thread.Sleep(10); listener.Unsubscribe(); Assert.AreEqual("Hello", listener.Receive().String); Assert.IsFalse(listener.TryReceive(TimeSpan.FromMilliseconds(300), out BeaconMessage message)); } }
public void Unsubscribe() { using (var speaker = new NetMQBeacon()) using (var listener = new NetMQBeacon()) { speaker.Configure(9999); listener.Configure(9999); listener.Subscribe("H"); // this should send one broadcast message and stop speaker.Publish("Hello", s_publishInterval); Thread.Sleep(10); listener.Unsubscribe(); Assert.AreEqual("Hello", listener.Receive().String); BeaconMessage message; Assert.IsFalse(listener.TryReceive(TimeSpan.FromMilliseconds(300), out message)); } }
public void Stop() { if (!IsRunning) { return; } this._nodes.Clear(); _poller.Stop(); _beacon.Unsubscribe(); _poller.Remove(_beacon); _poller.Remove(timer); _poller.Dispose(); _poller = null; _beacon.Dispose(); _beacon = null; timer = null; }
public void Unsubscribe() { using (var context = NetMQContext.Create()) using (var speaker = new NetMQBeacon(context)) using (var listener = new NetMQBeacon(context)) { speaker.Configure(9999); listener.Configure(9999); listener.Subscribe("H"); // this should send one broadcast message and stop speaker.Publish("Hello"); string peerName; string message = listener.ReceiveString(out peerName); listener.Unsubscribe(); Assert.AreEqual("Hello", message); ISocketPollable socket = listener; socket.Socket.Options.ReceiveTimeout = TimeSpan.FromSeconds(2); Assert.Throws<AgainException>(() => { message = listener.ReceiveString(out peerName); }); } }