Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Commit

Permalink
Begin adding support for Comm
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaykul committed Mar 4, 2018
1 parent 177117c commit 3de5bfd
Show file tree
Hide file tree
Showing 8 changed files with 815 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Jupyter/Messages/CommMessage.cs
@@ -0,0 +1,20 @@
// namespace Jupyter.Messages
// {
// using System.Linq;
// using System.Collections.Generic;
// using Newtonsoft.Json;

// public class CommMessage : Message
// {
// public CommMessage()
// {
// Data = new Dictionary<string, object>();
// }

// [JsonProperty("data")]
// public Dictionary<string, object> Data { get; set; } = new Dictionary<string, object>();

// [JsonProperty("comm_id")]
// public string CommId { get; set; } = string.Empty;
// }
// }
18 changes: 18 additions & 0 deletions Jupyter/Messages/CommOpenMessage.cs
@@ -0,0 +1,18 @@
// namespace Jupyter.Messages
// {
// using System.Linq;
// using System.Collections.Generic;
// using Newtonsoft.Json;

// public class CommOpenMessage: CommMessage
// {

// public CommOpenMessage(string name) : base()
// {
// Target = name;
// }

// [JsonProperty("target_name")]
// public string Target { get; set; } = string.Empty;
// }
// }
28 changes: 28 additions & 0 deletions Jupyter/Messages/Content/CommInfoReplyContent.cs
@@ -0,0 +1,28 @@
namespace Jupyter.Messages
{
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;

public class CommInfoReplyContent : Content
{

public CommInfoReplyContent()
{
Comms = new Dictionary<string, TargetName>();
}

public CommInfoReplyContent(Dictionary<string, TargetName> comms)
{
Comms = comms;
}

public CommInfoReplyContent(Dictionary<string, string> comms)
{
Comms = comms.ToDictionary(kvp => kvp.Key, kvp => new TargetName(kvp.Value));
}

[JsonProperty("comms")]
public Dictionary<string, TargetName> Comms { get; set; }
}
}
15 changes: 15 additions & 0 deletions Jupyter/Messages/Content/TargetName.cs
@@ -0,0 +1,15 @@
namespace Jupyter.Messages
{
using Newtonsoft.Json;

public class TargetName : Content
{
public TargetName(string name)
{
Name = name;
}

[JsonProperty("target_name")]
public string Name { get; set; } = string.Empty;
}
}
37 changes: 37 additions & 0 deletions Jupyter/Server/Handlers/CommInfoHandler.cs
@@ -0,0 +1,37 @@
namespace Jupyter.Server.Handlers
{
using Microsoft.Extensions.Logging;
using Jupyter.Messages;
using NetMQ.Sockets;
using Newtonsoft.Json;

public class CommInfoHandler : IMessageHandler
{
private readonly ILogger _logger;


public CommInfoHandler(ILogger logger)
{
_logger = logger;
}

public void HandleMessage(Message message, RouterSocket serverSocket, PublisherSocket ioPub)
{
TargetName targetName = message.Content as TargetName;
Message replyMessage = new Message(MessageType.CommInfoReply, CreateCommInfoReply(targetName), message.Header);

_logger.LogInformation("Sending comm_info_reply");
serverSocket.SendMessage(replyMessage);
}

private CommInfoReplyContent CreateCommInfoReply(TargetName name)
{
CommInfoReplyContent CommInfoReply = new CommInfoReplyContent( new System.Collections.Generic.Dictionary<string, TargetName> { })
{

};

return CommInfoReply;
}
}
}
28 changes: 28 additions & 0 deletions Jupyter/Server/Handlers/CommOpenHandler.cs
@@ -0,0 +1,28 @@
// namespace Jupyter.Server.Handlers
// {
// using Microsoft.Extensions.Logging;
// using Jupyter.Messages;
// using NetMQ.Sockets;
// using Newtonsoft.Json;

// public class CommOpenHandler : IMessageHandler
// {
// private readonly ILogger _logger;


// public CommOpenHandler(ILogger logger)
// {
// _logger = logger;
// }

// public void HandleMessage(Message message, RouterSocket serverSocket, PublisherSocket ioPub)
// {
// TargetName targetName = message.Content as TargetName;
// Message replyMessage = new Message(MessageType.CommClose, message.Header);

// _logger.LogInformation("Sending comm_info_reply");
// serverSocket.SendMessage(replyMessage);
// }

// }
// }

0 comments on commit 3de5bfd

Please sign in to comment.