Ejemplo n.º 1
0
        public ChannelProvider <TChannel> GetChannelProvider <TChannel>(ChannelAccessor <T, TChannel> channelAccessor,
                                                                        KeyAccessor <TChannel, TKey> messageKeyAccessor,
                                                                        InstanceChannelPolicy <T, TChannel> channelPolicy)
        {
            Guard.AgainstNull(channelAccessor, "channelAccessor");
            Guard.AgainstNull(messageKeyAccessor, "messageKeyAccessor");
            Guard.AgainstNull(channelPolicy, "channelPolicy");

            FiberProvider <TKey> fiberProvider = _configurator.GetConfiguredProvider();

            if (_sessionProvider == null)
            {
                throw new ChannelConfigurationException(typeof(TChannel),
                                                        "No NHibernate ISession provider specified for NHibernate instance: "
                                                        + typeof(T).ToShortTypeName());
            }

            SessionProvider <TChannel> sessionProvider = m => _sessionProvider.GetSession(m);

            var channelProvider = new NHibernateInstanceChannelProvider <T, TChannel, TKey>(fiberProvider,
                                                                                            sessionProvider,
                                                                                            messageKeyAccessor,
                                                                                            channelAccessor,
                                                                                            channelPolicy);

            return(channelProvider);
        }
Ejemplo n.º 2
0
        public FiberProvider <TKey> GetConfiguredProvider(ChannelBuilder <TChannel> builder)
        {
            FiberProvider <TKey> configuredProvider = GetConfiguredFiberProvider();

            builder.AddDisposable(configuredProvider);

            return(configuredProvider);
        }
Ejemplo n.º 3
0
        public CacheChannelProvider(FiberProvider <TKey> fiberProvider, ChannelProvider <TChannel> channelProvider,
                                    KeyAccessor <TChannel, TKey> keyAccessor)
        {
            Guard.AgainstNull(fiberProvider);
            Guard.AgainstNull(channelProvider);
            Guard.AgainstNull(keyAccessor);

            _fiberProvider   = fiberProvider;
            _channelProvider = channelProvider;
            _keyAccessor     = keyAccessor;
        }
        protected FiberProvider <TKey> GetConfiguredProvider <TChannel>(ChannelConfiguratorConnection <TChannel> connection)
        {
            if (_configuredProvider == null)
            {
                throw new FiberConfigurationException("No provider specified for FiberProvider");
            }

            FiberProvider <TKey> configuredProvider = _configuredProvider();

            connection.AddDisposable(configuredProvider);

            return(configuredProvider);
        }
        public ChannelProvider <TChannel> GetChannelProvider <TChannel>(ChannelAccessor <T, TChannel> channelAccessor,
                                                                        KeyAccessor <TChannel, TKey> messageKeyAccessor,
                                                                        InstanceChannelPolicy <T, TChannel> channelPolicy)
        {
            Guard.AgainstNull(channelAccessor, "channelAccessor");
            Guard.AgainstNull(messageKeyAccessor, "messageKeyAccessor");

            if (_cache == null)
            {
                Func <TKey, T> missingInstanceProvider = _configurator.GetConfiguredInstanceFactory();
                _cache = new Cache <TKey, T>(missingInstanceProvider);
            }

            Cache <TKey, T> cache = _cache;

            var instanceProvider = new DelegateChannelProvider <TChannel>(msg =>
            {
                TKey key = messageKeyAccessor(msg);

                T instance;

                if (cache.Has(key))
                {
                    if (!channelPolicy.IsHandledByExistingInstance(msg))
                    {
                        channelPolicy.WasNotHandled(msg);
                        return(null);
                    }

                    instance = cache[key];
                }
                else
                {
                    if (!channelPolicy.CanCreateInstance(msg, out instance))
                    {
                        channelPolicy.WasNotHandled(msg);
                        return(null);
                    }

                    cache.Add(key, instance);
                }

                return(channelAccessor(instance));
            });

            FiberProvider <TKey> fiberProvider = _configurator.GetConfiguredProvider();

            var channelProvider = new CacheChannelProvider <TChannel, TKey>(fiberProvider, instanceProvider, messageKeyAccessor);

            return(channelProvider);
        }
Ejemplo n.º 6
0
        public NHibernateInstanceChannelProvider(FiberProvider <TKey> fiberProvider, SessionProvider <TChannel> sessionProvider,
                                                 KeyAccessor <TChannel, TKey> keyAccessor,
                                                 ChannelAccessor <TInstance, TChannel> channelAccessor,
                                                 InstanceChannelPolicy <TInstance, TChannel> instanceChannelPolicy)
        {
            Guard.AgainstNull(fiberProvider);
            Guard.AgainstNull(sessionProvider);
            Guard.AgainstNull(keyAccessor);
            Guard.AgainstNull(channelAccessor);
            Guard.AgainstNull(instanceChannelPolicy);

            _fiberProvider         = fiberProvider;
            _sessionProvider       = sessionProvider;
            _keyAccessor           = keyAccessor;
            _channelAccessor       = channelAccessor;
            _instanceChannelPolicy = instanceChannelPolicy;
        }
        public ChannelProvider <TChannel> GetChannelProvider(ChannelBuilder <TChannel> builder)
        {
            if (_accessor == null)
            {
                throw new ChannelConfigurationException(typeof(TChannel),
                                                        "No channel accessor was specified for NHibernate instance: "
                                                        + typeof(TInstance).ToShortTypeName());
            }
            if (_keyAccessor == null)
            {
                throw new ChannelConfigurationException(typeof(TChannel),
                                                        "No message key accessor was specified for NHibernate instance: "
                                                        + typeof(TInstance).ToShortTypeName());
            }
            if (_instanceChannelPolicy == null)
            {
                throw new ChannelConfigurationException(typeof(TChannel),
                                                        "No missing instance provider specified for NHibernate instance: "
                                                        + typeof(TInstance).ToShortTypeName());
            }
            if (_sessionProvider == null)
            {
                throw new ChannelConfigurationException(typeof(TChannel),
                                                        "No NHibernate ISession provider specified for NHibernate instance: "
                                                        + typeof(TInstance).ToShortTypeName());
            }

            FiberProvider <TKey> fiberProvider = _configurator.GetConfiguredProvider(builder);

            var channelProvider = new NHibernateInstanceChannelProvider <TInstance, TChannel, TKey>(fiberProvider,
                                                                                                    _sessionProvider,
                                                                                                    _keyAccessor,
                                                                                                    _accessor,
                                                                                                    _instanceChannelPolicy());

            return(channelProvider);
        }
        public T UseFiberProvider(FiberProvider <TKey> fiberProvider)
        {
            _configuredProvider = (factory, timeout) => fiberProvider;

            return(this as T);
        }
        public T UseFiberProvider(FiberProvider <TKey> fiberProvider)
        {
            _configuredProvider = () => fiberProvider;

            return(this as T);
        }