// TODO: onDispose remove logic integrieren
        public void ParseDelegateInterestAttributes( INotificationListener Instance )
        {
            Type InstanceType 			= Instance.GetType();
            Type ListenerAttributeType 	= typeof( NotificationDelegateAttribute );

            foreach( MethodInfo method in InstanceType.GetMethods( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance ) )
            {
                foreach( Attribute attribute in method.GetCustomAttributes( ListenerAttributeType, false ) )
                {
                    #if DEBUG
                    Debug.WriteLine( this + ".ParseDelegateInterestAttributes()\n\tNoteType: " + ( attribute as NotificationDelegateAttribute ).NoteType + "\n\tNotificationDelegateInterest: " + ( attribute as NotificationDelegateAttribute ).Name + "\n---" );
                    #endif

                    MethodInfo scopeMethod = method;
                    // adding handler methods to the NotificationListenerList
                    Instance.NotificationListenerList.Add(
                        new NotificationDelegateInterest(
                            ( attribute as NotificationDelegateAttribute ).NoteType,
                            Instance.Context,
                            delegate( Object Sender, INotification Notification )
                            {
                                scopeMethod.Invoke( Instance, new Object[]{ Sender, Notification } );
                            }
                        )
                    );
                }
            }
        }
        public void ParseListenerAttributes( INotificationListener Instance )
        {
            Type instanceType 			= Instance.GetType();
            Type listenerAttributeType 	= typeof( NotificationListenerAttribute );
            INotifier notifier 			= Notifier.getInstance( Instance.Context );

            foreach( MethodInfo method in instanceType.GetMethods( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance ) )
            {
                foreach( Attribute attribute in method.GetCustomAttributes( listenerAttributeType, false ) )
                {
                    Console.WriteLine( "\t" + this + ".ParseListenerAttributes()\n\tAdding InterestListener: " + ( attribute as NotificationListenerAttribute ).Name );
                    MethodInfo scopeMethod = method;
                    notifier.Add(
                        new NotificationInterestListener(
                            ( attribute as NotificationListenerAttribute ).Type,
                            Instance.Context,
                            delegate( Object Sender, INotification Notification )
                            {
                                scopeMethod.Invoke( Instance, new Object[]{ Sender, Notification } );
                            }
                        )
                    );
                }
            }
        }
        public bool IsAddressedTo(INotificationListener listener)
        {
            Require.NotNull(listener, "listener");

            Ensure.True(m_recipient != null, "Notification was not addressed.");

            return(m_recipient.Equals(listener.GetType().FullName));
        }
Example #4
0
        public async Task RetryNotificationProcessingAsync(INotification notification)
        {
            Require.NotNull(notification, "notification");

            if (notification.DeliveryCount < Constants.Settings.MAX_NOTIFICATION_PROCESSING_ATTEMPT_COUNT)
            {
                var retryNotification = notification.SendTo(m_listener);
                var deliverTimeout    = TimeSpan.FromSeconds(
                    notification.DeliveryCount * Constants.Settings.NOTIFICATION_RETRY_DELIVERY_TIMEOUT_MULTIPLYER_SEC);

                if (s_logger.IsEnabled(LogEventLevel.Debug))
                {
                    s_logger.Debug(
                        "Sending retry notification ({RetryNotificationId}, {NotificationType}) with timeout {Timeout} " +
                        "to consumer {ListenerType}. " +
                        "Source notification: {SourceNotificationId}.",
                        retryNotification.NotificationId,
                        retryNotification.NotificationType,
                        deliverTimeout.ToInvariantString(),
                        GetConsumerId(),
                        notification.NotificationId);
                }

                await m_notificationsChannel.SendAsync(retryNotification, deliverTimeout);
            }
            else
            {
                s_logger.Error(
                    "Number of processing attempt has been exceeded. " +
                    "Listener type: {ListenerType}. " +
                    "NotificationId: {Notification}. " +
                    "NotificationType: {NotificationType}. " +
                    "Delivery count: {DeliveryCount}. " +
                    "Maximum deliver count: {MaxDeliveryCount}",
                    m_listener.GetType(),
                    notification.NotificationId,
                    notification.NotificationType,
                    notification.DeliveryCount.ToInvariantString(),
                    Constants.Settings.MAX_NOTIFICATION_PROCESSING_ATTEMPT_COUNT.ToInvariantString());
            }
        }
        public INotification RedeliverTo(INotificationListener listener)
        {
            Require.NotNull(listener, "listener");

            return(CopyAndUpdate(properties =>
            {
                properties[NotificationPropertyKeys.Common.NOTIFICATION_ID] = Guid.NewGuid().ToString("N");
                properties[NotificationPropertyKeys.Common.RECIPIENT] = listener.GetType().FullName;

                if (m_deliveryCount > 0)
                {
                    properties[NotificationPropertyKeys.Common.DELIVERY_COUNT] = (m_deliveryCount - 1).ToInvariantString();
                }
            }));
        }
        public INotification SendTo(INotificationListener listener)
        {
            Require.NotNull(listener, "listener");

            if (IsAddressed && IsAddressedTo(listener))
            {
                return(this);
            }

            return(CopyAndUpdate(properties =>
            {
                properties[NotificationPropertyKeys.Common.NOTIFICATION_ID] = NotificationId.Create().ToString();
                properties[NotificationPropertyKeys.Common.RECIPIENT] = listener.GetType().FullName;
            }));
        }
Example #7
0
        public void Unsubscribe(INotificationListener listener)
        {
            Require.NotNull(listener, "listener");

            m_subscriptions.Remove(listener.GetType());
        }
Example #8
0
        public void Subscribe(INotificationListener listener)
        {
            Require.NotNull(listener, "listener");

            m_subscriptions.Add(listener.GetType(), new NotificationListenerSubscription(m_channel, listener));
        }