/// <summary> /// Stops this channel from processing messages /// </summary> /// <param name="immediate">Retires the channel without processing the queue, which may cause lost messages</param> public Task RetireAsync(bool immediate) { // TODO: We should wait? // TODO: We should propagate the state back NetworkConfig.TransmitRequest(new PendingNetworkRequest(m_attribute.Name, typeof(T), NetworkMessageType.RetireRequest, immediate)); m_isRetired = true; return(Task.FromResult(true)); }
/// <summary> /// Creates a channel that is wrapped in a profiling channel instance /// </summary> /// <returns>The profiling-wrapped channel.</returns> /// <param name="attribute">The channel attribute.</param> /// <typeparam name="T">The channel type parameter.</typeparam> private static IChannel <T> CreateNetworkChannel <T>(ChannelNameAttribute attribute) { // We do not support annoymous channels, so we assign a random ID if (string.IsNullOrWhiteSpace(attribute.Name)) { attribute.Name = Guid.NewGuid().ToString("N"); } // Transmit the desired channel properties to the channel server NetworkConfig.TransmitRequestAsync(new PendingNetworkRequest(attribute.Name, typeof(T), NetworkMessageType.CreateChannelRequest, attribute)); return(new NetworkChannel <T>(attribute)); }
/// <summary> /// Runs a channel server in the current process /// </summary> /// <returns>The awaitable task for server exit.</returns> /// <param name="token">A cancellationtoken for stopping the server.</param> /// <param name="host">The hostname to use.</param> /// <param name="port">The port to use.</param> /// <param name="configureclient"><c>True</c> if the client config should be set automatically</param> public static Task HostServer(CancellationToken token, string host = "localhost", int port = 8888, bool configureclient = true) { var addr = string.Equals("localhost", host, StringComparison.InvariantCultureIgnoreCase) || string.Equals("127.0.0.1", host, StringComparison.InvariantCultureIgnoreCase) ? System.Net.IPAddress.Loopback : System.Net.IPAddress.Any; var channelserver = new NetworkChannelServer(new System.Net.IPEndPoint(addr, port)); if (configureclient) { NetworkConfig.Configure(host, port, true); } if (token.CanBeCanceled) { token.Register(() => { channelserver.Dispose(); }); } return(channelserver.RunAsync()); }