Ejemplo n.º 1
0
        public ClientProxy RemoveProxy(string service, string id)
        {
            var         ns = new ObjectNamespace(service, id);
            ClientProxy removed;

            _proxies.TryRemove(ns, out removed);
            return(removed);
        }
Ejemplo n.º 2
0
        public ClientProxy GetProxy(string service, string id)
        {
            var         ns = new ObjectNamespace(service, id);
            ClientProxy proxy;

            _proxies.TryGetValue(ns, out proxy);
            if (proxy != null)
            {
                return(proxy);
            }
            return(null);
        }
Ejemplo n.º 3
0
        public ClientProxy GetOrCreateProxy <T>(string service, string id) where T : IDistributedObject
        {
            var         ns = new ObjectNamespace(service, id);
            ClientProxy proxy;

            _proxies.TryGetValue(ns, out proxy);
            var requestedInterface = typeof(T);

            if (proxy != null)
            {
                // only return the existing proxy, if the requested type args match
                var proxyInterface = proxy.GetType().GetInterface(requestedInterface.Name);
                var proxyArgs      = proxyInterface.GetGenericArguments();
                var requestedArgs  = requestedInterface.GetGenericArguments();
                if (proxyArgs.SequenceEqual(requestedArgs))
                {
                    // the proxy we found matches what we were looking for
                    return(proxy);
                }

                // create a new proxy, which matches the interface requested
                proxy = makeProxy <T>(service, id, requestedInterface);
            }
            else
            {
                // create a new proxy, which needs initialization on server.
                proxy = makeProxy <T>(service, id, requestedInterface);
                InitializeWithRetry(proxy);
            }

            proxy.SetContext(new ClientContext(_client.GetSerializationService(),
                                               _client.GetClientClusterService(),
                                               _client.GetClientPartitionService(), _client.GetInvocationService(), _client.GetClientExecutionService(),
                                               _client.GetListenerService(),
                                               this, _client.GetClientConfig()));
            proxy.PostInit();

            _proxies.AddOrUpdate(ns, n => proxy, (n, oldProxy) => {
                Logger.Warning("Replacing old proxy for " + oldProxy.GetName() + " of type " + oldProxy.GetType() + " with " + proxy.GetType());
                return(proxy);
            });
            return(proxy);
        }
        public string AddDistributedObjectListener(IDistributedObjectListener listener)
        {
            var isSmart = _client.GetClientConfig().GetNetworkConfig().IsSmartRouting();
            var request = ClientAddDistributedObjectListenerCodec.EncodeRequest(isSmart);
            var context = new ClientContext(_client.GetSerializationService(), _client.GetClientClusterService(),
                                            _client.GetClientPartitionService(), _client.GetInvocationService(), _client.GetClientExecutionService(),
                                            _client.GetListenerService(),
                                            this, _client.GetClientConfig());
            //EventHandler<PortableDistributedObjectEvent> eventHandler = new _EventHandler_211(this, listener);

            DistributedEventHandler eventHandler = delegate(IClientMessage message)
            {
                ClientAddDistributedObjectListenerCodec.AbstractEventHandler.Handle(message,
                                                                                    (name, serviceName, type) =>
                {
                    var ns = new ObjectNamespace(serviceName, name);
                    ClientProxy proxy;
                    _proxies.TryGetValue(ns, out proxy);
                    if (proxy == null)
                    {
                        proxy = GetProxy(serviceName, name);
                    }
                    var _event = new DistributedObjectEvent(type, serviceName, proxy);
                    if (DistributedObjectEvent.EventType.Created.Equals(type))
                    {
                        listener.DistributedObjectCreated(_event);
                    }
                    else
                    {
                        if (DistributedObjectEvent.EventType.Destroyed.Equals(type))
                        {
                            listener.DistributedObjectDestroyed(_event);
                        }
                    }
                });
            };

            //PortableDistributedObjectEvent
            return(context.GetListenerService().RegisterListener(request,
                                                                 m => ClientAddDistributedObjectListenerCodec.DecodeResponse(m).response,
                                                                 ClientRemoveDistributedObjectListenerCodec.EncodeRequest,
                                                                 eventHandler));
        }
        public ClientProxy GetOrCreateProxy <T>(string service, string id)
        {
            var         ns = new ObjectNamespace(service, id);
            ClientProxy proxy;

            _proxies.TryGetValue(ns, out proxy);
            if (proxy != null)
            {
                return(proxy);
            }
            ClientProxyFactory factory;

            _proxyFactories.TryGetValue(service, out factory);
            if (factory == null)
            {
                throw new ArgumentException("No factory registered for service: " + service);
            }
            var clientProxy = factory(typeof(T), id);

            InitializeWithRetry(clientProxy);
            return(_proxies.GetOrAdd(ns, clientProxy));
        }