Пример #1
0
 public void Start()
 {
     simpleHandler = new SimpleMessageHandler();
     if (messageHandler == null)
     {
         taskHandler = new TaskHandler(simpleHandler, taskService, taskDownloadManager, defaultFileDir, revitCommandExcutor);
         taskHandler.SyncAllTask();
         messageHandler = new MessageHandler(simpleHandler, maxTaskCount, taskHandler);
         messageHandler.ResumeAllTasks();
         ThreadPool.QueueUserWorkItem(messageHandler.HandleMessage);
         ThreadPool.QueueUserWorkItem(taskHandler.RunTasks);
     }
     else
     {
         messageHandler.setSimpleMessageHandler(simpleHandler);
         taskHandler.setSimpleMessageHandler(simpleHandler);
     }
     client.RunClientAsync(simpleHandler).Wait();
 }
Пример #2
0
        public void Listen(IPEndPoint tcpListener, IPAddress udpAddress = null, int[] udpListenerPorts = null)
        {
            ThrowIfDisposed();

            var log = Configuration.Logger?
                      .ForContext("TcpEndPoint", tcpListener)
                      .ForContext("UdpAddress", udpAddress)
                      .ForContext("UdpPorts", udpListenerPorts);

            log?.Information("Starting - tcp={TcpEndPoint} udp={UdpAddress} udp-port={UdpPorts}");

            try
            {
                _listenerChannel = new ServerBootstrap()
                                   .Group(_socketListenerThreads, _socketWorkerThreads)
                                   .Channel <TcpServerSocketChannel>()
                                   .Handler(new ActionChannelInitializer <IServerSocketChannel>(ch => { }))
                                   .ChildHandler(new ActionChannelInitializer <ISocketChannel>(ch =>
                {
                    var userMessageHandler = new SimpleMessageHandler();
                    foreach (var handler in Configuration.MessageHandlers)
                    {
                        userMessageHandler.Add(handler);
                    }

                    ch.Pipeline
                    .AddLast(new SessionHandler(this))
                    .AddLast(new ProudFrameDecoder((int)Configuration.MessageMaxLength))
                    .AddLast(new ProudFrameEncoder())
                    .AddLast(new RecvContextDecoder())
                    .AddLast(new CoreMessageDecoder())
                    .AddLast(new CoreMessageEncoder())
                    .AddLast("coreHandler", new SimpleMessageHandler()
                             .Add(new CoreHandler(this)))
                    .AddLast(new SendContextEncoder())
                    .AddLast(new MessageDecoder(Configuration.MessageFactories))
                    .AddLast(new MessageEncoder(Configuration.MessageFactories))

                    // SimpleMessageHandler discards all handled messages
                    // So internal messages(if handled) wont reach the user messagehandler
                    .AddLast(new SimpleMessageHandler()
                             .Add(new ServerHandler()))
                    .AddLast(userMessageHandler)
                    .AddLast(new ErrorHandler(this));
                }))
                                   .ChildOption(ChannelOption.TcpNodelay, !Configuration.EnableNagleAlgorithm)
                                   .ChildOption(ChannelOption.SoRcvbuf, 51200)
                                   .ChildOption(ChannelOption.SoSndbuf, 8192)
                                   .ChildOption(ChannelOption.AllowHalfClosure, false)
                                   .ChildAttribute(ChannelAttributes.Session, default(ProudSession))
                                   .ChildAttribute(ChannelAttributes.Server, this)
                                   .BindAsync(tcpListener).WaitEx();

                if (udpListenerPorts != null)
                {
                    UdpSocketManager.Listen(udpAddress, tcpListener.Address, udpListenerPorts, _socketWorkerThreads);
                }
            }
            catch (Exception ex)
            {
                log?.Error(ex, "Unable to start server - tcp={TcpEndPoint} udp={UdpAddress} udp-port={UdpPorts}");
                ShutdownThreads();
                ex.Rethrow();
            }

            IsRunning = true;
            OnStarted();
            RetryUdpOrHolepunchIfRequired(this, null);
        }
Пример #3
0
 public void setSimpleMessageHandler(SimpleMessageHandler simpleHandler)
 {
     this.simpleHandler = simpleHandler;
 }
Пример #4
0
 public MessageHandler(SimpleMessageHandler simpleHandler, int maxTaskCount, TaskHandler taskHandler)
 {
     this.simpleHandler = simpleHandler;
     this.maxTaskCount  = maxTaskCount;
     this.taskHandler   = taskHandler;
 }
Пример #5
0
 public TaskHandler(SimpleMessageHandler simpleHandler, TaskService taskService, TaskDownloadManager taskDownloadManager, string defaultFileDir, IRevitCommandExcutor revitCommandExcutor) : this(simpleHandler, taskService)
 {
     this.taskDownloadManager = taskDownloadManager;
     this.defaultFileDir      = defaultFileDir;
     this.revitCommandExcutor = revitCommandExcutor;
 }
Пример #6
0
 private TaskHandler(SimpleMessageHandler simpleHandler, TaskService taskService)
 {
     this.simpleHandler = simpleHandler;
     this.taskService   = taskService;
 }
Пример #7
0
        public void Listen(IPEndPoint tcpListener, IPAddress udpAddress = null, int[] udpListenerPorts = null, IEventLoopGroup listenerEventLoopGroup = null, IEventLoopGroup workerEventLoopGroup = null)
        {
            ThrowIfDisposed();

            _listenerEventLoopGroup = listenerEventLoopGroup ?? new MultithreadEventLoopGroup(1);
            _workerEventLoopGroup   = workerEventLoopGroup ?? new MultithreadEventLoopGroup();
            try
            {
                _listenerChannel = new ServerBootstrap()
                                   .Group(_listenerEventLoopGroup, _workerEventLoopGroup)
                                   .Channel <TcpServerSocketChannel>()
                                   .Handler(new ActionChannelInitializer <IServerSocketChannel>(ch => { }))
                                   .ChildHandler(new ActionChannelInitializer <ISocketChannel>(ch =>
                {
                    var userMessageHandler = new SimpleMessageHandler();
                    foreach (var handler in Configuration.MessageHandlers)
                    {
                        userMessageHandler.Add(handler);
                    }

                    ch.Pipeline
                    .AddLast(new SessionHandler(this))

                    .AddLast(new ProudFrameDecoder((int)Configuration.MessageMaxLength))
                    .AddLast(new ProudFrameEncoder())

                    .AddLast(new CoreMessageDecoder())
                    .AddLast(new CoreMessageEncoder())

                    .AddLast("coreHandler", new SimpleMessageHandler()
                             .Add(new CoreHandler(this)))

                    .AddLast(new SendContextEncoder())
                    .AddLast(new MessageDecoder(Configuration.MessageFactories))
                    .AddLast(new MessageEncoder(Configuration.MessageFactories))

                    // SimpleMessageHandler discards all handled messages
                    // So internal messages(if handled) wont reach the user messagehandler
                    .AddLast(new SimpleMessageHandler()
                             .Add(new ServerHandler()))

                    .AddLast(userMessageHandler)
                    .AddLast(new ErrorHandler(this));
                }))
                                   .ChildOption(ChannelOption.TcpNodelay, !Configuration.EnableNagleAlgorithm)
                                   .ChildAttribute(ChannelAttributes.Session, default(ProudSession))
                                   .ChildAttribute(ChannelAttributes.Server, this)
                                   .BindAsync(tcpListener).WaitEx();

                if (udpListenerPorts != null)
                {
                    UdpSocketManager.Listen(udpAddress, tcpListener.Address, udpListenerPorts, _workerEventLoopGroup);
                }
            }
            catch (Exception ex)
            {
                _listenerEventLoopGroup.ShutdownGracefullyAsync();
                _listenerEventLoopGroup = null;
                _workerEventLoopGroup.ShutdownGracefullyAsync();
                _workerEventLoopGroup = null;
                ex.Rethrow();
            }

            IsRunning = true;
            OnStarted();
        }