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); } } }
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); }
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(); } }
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")); } }
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); }
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); } }
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); // 没意义 }
public override void OnTransactionStart(RpcServerContext context) { //MasterClientUri uri = (MasterClientUri)(context.ContextUri); //RpcDuplexServer.findClient(uri); //RpcConnection connection; //context. }
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(); }
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(); }
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; } }
public void Register(RpcServerContext ctx) { var token = (RpcDuplexConnectionToken)ctx.Connection.Contexts["Duplex"]; if (token.Registerd) { ctx.Return(RpcErrorCode.ConnectionFailed); return; } else { token.ProcessRegister(ctx); } }
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(); } }
public void ProcessRegister(RpcServerContext ctx) { _duplexServer.ProcessRegister(this, ctx); }
public void Array(RpcServerContext context) { byte[] a = context.GetArgs <byte[]>(); context.Return(a); }
public void CallCommand(RpcServerContext ctx) { throw new NotImplementedException(); }
public void ProcessKeepalive(RpcServerContext ctx) { _duplexServer.ProcessKeepAlive(this, ctx); }
public void AppendConsole(RpcServerContext context) { throw new NotImplementedException(); }
public void Stop(RpcServerContext ctx) { throw new NotImplementedException(); }
public abstract void OnTransactionStart(RpcServerContext context);
public void EnumMethodInfo(RpcServerContext ctx) { throw new NotImplementedException(); }
public void Mirror(RpcServerContext context) { var e = context.GetArgs <RpcClass <int> >(); context.Return(e); }
public TccRpcContext(RpcServerContext context) { Args = context.GetArgs <TArgs>(); InnerContext = context; }
public RpcServer(IPEndPoint endPoint) { _serverContext = new RpcServerContext(this); _tcpManager = new TcpTransportManager(endPoint, _serverContext); }
public void Null(RpcServerContext context) { context.Return <RpcClass <int> >(null); }
public void Default(RpcServerContext context) { RpcClass <int> a = new RpcClass <int>(); context.Return(a); }
public void TestException(RpcServerContext context) { context.ThrowException(new ApplicationException("TestException")); }
public void TestTimeout(RpcServerContext context) { Thread.Sleep(60000); context.Return(); }
public override void OnTransactionStart(RpcServerContext context) { _serviceProc(context); }