/// <summary> /// Sends an interaction. /// </summary> /// <param name="msg">the message or interaction to send /// </param> public virtual void SendInteraction(TransportationType transport, BaseInteractionMessage msg) { if (!channel2TransportationMap.ContainsKey(transport)) { throw new Exception("Transport unknown"); } foreach (KeyValuePair <TransportationType, ChannelType> keyValue in channel2TransportationMap) { if (keyValue.Key.Equals(transport)) { try { ChannelType channelType = keyValue.Value; if (channelType.Equals(ChannelType.TCP)) { SendRealiableInteraction(channelType, msg); } else { SendBestEffortInteraction(channelType, msg); } } catch (Exception e) { //TODO. What should I do when the channel is remotly closed and lost??. //TODO. if (log.IsWarnEnabled) { log.Warn("Error sending interaction: " + e.Message); } } } } }
/// <summary> /// Creates a channel to exchange data with the end-point represented by /// the supplied uniform resource identifier. If a channel to this end-point is already open, /// it returns the existing channel /// </summary> /// <param name="uri"></param> /// <param name="type">The type of channel to open. From the ChannelType enumeration</param> /// <returns>The channel requested or null if an error occurs</returns> /// <remarks>In this version it only handles SocketChannel</remarks> public virtual IChannel OpenChannel(string uri, ChannelType type) { String ipAddr; int port; IChannel ch = null; lock (_channels.SyncRoot) { try { if (type.Equals(ChannelType.Socket)) { if (!_channels.ContainsKey(uri)) { Socket socket = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); TcpIpUri.UriAsAddressPort(uri, out ipAddr, out port); socket.Connect(new IPEndPoint(IPAddress.Parse(ipAddr), port)); if (socket.Connected) { ch = new SocketChannel(socket, true); /// TODO: Implement a generic mechanism to decouple ChannelManager from the type of channel to be created ch.Uri = uri; AddToChannels(uri, ch); } } else { ch = (IChannel)_channels[uri]; } } } catch (SocketException /*sockEx*/) { //Debug.WriteLine("OpenChannel socket error - " + sockEx.Message); //CommMain.Logger.AddLog(sockEx); --> not necessary as we throw the exception throw; } catch (Exception /*ex*/) { //Debug.WriteLine("OpenChannel error - " + ex.Message); //CommMain.Logger.AddLog(ex); --> not necessary as we throw the exception throw; } } return(ch); }
public override IChannel OpenChannel(string uri, ChannelType type) { IChannel ch = null; if (type.Equals(ChannelType.BecsQueue)) { ch = GetChannel(uri); if (ch == null) { ch = new BecsChannel(_outQueue, _inQueue); ch.Uri = uri; AddToChannels(uri, ch); } } return(ch); }