public StreamerDevice(NetMQContext context, INetMQPoller poller, string frontendBindAddress, string backendBindAddress, DeviceMode mode = DeviceMode.Threaded) : base(poller, context.CreatePullSocket(), context.CreatePushSocket(), mode) { FrontendSetup.Bind(frontendBindAddress); BackendSetup.Bind(backendBindAddress); }
/// <summary> /// Initializes a new instance of the <see cref="ForwarderDevice"/> class. /// </summary> /// <param name="frontendBindAddress">The endpoint used to bind the frontend socket.</param> /// <param name="backendBindAddress">The endpoint used to bind the backend socket.</param> /// <param name="mode">The <see cref="DeviceMode"/> for the device.</param> public StreamerDevice(string frontendBindAddress, string backendBindAddress, DeviceMode mode = DeviceMode.Threaded) : base(new PullSocket(), new PushSocket(), mode) { FrontendSetup.Bind(frontendBindAddress); BackendSetup.Bind(backendBindAddress); }
/// <summary> /// Initializes a new instance of the <see cref="ForwarderDevice"/> class. /// </summary> /// <param name="context">The <see cref="NetMQContext"/> to use when creating the sockets.</param> /// <param name="poller">The <see cref="Poller"/> to use.</param> /// <param name="frontendBindAddress">The endpoint used to bind the frontend socket.</param> /// <param name="backendBindAddress">The endpoint used to bind the backend socket.</param> /// <param name="mode">The <see cref="DeviceMode"/> for the device.</param> public ForwarderDevice(NetMQContext context, Poller poller, string frontendBindAddress, string backendBindAddress, DeviceMode mode = DeviceMode.Threaded) : base(poller, context.CreateSubscriberSocket(), context.CreatePublisherSocket(), mode) { FrontendSetup.Bind(frontendBindAddress); BackendSetup.Bind(backendBindAddress); }
/// <summary> /// Initializes a new instance of the <see cref="ForwarderDevice"/> class. /// </summary> public PubSubDevice(ZContext context, string frontendBindAddr, string backendBindAddr) : base(context, FrontendType, BackendType) { FrontendSetup.Bind(frontendBindAddr); BackendSetup.Bind(backendBindAddr); BackendSetup.SubscribeAll(); }
/// <summary> /// Initializes a new instance of the <see cref="QueueDevice"/> class. /// </summary> /// <param name="context">The <see cref="NetMQContext"/> to use when creating the sockets.</param> /// <param name="poller">The <see cref="Poller"/> to use.</param> /// <param name="frontendBindAddress">The endpoint used to bind the frontend socket.</param> /// <param name="backendBindAddress">The endpoint used to bind the backend socket.</param> /// <param name="mode">The <see cref="DeviceMode"/> for the device.</param> public QueueDevice(NetMQContext context, Poller poller, string frontendBindAddress, string backendBindAddress, DeviceMode mode = DeviceMode.Threaded) : base(poller, context.CreateRouterSocket(), context.CreateDealerSocket(), mode) { FrontendSetup.Bind(frontendBindAddress); BackendSetup.Bind(backendBindAddress); }
/// <summary> /// Initializes a new instance of the <see cref="ForwarderDevice"/> class. /// </summary> /// <param name="poller">The <see cref="INetMQPoller"/> to use.</param> /// <param name="frontendBindAddress">The endpoint used to bind the frontend socket.</param> /// <param name="backendBindAddress">The endpoint used to bind the backend socket.</param> /// <param name="mode">The <see cref="DeviceMode"/> for the device.</param> public ForwarderDevice(INetMQPoller poller, string frontendBindAddress, string backendBindAddress, DeviceMode mode = DeviceMode.Threaded) : base(poller, new SubscriberSocket(), new PublisherSocket(), mode) { FrontendSetup.Bind(frontendBindAddress); BackendSetup.Bind(backendBindAddress); }
/*/ <summary> * /// Gets a <see cref="ManualResetEvent"/> that can be used to block while the device is running. * /// </summary> * public ManualResetEvent DoneEvent { get; private set; } /**/ /*/ <summary> * /// Gets an <see cref="AutoResetEvent"/> that is pulsed after every Poll call. * /// </summary> * public AutoResetEvent PollerPulse * { * get { return _poller.Pulse; } * }*/ /// <summary> /// Initializes the frontend and backend sockets. Called automatically when starting the device. /// If called multiple times, will only execute once. /// </summary> public virtual void Initialize() { EnsureNotDisposed(); if (FrontendSetup != null) { FrontendSetup.Configure(); } if (BackendSetup != null) { BackendSetup.Configure(); } }
/// <summary> /// Initializes a new instance of the <see cref="StreamDealerDevice"/> class. /// </summary> public StreamDealerDevice(ZContext context, string frontendBindAddr, string backendBindAddr) : base(context, FrontendType, BackendType) { FrontendSetup.Bind(frontendBindAddr); BackendSetup.Bind(backendBindAddr); }
/// <summary> /// Initializes a new instance of the <see cref="QueueDevice"/> class. /// </summary> /// <param name="frontendBindAddress">The endpoint used to bind the frontend socket.</param> /// <param name="backendBindAddress">The endpoint used to bind the backend socket.</param> /// <param name="mode">The <see cref="DeviceMode"/> for the device.</param> public QueueDevice(string frontendBindAddress, string backendBindAddress, DeviceMode mode = DeviceMode.Threaded) : base(new RouterSocket(), new DealerSocket(), mode) { FrontendSetup.Bind(frontendBindAddress); BackendSetup.Bind(backendBindAddress); }
/// <summary> /// Initializes a new instance of the <see cref="StreamerDevice"/> class. /// </summary> public PushPullDevice(ZContext context, string frontendBindAddr, string backendBindAddr) : base(context, FrontendType, BackendType) { FrontendSetup.Bind(frontendBindAddr); BackendSetup.Bind(backendBindAddr); }
/// <summary> /// Initializes a new instance of the <see cref="ForwarderDevice"/> class. /// </summary> /// <param name="context">The <see cref="ZmqContext"/> to use when creating the sockets.</param> /// <param name="frontendBindAddr">The address used to bind the frontend socket.</param> /// <param name="backendBindAddr">The endpoint used to bind the backend socket.</param> /// <param name="mode">The <see cref="DeviceMode"/> for the current device.</param> public ForwarderDevice(ZmqContext context, string frontendBindAddr, string backendBindAddr, DeviceMode mode) : this(context, mode) { FrontendSetup.Bind(frontendBindAddr); BackendSetup.Bind(backendBindAddr); }
/// <summary> /// Start the device in the current thread. Should be used by implementations of the <see cref="DeviceRunner.Start"/> method. /// </summary> /// <remarks> /// Initializes the sockets prior to starting the device with <see cref="Initialize"/>. /// </remarks> protected override void Run() { EnsureNotDisposed(); Initialize(); ZSocket[] sockets; ZPollItem[] polls; if (FrontendSocket != null && BackendSocket != null) { sockets = new ZSocket[] { FrontendSocket, BackendSocket }; polls = new ZPollItem[] { ZPollItem.Create(FrontendHandler), ZPollItem.Create(BackendHandler) }; } else if (FrontendSocket != null) { sockets = new ZSocket[] { FrontendSocket }; polls = new ZPollItem[] { ZPollItem.Create(FrontendHandler) }; } else { sockets = new ZSocket[] { BackendSocket }; polls = new ZPollItem[] { ZPollItem.Create(BackendHandler) }; } /* ZPollItem[] polls; * { * var pollItems = new List<ZPollItem>(); * switch (FrontendSocket.SocketType) * { * case ZSocketType.Code.ROUTER: * case ZSocketType.Code.XSUB: * case ZSocketType.Code.PUSH: * // case ZSocketType.Code.STREAM: * pollItems.Add(new ZPollItem(FrontendSocket, ZPoll.In) * { * ReceiveMessage = FrontendHandler * }); * * break; * } * switch (BackendSocket.SocketType) * { * case ZSocketType.Code.DEALER: * // case ZSocketType.Code.STREAM: * pollItems.Add(new ZPollItem(BackendSocket, ZPoll.In) * { * ReceiveMessage = BackendHandler * }); * * break; * } * polls = pollItems.ToArray(); * } */ // Because of using ZmqSocket.Forward, this field will always be null ZMessage[] lastMessageFrames = null; if (FrontendSetup != null) { FrontendSetup.BindConnect(); } if (BackendSetup != null) { BackendSetup.BindConnect(); } bool isValid = false; var error = default(ZError); try { while (_running) { if (!(isValid = sockets.Poll(polls, ZPoll.In, ref lastMessageFrames, out error, PollingInterval))) { if (error == ZError.EAGAIN) { Thread.Sleep(1); continue; } if (error == ZError.ETERM) { break; } // EFAULT throw new ZException(error); } } } catch (ZException) { // Swallow any exceptions thrown while stopping if (_running) { throw; } } if (FrontendSetup != null) { FrontendSetup.UnbindDisconnect(); } if (BackendSetup != null) { BackendSetup.UnbindDisconnect(); } if (error == ZError.ETERM) { Close(); } }
/// <summary> /// Initializes a new instance of the <see cref="QueueDevice"/> class that will run in a /// self-managed thread. /// </summary> /// <param name="context">The <see cref="ZmqContext"/> to use when creating the sockets.</param> /// <param name="frontendBindAddr">The endpoint used to bind the frontend socket.</param> /// <param name="backendBindAddr">The endpoint used to bind the backend socket.</param> public QueueDevice(ZmqContext context, string frontendBindAddr, string backendBindAddr) : this(context) { FrontendSetup.Bind(frontendBindAddr); BackendSetup.Bind(backendBindAddr); }
/// <summary> /// Initializes a new instance of the <see cref="PubSubDevice"/> class. /// </summary> public PubSubDevice(ZContext context) : base(context, FrontendType, BackendType) { BackendSetup.SubscribeAll(); }
/// <summary> /// Initializes the frontend and backend sockets. Called automatically when starting the device. /// If called multiple times, will only execute once. /// </summary> public void Initialize() { FrontendSetup.Configure(); BackendSetup.Configure(); }