예제 #1
0
        public override IInvoker Refer(URL url)
        {
            OptimizeSerialization(url);
            var      id      = url.GetId();
            var      name    = url.ServiceName;
            IInvoker invoker = null;

            lock (_invokers)
            {
                if (_invokers.TryGetValue(name, out var list))
                {
                    invoker = list.FirstOrDefault(c => c.InvokerId == id);
                    if (invoker != null)
                    {
                        return(invoker);
                    }
                }
                else
                {
                    list = new List <IInvoker>();
                    _invokers.TryAdd(name, list);
                }
                var type = TypeMatch.MatchType(name);
                invoker           = new DubboInvoker(type, url, GetClients(url), null);
                invoker.InvokerId = id;
                list.Add(invoker);
            }
            return(invoker);
        }
예제 #2
0
        private void OptimizeSerialization(URL url)
        {
            String className = url.GetParameter(Constants.OptimizerKey, "");

            if (string.IsNullOrEmpty(className) || _optimizers.Contains(className))
            {
                return;
            }
            Logger.Info("Optimizing the serialization process for Kryo, FST, etc...");
            var clazz = TypeMatch.MatchType(className);

            if (!typeof(ISerializationOptimizer).IsAssignableFrom(clazz))
            {
                throw new Exception("The serialization optimizer " + className + " isn't an instance of " + typeof(ISerializationOptimizer).FullName);
            }
            ISerializationOptimizer optimizer = (ISerializationOptimizer)Activator.CreateInstance(clazz);

            if (optimizer.GetSerializableClasses() == null)
            {
                return;
            }
            foreach (var c in optimizer.GetSerializableClasses())
            {
                SerializableClassRegistry.RegisterClass(c);
            }
            _optimizers.Add(className);
        }