コード例 #1
0
        public void Init(ClientConfig config)
        {
            // register defaults
            Register(ServiceNames.Map, (type, id) =>
            {
                var clientConfig    = _client.GetClientConfig();
                var nearCacheConfig = clientConfig.GetNearCacheConfig(id);
                var proxyType       = nearCacheConfig != null ? typeof(ClientMapNearCacheProxy <,>) : typeof(ClientMapProxy <,>);
                return(ProxyFactory(proxyType, type, ServiceNames.Map, id));
            });
            Register(ServiceNames.Queue,
                     (type, id) => ProxyFactory(typeof(ClientQueueProxy <>), type, ServiceNames.Queue, id));
            Register(ServiceNames.MultiMap,
                     (type, id) => ProxyFactory(typeof(ClientMultiMapProxy <,>), type, ServiceNames.MultiMap, id));
            Register(ServiceNames.List,
                     (type, id) => ProxyFactory(typeof(ClientListProxy <>), type, ServiceNames.List, id));
            Register(ServiceNames.Set,
                     (type, id) => ProxyFactory(typeof(ClientSetProxy <>), type, ServiceNames.Set, id));
            Register(ServiceNames.Topic,
                     (type, id) => ProxyFactory(typeof(ClientTopicProxy <>), type, ServiceNames.Topic, id));
            Register(ServiceNames.AtomicLong,
                     (type, id) => ProxyFactory(typeof(ClientAtomicLongProxy), type, ServiceNames.AtomicLong, id));
            Register(ServiceNames.Lock, (type, id) => ProxyFactory(typeof(ClientLockProxy), type, ServiceNames.Lock, id));
            Register(ServiceNames.CountDownLatch,
                     (type, id) => ProxyFactory(typeof(ClientCountDownLatchProxy), type, ServiceNames.CountDownLatch, id));
            Register(ServiceNames.PNCounter,
                     (type, id) => ProxyFactory(typeof(ClientPNCounterProxy), type, ServiceNames.PNCounter, id));
            Register(ServiceNames.Semaphore,
                     (type, id) => ProxyFactory(typeof(ClientSemaphoreProxy), type, ServiceNames.Semaphore, id));
            Register(ServiceNames.Ringbuffer,
                     (type, id) => ProxyFactory(typeof(ClientRingbufferProxy <>), type, ServiceNames.Ringbuffer, id));
            Register(ServiceNames.ReplicatedMap,
                     (type, id) => ProxyFactory(typeof(ClientReplicatedMapProxy <,>), type, ServiceNames.ReplicatedMap, id));

            Register(ServiceNames.IdGenerator, delegate(Type type, string id)
            {
                var atomicLong = _client.GetAtomicLong("IdGeneratorService.ATOMIC_LONG_NAME" + id);
                return(Activator.CreateInstance(typeof(ClientIdGeneratorProxy), ServiceNames.IdGenerator, id, atomicLong) as
                       ClientProxy);
            });

            foreach (var proxyFactoryConfig in config.GetProxyFactoryConfigs())
            {
                try
                {
                    ClientProxyFactory clientProxyFactory = null;
                    var type = Type.GetType(proxyFactoryConfig.GetClassName());
                    if (type != null)
                    {
                        clientProxyFactory = (ClientProxyFactory)Activator.CreateInstance(type);
                    }

                    Register(proxyFactoryConfig.GetService(), clientProxyFactory);
                }
                catch (Exception e)
                {
                    Logger.Severe(e);
                }
            }
        }