/// <summary> /// Create new NetMQQueue. /// </summary> /// <param name="context">NetMQContext must be provided to the queue</param> /// <param name="capacity">The capacity of the queue, use zero for unlimited</param> public NetMQQueue(NetMQContext context, int capacity = 0) { m_context = context; m_queue = new ConcurrentQueue <T>(); m_writer = m_context.CreatePairSocket(); m_reader = m_context.CreatePairSocket(); if (capacity != 0) { m_writer.Options.SendHighWatermark = m_reader.Options.ReceiveHighWatermark = capacity / 2; } else { m_writer.Options.SendHighWatermark = m_reader.Options.ReceiveHighWatermark = 0; } m_eventDelegator = new EventDelegator <NetMQQueueEventArgs <T> >(() => { m_reader.ReceiveReady += OnReceiveReady; }, () => { m_reader.ReceiveReady -= OnReceiveReady; }); string address = string.Format("inproc://NetMQQueue#{0}", Interlocked.Increment(ref s_sequence)); m_reader.Bind(address); m_writer.Connect(address); m_dequeueMsg = new Msg(); m_dequeueMsg.InitEmpty(); }
/// <summary> /// Create a new NetMQBeacon. /// </summary> public NetMQBeacon() { m_actor = NetMQActor.Create(new Shim()); m_receiveEvent = new EventDelegator <NetMQBeaconEventArgs>( () => m_actor.ReceiveReady += OnReceive, () => m_actor.ReceiveReady -= OnReceive); }
/// <summary> /// Create a new NetMQBeacon. /// </summary> public NetMQBeacon() { m_actor = NetMQActor.Create(new Shim()); void OnReceive(object sender, NetMQActorEventArgs e) => m_receiveEvent.Fire(this, new NetMQBeaconEventArgs(this)); m_receiveEvent = new EventDelegator <NetMQBeaconEventArgs>( () => m_actor.ReceiveReady += OnReceive, () => m_actor.ReceiveReady -= OnReceive); }
private NetMQActor(PairSocket self, PairSocket shim, IShimHandler shimHandler) { m_shimHandler = shimHandler; m_self = self; m_shim = shim; EventHandler <NetMQSocketEventArgs> onReceive = (sender, e) => m_receiveEvent.Fire(this, new NetMQActorEventArgs(this)); EventHandler <NetMQSocketEventArgs> onSend = (sender, e) => m_sendEvent.Fire(this, new NetMQActorEventArgs(this)); m_receiveEvent = new EventDelegator <NetMQActorEventArgs>( () => m_self.ReceiveReady += onReceive, () => m_self.ReceiveReady -= onReceive); m_sendEvent = new EventDelegator <NetMQActorEventArgs>( () => m_self.SendReady += onSend, () => m_self.SendReady -= onSend); var random = new Random(); // Bind and connect pipe ends string actorName; string endPoint; while (true) { try { actorName = string.Format("NetMQActor-{0}-{1}", random.Next(0, 10000), random.Next(0, 10000)); endPoint = string.Format("inproc://{0}", actorName); m_self.Bind(endPoint); break; } catch (AddressAlreadyInUseException) { // Loop around and try another random address } } m_shim.Connect(endPoint); m_shimThread = new Thread(RunShim) { Name = actorName }; m_shimThread.Start(); // Mandatory handshake for new actor so that constructor returns only // when actor has also initialised. This eliminates timing issues at // application start up. m_self.ReceiveSignal(); }
/// <summary> /// Create a new NetMQBeacon, contained within the given context. /// </summary> /// <param name="context">the NetMQContext to contain this new socket</param> public NetMQBeacon([NotNull] NetMQContext context) { m_actor = NetMQActor.Create(context, new Shim()); EventHandler <NetMQActorEventArgs> onReceive = (sender, e) => m_receiveEvent.Fire(this, new NetMQBeaconEventArgs(this)); m_receiveEvent = new EventDelegator <NetMQBeaconEventArgs>( () => m_actor.ReceiveReady += onReceive, () => m_actor.ReceiveReady -= onReceive); }
private NetMQActor([NotNull] NetMQContext context, [NotNull] IShimHandler shimHandler) { m_shimHandler = shimHandler; m_self = context.CreatePairSocket(); m_shim = context.CreatePairSocket(); EventHandler <NetMQSocketEventArgs> onReceive = (sender, e) => m_receiveEvent.Fire(this, new NetMQActorEventArgs(this)); EventHandler <NetMQSocketEventArgs> onSend = (sender, e) => m_sendEvent.Fire(this, new NetMQActorEventArgs(this)); m_receiveEvent = new EventDelegator <NetMQActorEventArgs>( () => m_self.ReceiveReady += onReceive, () => m_self.ReceiveReady -= onReceive); m_sendEvent = new EventDelegator <NetMQActorEventArgs>( () => m_self.SendReady += onSend, () => m_self.SendReady -= onSend); var random = new Random(); //now binding and connect pipe ends string endPoint; while (true) { try { endPoint = string.Format("inproc://NetMQActor-{0}-{1}", random.Next(0, 10000), random.Next(0, 10000)); m_self.Bind(endPoint); break; } catch (AddressAlreadyInUseException) { // In case address already in use we continue searching for an address } } m_shim.Connect(endPoint); m_shimThread = new Thread(RunShim); m_shimThread.Start(); // Mandatory handshake for new actor so that constructor returns only // when actor has also initialised. This eliminates timing issues at // application start up. m_self.ReceiveSignal(); }
/// <summary> /// Create new NetMQQueue. /// </summary> /// <param name="capacity">The capacity of the queue, use zero for unlimited</param> public NetMQQueue(int capacity = 0) { if (capacity < 0) { throw new ArgumentOutOfRangeException(nameof(capacity)); } m_queue = new ConcurrentQueue <T>(); PairSocket.CreateSocketPair(out m_writer, out m_reader); m_writer.Options.SendHighWatermark = m_reader.Options.ReceiveHighWatermark = capacity / 2; m_eventDelegator = new EventDelegator <NetMQQueueEventArgs <T> >( () => m_reader.ReceiveReady += OnReceiveReady, () => m_reader.ReceiveReady -= OnReceiveReady); m_dequeueMsg = new Msg(); m_dequeueMsg.InitEmpty(); }