##// END OF EJS Templates
Move js donc into function themselves....
Matthias Bussonnier -
Show More
@@ -284,6 +284,7 define([
284 });
284 });
285 };
285 };
286
286
287 Kernel.prototype.restart = function (success, error) {
287 /**
288 /**
288 * POST /api/kernels/[:kernel_id]/restart
289 * POST /api/kernels/[:kernel_id]/restart
289 *
290 *
@@ -293,7 +294,6 define([
293 * @param {function} [success] - function executed on ajax success
294 * @param {function} [success] - function executed on ajax success
294 * @param {function} [error] - functon executed on ajax error
295 * @param {function} [error] - functon executed on ajax error
295 */
296 */
296 Kernel.prototype.restart = function (success, error) {
297 this.events.trigger('kernel_restarting.Kernel', {kernel: this});
297 this.events.trigger('kernel_restarting.Kernel', {kernel: this});
298 this.stop_channels();
298 this.stop_channels();
299
299
@@ -325,6 +325,7 define([
325 });
325 });
326 };
326 };
327
327
328 Kernel.prototype.reconnect = function () {
328 /**
329 /**
329 * Reconnect to a disconnected kernel. This is not actually a
330 * Reconnect to a disconnected kernel. This is not actually a
330 * standard HTTP request, but useful function nonetheless for
331 * standard HTTP request, but useful function nonetheless for
@@ -332,7 +333,6 define([
332 *
333 *
333 * @function reconnect
334 * @function reconnect
334 */
335 */
335 Kernel.prototype.reconnect = function () {
336 if (this.is_connected()) {
336 if (this.is_connected()) {
337 return;
337 return;
338 }
338 }
@@ -344,6 +344,7 define([
344 this.start_channels();
344 this.start_channels();
345 };
345 };
346
346
347 Kernel.prototype._on_success = function (success) {
347 /**
348 /**
348 * Handle a successful AJAX request by updating the kernel id and
349 * Handle a successful AJAX request by updating the kernel id and
349 * name from the response, and then optionally calling a provided
350 * name from the response, and then optionally calling a provided
@@ -352,7 +353,6 define([
352 * @function _on_success
353 * @function _on_success
353 * @param {function} success - callback
354 * @param {function} success - callback
354 */
355 */
355 Kernel.prototype._on_success = function (success) {
356 var that = this;
356 var that = this;
357 return function (data, status, xhr) {
357 return function (data, status, xhr) {
358 if (data) {
358 if (data) {
@@ -366,6 +366,7 define([
366 };
366 };
367 };
367 };
368
368
369 Kernel.prototype._on_error = function (error) {
369 /**
370 /**
370 * Handle a failed AJAX request by logging the error message, and
371 * Handle a failed AJAX request by logging the error message, and
371 * then optionally calling a provided callback.
372 * then optionally calling a provided callback.
@@ -373,7 +374,6 define([
373 * @function _on_error
374 * @function _on_error
374 * @param {function} error - callback
375 * @param {function} error - callback
375 */
376 */
376 Kernel.prototype._on_error = function (error) {
377 return function (xhr, status, err) {
377 return function (xhr, status, err) {
378 utils.log_ajax_error(xhr, status, err);
378 utils.log_ajax_error(xhr, status, err);
379 if (error) {
379 if (error) {
@@ -382,6 +382,7 define([
382 };
382 };
383 };
383 };
384
384
385 Kernel.prototype._kernel_created = function (data) {
385 /**
386 /**
386 * Perform necessary tasks once the kernel has been started,
387 * Perform necessary tasks once the kernel has been started,
387 * including actually connecting to the kernel.
388 * including actually connecting to the kernel.
@@ -389,12 +390,12 define([
389 * @function _kernel_created
390 * @function _kernel_created
390 * @param {Object} data - information about the kernel including id
391 * @param {Object} data - information about the kernel including id
391 */
392 */
392 Kernel.prototype._kernel_created = function (data) {
393 this.id = data.id;
393 this.id = data.id;
394 this.kernel_url = utils.url_join_encode(this.kernel_service_url, this.id);
394 this.kernel_url = utils.url_join_encode(this.kernel_service_url, this.id);
395 this.start_channels();
395 this.start_channels();
396 };
396 };
397
397
398 Kernel.prototype._kernel_connected = function () {
398 /**
399 /**
399 * Perform necessary tasks once the connection to the kernel has
400 * Perform necessary tasks once the connection to the kernel has
400 * been established. This includes requesting information about
401 * been established. This includes requesting information about
@@ -402,7 +403,6 define([
402 *
403 *
403 * @function _kernel_connected
404 * @function _kernel_connected
404 */
405 */
405 Kernel.prototype._kernel_connected = function () {
406 this.events.trigger('kernel_connected.Kernel', {kernel: this});
406 this.events.trigger('kernel_connected.Kernel', {kernel: this});
407 this.events.trigger('kernel_starting.Kernel', {kernel: this});
407 this.events.trigger('kernel_starting.Kernel', {kernel: this});
408 // get kernel info so we know what state the kernel is in
408 // get kernel info so we know what state the kernel is in
@@ -413,6 +413,7 define([
413 });
413 });
414 };
414 };
415
415
416 Kernel.prototype._kernel_dead = function () {
416 /**
417 /**
417 * Perform necessary tasks after the kernel has died. This closing
418 * Perform necessary tasks after the kernel has died. This closing
418 * communication channels to the kernel if they are still somehow
419 * communication channels to the kernel if they are still somehow
@@ -420,17 +421,16 define([
420 *
421 *
421 * @function _kernel_dead
422 * @function _kernel_dead
422 */
423 */
423 Kernel.prototype._kernel_dead = function () {
424 this.stop_channels();
424 this.stop_channels();
425 };
425 };
426
426
427 Kernel.prototype.start_channels = function () {
427 /**
428 /**
428 * Start the `shell`and `iopub` channels.
429 * Start the `shell`and `iopub` channels.
429 * Will stop and restart them if they already exist.
430 * Will stop and restart them if they already exist.
430 *
431 *
431 * @function start_channels
432 * @function start_channels
432 */
433 */
433 Kernel.prototype.start_channels = function () {
434 var that = this;
434 var that = this;
435 this.stop_channels();
435 this.stop_channels();
436 var ws_host_url = this.ws_url + this.kernel_url;
436 var ws_host_url = this.ws_url + this.kernel_url;
@@ -504,19 +504,20 define([
504 this.channels.stdin.onmessage = $.proxy(this._handle_input_request, this);
504 this.channels.stdin.onmessage = $.proxy(this._handle_input_request, this);
505 };
505 };
506
506
507 Kernel.prototype._ws_opened = function (evt) {
507 /**
508 /**
508 * Handle a websocket entering the open state,
509 * Handle a websocket entering the open state,
509 * signaling that the kernel is connected when all channels are open.
510 * signaling that the kernel is connected when all channels are open.
510 *
511 *
511 * @function _ws_opened
512 * @function _ws_opened
512 */
513 */
513 Kernel.prototype._ws_opened = function (evt) {
514 if (this.is_connected()) {
514 if (this.is_connected()) {
515 // all events ready, trigger started event.
515 // all events ready, trigger started event.
516 this._kernel_connected();
516 this._kernel_connected();
517 }
517 }
518 };
518 };
519
519
520 Kernel.prototype._ws_closed = function(ws_url, error) {
520 /**
521 /**
521 * Handle a websocket entering the closed state. This closes the
522 * Handle a websocket entering the closed state. This closes the
522 * other communication channels if they are open. If the websocket
523 * other communication channels if they are open. If the websocket
@@ -526,7 +527,6 define([
526 * @param {string} ws_url - the websocket url
527 * @param {string} ws_url - the websocket url
527 * @param {bool} error - whether the connection was closed due to an error
528 * @param {bool} error - whether the connection was closed due to an error
528 */
529 */
529 Kernel.prototype._ws_closed = function(ws_url, error) {
530 this.stop_channels();
530 this.stop_channels();
531
531
532 this.events.trigger('kernel_disconnected.Kernel', {kernel: this});
532 this.events.trigger('kernel_disconnected.Kernel', {kernel: this});
@@ -553,13 +553,13 define([
553 }
553 }
554 };
554 };
555
555
556 Kernel.prototype.stop_channels = function () {
556 /**
557 /**
557 * Close the websocket channels. After successful close, the value
558 * Close the websocket channels. After successful close, the value
558 * in `this.channels[channel_name]` will be null.
559 * in `this.channels[channel_name]` will be null.
559 *
560 *
560 * @function stop_channels
561 * @function stop_channels
561 */
562 */
562 Kernel.prototype.stop_channels = function () {
563 var that = this;
563 var that = this;
564 var close = function (c) {
564 var close = function (c) {
565 return function () {
565 return function () {
@@ -580,6 +580,7 define([
580 }
580 }
581 };
581 };
582
582
583 Kernel.prototype.is_connected = function () {
583 /**
584 /**
584 * Check whether there is a connection to the kernel. This
585 * Check whether there is a connection to the kernel. This
585 * function only returns true if all channel objects have been
586 * function only returns true if all channel objects have been
@@ -588,7 +589,6 define([
588 * @function is_connected
589 * @function is_connected
589 * @returns {bool} - whether there is a connection
590 * @returns {bool} - whether there is a connection
590 */
591 */
591 Kernel.prototype.is_connected = function () {
592 for (var c in this.channels) {
592 for (var c in this.channels) {
593 // if any channel is not ready, then we're not connected
593 // if any channel is not ready, then we're not connected
594 if (this.channels[c] === null) {
594 if (this.channels[c] === null) {
@@ -601,6 +601,7 define([
601 return true;
601 return true;
602 };
602 };
603
603
604 Kernel.prototype.is_fully_disconnected = function () {
604 /**
605 /**
605 * Check whether the connection to the kernel has been completely
606 * Check whether the connection to the kernel has been completely
606 * severed. This function only returns true if all channel objects
607 * severed. This function only returns true if all channel objects
@@ -609,7 +610,6 define([
609 * @function is_fully_disconnected
610 * @function is_fully_disconnected
610 * @returns {bool} - whether the kernel is fully disconnected
611 * @returns {bool} - whether the kernel is fully disconnected
611 */
612 */
612 Kernel.prototype.is_fully_disconnected = function () {
613 for (var c in this.channels) {
613 for (var c in this.channels) {
614 if (this.channels[c] === null) {
614 if (this.channels[c] === null) {
615 return true;
615 return true;
@@ -618,12 +618,12 define([
618 return false;
618 return false;
619 };
619 };
620
620
621 Kernel.prototype.send_shell_message = function (msg_type, content, callbacks, metadata, buffers) {
621 /**
622 /**
622 * Send a message on the Kernel's shell channel
623 * Send a message on the Kernel's shell channel
623 *
624 *
624 * @function send_shell_message
625 * @function send_shell_message
625 */
626 */
626 Kernel.prototype.send_shell_message = function (msg_type, content, callbacks, metadata, buffers) {
627 if (!this.is_connected()) {
627 if (!this.is_connected()) {
628 throw new Error("kernel is not connected");
628 throw new Error("kernel is not connected");
629 }
629 }
@@ -633,6 +633,7 define([
633 return msg.header.msg_id;
633 return msg.header.msg_id;
634 };
634 };
635
635
636 Kernel.prototype.kernel_info = function (callback) {
636 /**
637 /**
637 * Get kernel info
638 * Get kernel info
638 *
639 *
@@ -643,7 +644,6 define([
643 * The callback will be passed the complete `kernel_info_reply` message documented
644 * The callback will be passed the complete `kernel_info_reply` message documented
644 * [here](http://ipython.org/ipython-doc/dev/development/messaging.html#kernel-info)
645 * [here](http://ipython.org/ipython-doc/dev/development/messaging.html#kernel-info)
645 */
646 */
646 Kernel.prototype.kernel_info = function (callback) {
647 var callbacks;
647 var callbacks;
648 if (callback) {
648 if (callback) {
649 callbacks = { shell : { reply : callback } };
649 callbacks = { shell : { reply : callback } };
@@ -651,6 +651,7 define([
651 return this.send_shell_message("kernel_info_request", {}, callbacks);
651 return this.send_shell_message("kernel_info_request", {}, callbacks);
652 };
652 };
653
653
654 Kernel.prototype.inspect = function (code, cursor_pos, callback) {
654 /**
655 /**
655 * Get info on an object
656 * Get info on an object
656 *
657 *
@@ -663,7 +664,6 define([
663 * @param cursor_pos {integer}
664 * @param cursor_pos {integer}
664 * @param callback {function}
665 * @param callback {function}
665 */
666 */
666 Kernel.prototype.inspect = function (code, cursor_pos, callback) {
667 var callbacks;
667 var callbacks;
668 if (callback) {
668 if (callback) {
669 callbacks = { shell : { reply : callback } };
669 callbacks = { shell : { reply : callback } };
@@ -677,6 +677,7 define([
677 return this.send_shell_message("inspect_request", content, callbacks);
677 return this.send_shell_message("inspect_request", content, callbacks);
678 };
678 };
679
679
680 Kernel.prototype.execute = function (code, callbacks, options) {
680 /**
681 /**
681 * Execute given code into kernel, and pass result to callback.
682 * Execute given code into kernel, and pass result to callback.
682 *
683 *
@@ -726,7 +727,6 define([
726 * arugment. Payload handlers will be passed the corresponding
727 * arugment. Payload handlers will be passed the corresponding
727 * payload and the execute_reply message.
728 * payload and the execute_reply message.
728 */
729 */
729 Kernel.prototype.execute = function (code, callbacks, options) {
730 var content = {
730 var content = {
731 code : code,
731 code : code,
732 silent : true,
732 silent : true,
General Comments 0
You need to be logged in to leave comments. Login now