//To-do: add ConnectStatus logic.
        public IDualChannel SetConnectInfo(IDualChannel channel, ConnectInfo.ConnectStatus status)
        {
            ConnectInfo connectInfo = null;

            if (((Address)_context.LocalAddress).CompareTo((Address)channel.PeerAddress) > 0)
            {
                connectInfo        = new ConnectInfo();
                connectInfo.Status = status;
                connectInfo.Id     = GetConnectionId();

                channel.SendMessage(connectInfo, true);
                if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsDebugEnabled)
                {
                    LoggerManager.Instance.ShardLogger.Debug("ResolveChannelDispute.SetConnectInfo() ", "Node " + _context.LocalAddress.ToString() + ": Sender, " + "Node " + channel.PeerAddress.ToString() + ": Receiver.");
                }
            }
            // This specific check was necessary because somehow an earlier check for a condition was passing when it should not
            // look for an alternative way to this.
            else if (((Address)_context.LocalAddress).CompareTo((Address)channel.PeerAddress) < 0)
            {
                byte[] data = channel.ReadFromSocket();

                IRequest message = _shard.ChannelFormatter.Deserialize(data) as IRequest;
                connectInfo = message.Message as ConnectInfo;

                if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsDebugEnabled)
                {
                    LoggerManager.Instance.ShardLogger.Debug("ResolveChannelDispute.SetConnectInfo() ", "Node " + _context.LocalAddress.ToString() + ": Receiver, " + "Node " + channel.PeerAddress.ToString() + ": Sender.");
                }
            }
            channel.ConnectInfo = connectInfo;
            return(channel);
        }
Beispiel #2
0
        public object SendUnicastMessage(Server destination, Object message)
        {
            if (destination == null)
            {
                throw new ClusterException(ErrorCodes.Cluster.DESTINATION_NULL);
            }

            if (this._shardChannels != null && _shardChannels.ContainsKey(destination))
            {
                IDualChannel channel = (IDualChannel)_shardChannels[destination];

                return(channel.SendMessage(message, false));
            }

            throw new ClusterException(ErrorCodes.Cluster.DESTINATION_SERVER_NOT_EXIST, new string[] { destination.Address.ToString() });
        }
Beispiel #3
0
        public WsIQClientRx()
        {
            // TODO INJECT
            _ws            = new WebSocketWrapper();
            _epoch         = new Epoch();
            _randomNumbers = new RandomNumbers();

            MessagesFeed = Observable
                           .FromEventPattern <OnMessageEventHandler, WsRecievemessageEventArgs>(
                h => _ws.OnMessage += h,
                h => _ws.OnMessage -= h)
                           //.ObserveOn(NewThreadScheduler.Default)
                           .Map((e) =>
            {
                var serializedMessage = e.EventArgs.Message;
                var iQmessage         = JsonConvert.DeserializeObject <IQOptionMessage>(serializedMessage);
                return(iQmessage);
            });

            _onConnection = Observable
                            .FromEventPattern <OnConnectedEventHandler, EventArgs>(
                h => _ws.OnConnected += h,
                h => _ws.OnConnected -= h)
                            .Map(e => e.EventArgs)
                            .Replay();

            _onConnectionConnection = _onConnection.Connect();

            //TODO DO THIS IN THE IQCLient
            _ssidDualChannel = new SsidPublisherChannel(this);

            _heartBeatDualChannel = new HeartBeatDualChannel(this);

            _wsMessagesSubscription = _heartBeatDualChannel.ChannelFeed
                                      .Map(heartbeat => _heartBeatDualChannel.SendMessage(new HeartBeatOutputMessage(_epoch.EpochMilliSeconds, heartbeat.HeartbeatTime)))
                                      .Subscribe();

            _candleGeneratedDualChannel = new CandleGeneratedDualChannel(this);

            _serverTimeSync = new TimeSyncListenerChannel(this);

            _profileChannel = new ProfileListenerChannel(this);

            _listInfoDataChannelListener = new ListInfoDataListenerChannel(this);

            _buyV2ChannelPublisher = new BuyV2Channel(this, _epoch);
        }
Beispiel #4
0
        public void OnConnectionRestoration(IDualChannel channel)
        {
            Server      server      = new Server(channel.PeerAddress, Status.Running);
            SessionInfo sessionInfo = new SessionInfo();

            sessionInfo.Cluster = this.context.ClusterName;
            sessionInfo.Shard   = this.context.LocalShardName;

            channel.SendMessage(sessionInfo, true);

            IDualChannel acceptedChannel = _resolveDispute.GetValidChannel(_resolveDispute.SetConnectInfo(channel, ConnectInfo.ConnectStatus.RECONNECTING), _shardChannels);

            lock (_shardChannels)
            {
                _shardChannels[server] = acceptedChannel;
                _shardChannels[server].RegisterRequestHandler(this);
                _shardChannels[server].StartReceiverThread();
            }
        }
Beispiel #5
0
 public IObservable <Candle> CreateCandles(Active active, TimeSpan size)
 {
     return(_candleGeneratedDualChannel
            .SendMessage(new CandleSubscription(active, size.TotalSeconds))
            .FlatMap(_candleGeneratedDualChannel.ChannelFeed));
 }