public bool Start() { HostServices.HostServices.Start(); Log.LogInfo("----------------------------------------------------------"); try { int port = Constants.DefaultPort; if (File.Exists(Constants.NodeConfigFileName)) { try { var nodeConfig = SerializationHelper.FormattedSerializer.Deserialize <NodeConfig>(new JsonTextReader(new StringReader(File.ReadAllText(Constants.NodeConfigFileName)))); port = nodeConfig.TcpPort; } catch (Exception e) { Log.LogError($"Error reading configuration file {Constants.NodeConfigFileName} : {e.Message}"); } } else { Log.LogWarning($"Configuration file {Constants.NodeConfigFileName} not found. Using defaults"); } _cacheServer = new Server.Server(new ServerConfig(), true); _listener = new TcpServerChannel(); _cacheServer.Channel = _listener; _listener.Init(port); _listener.Start(); Log.LogInfo("Starting hosted service on port " + port); _cacheServer.StopRequired += (sender, args) => { HostServices.HostServices.Stop(); Stop(); _stopEvent.Set(); }; _cacheServer.Start(); } catch (Exception e) { Log.LogError($"Failed to start host: {e}"); return(false); } Log.LogInfo("Host started successfully"); return(true); }
public void Init() { _serverChannel = new TcpServerChannel(); _server = new Server.Server(new ServerConfig()) { Channel = _serverChannel }; _serverPort = _serverChannel.Init(); _serverChannel.Start(); _server.Start(); Thread.Sleep(500); //be sure the server is started }
public void Init() { _serverChannel1 = new TcpServerChannel(); _server1 = new Server.Server(new NodeConfig { DataPath = "server1" }) { Channel = _serverChannel1 }; _serverPort1 = _serverChannel1.Init(); _serverChannel1.Start(); _server1.Start(); _serverChannel2 = new TcpServerChannel(); _server2 = new Server.Server(new NodeConfig { DataPath = "server2" }) { Channel = _serverChannel2 }; _serverPort2 = _serverChannel2.Init(); _serverChannel2.Start(); _server2.Start(); Thread.Sleep(500); //be sure the server nodes are started _client1 = new DataClient { Channel = new TcpClientChannel(new TcpClientPool(4, 1, "localhost", _serverPort1)), ShardIndex = 0, ShardsCount = 2 }; _client2 = new DataClient { Channel = new TcpClientChannel(new TcpClientPool(4, 1, "localhost", _serverPort2)), ShardIndex = 1, ShardsCount = 2 }; _aggregator = new DataAggregator { CacheClients = { _client1, _client2 } }; _aggregator.DeclareCollection <CacheableTypeOk>(); }
public void Init() { _serverChannel1 = new TcpServerChannel(); _server1 = new Server.Server(new ServerConfig()) { Channel = _serverChannel1 }; _serverPort1 = _serverChannel1.Init(); _serverChannel1.Start(); _server1.Start(); _serverChannel2 = new TcpServerChannel(); _server2 = new Server.Server(new ServerConfig()) { Channel = _serverChannel2 }; _serverPort2 = _serverChannel2.Init(); _serverChannel2.Start(); _server2.Start(); Thread.Sleep(500); //be sure the server nodes are started _client1 = new CacheClient { Channel = new TcpClientChannel(new TcpClientPool(4, 1, "localhost", _serverPort1)), ShardIndex = 0, ShardsCount = 2 }; _client2 = new CacheClient { Channel = new TcpClientChannel(new TcpClientPool(4, 1, "localhost", _serverPort2)), ShardIndex = 1, ShardsCount = 2 }; _aggregator = new Aggregator { CacheClients = { _client1, _client2 } }; _aggregator.RegisterTypeIfNeeded(typeof(CacheableTypeOk)); }
public void Init() { _serverChannel = new TcpServerChannel(); _server = new Server.Server(new NodeConfig()) { Channel = _serverChannel }; _serverPort = _serverChannel.Init(); _serverChannel.Start(); _server.Start(); _client = NewClient(); _client.DeclareCollection <CacheableTypeOk>(); }
public void Init() { _serverChannel = new TcpServerChannel(); _server = new Server.Server(new ServerConfig()) { Channel = _serverChannel }; _serverPort = _serverChannel.Init(); _serverChannel.Start(); _server.Start(); Thread.Sleep(500); //be sure the server is started _client = NewClient(); _client.RegisterTypeIfNeeded(typeof(CacheableTypeOk)); }
public bool Start(string instance) { try { var configFile = Constants.NodeConfigFileName; if (instance != null) { var baseName = configFile.Split('.').FirstOrDefault(); configFile = $"{baseName}_{instance}.json"; } var nodeConfig = new NodeConfig {TcpPort = Constants.DefaultPort, IsPersistent = true}; if (File.Exists(configFile)) { try { var configFromFile = SerializationHelper.FormattedSerializer.Deserialize<NodeConfig>( new JsonTextReader(new StringReader(File.ReadAllText(configFile)))); nodeConfig = configFromFile; HostServices.HostServices.Start(configFromFile.DataPath); Log.LogInfo("----------------------------------------------------------"); Log.LogInfo($"Reading configuration file {configFile} "); } catch (Exception e) { Log.LogError($"Error reading configuration file {configFile} : {e.Message}"); } } else { HostServices.HostServices.Start(nodeConfig.DataPath); Log.LogWarning($"Configuration file {configFile} not found. Using defaults"); } _cacheServer = new global::Server.Server(nodeConfig); _listener = new TcpServerChannel(); _cacheServer.Channel = _listener; _listener.Init(nodeConfig.TcpPort); _listener.Start(); var fullDataPath = Path.GetFullPath(nodeConfig.DataPath ?? Constants.DataPath); var persistentDescription = nodeConfig.IsPersistent ? fullDataPath : " NO"; try { Console.Title = $"Cachalot Core on port {nodeConfig.TcpPort} persistent = {persistentDescription}"; } catch (Exception ) { //ignore this may throw an exception when run in service mode } Log.LogInfo( $"Starting hosted service on port {nodeConfig.TcpPort} persistent = {persistentDescription}"); _cacheServer.StopRequired += (sender, args) => { HostServices.HostServices.Stop(); Stop(); _stopEvent.Set(); }; _cacheServer.Start(); } catch (Exception e) { Log.LogError($"Failed to start host: {e}"); return false; } Log.LogInfo("Host started successfully"); return true; }
public bool Start(HostControl hostControl) { HostServices.HostServices.Start(); Log.LogInfo("----------------------------------------------------------"); try { var nodeConfig = new NodeConfig { TcpPort = Constants.DefaultPort, IsPersistent = true }; if (File.Exists(Constants.NodeConfigFileName)) { try { var configFromFile = SerializationHelper.FormattedSerializer.Deserialize <NodeConfig>( new JsonTextReader(new StringReader(File.ReadAllText(Constants.NodeConfigFileName)))); nodeConfig = configFromFile; } catch (Exception e) { Log.LogError($"Error reading configuration file {Constants.NodeConfigFileName} : {e.Message}"); } } else { Log.LogWarning($"Configuration file {Constants.NodeConfigFileName} not found. Using defaults"); } _cacheServer = new Server.Server(nodeConfig); _listener = new TcpServerChannel(); _cacheServer.Channel = _listener; _listener.Init(nodeConfig.TcpPort); _listener.Start(); var fullDataPath = Path.GetFullPath(nodeConfig.DataPath ?? Constants.DataPath); var persistentDescription = nodeConfig.IsPersistent ? fullDataPath : " NO"; Log.LogInfo( $"Starting Cachalot server on port {nodeConfig.TcpPort} persistent {persistentDescription}"); Console.Title = $"Cachalot server on port {nodeConfig.TcpPort} persistent = {persistentDescription}"; _cacheServer.Start(); } catch (Exception e) { Log.LogError($"Failed to start host: {e}"); return(false); } Log.LogInfo("Host started successfully"); return(true); }