public Task StartAsync(CancellationToken cancellationToken) { SetupDefaultMimeTypes(); _shell.Bind(_shellAddress); _ioPubSocket.Bind(_ioPubAddress); _stdIn.Bind(_stdInAddress); _control.Bind(_controlAddress); var kernelIdentity = Guid.NewGuid().ToString(); Task.Run(async() => { using var activity = Log.OnEnterAndExit(); while (!cancellationToken.IsCancellationRequested) { var request = _shell.GetMessage(); activity.Info("Received: {message}", request.ToJson()); SetBusy(request); switch (request.Header.MessageType) { case JupyterMessageContentTypes.KernelInfoRequest: kernelIdentity = Encoding.Unicode.GetString(request.Identifiers[0].ToArray()); HandleKernelInfoRequest(request); SetIdle(request); break; case JupyterMessageContentTypes.KernelShutdownRequest: SetIdle(request); break; default: var context = new JupyterRequestContext( _shellChannel, _ioPubChannel, _stdInChannel, request, kernelIdentity); await _scheduler.Schedule(context); await context.Done(); SetIdle(request); break; } } }, cancellationToken); void SetBusy(ZeroMQMessage request) => _ioPubChannel.Publish(new Status(StatusValues.Busy), request, kernelIdentity); void SetIdle(ZeroMQMessage request) => _ioPubChannel.Publish(new Status(StatusValues.Idle), request, kernelIdentity); return(Task.CompletedTask); }
public async Task StartAsync(CancellationToken cancellationToken) { _shell.Bind(_shellAddress); _ioPubSocket.Bind(_ioPubAddress); _stdIn.Bind(_stdInAddress); _control.Bind(_controlAddress); var id = Guid.NewGuid().ToString(); using (var activity = Log.OnEnterAndExit()) { SetStarting(); while (!cancellationToken.IsCancellationRequested) { var message = _shell.GetMessage(); activity.Info("Received: {message}", message.ToJson()); SetBusy(); switch (message.Header.MessageType) { case JupyterMessageContentTypes.KernelInfoRequest: id = Encoding.Unicode.GetString(message.Identifiers[0].ToArray()); HandleKernelInfoRequest(message); SetIdle(); break; case JupyterMessageContentTypes.KernelShutdownRequest: SetIdle(); break; default: var context = new JupyterRequestContext( _shellSender, _ioPubSender, message, id); await _scheduler.Schedule(context); await context.Done(); SetIdle(); break; } } void SetBusy() => _ioPubSender.Send(Message.Create(new Status(StatusValues.Busy), identifiers: new [] { Message.Topic("status", id) })); void SetIdle() => _ioPubSender.Send(Message.Create(new Status(StatusValues.Idle), identifiers: new[] { Message.Topic("status", id) })); void SetStarting() => _ioPubSender.Send(Message.Create(new Status(StatusValues.Starting), identifiers: new[] { Message.Topic("status", id) })); } }
public async Task StartAsync(CancellationToken cancellationToken) { _shell.Bind(_shellAddress); _ioPubSocket.Bind(_ioPubAddress); _stdIn.Bind(_stdInAddress); _control.Bind(_controlAddress); using (var activity = Log.OnEnterAndExit()) { while (!cancellationToken.IsCancellationRequested) { var message = _shell.GetMessage(); activity.Info("Received: {message}", message.ToJson()); SetBusy(); switch (message.Header.MessageType) { case JupyterMessageContentTypes.KernelInfoRequest: HandleKernelInfoRequest(message); SetIdle(); break; case JupyterMessageContentTypes.KernelShutdownRequest: SetIdle(); break; default: var context = new JupyterRequestContext( _shellSender, _ioPubSender, message); await _scheduler.Schedule(context); await context.Done(); SetIdle(); break; } void SetBusy() => _shellSender.Send(Message.Create(new Status(StatusValues.Busy), message.Header)); void SetIdle() => _shellSender.Send(Message.Create(new Status(StatusValues.Busy), message.Header)); } } }
public async Task StartAsync(CancellationToken cancellationToken) { _shell.Bind(_shellAddress); _ioPubSocket.Bind(_ioPubAddress); _stdIn.Bind(_stdInAddress); _control.Bind(_controlAddress); using (var activity = Logger <Shell> .Log.OnEnterAndExit()) { while (!cancellationToken.IsCancellationRequested) { var message = _shell.GetMessage(); activity.Info("Received: {message}", message.ToJson()); var status = new RequestHandlerStatus(message.Header, new MessageSender(_ioPubSocket, _signatureValidator)); switch (message.Header.MessageType) { case MessageTypeValues.KernelInfoRequest: status.SetAsBusy(); HandleKernelInfoRequest(message); status.SetAsIdle(); break; case MessageTypeValues.KernelShutdownRequest: status.SetAsBusy(); status.SetAsIdle(); break; default: var context = new JupyterRequestContext( _shellSender, _ioPubSender, message, new RequestHandlerStatus(message.Header, _shellSender)); await _scheduler.Schedule(context); break; } } } }