예제 #1
0
        private static void Main(string[] args)
        {
            var host = IPAddress.Any;
            var port = 9991;

            Console.Title = "Server";
            Console.WriteLine("Starting server on {0}:{1}", host, port);
            var executor = new TryCatchExecutor(exception => Console.WriteLine("Unhandled exception: {0}", exception));

            var bootstrapper =
                new ServerBootstrap()
                .WorkerThreads(2)
                .Executor(executor)
                .SetTransport(TransportType.Tcp)
                .Build();
            var server = bootstrapper.NewReactor(NodeBuilder.BuildNode().Host(host).WithPort(port));

            server.OnConnection += (address, connection) =>
            {
                Console.WriteLine("Connected: {0}", address);
                connection.BeginReceive(Receive);
            };
            server.OnDisconnection += (reason, address) =>
                                      Console.WriteLine("Disconnected: {0}; Reason: {1}", address.RemoteHost, reason.Type);
            server.Start();
            Console.WriteLine("Running, press any key to exit");
            Console.ReadKey();
            Console.WriteLine("Shutting down...");
            server.Stop();
            Console.WriteLine("Terminated");
        }
예제 #2
0
            public Server(string address, int port, IClientListener <Request, Response> listener, ISerializeProcessor sp, bool isIPAddressAny)
            {
                this._address       = address;
                this._port          = port;
                this._lisenter      = listener;
                this.SP             = sp;
                this.isAnyIPAddress = isIPAddressAny || string.IsNullOrEmpty(_address);

                var excutor = new TryCatchExecutor((e) =>
                {
                    //Console.Write(e);
                });
                var bootStrapper = new ServerBootstrap()
                                   .Executor(excutor)
                                   .SetTransport(System.Net.TransportType.Tcp)
                                   .Build();

                _server = bootStrapper.NewReactor(
                    NodeBuilder.BuildNode()
                    .Host(isIPAddressAny? IPAddress.Any:IPAddress.Parse(_address))
                    .WithPort(port)
                    );

                _server.OnConnection    += _server_OnConnection;;
                _server.OnDisconnection += TempServer_OnDisconnection;
            }
예제 #3
0
        public void Should_pipe_remaining_operations_when_exception_thrown()
        {
            //arrange
            var handledException           = false;
            var remainingJobsCalled        = true;
            var remainingJobsCount         = 0;
            Action <Exception> exCallback  = exception => { handledException = true; };
            Action             exOperation = () => { throw new Exception("Plain old exception"); };

            Executor = new TryCatchExecutor(exCallback);

            var wasCalled = 3.Of(false).ToList();
            var callbacks = new Action[wasCalled.Count];

            for (var i = 0; i < wasCalled.Count; i++)
            {
                var i1 = i;
                callbacks[i] = () => { wasCalled[i1] = true; };
            }
            callbacks[1] = exOperation;

            //act
            Executor.Execute(callbacks, actions =>
            {
                remainingJobsCalled = true;
                remainingJobsCount  = actions.Count();
            });

            //assert
            Assert.False(wasCalled.All(x => x));
            Assert.True(handledException);
            Assert.True(remainingJobsCalled);
            Assert.Equal(1, remainingJobsCount);
        }
예제 #4
0
 protected HeliosTransport(ActorSystem system, Config config)
 {
     Config   = config;
     System   = system;
     Settings = new HeliosTransportSettings(config);
     Log      = Logging.GetLogger(System, GetType());
     Executor = new TryCatchExecutor(exception => Log.Error(exception, "Unknown network error"));
 }
예제 #5
0
        public void Should_report_exception_when_thrown()
        {
            //arrange
            var handledException           = false;
            Action <Exception> exCallback  = exception => { handledException = true; };
            Action             exOperation = () => { throw new Exception("Plain old exception"); };

            Executor = new TryCatchExecutor(exCallback);

            //act
            Executor.Execute(exOperation);

            //assert
            Assert.True(handledException);
        }
예제 #6
0
        public void Should_not_report_exception_when_not_thrown()
        {
            //arrange
            var handledException           = false;
            var called                     = false;
            Action <Exception> exCallback  = exception => { handledException = true; };
            Action             exOperation = () => { called = true; };

            Executor = new TryCatchExecutor(exCallback);

            //act
            Executor.Execute(exOperation);

            //assert
            Assert.False(handledException);
            Assert.True(called);
        }
예제 #7
0
 public TryCatchExecutorTests()
 {
     Executor = new TryCatchExecutor();
 }
예제 #8
0
 public override void SetUp()
 {
     Executor = new TryCatchExecutor();
 }