public NHibernateChannelProviderConfigurator <TInstance, TChannel, TKey> OnChannel(
            ChannelAccessor <TInstance, TChannel> accessor)
        {
            _accessor = accessor;

            return(this);
        }
Ejemplo n.º 2
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);
        }
        public InstanceChannelProviderConfigurator <TInstance, TChannel> OnChannel(
            ChannelAccessor <TInstance, TChannel> accessor)
        {
            _accessor = accessor;

            return(this);
        }
Ejemplo n.º 4
0
        public InstanceChannelProvider(InstanceProvider <TInstance, TChannel> instanceProvider,
                                       ChannelAccessor <TInstance, TChannel> accessor)
        {
            Magnum.Guard.AgainstNull(instanceProvider);
            Magnum.Guard.AgainstNull(accessor);

            _instanceProvider = instanceProvider;
            _accessor         = accessor;
        }
Ejemplo n.º 5
0
        public ActorChannelProvider(ActorFactory <TActor> actorFactory, PropertyInfo property)
        {
            Magnum.Guard.AgainstNull(actorFactory, "actorInstanceProvider");
            Magnum.Guard.AgainstNull(property, "property");

            _actorFactory = actorFactory;

            _channelAccessor = CreateChannelAccessor(property);
        }
Ejemplo n.º 6
0
Archivo: JobQueue.cs Proyecto: zxbe/abp
        public virtual void Dispose()
        {
            if (IsDiposed)
            {
                return;
            }

            IsDiposed = true;

            ChannelAccessor?.Dispose();
        }
Ejemplo n.º 7
0
 public NHibernateInstanceChannel(Fiber fiber,
                                  SessionProvider <TChannel> sessionProvider,
                                  KeyAccessor <TChannel, TKey> messageKeyAccessor,
                                  ChannelAccessor <TInstance, TChannel> channelAccessor,
                                  InstanceChannelPolicy <TInstance, TChannel> channelPolicy)
 {
     _fiber              = fiber;
     _sessionProvider    = sessionProvider;
     _channelPolicy      = channelPolicy;
     _channelAccessor    = channelAccessor;
     _messageKeyAccessor = messageKeyAccessor;
 }
Ejemplo n.º 8
0
        Action <ChannelConfiguratorConnection, Fiber, T> GetChannelConfigurator <TChannel>(PropertyInfo property)
        {
            _log.Debug(x => x.Write("Configuring channel for message type {0}",
                                    typeof(TChannel).ToShortTypeName()));

            ParameterExpression  target = Expression.Parameter(typeof(T), "x");
            MethodCallExpression getter = Expression.Call(target, property.GetGetMethod(true));

            ChannelAccessor <T, TChannel> accessor =
                Expression.Lambda <ChannelAccessor <T, TChannel> >(getter, new[] { target }).Compile();

            return((connection, fiber, instance) => { connection.AddChannel(fiber, x => accessor(instance)); });
        }
        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.º 10
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;
        }
Ejemplo n.º 11
0
        internal Connection(ConnectionImpl impl)
        {
            m_Channel       = new ChannelManager(impl);
            m_StatusUpdater = new ConnectionStatusUpdater(this);
            Channel         = new ChannelMapAccessor(this, m_Channel);

            Reliable             = Channel.Reliable;
            Unreliable           = Channel.Unreliable;
            m_Impl               = impl;
            m_Impl.OnAddPeer    += OnAdd;
            m_Impl.OnRemotePeer += OnRemove;
            if (impl.UseP2P)
            {
                P2P = new P2PAccessor(m_Impl);
            }

            Config = new RuntimeConfig(this, m_Impl, m_StatusUpdater);

            foreach (var peer in m_Impl.GetPeers())
            {
                OnAdd(peer);
            }
        }
Ejemplo n.º 12
0
 public virtual void Dispose()
 {
     ChannelAccessor?.Dispose();
 }
Ejemplo n.º 13
0
 public PropertyChannelConvention(PropertyInfo property)
 {
     _channelAccessor = GenerateChannelAccessor(property);
 }
 public PropertyChannelConfiguratorImpl(PropertyInfo property)
 {
     _accessor = CreateAccessor(property);
 }