|
77 | 77 | (require 'jupyter-repl)
|
78 | 78 | (require 'jupyter-rest-api)
|
79 | 79 | (require 'jupyter-kernel-manager)
|
80 |
| -(require 'jupyter-ioloop-comm) |
81 |
| -(require 'jupyter-server-ioloop) |
82 | 80 |
|
83 | 81 | (declare-function jupyter-tramp-file-name-p "jupyter-tramp" (filename))
|
84 | 82 | (declare-function jupyter-tramp-server-from-file-name "jupyter-tramp" (filename))
|
@@ -109,7 +107,6 @@ Used in, e.g. a `jupyter-server-kernel-list-mode' buffer.")
|
109 | 107 | ;; `jupyter-server-client' since it isn't a representation of a server, but a
|
110 | 108 | ;; communication channel with one.
|
111 | 109 | (defclass jupyter-server (jupyter-rest-client
|
112 |
| - jupyter-ioloop-comm |
113 | 110 | eieio-instance-tracker)
|
114 | 111 | ((tracking-symbol :initform 'jupyter--servers)
|
115 | 112 | (kernelspecs
|
@@ -265,17 +262,21 @@ ID of the kernel will be associated with NAME, see
|
265 | 262 |
|
266 | 263 | (cl-defgeneric jupyter-server-kernel-connected-p ((client jupyter-server) id)
|
267 | 264 | "Return non-nil if CLIENT can communicate with a kernel that has ID.")
|
| 265 | + |
| 266 | +;; TODO: Move the following two functions to jupyter-server-ioloop-comm.el |
268 | 267 | (defun jupyter-server--connect-channels (server id)
|
269 |
| - (jupyter-send server 'connect-channels id) |
270 |
| - (jupyter-with-timeout |
271 |
| - (nil jupyter-default-timeout |
272 |
| - (error "Timeout when connecting websocket to kernel id %s" id)) |
273 |
| - (jupyter-server-kernel-connected-p server id))) |
| 268 | + (when (object-of-class-p server 'jupyter-comm-layer) |
| 269 | + (jupyter-send server 'connect-channels id) |
| 270 | + (jupyter-with-timeout |
| 271 | + (nil jupyter-default-timeout |
| 272 | + (error "Timeout when connecting websocket to kernel id %s" id)) |
| 273 | + (jupyter-server-kernel-connected-p server id)))) |
274 | 274 |
|
275 | 275 | (defun jupyter-server--refresh-comm (server)
|
276 | 276 | "Stop and then start SERVER communication.
|
277 | 277 | Reconnect the previously connected kernels when starting."
|
278 |
| - (when (jupyter-comm-alive-p server) |
| 278 | + (when (and (object-of-class-p server 'jupyter-comm-layer) |
| 279 | + (jupyter-comm-alive-p server)) |
279 | 280 | (let ((connected (cl-remove-if-not
|
280 | 281 | (apply-partially #'jupyter-server-kernel-connected-p server)
|
281 | 282 | (mapcar (lambda (kernel) (plist-get kernel :id))
|
@@ -408,7 +409,10 @@ MANAGER's COMM slot will be set to the `jupyter-comm-layer'
|
408 | 409 | receiving events on the websocket when this method returns."
|
409 | 410 | (with-slots (kernel comm) manager
|
410 | 411 | (unless (slot-boundp manager 'comm)
|
411 |
| - (oset manager comm (jupyter-server-kernel-comm :kernel kernel))) |
| 412 | + (oset manager comm |
| 413 | + (if (object-of-class-p (oref kernel server) 'jupyter-comm-layer) |
| 414 | + (jupyter-server-ioloop-kernel-comm :kernel kernel) |
| 415 | + (jupyter-server-kernel-comm :kernel kernel)))) |
412 | 416 | (unless (jupyter-comm-alive-p comm)
|
413 | 417 | (jupyter-comm-start comm))))
|
414 | 418 |
|
@@ -508,6 +512,18 @@ least the following keys:
|
508 | 512 | (define-error 'jupyter-server-non-existent
|
509 | 513 | "The server doesn't exist")
|
510 | 514 |
|
| 515 | +(defun jupyter-server-make-instance (&rest args) |
| 516 | + "Return a different subclass of `jupyter-server' depending on `jupyter-server-use-zmq'. |
| 517 | +A `jupyter-server-ioloop-comm' object is returned if |
| 518 | +`jupyter-server-use-zmq' is non-nil, a `jupyter-server' is |
| 519 | +returned otherwise. ARGS is passed to the `make-instance' |
| 520 | +invocation for the subclass." |
| 521 | + (if jupyter-server-use-zmq |
| 522 | + (progn |
| 523 | + (require 'jupyter-server-ioloop-comm) |
| 524 | + (apply #'jupyter-server-ioloop-comm args)) |
| 525 | + (apply #'jupyter-server args))) |
| 526 | + |
511 | 527 | (defun jupyter-current-server (&optional ask)
|
512 | 528 | "Return an existing `jupyter-server' or ASK for a new one.
|
513 | 529 | If ASK is non-nil, always ask for a URL and return the
|
@@ -546,7 +562,7 @@ a URL."
|
546 | 562 | (setf (url-type u) "ws")
|
547 | 563 | (url-recreate-url u)))))
|
548 | 564 | (or (jupyter-find-server url ws-url)
|
549 |
| - (let ((server (jupyter-server :url url :ws-url ws-url))) |
| 565 | + (let ((server (jupyter-server-make-instance :url url :ws-url ws-url))) |
550 | 566 | (if (jupyter-api-server-exists-p server) server
|
551 | 567 | (delete-instance server)
|
552 | 568 | (signal 'jupyter-server-non-existent (list url)))))))))
|
|
0 commit comments