Inheritance: System.Threading.Tasks.TaskScheduler, IDisposable
Ejemplo n.º 1
0
		public async Task Start ()
		{
			ThrowIfDisposed ();
			var ct = cancellationTokenSource.Token;

			nmqPoller = new Poller ();
			nmqScheduler = new NetMQScheduler (nmqContext, nmqPoller);
			nmqServer = nmqContext.CreateResponseSocket ();
			nmqServer.Bind (Address.AbsoluteUri.TrimEnd ('/'));

			serverTask = Task.Factory.StartNew (() => {
				ct.ThrowIfCancellationRequested ();

				while (true) {
					if (ct.IsCancellationRequested) {
						// clean up here
						ct.ThrowIfCancellationRequested ();
					}
					var msg = nmqServer.Receive ();
					var request = Request.Deserialize (msg);
					var result = Handle (request);

					byte[] output_buffer = result.Serialize ();
					nmqServer.Send (output_buffer);
				}
			}, ct);

			await serverTask;
		}
		public void Start ()
		{
			ThrowIfDisposed ();
			nmqPoller = new Poller ();
			nmqClient = nmqContext.CreateRequestSocket ();
			nmqClient.Connect (Address.AbsoluteUri.TrimEnd ('/'));
			nmqScheduler = new NetMQScheduler (nmqContext, nmqPoller);
			Task.Factory.StartNew (() => nmqPoller.Start (), TaskCreationOptions.LongRunning);
		}
Ejemplo n.º 3
0
 public void Start()
 {
     poller = new Poller();
     clientSocket = context.CreateDealerSocket();
     clientSocket.ReceiveReady += clientSocket_ReceiveReady;
     clientSocket.Connect(address);
     scheduler = new NetMQScheduler(context, poller);
     Task.Factory.StartNew(poller.Start, TaskCreationOptions.LongRunning);
 }
Ejemplo n.º 4
0
		public static ITransportSource GenerateTransportSource(this NetMQSocket socket, NetMQScheduler scheduler)
		{
			return new NetMQSocketTransportSource(socket, scheduler);
		}
		public void Dispose ()
		{
			ThrowIfDisposed ();
			if (!disposed) {
				if (nmqClient != null) {
					nmqPoller.RemoveSocket (nmqClient);
					nmqClient.Close ();
					nmqClient.Dispose ();
				}
				if (nmqPoller != null) {
					nmqPoller.Stop (false);
				}
				if (nmqScheduler != null) {
					nmqScheduler.Dispose ();
				}
				if (nmqContext != null) {
					nmqContext.Terminate ();
					nmqContext.Dispose ();
				}
				nmqClient = null;
				nmqPoller = null;
				nmqScheduler = null;
				nmqContext = null;
				disposed = true;
			}
		}
		public NetMQSocketTransportSource(NetMQSocket socket, NetMQScheduler scheduler)
		{
			_socket = socket;
			_scheduler = scheduler;
			_socket.ReceiveReady += OnReceiveMessage;
		}
Ejemplo n.º 7
0
		private static IDisposable StartNetMQServer()
		{
			var host = new WampHost();

			var serverContext = NetMQContext.Create();
			var serverSocket = serverContext.CreateResponseSocket();// serverContext.CreateRouterSocket();
			var serverPoller = new Poller(serverSocket);
			var serverScheduler = new NetMQScheduler(serverContext, serverPoller);
			serverPoller.PollTillCancelledNonBlocking();

			host.RegisterTransport(new NetMQTransport(serverSocket, serverScheduler),
				new JTokenJsonBinding(), new JTokenMsgpackBinding(), new ProtobufBinding());

			host.Open();

			var realm = host.RealmContainer.GetRealmByName("realm1");
			realm.Services.RegisterCallee(new SumService(), new CalleeNameInterceptor()).Wait(); // add services (aka, RPC endpoints) like this
			// realm.Services.RegisterPublisher // register some event triggerer here

			return host;
		}