private void RunActor(PairSocket shim)
{
// save the shim to the class to use later
m_shim = shim;
// create all subscriber, publisher and beacon
using (m_subscriber = new SubscriberSocket())
using (m_publisher = new PublisherSocket())
using (m_beacon = new NetMQBeacon())
{
// listen to actor commands
m_shim.ReceiveReady += OnShimReady;
// subscribe to all messages
m_subscriber.Subscribe("");
// we bind to a random port, we will later publish this port
// using the beacon
m_randomPort = m_subscriber.BindRandomPort("tcp://*");
Console.WriteLine("Bus subscriber is bound to {0}", m_subscriber.Options.LastEndpoint);
// listen to incoming messages from other publishers, forward them to the shim
m_subscriber.ReceiveReady += OnSubscriberReady;
// configure the beacon to listen on the broadcast port
Console.WriteLine("Beacon is being configured to UDP port {0}", m_broadcastPort);
m_beacon.Configure(m_broadcastPort);
// publishing the random port to all other nodes
Console.WriteLine("Beacon is publishing the Bus subscriber port {0}", m_randomPort);
m_beacon.Publish(m_randomPort.ToString(), TimeSpan.FromSeconds(1));
// Subscribe to all beacon on the port
Console.WriteLine("Beacon is subscribing to all beacons on UDP port {0}", m_broadcastPort);
m_beacon.Subscribe("");
// listen to incoming beacons
m_beacon.ReceiveReady += OnBeaconReady;
// Create a timer to clear dead nodes
NetMQTimer timer = new NetMQTimer(TimeSpan.FromSeconds(1));
timer.Elapsed += ClearDeadNodes;
// Create and configure the poller with all sockets and the timer
m_poller = new NetMQPoller { m_shim, m_subscriber, m_beacon, timer };
// signal the actor that we finished with configuration and
// ready to work
m_shim.SignalOK();
// polling until cancelled
m_poller.Run();
}
}