Ejemplo n.º 1
0
        protected object ExecuteCommandOnMgtServer(object message, bool Response)
        {
            ManagementResponse managementResponse = null;

            if (_channel != null)
            {
                try
                {
                    managementResponse = _channel.SendMessage(message, !Response) as ManagementResponse;
                }
                catch (System.Exception e)
                {
                    throw new System.Exception(e.Message, e);
                }
                if (managementResponse != null && managementResponse.Exception != null)
                {
                    throw new System.Exception(managementResponse.Exception.Message);
                }
            }
            if (managementResponse != null)
            {
                return(managementResponse.ResponseMessage);
            }

            return(null);
        }
        protected object  ExecuteCommandOnConfigurationServer(Alachisoft.NosDB.Common.Protobuf.ManagementCommands.ManagementCommand command, bool response)
        {
            ManagementResponse managementResponse = null;

            if (_channel != null)
            {
                try
                {
                    managementResponse = _channel.SendMessage(command, response) as ManagementResponse;
                }
                catch (System.Exception e)
                {
                    throw e;
                }

                if (managementResponse != null && managementResponse.Exception != null)
                {
                    throw new System.Exception(managementResponse.Exception.Message);
                }
            }

            if (managementResponse != null)
            {
                return(managementResponse.ReturnVal);
            }

            return(null);
        }
Ejemplo n.º 3
0
        private void FormChannelConnection(Server server)
        {
            if (server.Address.Equals(context.LocalAddress))
            {
                try
                {
                    IDualChannel channel = new LocalChannel(context.LocalAddress, this);
                    lock (_shardChannels)
                    {
                        _shardChannels[server] = channel;
                    }
                }
                catch (Exception e)
                {
                    if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsErrorEnabled)
                    {
                        LoggerManager.Instance.ShardLogger.Error("LocalShard.FormChannel()", "Local node: " + e.ToString());
                    }
                }
            }
            else
            {
                DualChannel channel = new DualChannel(server.Address.IpAddress.ToString(), server.Address.Port, context.LocalAddress.IpAddress.ToString(), SessionTypes.Shard, _traceProvider, _channelFormatter);
                try
                {
                    if (channel.Connect(false))
                    {
                        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.CONNECT_FIRST_TIME), _shardChannels);
                        lock (_shardChannels)
                        {
                            _shardChannels[server] = acceptedChannel;
                        }

                        _shardChannels[server].RegisterRequestHandler(this);
                        _shardChannels[server].StartReceiverThread();
                    }
                }
                catch (ChannelException ex)
                {
                    if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsErrorEnabled)
                    {
                        LoggerManager.Instance.ShardLogger.Error("LocalShard.Start()", "Local shard: " + Name + ": Connection with " + server.Address + " failed to establish. " + ex);
                    }
                }
            }
        }