Пример #1
0
        public object SendAsync(Server destination, Object message, bool noResponse)
        {
            if (_primaryChannel != null)
            {
                try
                {
                    if (_primaryChannel.IsAuthenticated)
                    {
                        return(_primaryChannel.SendMessage(message, noResponse));
                    }
                    else
                    {
                        throw new SecurityException(ErrorCodes.Security.UNAUTHENTIC_DB_SERVER_CONNECTION,
                                                    new string[] { this.Name, _primaryChannel.PeerAddress.IpAddress.ToString() });
                    }
                }
                catch (System.TimeoutException)
                {
                    throw new DistributorException(ErrorCodes.Distributor.TIMEOUT,
                                                   new string[] { _primaryChannel.PeerAddress.ToString() });
                }
                catch (Common.Exceptions.TimeoutException)
                {
                    throw new DistributorException(ErrorCodes.Distributor.TIMEOUT,
                                                   new string[] { _primaryChannel.PeerAddress.ToString() });
                }
                catch (ChannelException)
                {
                    throw new DistributorException(ErrorCodes.Distributor.CHANNEL_NOT_RESPONDING,
                                                   new string[] { _primaryChannel.PeerAddress.ToString() });
                }
            }

            throw new DistributorException(ErrorCodes.Distributor.NO_CHANNEL_EXISTS,
                                           new string[] { destination.Address.ToString(), this.Name });
        }
Пример #2
0
        private void ConnectPrimary(Address primary)
        {
            // check if the shardConnected event is required to be raised
            bool shardConnected = false;

            // If primary is null, it means the respective shard has no primary anymore so
            if (primary == null)
            {
                if (_remoteShardChannel != null)
                {
                    ((DualChannel)_remoteShardChannel).ShouldTryReconnecting = false;
                    _remoteShardChannel.Disconnect();
                    _remoteShardChannel = null;
                }
            }
            else
            {
                if (_remoteShardChannel != null)
                {
                    if (_remoteShardChannel.PeerAddress.Equals(primary) && ((IDualChannel)this._remoteShardChannel).Connected)
                    {
                        return;
                    }
                }


                bool isConnected = false;
                IRequestResponseChannel channel = factory.GetChannel(primary.IpAddress.ToString(), _shardPort, context.LocalAddress.IpAddress.ToString(), SessionTypes.Shard, _traceProvider, _channelFormatter);
                try
                {
                    isConnected = channel.Connect(false);
                }
                catch (ChannelException e)
                {
                    if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsErrorEnabled)
                    {
                        LoggerManager.Instance.ShardLogger.Error("Error: RemoteShard.OnPrimaryChanged()", e.ToString());
                    }
                }
                //catch (Exception ex)
                //{
                //    if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsErrorEnabled)
                //        LoggerManager.Instance.ShardLogger.Error("Error: RemoteShard.OnPrimaryChanged()", e.ToString());
                //}

                if (isConnected)
                {
                    SessionInfo info = new SessionInfo();
                    info.Cluster = this.Context.ClusterName;
                    info.Shard   = this.Context.LocalShardName;

                    channel.SendMessage(info, true);

                    lock (_onChannel)
                    {
                        _remoteShardChannel = _resolveDispute.GetValidChannel(_resolveDispute.SetConnectInfo(channel as IDualChannel, ConnectInfo.ConnectStatus.CONNECT_FIRST_TIME), _remoteShardChannel);
                        ((IDualChannel)_remoteShardChannel).StartReceiverThread();
                        ((IDualChannel)_remoteShardChannel).RegisterRequestHandler(this);
                        shardConnected = true;
                    }
                    lock (_onPrimary)
                    {
                        _primary = new Server(new Address(primary.IpAddress.ToString(), primary.Port), Status.Running);
                    }
                }
            }

            if (shardConnected)
            {
                ShardConnected();
            }
        }