示例#1
0
        public UdpConnection(UdpConnectedExt udpConn,
                             IChannelRegistry channelRegistry,
                             IActorRef commander,
                             UdpConnected.Connect connect)
        {
            _udpConn         = udpConn;
            _channelRegistry = channelRegistry;
            _commander       = commander;
            _connect         = connect;

            Context.Watch(connect.Handler);

            var remoteAddress = connect.RemoteAddress as DnsEndPoint;

            if (remoteAddress != null)
            {
                var resolved = Dns.ResolveName(remoteAddress.Host, Context.System, Self);
                if (resolved != null)
                {
                    DoConnect(new IPEndPoint(resolved.Addr, remoteAddress.Port));
                }
                else
                {
                    Context.Become(Resolving(remoteAddress));
                }
            }
            else
            {
                DoConnect(_connect.RemoteAddress);
            }
        }
示例#2
0
 public RabbitClient(string teamName, string accessCode, IChannelRegistry channelRegistry, IQueueRegistry queueRegistry, IConnectionFactory connectionFactory)
 {
     this.teamName          = teamName;
     this.accessCode        = accessCode;
     this.channelRegistry   = channelRegistry;
     this.queueRegistry     = queueRegistry;
     this.connectionFactory = connectionFactory;
     Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
 }
        public TcpIncomingConnection(TcpExt tcp,
                                     SocketChannel channel,
                                     IChannelRegistry registry,
                                     IActorRef bindHandler,
                                     IEnumerable <Inet.SocketOption> options,
                                     bool readThrottling)
            : base(tcp, channel, readThrottling)
        {
            _bindHandler = bindHandler;
            _options     = options;

            Context.Watch(bindHandler); // sign death pact

            registry.Register(channel, SocketAsyncOperation.None, Self);
        }
        public TcpIncomingConnection(TcpExt tcp, 
                                     SocketChannel channel, 
                                     IChannelRegistry registry, 
                                     IActorRef bindHandler,
                                     IEnumerable<Inet.SocketOption> options, 
                                     bool readThrottling)
            : base(tcp, channel, readThrottling)
        {
            _bindHandler = bindHandler;
            _options = options;

            Context.Watch(bindHandler); // sign death pact

            registry.Register(channel, SocketAsyncOperation.None, Self);
        }
        public TcpOutgoingConnection(TcpExt tcp, IChannelRegistry channelRegistry, IActorRef commander, Tcp.Connect connect)
            : base(tcp, SocketChannel.Open().ConfigureBlocking(false), connect.PullMode)
        {
            _channelRegistry = channelRegistry;
            _commander = commander;
            _connect = connect;

            Context.Watch(commander);    // sign death pact

            connect.Options.ForEach(_ => _.BeforeConnect(Channel.Socket));
            if (connect.LocalAddress != null)
                Channel.Socket.Bind(connect.LocalAddress);
            channelRegistry.Register(Channel, SocketAsyncOperation.None, Self);
            if (connect.Timeout.HasValue)
                Context.SetReceiveTimeout(connect.Timeout.Value);  //Initiate connection timeout if supplied
        }
示例#6
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="udp">TBD</param>
        /// <param name="channelRegistry">TBD</param>
        /// <param name="commander">TBD</param>
        /// <param name="options">TBD</param>
        public UdpSender(UdpExt udp, IChannelRegistry channelRegistry, IActorRef commander, IEnumerable <Inet.SocketOption> options)
        {
            _udp       = udp;
            _commander = commander;
            _options   = options;

            _channel = new Func <DatagramChannel>(() =>
            {
                var datagramChannel = DatagramChannel.Open();
                datagramChannel.ConfigureBlocking(false);
                var socket = datagramChannel.Socket;
                _options.ForEach(x => x.BeforeDatagramBind(socket));

                return(datagramChannel);
            })();

            channelRegistry.Register(_channel, SocketAsyncOperation.None, Self);
        }
示例#7
0
        public TcpOutgoingConnection(TcpExt tcp, IChannelRegistry channelRegistry, IActorRef commander, Tcp.Connect connect)
            : base(tcp, SocketChannel.Open().ConfigureBlocking(false), connect.PullMode)
        {
            _channelRegistry = channelRegistry;
            _commander       = commander;
            _connect         = connect;

            Context.Watch(commander);    // sign death pact

            connect.Options.ForEach(_ => _.BeforeConnect(Channel.Socket));
            if (connect.LocalAddress != null)
            {
                Channel.Socket.Bind(connect.LocalAddress);
            }
            channelRegistry.Register(Channel, SocketAsyncOperation.None, Self);
            if (connect.Timeout.HasValue)
            {
                Context.SetReceiveTimeout(connect.Timeout.Value);  //Initiate connection timeout if supplied
            }
        }
示例#8
0
        public UdpListener(UdpExt udp, IChannelRegistry channelRegistry, IActorRef bindCommander, Udp.Bind bind)
        {
            _udp             = udp;
            _channelRegistry = channelRegistry;
            _bindCommander   = bindCommander;
            _bind            = bind;

            _selector = Context.Parent;

            Context.Watch(bind.Handler);        // sign death pact

            _channel = (bind.Options.OfType <Inet.DatagramChannelCreator>()
                        .FirstOrDefault() ?? new Inet.DatagramChannelCreator()).Create();
            _channel.ConfigureBlocking(false);

            var localAddress = new Func <object>(() =>
            {
                try
                {
                    var socket = Channel.Socket;
                    bind.Options.ForEach(x => x.BeforeDatagramBind(socket));
                    socket.Bind(bind.LocalAddress);
                    var ret = socket.LocalEndPoint;
                    if (ret == null)
                    {
                        throw new ArgumentException(string.Format("bound to unknown SocketAddress [{0}]", socket.LocalEndPoint));
                    }
                    channelRegistry.Register(Channel, SocketAsyncOperation.Receive, Self);
                    _log.Debug("Successfully bound to [{0}]", ret);
                    bind.Options.OfType <Inet.SocketOptionV2>().ForEach(x => x.AfterBind(socket));
                    return(ret);
                }
                catch (Exception e)
                {
                    bindCommander.Tell(new Udp.CommandFailed(bind));
                    _log.Error(e, "Failed to bind UDP channel to endpoint [{0}]", bind.LocalAddress);
                    Context.Stop(Self);
                    return(null);
                }
            })();
        }
 public TestTcpOutgoingConnection(TcpExt tcp, IChannelRegistry channelRegistry, IActorRef commander, Tcp.Connect connect)
     : base(tcp, channelRegistry, commander, connect)
 {
 }
示例#10
0
 public ChannelMessagingTemplate(IChannelRegistry registry)
 {
     _registry = registry;
 }
示例#11
0
 public TestTcpOutgoingConnection(TcpExt tcp, IChannelRegistry channelRegistry, IActorRef commander, Tcp.Connect connect)
     : base(tcp, channelRegistry, commander, connect) 
 { }