Removed executors. All traffic goes through RPC

This commit is contained in:
watsonb8
2019-07-10 18:23:19 -04:00
parent e0d5a66cac
commit 6a70b3d90f
5 changed files with 199 additions and 382 deletions

View File

@ -1,21 +1,45 @@
using System;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using Grpc.Core;
using Aurora.Proto;
using Aurora.RemoteImpl;
using Aurora.Proto.Events;
using Aurora.Proto.Party;
using Aurora.Proto.Playback;
namespace Aurora.Services
{
public class ServerService : BaseService<ServerService>
{
private string _hostname = "127.0.0.1";
private int _port = SettingsService.Instance.DefaultPort;
private string _hostname;
private Grpc.Core.Server _server;
//Implementation class declarations
RemotePartyServiceImpl _remotePartyServiceImpl;
RemotePlaybackServiceImpl _remotePlaybackImpl;
RemoteEventServiceImpl _remoteEventImpl;
/// <summary>
/// Constructor. Registers GRPC service implementations.
/// </summary>
public ServerService()
{
string host = GetLocalIPAddress();
if (string.IsNullOrWhiteSpace(host))
{
throw new Exception("This device must have a valid IP address");
}
_hostname = host;
_server = new Grpc.Core.Server
{
Ports = { new ServerPort(_hostname, _port, ServerCredentials.Insecure) }
};
}
public int Port
@ -28,15 +52,18 @@ namespace Aurora.Services
get { return _hostname; }
}
public void Initialize(string hostname)
public bool Initialized
{
this._hostname = hostname;
_server = new Grpc.Core.Server
get
{
Ports = { new ServerPort(_hostname, _port, ServerCredentials.Insecure) }
};
return (_remoteEventImpl != null &&
_remotePartyServiceImpl != null &&
_remotePlaybackImpl != null &&
_server != null);
}
}
/// <summary>
/// Start Server
/// </summary>
@ -44,7 +71,22 @@ namespace Aurora.Services
{
try
{
Console.WriteLine(string.Format("Starting gRPC server at hostname: {0}, port: {1}", _hostname, _port));
if (!Initialized)
{
//Construct implementations
_remotePartyServiceImpl = new RemotePartyServiceImpl();
_remotePlaybackImpl = new RemotePlaybackServiceImpl();
_remoteEventImpl = new RemoteEventServiceImpl();
// Register grpc RemoteService with singleton server service
RegisterService(RemotePartyService.BindService(_remotePartyServiceImpl));
RegisterService(RemotePlaybackService.BindService(_remotePlaybackImpl));
RegisterService(RemoteEventService.BindService(_remoteEventImpl));
}
_server.Start();
}
catch (Exception ex)
@ -71,9 +113,23 @@ namespace Aurora.Services
};
}
public void RegisterService(ServerServiceDefinition definition)
private void RegisterService(ServerServiceDefinition definition)
{
_server.Services.Add(definition);
}
public static string GetLocalIPAddress()
{
string returnIp = "";
var host = Dns.GetHostEntry(Dns.GetHostName());
foreach (var ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
returnIp = ip.ToString();
}
}
return returnIp;
}
}
}