public RpcSessionContext() { DefaultExecutionTimeout = 10000; OrderedExecution = false; OrderedExecutionMaxQueue = 32; TaskScheduler = TaskScheduler.Default; RemotingObjectConfiguration = RemotingObjectConfiguration.Default; }
public RpcSession(RpcSessionContext sessionContext) { if (sessionContext.Serializer == null) { throw new ArgumentNullException(nameof(sessionContext.Serializer)); } if (sessionContext.Connection == null) { throw new ArgumentNullException(nameof(sessionContext.Connection)); } if (sessionContext.LogManager == null) { throw new ArgumentNullException(nameof(sessionContext.LogManager)); } if (sessionContext.TaskScheduler == null) { throw new ArgumentNullException(nameof(sessionContext.TaskScheduler)); } this.requests = new ConcurrentDictionary <uint, RemotingRequest>(); this.rpcSerializer = sessionContext.Serializer; this.orderedExecution = sessionContext.OrderedExecution; this.orderedExecutionTask = Task.CompletedTask; this.orderedExecutionMaxQueue = sessionContext.OrderedExecutionMaxQueue; this.remotingObjectConfiguration = sessionContext.RemotingObjectConfiguration; this.taskScheduler = sessionContext.TaskScheduler; this.Connection = sessionContext.Connection; this.defaultExecutionTimeout = sessionContext.DefaultExecutionTimeout; this.logger = sessionContext.LogManager.GetLogger(nameof(RpcSession)); this.logger.Meta["kind"] = this.GetType().Name; this.logger.Meta["connection_id"] = this.Connection.Id; this.logger.Meta["connection_endpoint"] = new RefLogLabel <IRpcConnection>(this.Connection, s => s.RemoteEndpoint); this.logger.Meta["closed"] = new RefLogLabel <RpcSession>(this, s => s.closed); this.logger.Meta["tag"] = new RefLogLabel <RpcSession>(this, s => s.Tag); this.logger.Meta["latency"] = new RefLogLabel <RpcSession>(this, s => { var lat = s.Connection.Latency; if (lat.HasValue) { return(lat.Value); } else { return(""); } }); this.logger.Debug($"{sessionContext.Connection} created {this}"); }
void Init(RemotingObjectConfiguration configuration, Type entityType) { Dictionary <object, MethodContainer> myRemotingMethods2 = new Dictionary <object, MethodContainer>(); BindingFlags flags = BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance; if (configuration.AllowNonPublicMethods) { flags |= BindingFlags.NonPublic; } foreach (var method in entityType .GetMethods(flags)) { var attr = method.GetCustomAttribute <RemotingMethodAttribute>(true); var asyncAttr = method.GetCustomAttribute <AsyncStateMachineAttribute>(true); if (attr == null) { continue; } var isReturnGenericTask = method.ReturnType.IsGenericType && method.ReturnType.GetGenericTypeDefinition() == typeof(Task <>); var isReturnTask = method.ReturnType == typeof(Task); if (!configuration.AllowAsync && (asyncAttr != null || isReturnGenericTask || isReturnTask)) { throw new TypeLoadException($"Async method {method.Name} not allowed in {entityType.FullName}"); } if (!configuration.AllowNonVoid && method.ReturnType != typeof(void)) { throw new TypeLoadException($"Non void method {method.Name} not allowed in {entityType.FullName}"); } if (asyncAttr != null && method.ReturnType == typeof(void)) { throw new TypeLoadException($"Async void methods not allowed: {entityType.FullName}, {method.Name}. Please change it to async Task."); } switch (attr.MethodIdentityType) { case RemotingMethodAttribute.MethodIdentityTypeEnum.ByIndex: myRemotingMethods2.Add(attr.Index, new MethodContainer(method, configuration.AllowLambdaExpressions)); break; case RemotingMethodAttribute.MethodIdentityTypeEnum.ByName: myRemotingMethods2.Add(attr.Name, new MethodContainer(method, configuration.AllowLambdaExpressions)); break; case RemotingMethodAttribute.MethodIdentityTypeEnum.Default: myRemotingMethods2.Add(method.Name, new MethodContainer(method, configuration.AllowLambdaExpressions)); break; default: throw new ArgumentException($"Could not get method identification for {method.Name}"); } } this.remotingMethods = myRemotingMethods2; }
public RemotingObjectScheme(RemotingObjectConfiguration configuration, Type entityType) { this.EntityType = entityType; Init(configuration, entityType); }