示例#1
0
        private void RegisterListenerOnConnection(ListenerRegistration listenerRegistration, ClientConnection connection)
        {
            //This method should only be called from registrationExecutor
            Debug.Assert(Thread.CurrentThread.Name != null && Thread.CurrentThread.Name.Contains("eventRegistration"));

            if (listenerRegistration.ConnectionRegistrations.ContainsKey(connection))
            {
                return;
            }
            var future = ((ClientInvocationService)_client.GetInvocationService()).InvokeListenerOnConnection(
                listenerRegistration.RegistrationRequest, listenerRegistration.EventHandler, connection);

            IClientMessage clientMessage;

            try
            {
                clientMessage = ThreadUtil.GetResult(future);
            }
            catch (Exception e)
            {
                throw ExceptionUtil.Rethrow(e);
            }

            var serverRegistrationId = listenerRegistration.DecodeRegisterResponse(clientMessage);
            var correlationId        = listenerRegistration.RegistrationRequest.GetCorrelationId();
            var registration         = new EventRegistration(serverRegistrationId, correlationId, connection);

            Debug.Assert(listenerRegistration.ConnectionRegistrations != null, "registrationMap should be created!");
            listenerRegistration.ConnectionRegistrations[connection] = registration;
        }
 private void RegisterListenerFromInternal(ListenerRegistration listenerRegistration, Connection connection)
 {
     //This method should only be called from registrationExecutor
     Debug.Assert(Thread.CurrentThread.Name != null && Thread.CurrentThread.Name.Contains("eventRegistration"));
     try
     {
         RegisterListenerOnConnection(listenerRegistration, connection);
     }
     catch (Exception e)
     {
         Logger.Warning(
             $"Listener {listenerRegistration} can not be added to a new connection: {connection}, reason: {e.Message}");
     }
 }
示例#3
0
        public string RegisterListener(IClientMessage registrationMessage, DecodeRegisterResponse responseDecoder,
                                       EncodeDeregisterRequest encodeDeregisterRequest, DistributedEventHandler eventHandler)
        {
            //This method should not be called from registrationExecutor
            Debug.Assert(Thread.CurrentThread.Name == null || !Thread.CurrentThread.Name.Contains("eventRegistration"));

            TrySyncConnectToAllConnections();
            var registrationTask = new Task <string>(() =>
            {
                var userRegistrationId = Guid.NewGuid().ToString();

                var listenerRegistration = new ListenerRegistration(userRegistrationId, registrationMessage, responseDecoder,
                                                                    encodeDeregisterRequest, eventHandler);

                _registrations.TryAdd(userRegistrationId, listenerRegistration);

                var connections = _connectionManager.ActiveConnections;
                foreach (var connection in connections)
                {
                    try
                    {
                        RegisterListenerOnConnection(listenerRegistration, connection);
                    }
                    catch (Exception e)
                    {
                        if (connection.Live)
                        {
                            DeregisterListenerInternal(userRegistrationId);
                            throw new HazelcastException("Listener cannot be added ", e);
                        }
                    }
                }
                return(userRegistrationId);
            });

            try
            {
                registrationTask.Start(_registrationScheduler);
                return(registrationTask.Result);
            }
            catch (Exception e)
            {
                throw ExceptionUtil.Rethrow(e);
            }
        }
示例#4
0
 private void RegisterListenerFromInternal(ListenerRegistration listenerRegistration, ClientConnection connection)
 {
     //This method should only be called from registrationExecutor
     Debug.Assert(Thread.CurrentThread.Name != null && Thread.CurrentThread.Name.Contains("eventRegistration"));
     try
     {
         RegisterListenerOnConnection(listenerRegistration, connection);
     }
     catch (IOException)
     {
         ICollection <ListenerRegistration> failedRegsToConnection;
         if (!_failedRegistrations.TryGetValue(connection, out failedRegsToConnection))
         {
             failedRegsToConnection           = new HashSet <ListenerRegistration>();
             _failedRegistrations[connection] = failedRegsToConnection;
         }
         failedRegsToConnection.Add(listenerRegistration);
     }
     catch (Exception e)
     {
         Logger.Warning(string.Format("Listener {0} can not be added to a new connection: {1}, reason: {2}",
                                      listenerRegistration, connection, e.Message));
     }
 }
示例#5
0
 protected bool Equals(ListenerRegistration other)
 {
     return(string.Equals(UserRegistrationId, other.UserRegistrationId));
 }