Example #1
0
        public Actor(NetMQContext context,
                     IShimHandler <T> shimHandler, T state)
        {
            this.m_self = context.CreatePairSocket();
            this.m_shim = new Shim <T>(shimHandler, context.CreatePairSocket());
            this.m_self.Options.SendHighWatermark = 1000;
            this.m_self.Options.SendHighWatermark = 1000;
            this.m_state = state;

            m_receiveEventDelegatorHelper = new EventDelegatorHelper <NetMQActorEventArgs <T> >(() => m_self.ReceiveReady += OnReceive,
                                                                                                () => m_self.ReceiveReady += OnReceive);
            m_sendEventDelegatorHelper = new EventDelegatorHelper <NetMQActorEventArgs <T> >(() => m_self.SendReady += OnReceive,
                                                                                             () => m_self.SendReady += OnSend);

            //now binding and connect pipe ends
            string endPoint = string.Empty;

            while (true)
            {
                Action bindAction = () =>
                {
                    endPoint = GetEndPointName();
                    m_self.Bind(endPoint);
                };

                try
                {
                    bindAction();
                    break;
                }
                catch (NetMQException nex)
                {
                    if (nex.ErrorCode == ErrorCode.EFAULT)
                    {
                        bindAction();
                    }
                }
            }

            m_shim.Pipe.Connect(endPoint);

            //Initialise the shim handler
            this.m_shim.Handler.Initialise(state);

            //Create Shim thread handler
            CreateShimThread(state);

            //  Mandatory handshake for new actor so that constructor returns only
            //  when actor has also initialized. This eliminates timing issues at
            //  application start up.
            m_self.WaitForSignal();
        }
Example #2
0
        private void LaunchViewForm(GpfProjectFile project)
        {
            _socket.Send(BitConverter.GetBytes((int)ServerCodes.Util));
            int reply = BitConverter.ToInt32(_socket.Receive(), 0);

            if (reply != (int)ServerCodes.Util)
            {
                throw new Exception("Count funtion failure. Server response was invalid.");
            }

            int port = Convert.ToInt32(tbTcpPort.Text) + 1;

            _socket.Send(BitConverter.GetBytes(port));

            reply = BitConverter.ToInt32(_socket.Receive(), 0);
            if (reply != port)
            {
                throw new Exception("Count funtion failure. Server response was invalid.");
            }

            ViewForm frm = new ViewForm();

            NetMQSocket countSocket = _context.CreatePairSocket();

            countSocket.Connect("tcp://" + tbAddress.Text + ":" + port);


            frm.Initialise(new ViewFormSetup(countSocket, project, Gpus));

            this.Hide();
            frm.Show();
        }
Example #3
0
        public Actor(NetMQContext context,
                     IShimHandler <T> shimHandler, T state)
        {
            this.self = context.CreatePairSocket();
            this.shim = new Shim <T>(shimHandler, context.CreatePairSocket());
            this.self.Options.SendHighWatermark = 1000;
            this.self.Options.SendHighWatermark = 1000;
            this.state = state;

            //now binding and connect pipe ends
            string endPoint = string.Empty;

            while (true)
            {
                Action bindAction = () =>
                {
                    endPoint = GetEndPointName();
                    self.Bind(endPoint);
                };

                try
                {
                    bindAction();
                    break;
                }
                catch (NetMQException nex)
                {
                    if (nex.ErrorCode == ErrorCode.EFAULT)
                    {
                        bindAction();
                    }
                }
            }

            shim.Pipe.Connect(endPoint);

            //Initialise the shim handler
            this.shim.Handler.Initialise(state);

            //Create Shim thread handler
            CreateShimThread(state);
        }
        public NetMQMonitor(NetMQContext context, NetMQSocket monitoredSocket, string endpoint, SocketEvents eventsToMonitor)
        {
            Endpoint = endpoint;
            Timeout  = TimeSpan.FromSeconds(0.5);

            monitoredSocket.Monitor(endpoint, eventsToMonitor);

            m_monitoringSocket = context.CreatePairSocket();
            m_monitoringSocket.Options.Linger = TimeSpan.Zero;
            m_monitoringSocket.ReceiveReady  += Handle;

            m_ownsMonitoringSocket = true;
        }
Example #5
0
        protected WSSocket(NetMQContext context, IShimHandler<int> shimHandler )
        {
            int id = Interlocked.Increment(ref s_id);
            m_context = context;

            m_messagesPipe = context.CreatePairSocket();
            m_messagesPipe.Bind(string.Format("inproc://wsrouter-{0}", id));

            m_messagesPipe.ReceiveReady += OnMessagePipeReceiveReady;

            m_actor = new Actor<int>(context, shimHandler, id);

            m_messagesPipe.WaitForSignal();
        }
Example #6
0
        protected WSSocket(NetMQContext context, IShimHandler <int> shimHandler)
        {
            int id = Interlocked.Increment(ref s_id);

            m_context = context;

            m_messagesPipe = context.CreatePairSocket();
            m_messagesPipe.Bind(string.Format("inproc://wsrouter-{0}", id));

            m_messagesPipe.ReceiveReady += OnMessagePipeReceiveReady;

            m_actor = new Actor <int>(context, shimHandler, id);

            m_messagesPipe.WaitForSignal();
        }
        public void RunPipeline(PairSocket shim)
        {
            shim.SignalOK();

            shim.ReceiveReady += OnShimReady;

            m_messagesPipe = m_context.CreatePairSocket();
            m_messagesPipe.Connect(string.Format("inproc://wsrouter-{0}", m_id));
            m_messagesPipe.ReceiveReady += OnMessagePipeReady;

            m_stream = m_context.CreateStreamSocket();
            m_stream.ReceiveReady += OnStreamReady;

            m_poller = new Poller(m_messagesPipe, shim, m_stream);

            m_messagesPipe.SignalOK();

            m_poller.Start();

            m_messagesPipe.Dispose();
            m_stream.Dispose();
        }