private SecureTcpChannel CreateServerChannel(IBufferSlice slice, IMessageEncoder encoder, IMessageDecoder decoder)
        {

            var streamBuilder = new ServerSideSslStreamBuilder(_certificate);
            var channel = new SecureTcpChannel(slice, encoder, decoder, streamBuilder);
            return channel;
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="TcpChannel" /> class.
        /// </summary>
        /// <param name="readBuffer">Buffer used for our reading.</param>
        /// <param name="encoder">Used to encode messages before they are put in the MicroMessage body of outbound messages.</param>
        /// <param name="decoder">
        ///     Used to decode the body of incoming MicroMessages. The <c>MessageReceived</c> delegate will be
        ///     overridden by this class.
        /// </param>
        public TcpChannel(IBufferSlice readBuffer, IMessageEncoder encoder, IMessageDecoder decoder) {
            if (readBuffer == null) throw new ArgumentNullException("readBuffer");
            if (encoder == null) throw new ArgumentNullException("encoder");
            if (decoder == null) throw new ArgumentNullException("decoder");

            _readArgs = new SocketAsyncEventArgs();
            _readArgs.SetBuffer(readBuffer.Buffer, readBuffer.Offset, readBuffer.Capacity);
            _readArgs.Completed += OnReadCompleted;
            _readArgsWrapper = new SocketAsyncEventArgsWrapper(_readArgs);

            _encoder = encoder;
            _decoder = decoder;
            _decoder.MessageReceived = OnMessageReceived;

            _writeArgs = new SocketAsyncEventArgs();
            _writeArgs.Completed += OnSendCompleted;
            _writeArgsWrapper = new SocketAsyncEventArgsWrapper(_writeArgs);

            _sendCompleteAction = (channel, message) => { };
            _disconnectAction = (channel, exception) => { };
            ChannelFailure = (channel, error) => HandleDisconnect(SocketError.ProtocolNotSupported);

            RemoteEndpoint = EmptyEndpoint.Instance;
            ChannelId = GuidFactory.Create().ToString();
            Data = new ChannelData();
        }
 public MulticastUdpConnection(NetworkEventLoop eventLoop, INode binding, INode multicastAddress,
     IMessageEncoder encoder, IMessageDecoder decoder, IByteBufAllocator allocator)
     : this(
         eventLoop, binding, multicastAddress, NetworkConstants.DefaultConnectivityTimeout, encoder, decoder,
         allocator)
 {
 }
Exemple #4
0
 public UdpConnection(Socket client, IMessageEncoder encoder, IMessageDecoder decoder, IByteBufAllocator allocator)
 {
     InitClient(client);
     Encoder = encoder;
     Decoder = decoder;
     Allocator = allocator;
 }
 /// <summary>
 ///     Create a new channel
 /// </summary>
 /// <param name="readBuffer">Buffer which should be used when reading from the socket</param>
 /// <param name="encoder">Used to encode outgoing data</param>
 /// <param name="decoder">Used to decode incoming data</param>
 /// <returns>Created channel</returns>
 public ITcpChannel Create(IBufferSlice readBuffer, IMessageEncoder encoder, IMessageDecoder decoder)
 {
     var channel = new TcpChannel(readBuffer, encoder, decoder);
     if (OutboundMessageQueueFactory != null)
         channel.OutboundMessageQueue = OutboundMessageQueueFactory();
     return channel;
 }
 public MulticastUdpConnection(NetworkEventLoop eventLoop, INode binding, INode multicastAddress,
     TimeSpan timeout, IMessageEncoder encoder, IMessageDecoder decoder, IByteBufAllocator allocator)
     : base(eventLoop, binding, timeout, encoder, decoder, allocator)
 {
     MulticastAddress = multicastAddress;
     InitMulticastClient();
 }
 protected SingleReceiveLoopProxyReactor(IPAddress localAddress, int localPort, NetworkEventLoop eventLoop,
     IMessageEncoder encoder, IMessageDecoder decoder, IByteBufAllocator allocator,
     SocketType socketType = SocketType.Stream, ProtocolType protocol = ProtocolType.Tcp,
     int bufferSize = NetworkConstants.DEFAULT_BUFFER_SIZE)
     : base(localAddress, localPort, eventLoop, encoder, decoder, allocator, socketType, protocol, bufferSize)
 {
 }
Exemple #8
0
        public ClientHandler(Socket clientSock)
        {
            _socket = clientSock;

            _encoder = new GeneralMessageEncoder();
            _decoder = new GeneralMessageDecoder();
        }
 protected UnstreamedConnectionBase(NetworkEventLoop eventLoop, INode binding, IMessageEncoder encoder,
     IMessageDecoder decoder, IByteBufAllocator allocator, int bufferSize = NetworkConstants.DEFAULT_BUFFER_SIZE)
     : this(
         eventLoop, binding, NetworkConstants.DefaultConnectivityTimeout, encoder, decoder, allocator, bufferSize
         )
 {
 }
 public MulticastUdpConnection(Socket client, IMessageEncoder encoder, IMessageDecoder decoder, IByteBufAllocator allocator)
     : base(client)
 {
     InitMulticastClient();
     Encoder = encoder;
     Decoder = decoder;
     Allocator = allocator;
 }
Exemple #11
0
 public TcpConnection(Socket client, IMessageEncoder encoder, IMessageDecoder decoder, IByteBufAllocator allocator, int bufferSize = NetworkConstants.DEFAULT_BUFFER_SIZE)
     : base(bufferSize)
 {
     InitClient(client);
     Encoder = encoder;
     Decoder = decoder;
     Allocator = allocator;
 }
Exemple #12
0
 public UdpProxyReactor(IPAddress localAddress, int localPort, NetworkEventLoop eventLoop,
     IMessageEncoder encoder, IMessageDecoder decoder, IByteBufAllocator allocator,
     int bufferSize = NetworkConstants.DEFAULT_BUFFER_SIZE)
     : base(
         localAddress, localPort, eventLoop, encoder, decoder, allocator, SocketType.Dgram, ProtocolType.Udp,
         bufferSize)
 {
     LocalEndpoint = new IPEndPoint(localAddress, localPort);
     RemoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
 }
Exemple #13
0
 public TcpProxyReactor(IPAddress localAddress, int localPort, NetworkEventLoop eventLoop,
     IMessageEncoder encoder, IMessageDecoder decoder, IByteBufAllocator allocator,
     int bufferSize = NetworkConstants.DEFAULT_BUFFER_SIZE)
     : base(
         localAddress, localPort, eventLoop, encoder, decoder, allocator, SocketType.Stream, ProtocolType.Tcp,
         bufferSize)
 {
     LocalEndpoint = new IPEndPoint(localAddress, localPort);
     Listener = new Socket(LocalEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
 }
Exemple #14
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="HttpService" /> class.
        /// </summary>
        public HttpService(IModuleManager moduleManager)
        {
            ApplicationInfo = new MemoryItemStorage();
            BodyDecoder = new CompositeSerializer();

            _service = this;
            _moduleManager = moduleManager;
            _encoder =  new HttpMessageEncoder();
            _decoder = new HttpMessageDecoder(BodyDecoder);
            _decoder.MessageReceived = OnMessageReceived;
        }
 protected UnstreamedConnectionBase(NetworkEventLoop eventLoop, INode binding, TimeSpan timeout, IMessageEncoder encoder, IMessageDecoder decoder, IByteBufAllocator allocator, int bufferSize = NetworkConstants.DEFAULT_BUFFER_SIZE)
     : base()
 {
     Decoder = decoder;
     Encoder = encoder;
     Allocator = allocator;
     Created = DateTimeOffset.UtcNow;
     Binding = binding;
     Timeout = timeout;
     BufferSize = bufferSize;
     NetworkEventLoop = eventLoop;
 }
Exemple #16
0
 protected ReactorBase(IPAddress localAddress, int localPort, NetworkEventLoop eventLoop, IMessageEncoder encoder, IMessageDecoder decoder, IByteBufAllocator allocator, SocketType socketType = SocketType.Stream, ProtocolType protocol = ProtocolType.Tcp, int bufferSize = NetworkConstants.DEFAULT_BUFFER_SIZE)
 {
     Decoder = decoder;
     Encoder = encoder;
     Allocator = allocator;
     LocalEndpoint = new IPEndPoint(localAddress, localPort);
     Listener = new Socket(AddressFamily.InterNetwork, socketType, protocol);
     if (protocol == ProtocolType.Tcp) { Transport = TransportType.Tcp; } else if (protocol == ProtocolType.Udp) { Transport = TransportType.Udp; }
     Backlog = NetworkConstants.DefaultBacklog;
     EventLoop = eventLoop;
     ConnectionAdapter = new ReactorConnectionAdapter(this);
     BufferSize = bufferSize;
 }
 public ServiceBrokerTransportReceiver(ServiceBrokerServiceBusReceiverConfiguration receiverConfiguration, ServiceBrokerServiceBusConfiguration configuration)
 {
     messageMapper = configuration.MessageMapper;
     messageEncoder = configuration.MessageEncoder;
     ServiceBrokerMessageType = configuration.ServiceBrokerMessageType;
     if (string.IsNullOrWhiteSpace(ServiceBrokerMessageType))
     {
         throw new InvalidConfigurationException("ServiceBrokerMessageType cannot be null or whitespace.");
     }
     ServiceBrokerContract = configuration.ServiceBrokerContract;
     if (string.IsNullOrWhiteSpace(ServiceBrokerContract))
     {
         throw new InvalidConfigurationException("ServiceBrokerContract cannot be null or whitespace.");
     }
     ServiceBrokerService = receiverConfiguration.ServiceBrokerService;
     if (string.IsNullOrWhiteSpace(ServiceBrokerService))
     {
         throw new InvalidConfigurationException("ServiceBrokerService cannot be null or whitespace.");
     }
     ServiceBrokerQueue = receiverConfiguration.ServiceBrokerQueue;
     if (string.IsNullOrWhiteSpace(ServiceBrokerQueue))
     {
         throw new InvalidConfigurationException("ServiceBrokerQueue cannot be null or whitespace.");
     }
     ConnectionString = configuration.ServiceBrokerConnectionString;
     if (string.IsNullOrWhiteSpace(ConnectionString) &&
         !string.IsNullOrWhiteSpace(configuration.ServiceBrokerConnectionStringName) &&
         ConfigurationManager.ConnectionStrings[configuration.ServiceBrokerConnectionStringName] != null)
     {
         ConnectionString = ConfigurationManager.ConnectionStrings[configuration.ServiceBrokerConnectionStringName].ConnectionString;
     }
     if (string.IsNullOrWhiteSpace(ConnectionString))
     {
         throw new InvalidConfigurationException("ServiceBrokerConnectionString cannot be null or whitespace.");
     }
     MaxRetries = receiverConfiguration.MaxRetries;
     if (MaxRetries < 0)
     {
         MaxRetries = 0;
     }
     MaxConcurrency = receiverConfiguration.MaxConcurrency;
     if (MaxConcurrency < 0)
     {
         MaxConcurrency = 0;
     }
     if (MaxConcurrency > 0)
     {
         workerThreadPool = new Semaphore(MaxConcurrency, MaxConcurrency);
     }
     faultManager = new TransportMessageFaultManager(MaxRetries);
 }
 public AmqpTransportReceiver(AmqpMessageReceiverConfiguration config, AmqpServiceBusConfiguration serviceBusConfig)
 {
     amqpAddress = serviceBusConfig.AmqpAddress;
     ReceiverLinkAddress = config.ReceiverLinkAddress;
     MaxRetries = config.MaxRetries;
     if (MaxRetries < 0)
     {
         MaxRetries = 0;
     }
     MaxConcurrency = config.MaxConcurrency;
     if (MaxConcurrency < 0)
     {
         MaxConcurrency = 0;
     }
     messageMapper = serviceBusConfig.MessageMapper;
     messageEncoder = serviceBusConfig.MessageEncoder;
     faultManager = new TransportMessageFaultManager(MaxRetries);
 }
 /// <summary>
 ///     This constructor sets user defined values to connect to FreeSwitch.
 /// </summary>
 /// <param name="address">FreeSwitch mod_event_socket IP address or hostname</param>
 /// <param name="port">FreeSwitch mod_event_socket Port number</param>
 /// <param name="messageEncoder">FreeSwitch message encoder</param>
 /// <param name="messageDecoder">FreeSwitch message decoder</param>
 /// <param name="freeSwitchEventFilter">FreeSwitch event filters</param>
 /// <param name="connectionTimeout">Connection Timeout</param>
 /// <param name="password">FreeSwitch mod_event_socket Password</param>
 public OutboundChannelSession(string address, int port, IMessageEncoder messageEncoder,
     IMessageDecoder messageDecoder, string freeSwitchEventFilter, TimeSpan connectionTimeout, string password) {
     Address = address;
     Port = port;
     MessageEncoder = messageEncoder;
     MessageDecoder = messageDecoder;
     FreeSwitchEventFilter = freeSwitchEventFilter;
     ConnectionTimeout = connectionTimeout;
     Password = password;
     _authenticated = false;
     _requestsQueue = new ConcurrentQueue<CommandAsyncEvent>();
     _channel = new TcpChannel(new BufferSlice(new byte[65535], 0, 65535), MessageEncoder, MessageDecoder);
     _channel.MessageReceived += OnMessageReceived;
     _channel.Disconnected += OnDisconnect;
     _channel.MessageSent += OnSendCompleted;
     _args.Completed += OnConnect;
     OnAuthentication += SendAuthentication;
 }
        public void SetupBeforeEachTest()
        {
            this.channelManagerFactory = A.Fake<IChannelManagerFactory>();
             this.messageHandlerTypesIndexFactory = A.Fake<IMessageHandlerTypesIndexFactory>();
             this.messageHandlerInvokerFactory = A.Fake<IMessageHandlerInvokerFactory>();
             this.queueNameConvention = A.Fake<IQueueNameConvention>();
             this.messageEncoder = A.Fake<IMessageEncoder>();
             this.messageSerialiser = A.Fake<IMessageSerialiser>();
             this.logger = A.Fake<ILogger>();
             this.configuration = A.Fake<IConfiguration>();
             this.channelManager = A.Fake<IChannelManager>();
             this.channel = A.Fake<IModel>();

             A.CallTo(() => this.channelManagerFactory.Create()).Returns(this.channelManager);
             A.CallTo(() => this.channelManager.CreateChannel()).Returns(this.channel);

             this.componentUnderTest = new RabbitMQMessageListener(this.channelManagerFactory, new Type[0], this.messageHandlerTypesIndexFactory, this.messageHandlerInvokerFactory, this.queueNameConvention, this.messageEncoder, this.messageSerialiser, this.logger, this.configuration);
        }
 /// <summary>
 ///     This constructor sets user defined values to connect to FreeSwitch.
 /// </summary>
 /// <param name="address">FreeSwitch mod_event_socket IP address or hostname</param>
 /// <param name="port">FreeSwitch mod_event_socket Port number</param>
 /// <param name="messageEncoder">FreeSwitch message encoder</param>
 /// <param name="messageDecoder">FreeSwitch message decoder</param>
 /// <param name="freeSwitchEventFilter">FreeSwitch event filters</param>
 /// <param name="connectionTimeout">Connection Timeout</param>
 /// <param name="password">FreeSwitch mod_event_socket Password</param>
 public OutboundChannelSession(string address, int port, IMessageEncoder messageEncoder,
                               IMessageDecoder messageDecoder, string freeSwitchEventFilter, TimeSpan connectionTimeout, string password)
 {
     Address                   = address;
     Port                      = port;
     MessageEncoder            = messageEncoder;
     MessageDecoder            = messageDecoder;
     FreeSwitchEventFilter     = freeSwitchEventFilter;
     ConnectionTimeout         = connectionTimeout;
     Password                  = password;
     _authenticated            = false;
     _requestsQueue            = new ConcurrentQueue <CommandAsyncEvent>();
     _channel                  = new TcpChannel(new BufferSlice(new byte[65535], 0, 65535), MessageEncoder, MessageDecoder);
     _channel.MessageReceived += OnMessageReceived;
     _channel.Disconnected    += OnDisconnect;
     _channel.MessageSent     += OnSendCompleted;
     _args.Completed          += OnConnect;
     OnAuthentication         += SendAuthentication;
 }
 public RabbitMQMessageSubscriptionFactory(
  IMessageHandlerTypesIndexFactory messageHandlerTypesIndexFactory,
  IMessageHandlerInvokerFactory messageHandlerInvokerFactory,
  ITaskLibrary taskLibrary,
  IQueueNameConvention queueNameConvention,
  IMessageEncoder messageEncoder,
  IMessageSerialiser messageSerialiser,
  ILogger logger,
  IConfiguration configuration)
 {
     this.messageHandlerTypesIndexFactory = messageHandlerTypesIndexFactory;
      this.messageHandlerInvokerFactory = messageHandlerInvokerFactory;
      this.taskLibrary = taskLibrary;
      this.queueNameConvention = queueNameConvention;
      this.messageEncoder = messageEncoder;
      this.messageSerialiser = messageSerialiser;
      this.logger = logger;
      this.configuration = configuration;
 }
Exemple #23
0
 protected ReactorBase(IPAddress localAddress, int localPort, NetworkEventLoop eventLoop, IMessageEncoder encoder, IMessageDecoder decoder, IByteBufAllocator allocator, SocketType socketType = SocketType.Stream, ProtocolType protocol = ProtocolType.Tcp, int bufferSize = NetworkConstants.DEFAULT_BUFFER_SIZE)
 {
     Decoder       = decoder;
     Encoder       = encoder;
     Allocator     = allocator;
     LocalEndpoint = new IPEndPoint(localAddress, localPort);
     Listener      = new Socket(AddressFamily.InterNetwork, socketType, protocol);
     if (protocol == ProtocolType.Tcp)
     {
         Transport = TransportType.Tcp;
     }
     else if (protocol == ProtocolType.Udp)
     {
         Transport = TransportType.Udp;
     }
     Backlog           = NetworkConstants.DefaultBacklog;
     EventLoop         = eventLoop;
     ConnectionAdapter = new ReactorConnectionAdapter(this);
     BufferSize        = bufferSize;
 }
Exemple #24
0
        protected ReactorBase(NodeConfig nodeConfig, IMessageEncoder encoder,
                              IMessageDecoder decoder, IByteBufAllocator allocator, int bufferSize = NetworkConstants.DEFAULT_BUFFER_SIZE)
        {
            Decoder   = decoder;
            Encoder   = encoder;
            Allocator = allocator;

            Listener          = new SerialPort();
            Listener.PortName = nodeConfig.PortName;
            Listener.BaudRate = nodeConfig.BaudRate;
            Listener.DataBits = nodeConfig.DataBits;
            Listener.StopBits = nodeConfig.StopBits;
            Listener.Parity   = nodeConfig.Parity;
            Listener.ReceivedBytesThreshold = 1;

            //LocalEndpoint = new IPEndPoint(localAddress, localPort);
            Backlog           = NetworkConstants.DefaultBacklog;
            BufferSize        = bufferSize;
            ConnectionAdapter = new ReactorConnectionAdapter(this);
        }
 public RabbitMQMessageListener(
  IChannelManagerFactory channelManagerFactory,
  Type[] messageHandlerTypes,
  IMessageHandlerTypesIndexFactory messageHandlerTypesIndexFactory,
  IMessageHandlerInvokerFactory messageHandlerInvokerFactory,
  IQueueNameConvention queueNameConvention,
  IMessageEncoder messageEncoder,
  IMessageSerialiser messageSerialiser,
  ILogger logger,
  IConfiguration configuration)
 {
     this.channelManager = channelManagerFactory.Create();
      this.queueNameConvention = queueNameConvention;
      this.messageEncoder = messageEncoder;
      this.messageSerialiser = messageSerialiser;
      this.logger = logger;
      this.configuration = configuration;
      this.messageHandlerTypesIndex = messageHandlerTypesIndexFactory.Create(messageHandlerTypes);
      this.messageHandlerInvoker = messageHandlerInvokerFactory.CreateAggregate(this.messageHandlerTypesIndex);
 }
Exemple #26
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ChannelTcpClient" /> class.
        /// </summary>
        /// <param name="encoder">Used to encode outbound messages.</param>
        /// <param name="decoder">Used to decode inbound messages.</param>
        /// <param name="readBuffer">Buffer used to receive bytes..</param>
        /// <exception cref="System.ArgumentNullException">
        ///     encoder
        ///     or
        ///     decoder
        ///     or
        ///     readBuffer
        /// </exception>
        public ChannelTcpClient(IMessageEncoder encoder, IMessageDecoder decoder, IBufferSlice readBuffer)
        {
            if (encoder == null)
            {
                throw new ArgumentNullException("encoder");
            }
            if (decoder == null)
            {
                throw new ArgumentNullException("decoder");
            }
            if (readBuffer == null)
            {
                throw new ArgumentNullException("readBuffer");
            }

            _encoder    = encoder;
            _decoder    = decoder;
            _readBuffer = readBuffer;

            _args.Completed += OnConnect;
        }
Exemple #27
0
        /// <summary>
        /// Create engine
        /// </summary>
        /// <param name="messageTrigger"></param>
        /// <param name="encoder"></param>
        /// <param name="messageSink"></param>
        /// <param name="engineConfiguration"></param>
        /// <param name="logger"></param>
        public DataFlowProcessingEngine(IMessageTrigger messageTrigger, IMessageEncoder encoder,
                                        IMessageSink messageSink, IEngineConfiguration engineConfiguration, ILogger logger)
        {
            _messageTrigger = messageTrigger;
            _messageSink    = messageSink;
            _messageEncoder = encoder;
            _logger         = logger;

            _messageTrigger.OnMessage += MessageTriggerMessageReceived;

            if (engineConfiguration.DiagnosticsInterval.HasValue &&
                engineConfiguration.DiagnosticsInterval > TimeSpan.Zero)
            {
                _diagnosticsOutputTimer = new Timer(DiagnosticsOutputTimer_Elapsed, null, 0,
                                                    (int)engineConfiguration.DiagnosticsInterval.Value.TotalMilliseconds);
            }

            if (engineConfiguration.BatchSize.HasValue && engineConfiguration.BatchSize.Value > 1)
            {
                _bufferSize = engineConfiguration.BatchSize.Value;
            }
        }
 public ServiceBrokerTransportSender(ServiceBrokerServiceBusConfiguration configuration)
 {
     ServiceBrokerMessageType = configuration.ServiceBrokerMessageType;
     if (string.IsNullOrWhiteSpace(ServiceBrokerMessageType))
     {
         throw new InvalidConfigurationException("ServiceBrokerMessageType cannot be null or whitespace.");
     }
     ServiceBrokerContract = configuration.ServiceBrokerContract;
     if (string.IsNullOrWhiteSpace(ServiceBrokerContract))
     {
         throw new InvalidConfigurationException("ServiceBrokerContract cannot be null or whitespace.");
     }
     ServiceBrokerSendingService = configuration.ServiceBrokerSendingService;
     if (string.IsNullOrWhiteSpace(ServiceBrokerSendingService))
     {
         throw new InvalidConfigurationException("ServiceBrokerSendingService cannot be null or whitespace.");
     }
     ConnectionString = configuration.ServiceBrokerConnectionString;
     if (string.IsNullOrWhiteSpace(ConnectionString) &&
         !string.IsNullOrWhiteSpace(configuration.ServiceBrokerConnectionStringName) &&
         ConfigurationManager.ConnectionStrings[configuration.ServiceBrokerConnectionStringName] != null)
     {
         ConnectionString = ConfigurationManager.ConnectionStrings[configuration.ServiceBrokerConnectionStringName].ConnectionString;
     }
     if (string.IsNullOrWhiteSpace(ConnectionString))
     {
         throw new InvalidConfigurationException("ServiceBrokerConnectionString cannot be null or whitespace.");
     }
     messageEncoder = configuration.MessageEncoder;
     if (messageEncoder == null)
     {
         throw new InvalidConfigurationException("MessageEncoder cannot be null.");
     }
     messageMapper = configuration.MessageMapper;
     if (messageMapper == null)
     {
         throw new InvalidConfigurationException("MessageMapper cannot be null.");
     }
 }
        /// <summary>
        /// Create engine
        /// </summary>
        /// <param name="messageTrigger"></param>
        /// <param name="encoder"></param>
        /// <param name="messageSink"></param>
        /// <param name="engineConfiguration"></param>
        /// <param name="logger"></param>
        /// <param name="identity"></param>
        public DataFlowProcessingEngine(IMessageTrigger messageTrigger, IMessageEncoder encoder,
                                        IMessageSink messageSink, IEngineConfiguration engineConfiguration, ILogger logger,
                                        IIdentity identity)
        {
            _config         = engineConfiguration;
            _messageTrigger = messageTrigger;
            _messageSink    = messageSink;
            _messageEncoder = encoder;
            _logger         = logger;
            _identity       = identity;

            _messageTrigger.OnMessage += MessageTriggerMessageReceived;

            if (_config.BatchSize.HasValue && _config.BatchSize.Value > 1)
            {
                _dataSetMessageBufferSize = _config.BatchSize.Value;
            }
            if (_config.MaxMessageSize.HasValue && _config.MaxMessageSize.Value > 0)
            {
                _maxEncodedMessageSize = _config.MaxMessageSize.Value;
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="readBuffer"></param>
        /// <param name="encoder"></param>
        /// <param name="decoder"></param>
        /// <param name="sslStreamBuilder">Used to wrap the socket with a SSL stream</param>
        public SecureTcpChannel(IBufferSlice readBuffer, IMessageEncoder encoder, IMessageDecoder decoder, ISslStreamBuilder sslStreamBuilder) {
            if (readBuffer == null) throw new ArgumentNullException("readBuffer");
            if (encoder == null) throw new ArgumentNullException("encoder");
            if (decoder == null) throw new ArgumentNullException("decoder");
            if (sslStreamBuilder == null) throw new ArgumentNullException("sslStreamBuilder");

            _encoder = encoder;
            _decoder = decoder;
            _sslStreamBuilder = sslStreamBuilder;
            _decoder.MessageReceived = OnMessageReceived;

            _sendCompleteAction = (channel, message) => { };
            _disconnectAction = (channel, exception) => { };
            ChannelFailure = (channel, error) => HandleDisconnect(SocketError.ProtocolNotSupported);

            RemoteEndpoint = EmptyEndpoint.Instance;

            _readBuffer = new SocketBuffer(readBuffer);
            _writeBuffer = new SocketBuffer();
            ChannelId = GuidFactory.Create().ToString();
            Data = new ChannelData();
        }
Exemple #31
0
        /// <summary>
        /// ClientCommunicator构造函数
        /// </summary>
        /// <param name="clientid">客户端ID</param>
        /// <param name="client">客户端的TCP实体</param>
        /// <param name="filter">报文过滤器</param>
        public Communicator(ICommer parent_commer, long clientid, Socket client, ICommandInterpreter intepreter,
                            IMessageExtractor extractor, IMessageEncoder encoder, bool compress)
        {
            m_ParentCommer = parent_commer;
            m_ClientID     = clientid;
            m_Client       = client;
            m_ClientInfo   = client.RemoteEndPoint as IPEndPoint;

            m_Interpreter = intepreter;

            if (m_Interpreter != null)
            {
                m_Interpreter.CommunicatorObj = this;
            }

            m_bCompress = compress;

            m_Extractor            = extractor;
            m_Extractor.Compressed = compress;

            m_Encoder           = encoder;
            onConnectionBroken += new ConnectionBrokenHandler(ClientCommunicator_onConnectionBroken);
        }
Exemple #32
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="TcpChannel" /> class.
        /// </summary>
        /// <param name="readBuffer">Buffer used for our reading.</param>
        /// <param name="encoder">Used to encode messages before they are put in the MicroMessage body of outbound messages.</param>
        /// <param name="decoder">
        ///     Used to decode the body of incoming MicroMessages. The <c>MessageReceived</c> delegate will be
        ///     overridden by this class.
        /// </param>
        public TcpChannel(IBufferSlice readBuffer, IMessageEncoder encoder, IMessageDecoder decoder)
        {
            IsConnected = false;
            if (readBuffer == null)
            {
                throw new ArgumentNullException("readBuffer");
            }
            if (encoder == null)
            {
                throw new ArgumentNullException("encoder");
            }
            if (decoder == null)
            {
                throw new ArgumentNullException("decoder");
            }

            _readArgs = new SocketAsyncEventArgs();
            _readArgs.SetBuffer(readBuffer.Buffer, readBuffer.Offset, readBuffer.Capacity);
            _readArgs.Completed += OnReadCompleted;
            _readArgsWrapper     = new SocketAsyncEventArgsWrapper(_readArgs);

            _encoder = encoder;
            _decoder = decoder;
            _decoder.MessageReceived = OnMessageReceived;

            _writeArgs            = new SocketAsyncEventArgs();
            _writeArgs.Completed += OnSendCompleted;
            _writeArgsWrapper     = new SocketAsyncEventArgsWrapper(_writeArgs);

            _sendCompleteAction = (channel, message) => { };
            _disconnectAction   = (channel, exception) => { };
            ChannelFailure      = (channel, error) => HandleRemoteDisconnect(SocketError.ProtocolNotSupported, error);

            RemoteEndpoint = EmptyEndpoint.Instance;
            ChannelId      = GuidFactory.Create().ToString();
            Data           = new ChannelData();
        }
Exemple #33
0
 public void SetUp()
 {
     Encoder = MLLP.MLLPEncoder.Default;
     Decoder = SimpleMLLPDecoder.Default;
 }
Exemple #34
0
 public DotNettyServerSender(IMessageEncoder messageEncoder, IChannelHandlerContext context)
     : base(messageEncoder)
 {
     _context = context;
 }
Exemple #35
0
 public new ServerBootstrap SetEncoder(IMessageEncoder encoder)
 {
     base.SetEncoder(encoder);
     return this;
 }
Exemple #36
0
 public TcpSingleEventLoopProxyReactor(IPAddress localAddress, int localPort, NetworkEventLoop eventLoop,
                                       IMessageEncoder encoder, IMessageDecoder decoder, IByteBufAllocator allocator,
                                       int bufferSize = NetworkConstants.DEFAULT_BUFFER_SIZE)
     : base(localAddress, localPort, eventLoop, encoder, decoder, allocator, bufferSize)
 {
 }
 public LengthFieldEncodingTests()
 {
     Encoder = new LengthFieldPrepender(LengthFieldLength);
     Decoder = new LengthFieldFrameBasedDecoder(2000, 0, LengthFieldLength, 0, LengthFieldLength); //stip headers
 }
Exemple #38
0
 protected SingleReceiveLoopProxyReactor(IPAddress localAddress, int localPort, NetworkEventLoop eventLoop, IMessageEncoder encoder, IMessageDecoder decoder, IByteBufAllocator allocator, SocketType socketType = SocketType.Stream, ProtocolType protocol = ProtocolType.Tcp, int bufferSize = NetworkConstants.DEFAULT_BUFFER_SIZE)
     : base(localAddress, localPort, eventLoop, encoder, decoder, allocator, socketType, protocol, bufferSize)
 {
 }
Exemple #39
0
 public TcpChannel(IMessageDecoder <IMessage> decoder, IMessageEncoder <IMessage> encoder) : this(decoder, encoder, null)
 {
 }
Exemple #40
0
 public UdpConnection(NetworkEventLoop eventLoop, INode binding, IMessageEncoder encoder, IMessageDecoder decoder,
     IByteBufAllocator allocator)
     : base(eventLoop, binding, encoder, decoder, allocator)
 {
     InitClient();
 }
Exemple #41
0
 public Producer(IMessageEncoder encoder)
 {
     mEncoder = encoder;
 }
Exemple #42
0
 public virtual AbstractBootstrap SetEncoder(IMessageEncoder encoder)
 {
     Encoder = encoder;
     return(this);
 }
Exemple #43
0
 public new ClientBootstrap SetEncoder(IMessageEncoder encoder)
 {
     base.SetEncoder(encoder);
     return this;
 }
Exemple #44
0
 public DotNettyClientSender(IMessageEncoder messageEncoder, IChannel channel) : base(messageEncoder)
 {
     _channel = channel;
 }
Exemple #45
0
 public UdpConnection(NetworkEventLoop eventLoop, INode binding, IMessageEncoder encoder, IMessageDecoder decoder,
                      IByteBufAllocator allocator)
     : base(eventLoop, binding, encoder, decoder, allocator)
 {
     InitClient();
 }
 public TcpChannel(IMessageDecoder <IMessage> decoder, IMessageEncoder <IMessage> encoder) : base(decoder, encoder)
 {
 }
Exemple #47
0
 public TcpConnection(NetworkEventLoop eventLoop, INode node, IMessageEncoder encoder, IMessageDecoder decoder, IByteBufAllocator allocator, int bufferSize = NetworkConstants.DEFAULT_BUFFER_SIZE)
     : base(eventLoop, node, encoder, decoder, allocator, bufferSize)
 {
     InitClient();
 }
 public NonblockingSocketStream(Socket socket, IConnectionUtility connectionUtility, IMessageEncoder encoder)
 {
     this.socket            = socket;
     this.connectionUtility = connectionUtility;
     this.encoder           = encoder;
 }
 public AmqpTransportSender(AmqpServiceBusConfiguration config)
 {
     amqpAddress = config.AmqpAddress;
     messageEncoder = config.MessageEncoder;
     messageMapper = config.MessageMapper;
 }
Exemple #50
0
        /// <summary>
        ///     Create a new channel
        /// </summary>
        /// <param name="readBuffer">Buffer which should be used when reading from the socket</param>
        /// <param name="encoder">Used to encode outgoing data</param>
        /// <param name="decoder">Used to decode incoming data</param>
        /// <returns>Created channel</returns>
        public ITcpChannel Create(IBufferSlice readBuffer, IMessageEncoder encoder, IMessageDecoder decoder)
        {
            var channel = new TcpChannel(readBuffer, encoder, decoder);

            return(channel);
        }
Exemple #51
0
 public TcpChannel(IMessageDecoder <IMessage> decoder, IMessageEncoder <IMessage> encoder, IHandshakeHandler handshakeHandler) : base(decoder, encoder, handshakeHandler)
 {
 }
        /// <summary>
        /// Create engine
        /// </summary>
        public DataFlowProcessingEngine(IMessageTrigger messageTrigger, IMessageEncoder encoder,
                                        IMessageSink messageSink, IEngineConfiguration engineConfiguration, ILogger logger,
                                        IIdentity identity)
        {
            _config         = engineConfiguration;
            _messageTrigger = messageTrigger;
            _messageSink    = messageSink;
            _messageEncoder = encoder;
            _logger         = logger;
            _identity       = identity;

            if (_config.BatchSize.HasValue && _config.BatchSize.Value > 1)
            {
                _dataSetMessageBufferSize = _config.BatchSize.Value;
            }
            if (_config.MaxMessageSize.HasValue && _config.MaxMessageSize.Value > 0)
            {
                _maxEncodedMessageSize = _config.MaxMessageSize.Value;
            }

            _diagnosticInterval        = _config.DiagnosticsInterval.GetValueOrDefault(TimeSpan.Zero);
            _batchTriggerInterval      = _config.BatchTriggerInterval.GetValueOrDefault(TimeSpan.Zero);
            _diagnosticsOutputTimer    = new Timer(DiagnosticsOutputTimer_Elapsed);
            _batchTriggerIntervalTimer = new Timer(BatchTriggerIntervalTimer_Elapsed);
            _maxOutgressMessages       = _config.MaxOutgressMessages.GetValueOrDefault(4096); // = 1 GB

            _encodingBlock = new TransformManyBlock <DataSetMessageModel[], NetworkMessageModel>(
                async input => {
                try {
                    if (_dataSetMessageBufferSize == 1)
                    {
                        return(await _messageEncoder.EncodeAsync(input, _maxEncodedMessageSize).ConfigureAwait(false));
                    }
                    else
                    {
                        return(await _messageEncoder.EncodeBatchAsync(input, _maxEncodedMessageSize).ConfigureAwait(false));
                    }
                }
                catch (Exception e) {
                    _logger.Error(e, "Encoding failure");
                    return(Enumerable.Empty <NetworkMessageModel>());
                }
            },
                new ExecutionDataflowBlockOptions());

            _batchDataSetMessageBlock = new BatchBlock <DataSetMessageModel>(
                _dataSetMessageBufferSize,
                new GroupingDataflowBlockOptions());

            _batchNetworkMessageBlock = new BatchBlock <NetworkMessageModel>(
                _networkMessageBufferSize,
                new GroupingDataflowBlockOptions());

            _sinkBlock = new ActionBlock <NetworkMessageModel[]>(
                async input => {
                if (input != null && input.Any())
                {
                    _logger.Debug("Sink block in engine {Name} triggered with {count} messages",
                                  Name, input.Length);
                    await _messageSink.SendAsync(input).ConfigureAwait(false);
                }
                else
                {
                    _logger.Warning("Sink block in engine {Name} triggered with empty input",
                                    Name);
                }
            },
                new ExecutionDataflowBlockOptions());
            _batchDataSetMessageBlock.LinkTo(_encodingBlock);
            _encodingBlock.LinkTo(_batchNetworkMessageBlock);
            _batchNetworkMessageBlock.LinkTo(_sinkBlock);

            _messageTrigger.OnMessage      += MessageTriggerMessageReceived;
            _messageTrigger.OnCounterReset += MessageTriggerCounterResetReceived;

            if (_diagnosticInterval > TimeSpan.Zero)
            {
                _diagnosticsOutputTimer.Change(_diagnosticInterval, _diagnosticInterval);
            }
        }
 /// <summary>
 /// Create a new channel
 /// </summary>
 /// <param name="readBuffer">Buffer which should be used when reading from the socket</param>
 /// <param name="encoder">Used to encode outgoing data</param>
 /// <param name="decoder">Used to decode incoming data</param>
 /// <returns>Created channel</returns>
 public ITcpChannel Create(IBufferSlice readBuffer, IMessageEncoder encoder, IMessageDecoder decoder)
 {
     return new TcpChannel(readBuffer, encoder, decoder);
 }
Exemple #54
0
 public void SetUp()
 {
     Encoder = MLLP.MLLPEncoder.Default;
 }
Exemple #55
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ChannelTcpClient" /> class.
 /// </summary>
 /// <param name="encoder">Used to encode outbound messages.</param>
 /// <param name="decoder">Used to decode inbound messages.</param>
 public ChannelTcpClient(IMessageEncoder encoder, IMessageDecoder decoder) : this(encoder, decoder, new BufferSlice(new byte[65535], 0, 65535))
 {
 }
Exemple #56
0
 public UdpProxyReactor(IPAddress localAddress, int localPort, NetworkEventLoop eventLoop, IMessageEncoder encoder, IMessageDecoder decoder, IByteBufAllocator allocator, int bufferSize = NetworkConstants.DEFAULT_BUFFER_SIZE)
     : base(localAddress, localPort, eventLoop, encoder, decoder, allocator, SocketType.Dgram, ProtocolType.Udp, bufferSize)
 {
     LocalEndpoint  = new IPEndPoint(localAddress, localPort);
     RemoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
 }
Exemple #57
0
 public new ServerBootstrap SetEncoder(IMessageEncoder encoder)
 {
     base.SetEncoder(encoder);
     return(this);
 }
Exemple #58
0
 public TcpConnection(NetworkEventLoop eventLoop, INode node, IMessageEncoder encoder, IMessageDecoder decoder, IByteBufAllocator allocator, int bufferSize = NetworkConstants.DEFAULT_BUFFER_SIZE)
     : base(eventLoop, node, encoder, decoder, allocator, bufferSize)
 {
     InitClient();
 }
 public HttpServerMessageSender(IMessageEncoder encoder, HttpResponse response)
 {
     _encoder  = encoder;
     _response = response;
 }
Exemple #60
0
 protected DotNettyMicroSender(IMessageEncoder messageEncoder)
 {
     _messageEncoder = messageEncoder;
 }