Beispiel #1
0
        private void EventLoop(NetMQSocket socket)
        {
            this.logger.LogDebug("Starting shell server event loop at {Address}.", socket);
            while (alive)
            {
                try
                {
                    // Start by pulling off the next <action>_request message
                    // from the client.
                    var nextMessage = socket.ReceiveMessage(context);
                    logger.LogDebug(
                        $"Received new message:\n" +
                        $"\t{JsonConvert.SerializeObject(nextMessage.Header)}\n" +
                        $"\t{JsonConvert.SerializeObject(nextMessage.ParentHeader)}\n" +
                        $"\t{JsonConvert.SerializeObject(nextMessage.Metadata)}\n" +
                        $"\t{JsonConvert.SerializeObject(nextMessage.Content)}"
                        );

                    // If this is our first message, we need to set the session
                    // id.
                    if (session == null)
                    {
                        session = nextMessage.Header.Session;
                    }

                    // Get a service that can handle the message type and
                    // dispatch.
                    switch (nextMessage.Header.MessageType)
                    {
                    case "kernel_info_request":
                        KernelInfoRequest?.Invoke(nextMessage);
                        break;

                    case "execute_request":
                        ExecuteRequest?.Invoke(nextMessage);
                        break;

                    case "shutdown_request":
                        ShutdownRequest?.Invoke(nextMessage);
                        break;
                    }
                }
                catch (ProtocolViolationException ex)
                {
                    logger.LogCritical(ex, $"Protocol violation when trying to receive next ZeroMQ message.");
                }
                catch (ThreadInterruptedException)
                {
                    if (alive)
                    {
                        continue;
                    }
                    else
                    {
                        return;
                    }
                }
            }
        }
Beispiel #2
0
        public ShellServer(
            ILogger <ShellServer> logger,
            IOptions <KernelContext> context,
            IServiceProvider provider,
            IShellRouter router
            )
        {
            this.logger   = logger;
            this.context  = context.Value;
            this.provider = provider;
            this.router   = router;

            router.RegisterHandler("kernel_info_request", message => KernelInfoRequest?.Invoke(message));
            router.RegisterHandler("execute_request", message => ExecuteRequest?.Invoke(message));
            router.RegisterHandler("shutdown_request", message => ShutdownRequest?.Invoke(message));
        }
 protected ActionResult ExecuteRequestAndHandle(ExecuteRequest executeRequest, int responseCode)
 {
     try
     {
         return(RestErrorHandler.Handle(() =>
         {
             Log.Info(string.Format("Entering {0} method", executeRequest.Method));
             executeRequest.Invoke();
             var response = this.StatusCode(responseCode);
             Log.Info(string.Format("Leaving {0} method", executeRequest.Method));
             return response;
         }));
     }
     catch (Exception ex)
     {
         return(this.ProcessException(ex));
     }
 }