/// <summary> /// Initializes the current instance with a contained <see cref="RelayNode"/> /// </summary> /// <param name="dataHandler">The data handler.</param> /// <param name="relayNode">The relay node.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="dataHandler"/> is null /// or when <paramref name="relayNode"/> is null.</exception> public SocketServerRelayMessageHandler(IDataHandler dataHandler, IRelayNode relayNode) { if (dataHandler == null) throw new ArgumentNullException("dataHandler"); if (relayNode == null) throw new ArgumentNullException("relayNode"); _dataHandler = dataHandler; _relayNode = relayNode; }
/// <summary> /// Starts the server and loads the <see cref="IRelayNode"/> instance's assembly. /// </summary> /// <param name="runStates">State information to start the instance with.</param> /// <exception cref="Exception">Thrown when an error occurs, caller should call <see cref="Stop"/> in this cass.</exception> public void Start(ComponentRunState[] runStates) { bool setDllDirectorySuccess = SetDllDirectory(assemblyPath); if (setDllDirectorySuccess) { if (log.IsInfoEnabled) { log.InfoFormat("Set DllDirectory to {0}. Unmanaged dlls will be imported from this folder.", assemblyPath); } } else { if (log.IsErrorEnabled) { log.ErrorFormat("Failed to set DllDirectory to {0}. Components that rely on unmanaged DLLs will not work.", assemblyPath); } } if (log.IsInfoEnabled) { log.Info("Getting new node."); } //enable this manually after the server is up an running because on server startup //code that modifies the directory will cause the domain to reload. AssemblyLoader.Instance.EnableRaisingEvents = false; relayNode = AssemblyLoader.Instance.GetRelayNode(nodeChangedDelegate); if (relayNode != null) { if (log.IsInfoEnabled) { log.Info("New node created."); log.Info("Initializing Relay Node Instance"); } relayNode.Initialize(runStates); if (log.IsInfoEnabled) { log.Info("Relay Node Initialized, Starting"); } relayNode.Start(); if (log.IsInfoEnabled) { log.Info("Relay Node Started"); } AssemblyLoader.Instance.EnableRaisingEvents = true; } else { if (log.IsErrorEnabled) { log.Error("Error starting Relay Server: No Relay Node implemenation found!"); } } }
/// <summary> /// Initializes the current instance with a contained <see cref="RelayNode"/> /// </summary> /// <param name="dataHandler">The data handler.</param> /// <param name="relayNode">The relay node.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="dataHandler"/> is null /// or when <paramref name="relayNode"/> is null.</exception> public SocketServerRelayMessageHandler(IDataHandler dataHandler, IRelayNode relayNode) { if (dataHandler == null) { throw new ArgumentNullException("dataHandler"); } if (relayNode == null) { throw new ArgumentNullException("relayNode"); } _dataHandler = dataHandler; _relayNode = relayNode; }
/// <summary> /// Stops the server, reloads the assembly and restarts the server. /// </summary> public void AssemblyChanged() //should rename to ReloadAssembly { try { //preserve state information between assembly reloads ComponentRunState[] runStates = GetRunState(); Stop(); Start(runStates); } catch (Exception ex) { if (log.IsErrorEnabled) { log.Error("Exception recycling Relay Node Domain: " + ex.ToString() + Environment.NewLine + "Trying again with no runstate."); } relayNode = AssemblyLoader.Instance.GetRelayNode(nodeChangedDelegate); relayNode.Initialize(null); relayNode.Start(); } }
/// <summary> /// Stops the server and unloads the <see cref="IRelayNode"/> instance's assembly. /// </summary> /// <exception cref="Exception">Thrown when an error occurs.</exception> public void Stop() { if (relayNode != null) { try { if (log.IsInfoEnabled) { log.Info("Stopping Relay Node."); } relayNode.Stop(); if (log.IsInfoEnabled) { log.Info("Relay Node Stopped."); log.Info("Releasing old domain."); } AssemblyLoader.Instance.ReleaseRelayNode(); if (log.IsInfoEnabled) { log.Info("Old domain released."); } relayNode = null; } catch (Exception ex) { if (log.IsErrorEnabled) { log.ErrorFormat("Error shutting down relay node: {0}", ex); } } } else { if (log.IsErrorEnabled) { log.Error("No Node To Stop."); } } }
/// <summary> /// Starts the server and loads the <see cref="IRelayNode"/> instance's assembly. /// </summary> /// <param name="runStates">State information to start the instance with.</param> /// <exception cref="Exception">Thrown when an error occurs, caller should call <see cref="Stop"/> in this cass.</exception> public void Start(ComponentRunState[] runStates) { bool setDllDirectorySuccess = SetDllDirectory(assemblyPath); if (setDllDirectorySuccess) { if (log.IsInfoEnabled) log.InfoFormat("Set DllDirectory to {0}. Unmanaged dlls will be imported from this folder.", assemblyPath); } else { if (log.IsErrorEnabled) log.ErrorFormat("Failed to set DllDirectory to {0}. Components that rely on unmanaged DLLs will not work.", assemblyPath); } if (log.IsInfoEnabled) log.Info("Getting new node."); //enable this manually after the server is up an running because on server startup //code that modifies the directory will cause the domain to reload. AssemblyLoader.Instance.EnableRaisingEvents = false; relayNode = AssemblyLoader.Instance.GetRelayNode(nodeChangedDelegate); if (relayNode != null) { if (log.IsInfoEnabled) { log.Info("New node created."); log.Info("Initializing Relay Node Instance"); } relayNode.Initialize(runStates); if (log.IsInfoEnabled) log.Info("Relay Node Initialized, Starting"); relayNode.Start(); if (log.IsInfoEnabled) log.Info("Relay Node Started"); AssemblyLoader.Instance.EnableRaisingEvents = true; } else { if (log.IsErrorEnabled) log.Error("Error starting Relay Server: No Relay Node implemenation found!"); } }
/// <summary> /// Stops the server, reloads the assembly and restarts the server. /// </summary> public void AssemblyChanged() //should rename to ReloadAssembly { try { //preserve state information between assembly reloads ComponentRunState[] runStates = GetRunState(); Stop(); Start(runStates); } catch (Exception ex) { if (log.IsErrorEnabled) log.Error("Exception recycling Relay Node Domain: " + ex.ToString() + Environment.NewLine + "Trying again with no runstate."); relayNode = AssemblyLoader.Instance.GetRelayNode(nodeChangedDelegate); relayNode.Initialize(null); relayNode.Start(); } }
/// <summary> /// Stops the server and unloads the <see cref="IRelayNode"/> instance's assembly. /// </summary> /// <exception cref="Exception">Thrown when an error occurs.</exception> public void Stop() { if (relayNode != null) { try { if (log.IsInfoEnabled) log.Info("Stopping Relay Node."); relayNode.Stop(); if (log.IsInfoEnabled) { log.Info("Relay Node Stopped."); log.Info("Releasing old domain."); } AssemblyLoader.Instance.ReleaseRelayNode(); if (log.IsInfoEnabled) log.Info("Old domain released."); relayNode = null; } catch (Exception ex) { if (log.IsErrorEnabled) log.ErrorFormat("Error shutting down relay node: {0}", ex); } } else { if (log.IsErrorEnabled) log.Error("No Node To Stop."); } }