Ejemplo n.º 1
0
        public AsyncSocketMessageTransport([NotNull] Listener listener,
                                           [NotNull] ProcessingConfiguration processingConfiguration,
                                           [NotNull] BufferManagerFactory bufferManagerFactory)
        {
            if (listener == null)
            {
                throw new ArgumentNullException("listener");
            }
            if (processingConfiguration == null)
            {
                throw new ArgumentNullException("processingConfiguration");
            }
            if (bufferManagerFactory == null)
            {
                throw new ArgumentNullException("bufferManagerFactory");
            }

            this._listener = listener;
            // TODO добавить поддержку ограничений из processingConfiguration
            this._bodyBufferManager   = bufferManagerFactory.GetBufferManager(16, 16 * 1024, 1000);
            this._headerBufferManager = bufferManagerFactory.GetBufferManager(100, TcpMessageHeader.HeaderSize, 1000);
            ObjectPool <SocketAsyncEventArgs> socketArgsPool = new ObjectPool <SocketAsyncEventArgs>();

            //preallocate pool
            for (int i = 0; i < listener.Configuration.ConnectionCapacity; i++)
            {
                socketArgsPool.Put(new SocketAsyncEventArgs());
            }

            this._headerReciever = new Reciever <RecieveUserToken>(this._headerBufferManager, socketArgsPool);
            this._bodyReciever   = new Reciever <RecieveUserToken>(this._bodyBufferManager, socketArgsPool);
            this._sender         = new Sender <SendUserToken>(socketArgsPool);
        }
Ejemplo n.º 2
0
        public Listener([NotNull] ListenerConfiguration configuration,
                        [NotNull] ProcessingConfiguration processingConfiguration,
                        [NotNull] BufferManagerFactory bufferManagerFactory,
                        [NotNull] MessageTransportFactory messageTransportFactory)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }
            if (processingConfiguration == null)
            {
                throw new ArgumentNullException("processingConfiguration");
            }
            if (bufferManagerFactory == null)
            {
                throw new ArgumentNullException("bufferManagerFactory");
            }
            if (messageTransportFactory == null)
            {
                throw new ArgumentNullException("messageTransportFactory");
            }

            this._configuration        = configuration;
            this._bufferManagerFactory = bufferManagerFactory;

            this._clientConnectionInfoPool = new ObjectPool <ClientConnectionInfo>();
            this._disconnectSocketArgsPool = new ObjectPool <SocketAsyncEventArgs>();
            this._socketPool = new ObjectPool <Socket>();

            _connectionHolder         = new ConnectionHolder(configuration.ConnectionCapacity);
            _stoppedWaitHandle        = new ManualResetEvent(false);
            _messageTransport         = messageTransportFactory.GetMessageTransport(this);
            _compressionBufferManager = bufferManagerFactory.GetBufferManager(1024, 1024 * 8);
        }
Ejemplo n.º 3
0
        public NetworkStreamMessageTransport([NotNull] ProcessingConfiguration сonfiguration, [NotNull] BufferManagerFactory bufferManagerFactory)
        {
            if (сonfiguration == null)
            {
                throw new ArgumentNullException("сonfiguration");
            }
            if (bufferManagerFactory == null)
            {
                throw new ArgumentNullException("bufferManagerFactory");
            }

            this._сonfiguration       = сonfiguration;
            this._bodyBufferManager   = bufferManagerFactory.GetBufferManager(16, 16 * 1024, 1000);
            this._headerBufferManager = bufferManagerFactory.GetBufferManager(100, TcpMessageHeader.HeaderSize, 1000);
        }
Ejemplo n.º 4
0
 public MessageTransportFactory(ListenerConfiguration listenerConfiguration, ProcessingConfiguration processingConfiguration, BufferManagerFactory bufferManagerFactory)
 {
     if (listenerConfiguration == null)
     {
         throw new ArgumentNullException("listenerConfiguration");
     }
     if (processingConfiguration == null)
     {
         throw new ArgumentNullException("processingConfiguration");
     }
     if (bufferManagerFactory == null)
     {
         throw new ArgumentNullException("bufferManagerFactory");
     }
     _listenerConfiguration   = listenerConfiguration;
     _processingConfiguration = processingConfiguration;
     _bufferManagerFactory    = bufferManagerFactory;
 }
Ejemplo n.º 5
0
        public static ProcessingConfiguration LoadConfigurationFromAppConfig()
        {
            ServerConfigurationSection     serverConfigurationSection = (ServerConfigurationSection)ConfigurationManager.GetSection("server");
            ProcessingConfigurationElement processingConfig           = serverConfigurationSection.Processing;

            Dictionary <string, CommandProcessingConfiguration> commandOverrrides = processingConfig.Commands
                                                                                    .Cast <CommandConfigurationElement>()
                                                                                    .ToDictionary(element => element.Name, CommandProcessingConfiguration.Create);

            ProcessingConfiguration processingConfiguration = new ProcessingConfiguration
            {
                MaxMessageBodySize     = processingConfig.MaxMessageBodySize,
                HeaderReadingTimeout   = processingConfig.HeaderReadingTimeout,
                MessageRecieveTimeout  = processingConfig.MessageRecieveTimeout,
                ResponseSendingTimeout = processingConfig.ResponseSendingTimeout,
                CommandOverrides       = new ReadOnlyDictionary <string, CommandProcessingConfiguration>(commandOverrrides)
            };

            return(processingConfiguration);
        }