Example #1
0
        public void Should_be_able_to_change_NetworkEventLoop_error_handler_at_runtime()
        {
            var eventLoop          = EventLoopFactory.CreateNetworkEventLoop();
            var count              = new AtomicCounter(0);
            var trappedException   = false;
            var backgroundProducer = Task.Run(() =>
            {
                for (var i = 0; i < 10; i++)
                {
                    eventLoop.Execute(() => count.GetAndIncrement());
                    Thread.Sleep(10);
                }
            });

            eventLoop.SetExceptionHandler((connection, exception) => trappedException = true, null);
            eventLoop.Execute(() =>
            {
                throw new Exception("I'm an exception!");
            });

            backgroundProducer.Wait();

            Assert.AreEqual(10, count.Current);
            Assert.IsTrue(trappedException);
        }
Example #2
0
        public IConnection BuildMulticastConnection(INode bindNode, INode multicastNode)
        {
            if (MulticastHelper.IsValidMulticastAddress(multicastNode.Host))
            {
                return(new MulticastUdpConnection(EventLoopFactory.CreateNetworkEventLoop(), bindNode, multicastNode, Encoders.DefaultEncoder, Encoders.DefaultDecoder, UnpooledByteBufAllocator.Default));
            }

            throw new HeliosConnectionException(ExceptionType.NotSupported, string.Format("{0} is an invalid multicast IP address", multicastNode.Host));
        }
Example #3
0
        public IConnection BuildConnection(INode node)
        {
            switch (node.TransportType)
            {
            case TransportType.Tcp:
                return(new TcpConnection(EventLoopFactory.CreateNetworkEventLoop(), node, Timeout, Encoders.DefaultEncoder, Encoders.DefaultDecoder, UnpooledByteBufAllocator.Default));

            case TransportType.Udp:
                return(new UdpConnection(EventLoopFactory.CreateNetworkEventLoop(), node, Timeout, Encoders.DefaultEncoder, Encoders.DefaultDecoder, UnpooledByteBufAllocator.Default));

            default:
                throw new HeliosConnectionException(ExceptionType.NotSupported, "No support for non-UDP / TCP connections at this time.");
            }
        }
Example #4
0
 protected UnstreamedConnectionBase(int bufferSize = NetworkConstants.DEFAULT_BUFFER_SIZE)
     : this(
         EventLoopFactory.CreateNetworkEventLoop(), null, Encoders.DefaultEncoder, Encoders.DefaultDecoder,
         UnpooledByteBufAllocator.Default, bufferSize)
 {
 }