示例#1
0
        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(), _client.GetNearCacheManager(), this, _client.GetClientConfig());
            DistributedEventHandler eventHandler = delegate(IClientMessage message)
            {
                ClientAddDistributedObjectListenerCodec.EventHandler.HandleEvent(message, (name, serviceName, eventType) =>
                {
                    var _event = new LazyDistributedObjectEvent(eventType, serviceName, name, this);
                    switch (eventType)
                    {
                    case DistributedObjectEvent.EventType.Created:
                        listener.DistributedObjectCreated(_event);
                        break;

                    case DistributedObjectEvent.EventType.Destroyed:
                        listener.DistributedObjectDestroyed(_event);
                        break;

                    default:
                        Logger.Warning(string.Format("Undefined DistributedObjectListener event type received: {0} !!!",
                                                     eventType));
                        break;
                    }
                });
            };

            return(context.GetListenerService().RegisterListener(request,
                                                                 m => ClientAddDistributedObjectListenerCodec.DecodeResponse(m).response,
                                                                 ClientRemoveDistributedObjectListenerCodec.EncodeRequest, eventHandler));
        }
        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));
        }
示例#3
0
        private void HandleResponseMessage(IClientMessage response)
        {
            var correlationId = response.GetCorrelationId();
            ClientInvocation invocation;

            if (_invocations.TryRemove(correlationId, out invocation))
            {
                if (response.GetMessageType() == Error.Type)
                {
                    var error = Error.Decode(response);
                    if (Logger.IsFinestEnabled())
                    {
                        Logger.Finest("Error received from server: " + error);
                    }
                    var exception = ExceptionUtil.ToException(error);

                    // retry only specific exceptions
                    HandleInvocationException(invocation, exception);
                }
                // if this was a re-registration operation, then we will throw away the response and just store the alias
                else if ((invocation is ClientListenerInvocation) &&
                         (invocation.Future.IsComplete && invocation.Future.Result != null))
                {
                    var listenerInvocation     = (ClientListenerInvocation)invocation;
                    var originalRegistrationId = GetRegistrationIdFromResponse(listenerInvocation);
                    var newRegistrationId      = listenerInvocation.ResponseDecoder(response);
                    _client.GetListenerService()
                    .ReregisterListener(originalRegistrationId, newRegistrationId,
                                        invocation.Message.GetCorrelationId());
                    if (Logger.IsFinestEnabled())
                    {
                        Logger.Finest(string.Format("Re-registered listener for {0} of type {1:X}",
                                                    originalRegistrationId,
                                                    listenerInvocation.Message.GetMessageType()));
                    }
                }
                else
                {
                    invocation.Future.Result = response;
                }
            }
            else
            {
                Logger.Warning("No call for correlationId: " + correlationId + ", response: " + response);
            }
        }
 public void Start()
 {
     _clientConnectionManager = _client.GetConnectionManager();
     _clientListenerService   = _client.GetListenerService();
     _clientConnectionManager.AddConnectionListener(this);
 }