Exemple #1
0
        protected Device(IZmqContext ctx, string frontEndEndpoint, string backendEndpoint,
                         SocketType frontendType, SocketType backendType, bool enableCapture = false)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            if (string.IsNullOrEmpty(frontEndEndpoint))
            {
                throw new ArgumentNullException("frontEndEndpoint");
            }
            if (string.IsNullOrEmpty(backendEndpoint))
            {
                throw new ArgumentNullException("backendEndpoint");
            }

            this._ctx           = ctx;
            this._frontendType  = frontendType;
            this._backendType   = backendType;
            this._enableCapture = enableCapture;
            this._ownSockets    = true;
            this._needsBinding  = true;

            this.FrontEndEndpoint = frontEndEndpoint;
            this.BackendEndpoint  = backendEndpoint;
        }
 public CastleZmqSocketFactory(IZmqContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     _context = context;
 }
        public RequestPoll(IZmqContext context)
        {
            this._context          = context;
            this._endpoint2Sockets = new ConcurrentDictionary <string, EndpointPoll>(StringComparer.InvariantCultureIgnoreCase);
            this._socketsInUse     = new HashSet <IZmqSocket>();

            this._context.Disposing += OnZmqContextDisposing;
        }
Exemple #4
0
		public RequestPoll(IZmqContext context)
		{
			this._context = context;
			this._endpoint2Sockets = new ConcurrentDictionary<string, EndpointPoll>(StringComparer.InvariantCultureIgnoreCase);
			this._socketsInUse = new HashSet<IZmqSocket>();

			this._context.Disposing += OnZmqContextDisposing;
		}
Exemple #5
0
 public WorkerPool(IZmqContext ctx, string frontEndEndpoint, string backendEndpoint,
                   Action <byte[], IZmqSocket> proc, int workers, bool enableCapture = false)
     : base(ctx, frontEndEndpoint, backendEndpoint, enableCapture)
 {
     this._ctx             = ctx;
     this._backendEndpoint = backendEndpoint;
     this._proc            = proc;
     this._workers         = workers;
 }
Exemple #6
0
 public RemoteRequestListener2(IZmqContext context, string endpoint, int workers,
                               LocalInvocationDispatcher dispatcher,
                               SerializationStrategy serializationStrategy)
 {
     _endpoint              = endpoint;
     _dispatcher            = dispatcher;
     _serializationStrategy = serializationStrategy;
     _reply = context.Rep();
 }
Exemple #7
0
		public WorkerPool(IZmqContext ctx, string frontEndEndpoint, string backendEndpoint,
						  Action<byte[], IZmqSocket> proc, int workers, bool enableCapture = false)
			: base(ctx, frontEndEndpoint, backendEndpoint, enableCapture)
		{
			this._ctx = ctx;
			this._backendEndpoint = backendEndpoint;
			this._proc = proc;
			this._workers = workers;
		}
		public RemoteRequestListener2(IZmqContext context, string endpoint, int workers,
			LocalInvocationDispatcher dispatcher,
			SerializationStrategy serializationStrategy)
		{
			_endpoint = endpoint;
			_dispatcher = dispatcher;
			_serializationStrategy = serializationStrategy;
			_reply = context.Rep();
		}
Exemple #9
0
 public RemoteRequestService(IZmqContext context,
                             RemoteEndpointRegistry endpointRegistry,
                             SerializationStrategy serializationStrategy,
                             RequestPoll requestPoll)
 {
     this._context               = context;
     this._endpointRegistry      = endpointRegistry;
     this._serializationStrategy = serializationStrategy;
     this._requestPoll           = requestPoll;
 }
Exemple #10
0
        public RemoteRequest(IZmqContext context, string endpoint,
                             RequestMessage requestMessage,
                             SerializationStrategy serializationStrategy) : base(context, endpoint)
        {
            this._endpoint              = endpoint;
            this._requestMessage        = requestMessage;
            this._serializationStrategy = serializationStrategy;

            this.Timeout = 30 * 1000;
        }
		public RemoteRequestService(IZmqContext context, 
									RemoteEndpointRegistry endpointRegistry, 
									SerializationStrategy serializationStrategy, 
									RequestPoll requestPoll)
		{
			this._context = context;
			this._endpointRegistry = endpointRegistry;
			this._serializationStrategy = serializationStrategy;
			this._requestPoll = requestPoll;
		}
Exemple #12
0
        public RemoteRequestListener(IZmqContext context, string endpoint, int workers,
                                     LocalInvocationDispatcher dispatcher,
                                     SerializationStrategy serializationStrategy)
        {
            this._context               = context;
            this._endpoint              = endpoint;
            this._workers               = workers;
            this._dispatcher            = dispatcher;
            this._serializationStrategy = serializationStrategy;

            var count = Interlocked.Increment(ref localAddUseCounter);

            this._localEndpoint = "inproc://rrworker_" + count;
        }
        public MonitoredSocket(IZmqContext context, IZmqSocket socket)
        {
            this._socket = socket;

            this._monitor              = new Castle.Zmq.Monitor(socket, context);
            this._monitor.SocketEvent += (sender, args) =>
            {
                switch (args.Event)
                {
                case MonitorEvents.BindFailed:
                case MonitorEvents.AcceptFailed:
                case MonitorEvents.CloseFailed:
                    if (!_inError)
                    {
                        _inError = true;
                        Thread.MemoryBarrier();

                        FireError(args);
                    }
                    break;

                case MonitorEvents.ConnectRetried:
                case MonitorEvents.Closed:
                case MonitorEvents.Disconnected:
                    if (!_disconnected)
                    {
                        _disconnected = true;
                        _connected    = false;
                        Thread.MemoryBarrier();

                        FireDisconnected(args);
                    }
                    break;

                case MonitorEvents.Connected:
                case MonitorEvents.Listening:
                    if (!_connected)
                    {
                        _connected = true;
                        _inError   = _disconnected = false;
                        Thread.MemoryBarrier();

                        FireConnected(args);
                    }
                    break;
                }
            };
        }
Exemple #14
0
        protected BaseRequest(IZmqContext context, string endpoint)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            this._context  = context;
            this._endpoint = endpoint;

            this.Timeout = Socket.InfiniteTimeout;
        }
Exemple #15
0
		protected Device(IZmqContext ctx, string frontEndEndpoint, string backendEndpoint,
						 SocketType frontendType, SocketType backendType, bool enableCapture = false)
		{
			if (ctx == null) throw new ArgumentNullException("ctx");
			if (string.IsNullOrEmpty(frontEndEndpoint)) throw new ArgumentNullException("frontEndEndpoint");
			if (string.IsNullOrEmpty(backendEndpoint)) throw new ArgumentNullException("backendEndpoint");

			this._ctx = ctx;
			this._frontendType = frontendType;
			this._backendType = backendType;
			this._enableCapture = enableCapture;
			this._ownSockets = true;
			this._needsBinding = true;

			this.FrontEndEndpoint = frontEndEndpoint;
			this.BackendEndpoint = backendEndpoint;
		}
		public MonitoredSocket(IZmqContext context, IZmqSocket socket)
		{
			this._socket = socket;

			this._monitor = new Castle.Zmq.Monitor(socket, context);
			this._monitor.SocketEvent += (sender, args) =>
			{
				switch (args.Event)
				{
					case MonitorEvents.BindFailed:
					case MonitorEvents.AcceptFailed:
					case MonitorEvents.CloseFailed:
						if (!_inError)
						{
							_inError = true;
							Thread.MemoryBarrier();

							FireError(args);
						}
						break;
					case MonitorEvents.ConnectRetried:
					case MonitorEvents.Closed:
					case MonitorEvents.Disconnected:
						if (!_disconnected)
						{
							_disconnected = true;
							_connected = false;
							Thread.MemoryBarrier();

							FireDisconnected(args);
						}
						break;
					case MonitorEvents.Connected:
					case MonitorEvents.Listening:
						if (!_connected)
						{
							_connected = true;
							_inError = _disconnected = false;
							Thread.MemoryBarrier();

							FireConnected(args);
						}
						break;
				}
			};
		}
Exemple #17
0
        public Monitor(IZmqSocket socket, IZmqContext context,
                       string monitorName   = null,
                       MonitorEvents events = MonitorEvents.All)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (monitorName != null)
            {
                if (!monitorName.StartsWith("inproc://"))
                {
                    monitorName = "inproc://" + monitorName;
                }
            }
            else
            {
                monitorName = "inproc://temp" + Rnd.Next(0, Int32.MaxValue);
            }

            this._monitorName = monitorName;

            // Creates a inproc socket pair
            var res = Native.Monitor.zmq_socket_monitor(socket.Handle(), monitorName, (int)events);

            if (res == Native.ErrorCode)
            {
                Native.ThrowZmqError("Monitor");
            }

            // Connects to the newly created socket pair
            this._pairSocket = context.Pair();
            this._pairSocket.Connect(this._monitorName);

            this._thread = new Thread(EventsWorker)
            {
                IsBackground = true
            };
            this._thread.Start();
        }
Exemple #18
0
        protected BasePublisher(IZmqContext context, string endpoint, Func <T, byte[]> serializer)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }
            if (serializer == null)
            {
                throw new ArgumentNullException("serializer");
            }

            this._context    = context;
            this._endpoint   = endpoint;
            this._serializer = serializer;
        }
        protected BaseSubscriber(IZmqContext context, string endpoint, Func <byte[], T> deserializer)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }
            if (deserializer == null)
            {
                throw new ArgumentNullException("deserializer");
            }

            this._context      = context;
            this._endpoint     = endpoint;
            this._deserializer = deserializer;
        }
Exemple #20
0
		public Monitor(IZmqSocket socket, IZmqContext context, 
					   string monitorName = null, 
					   MonitorEvents events = MonitorEvents.All)
		{
			if (socket == null) throw new ArgumentNullException("socket");
			if (context == null) throw new ArgumentNullException("context");

			if (monitorName != null)
			{
				if (!monitorName.StartsWith("inproc://"))
					monitorName = "inproc://" + monitorName;
			}
			else
			{
				monitorName = "inproc://temp" + Rnd.Next(0, Int32.MaxValue);
			}

			this._monitorName = monitorName;

			// Creates a inproc socket pair
			var res = Native.Monitor.zmq_socket_monitor(socket.Handle(), monitorName, (int)events);
			if (res == Native.ErrorCode)
			{
				Native.ThrowZmqError("Monitor");
			}

			// Connects to the newly created socket pair
			this._pairSocket = context.Pair();
			this._pairSocket.Connect(this._monitorName);

			this._thread = new Thread(EventsWorker)
			{
				IsBackground = true
			};
			this._thread.Start();
		}
		public RemoteRequestListener(IZmqContext context, string endpoint, int workers, 
									 LocalInvocationDispatcher dispatcher, 
									 SerializationStrategy serializationStrategy)
		{
			this._context = context;
			this._endpoint = endpoint;
			this._workers = workers;
			this._dispatcher = dispatcher;
			this._serializationStrategy = serializationStrategy;

			var count = Interlocked.Increment(ref localAddUseCounter);
			this._localEndpoint = "inproc://rrworker_" + count;
		}
Exemple #22
0
 public ZmqRpcCleaner(IZmqContext context)
 {
     _context = context;
 }
Exemple #23
0
 public MySub(IZmqContext context, string endpoint) : base(context, endpoint, Deserializer)
 {
 }
Exemple #24
0
 public SharedQueue(IZmqContext ctx, string frontEndEndpoint, string backendEndpoint, bool enableCapture = false)
     : base(ctx, frontEndEndpoint, backendEndpoint, SocketType.Router, SocketType.Dealer, enableCapture)
 {
 }
 public static IZmqSocket Dealer(this IZmqContext source)
 {
     return(source.CreateSocket(SocketType.Dealer));
 }
 public static IZmqSocket XSub(this IZmqContext source)
 {
     return(source.CreateSocket(SocketType.XSub));
 }
Exemple #27
0
		public ZmqRpcCleaner(IZmqContext context)
		{
			_context = context;
		}
Exemple #28
0
		public Forwarder(IZmqContext ctx, string frontEndEndpoint, string backendEndpoint, bool enableCapture = false)
			: base(ctx, frontEndEndpoint, backendEndpoint, SocketType.XSub, SocketType.XPub, enableCapture)
		{
		}
 public static IZmqSocket Req(this IZmqContext source)
 {
     return(source.CreateSocket(SocketType.Req));
 }
 public static IZmqSocket Pair(this IZmqContext source)
 {
     return(source.CreateSocket(SocketType.Pair));
 }
Exemple #31
0
		public SharedQueue(IZmqContext ctx, string frontEndEndpoint, string backendEndpoint, bool enableCapture = false)
			: base(ctx, frontEndEndpoint, backendEndpoint, SocketType.Router, SocketType.Dealer, enableCapture)
		{
		}
Exemple #32
0
 public Forwarder(IZmqContext ctx, string frontEndEndpoint, string backendEndpoint, bool enableCapture = false)
     : base(ctx, frontEndEndpoint, backendEndpoint, SocketType.XSub, SocketType.XPub, enableCapture)
 {
 }