示例#1
0
 public override void Call(RpcServerContext ctx)
 {
     if (RatePerSecond != null)
     {
         try {
             if (RatePerSecond != null)
             {
                 RatePerSecond.Increment();
                 Concurrent.Increment();
             }
             Method.Invoke(Service, new object[] { new RpcBatchServerContext(ctx) });
         } catch (Exception ex) {
             ctx.ReturnError(RpcErrorCode.ServerError, ex);
         } finally {
             Concurrent.Decrement();
         }
     }
     else
     {
         try {
             Method.Invoke(Service, new object[] { new RpcBatchServerContext(ctx) });
         } catch (Exception ex) {
             ctx.ReturnError(RpcErrorCode.ServerError, ex);
         }
     }
 }
示例#2
0
        public void Add(RpcServerContext context)
        {
            RpcClass <int, int> c = context.GetArgs <RpcClass <int, int> >();

            // Console.WriteLine("Rpc.Test1 {0} {1}", c.Value1, c.Value2);
            context.Return(c.Value1 + c.Value2);
        }
示例#3
0
        public void ProcessTransaction(RpcServerTransaction tx)
        {
            RpcServerContext context = null;

            try {
                context = new RpcServerContext(tx);

                RpcServiceBase serviceBase;
                _perfCounter.InvokePerSec.Increment();
                _perfCounter.InvokeTotal.Increment();
                _perfCounter.ConcurrentThreads.Increment();
                _perfCounter.ConcurrentContext.Increment();

                if (_services.TryGetValue(context.ServiceName, out serviceBase))
                {
                    serviceBase.OnTransactionStart(context);
                }
                else
                {
                    context.ReturnError(RpcErrorCode.ServiceNotFound, new Exception(context.ServiceName + " NotFound"));
                }
            } catch (RpcException ex) {
                context.ReturnError(ex.RpcCode, ex);
            } catch (Exception ex) {
                context.ReturnError(RpcErrorCode.ServerError, ex);
            } finally {
                _perfCounter.ConcurrentThreads.Decrement();
            }
        }
示例#4
0
        public void Register(RpcServerContext ctx)
        {
            //
            // 已经连接过的就返回失败
            if (ctx.Connection.Contexts["session"] != null)
            {
                ctx.ReturnError(RpcErrorCode.ConnectionBroken, null);
                return;
            }

            var args = ctx.GetArgs <DuplexDemoRegisterArgs>();

            if (args.UserName == "foo" && args.Passwd == "bar")
            {
                //
                // 注册成功, 建立session对象
                var session = new DuplexDemoSession()
                {
                    Id         = Guid.NewGuid().ToString(),
                    LastTime   = DateTime.Now,
                    Connection = ctx.Connection,
                };
                ctx.Connection.Contexts["session"] = session;
                lock (_syncRoot) {
                    _agents.Add(ctx.From, session);
                }
                ctx.Return();
            }
            else
            {
                ctx.ReturnError(RpcErrorCode.ConnectionFailed, new Exception("UserNotFound"));
            }
        }
示例#5
0
        public void  ListFailedTransactions(RpcServerContext ctx)
        {
            if (_coordinator == null)
            {
                throw new Exception("Coordinator is Null");
            }
            string transName = ctx.GetArgs <string>();

            if (transName != _coordinator.TransName)
            {
                throw new Exception("TransName not Matched");
            }
            List <TccTransactionData>    dataList = (List <TccTransactionData>)_coordinator.GetFailedTransactions();
            RpcList <TccTransactionData> rpcList  = null;

            if (dataList != null && dataList.Count > 0)
            {
                rpcList = new RpcList <TccTransactionData>();
                foreach (TccTransactionData data in dataList)
                {
                    rpcList.Value.Add(data);
                }
            }
            ctx.Return <RpcList <TccTransactionData> >(rpcList);
        }
示例#6
0
        public override void OnTransactionStart(RpcServerContext context)
        {
            string m = context.MethodName;
            string unitName;
            TccAction action;
            if (m.StartsWith("try_")) {
                action = TccAction.Try;
                unitName = m.Substring("try_".Length);
            } else if (m.StartsWith("confirm_")) {
                action = TccAction.Confirm;
                unitName = m.Substring("confirm_".Length);
            } else if (m.StartsWith("cancel_")) {
                action = TccAction.Cancel;
                unitName = m.Substring("cancel_".Length);
            } else {
                context.ReturnError(RpcErrorCode.MethodNotFound, null);
                return;
            }

            ITccRpcHostUnit unit;
            if (_instance._units.TryGetValue(unitName, out unit)) {
                unit.Invoke(context, action);
            } else {
                context.ReturnError(RpcErrorCode.MethodNotFound, null);
            }
        }
示例#7
0
        public void KeepAlive(RpcServerContext ctx)
        {
            int seconds = ctx.GetArgs <int>();
            DuplexDemoSession session = (DuplexDemoSession)ctx.Connection.Contexts["session"];

            session.LastTime = DateTime.Now.AddSeconds(seconds);
            ctx.Return(0);              // 没意义
        }
示例#8
0
        public override void OnTransactionStart(RpcServerContext context)
        {
            //MasterClientUri uri = (MasterClientUri)(context.ContextUri);
            //RpcDuplexServer.findClient(uri);

            //RpcConnection connection;

            //context.
        }
示例#9
0
        public void AppendSystemLog(RpcServerContext context)
        {
            RpcList <SystemLogEvent> evts = context.GetArgs <RpcList <SystemLogEvent> >();

            foreach (SystemLogEvent evt in evts.Value)
            {
                Console.WriteLine(evt.ToString());
            }
            WaitEvent.Set();
            context.Return();
        }
示例#10
0
 public void GetProtocolInfo(RpcServerContext ctx)
 {
     //RpcProtocolInfo ret = new RpcProtocolInfo() {
     //    Version = "4.0",
     //    ServiceName = ServiceEnviornment.ServiceName,
     //    ComputerName = ServiceEnviornment.ComputerName,
     //    AutoBatch = true,
     //    BatchCount = 32,
     //    BatchIdleMs = 60,
     //    MaxBodySize = ctx.Channel.ChannelSettings,
     //};
     //ctx.Return(ret);
     throw new NotImplementedException();
 }
示例#11
0
        public void KeepAlive(RpcServerContext ctx)
        {
            var token = (RpcDuplexConnectionToken)ctx.Connection.Contexts["Duplex"];

            if (token != null && token.Registerd)
            {
                token.ProcessKeepalive(ctx);
            }
            else
            {
                ctx.Return(RpcErrorCode.ConnectionFailed);
                return;
            }
        }
示例#12
0
        public void Register(RpcServerContext ctx)
        {
            var token = (RpcDuplexConnectionToken)ctx.Connection.Contexts["Duplex"];

            if (token.Registerd)
            {
                ctx.Return(RpcErrorCode.ConnectionFailed);
                return;
            }
            else
            {
                token.ProcessRegister(ctx);
            }
        }
示例#13
0
        void ITccRpcHostUnit.Invoke(RpcServerContext context, TccAction action)
        {
            var ctx = new TccRpcContext <TArgs, TResults>(context);

            switch (action)
            {
            case TccAction.Try:
                Try(ctx);
                break;

            case TccAction.Confirm:
                Confirm(ctx);
                break;

            case TccAction.Cancel:
                Cancel(ctx);
                break;

            default:
                throw new NotSupportedException();
            }
        }
示例#14
0
        public override void OnTransactionStart(RpcServerContext context)
        {
            string    m = context.MethodName;
            string    unitName;
            TccAction action;

            if (m.StartsWith("try_"))
            {
                action   = TccAction.Try;
                unitName = m.Substring("try_".Length);
            }
            else if (m.StartsWith("confirm_"))
            {
                action   = TccAction.Confirm;
                unitName = m.Substring("confirm_".Length);
            }
            else if (m.StartsWith("cancel_"))
            {
                action   = TccAction.Cancel;
                unitName = m.Substring("cancel_".Length);
            }
            else
            {
                context.ReturnError(RpcErrorCode.MethodNotFound, null);
                return;
            }

            ITccRpcHostUnit unit;

            if (_instance._units.TryGetValue(unitName, out unit))
            {
                unit.Invoke(context, action);
            }
            else
            {
                context.ReturnError(RpcErrorCode.MethodNotFound, null);
            }
        }
示例#15
0
 public void ProcessRegister(RpcServerContext ctx)
 {
     _duplexServer.ProcessRegister(this, ctx);
 }
示例#16
0
 public void Array(RpcServerContext context)
 {
     byte[] a = context.GetArgs <byte[]>();
     context.Return(a);
 }
示例#17
0
 public void CallCommand(RpcServerContext ctx)
 {
     throw new NotImplementedException();
 }
示例#18
0
 public void ProcessKeepalive(RpcServerContext ctx)
 {
     _duplexServer.ProcessKeepAlive(this, ctx);
 }
示例#19
0
 public void AppendConsole(RpcServerContext context)
 {
     throw new NotImplementedException();
 }
示例#20
0
 public void Stop(RpcServerContext ctx)
 {
     throw new NotImplementedException();
 }
示例#21
0
 public abstract void OnTransactionStart(RpcServerContext context);
示例#22
0
 public void EnumMethodInfo(RpcServerContext ctx)
 {
     throw new NotImplementedException();
 }
示例#23
0
        public void Mirror(RpcServerContext context)
        {
            var e = context.GetArgs <RpcClass <int> >();

            context.Return(e);
        }
示例#24
0
 public TccRpcContext(RpcServerContext context)
 {
     Args         = context.GetArgs <TArgs>();
     InnerContext = context;
 }
 public RpcServer(IPEndPoint endPoint)
 {
     _serverContext = new RpcServerContext(this);
     _tcpManager = new TcpTransportManager(endPoint, _serverContext);
 }
示例#26
0
 public void Null(RpcServerContext context)
 {
     context.Return <RpcClass <int> >(null);
 }
示例#27
0
        public void Default(RpcServerContext context)
        {
            RpcClass <int> a = new RpcClass <int>();

            context.Return(a);
        }
示例#28
0
 public void TestException(RpcServerContext context)
 {
     context.ThrowException(new ApplicationException("TestException"));
 }
示例#29
0
 public void TestTimeout(RpcServerContext context)
 {
     Thread.Sleep(60000);
     context.Return();
 }
示例#30
0
 public RpcServer(IPEndPoint endPoint)
 {
     _serverContext = new RpcServerContext(this);
     _tcpManager    = new TcpTransportManager(endPoint, _serverContext);
 }
示例#31
0
 public override void OnTransactionStart(RpcServerContext context)
 {
     _serviceProc(context);
 }