Exemplo n.º 1
0
        public DbCache(IIgnite ignite, CacheConfiguration metaCacheConfiguration,
                       CacheConfiguration dataCacheConfiguration)
        {
            IgniteArgumentCheck.NotNull(ignite, "ignite");
            IgniteArgumentCheck.NotNull(metaCacheConfiguration, "metaCacheConfiguration");
            IgniteArgumentCheck.NotNull(dataCacheConfiguration, "metaCacheConfiguration");

            IgniteArgumentCheck.Ensure(metaCacheConfiguration.Name != dataCacheConfiguration.Name,
                                       "dataCacheConfiguration", "Meta and Data cache can't have the same name.");

            _metaCache = ignite.GetOrCreateCache <string, long>(metaCacheConfiguration);
            _cache     = ignite.GetOrCreateCache <string, object>(dataCacheConfiguration);

            var metaCfg = _metaCache.GetConfiguration();

            if (metaCfg.AtomicityMode != CacheAtomicityMode.Transactional)
            {
                throw new IgniteException("EntityFramework meta cache should be Transactional.");
            }

            if (metaCfg.CacheMode == CacheMode.Partitioned && metaCfg.Backups < 1)
            {
                ignite.Logger.Warn("EntityFramework meta cache is partitioned and has no backups. " +
                                   "This can lead to data loss and incorrect query results.");
            }
        }
Exemplo n.º 2
0
        /** <inheritDoc /> */
        public T GetServiceProxy <T>(string name, bool sticky) where T : class
        {
#if !NETCOREAPP2_0
            IgniteArgumentCheck.NotNullOrEmpty(name, "name");
            IgniteArgumentCheck.Ensure(typeof(T).IsInterface, "T", "Service proxy type should be an interface: " + typeof(T));

            // In local scenario try to return service instance itself instead of a proxy
            // Get as object because proxy interface may be different from real interface
            var locInst = GetService <object>(name) as T;

            if (locInst != null)
            {
                return(locInst);
            }

            var javaProxy = DoOutOpObject(OpServiceProxy, w =>
            {
                w.WriteString(name);
                w.WriteBoolean(sticky);
            });

            var platform = GetServiceDescriptors().Cast <ServiceDescriptor>().Single(x => x.Name == name).Platform;

            return(new ServiceProxy <T>((method, args) =>
                                        InvokeProxyMethod(javaProxy, method, args, platform)).GetTransparentProxy());
#else
            throw new Apache.Ignite.Core.Common.IgniteException("Service proxies are not supported on .NET Core: IGNITE-7281");
#endif
        }
Exemplo n.º 3
0
        public Guid?RemoteListen <T>(int bufSize = 1, TimeSpan?interval = null, bool autoUnsubscribe = true,
                                     IEventFilter <T> localListener = null, IEventFilter <T> remoteFilter = null, params int[] types)
            where T : IEvent
        {
            IgniteArgumentCheck.Ensure(bufSize > 0, "bufSize", "should be > 0");
            IgniteArgumentCheck.Ensure(interval == null || interval.Value.TotalMilliseconds > 0, "interval", "should be null or >= 0");

            return(DoOutInOp((int)Op.RemoteListen,
                             writer =>
            {
                writer.WriteInt(bufSize);
                writer.WriteLong((long)(interval == null ? 0 : interval.Value.TotalMilliseconds));
                writer.WriteBoolean(autoUnsubscribe);

                writer.WriteBoolean(localListener != null);

                if (localListener != null)
                {
                    var listener = new RemoteListenEventFilter(Ignite, e => localListener.Invoke((T)e));
                    writer.WriteLong(Ignite.HandleRegistry.Allocate(listener));
                }

                writer.WriteBoolean(remoteFilter != null);

                if (remoteFilter != null)
                {
                    writer.Write(remoteFilter);
                }

                WriteEventTypes(types, writer);
            },
                             reader => Marshaller.StartUnmarshal(reader).ReadGuid()));
        }
Exemplo n.º 4
0
        /** <inheritDoc /> */
        public T GetServiceProxy <T>(string name, bool sticky, IServiceCallContext callCtx) where T : class
        {
            IgniteArgumentCheck.NotNullOrEmpty(name, "name");
            IgniteArgumentCheck.Ensure(typeof(T).IsInterface, "T",
                                       "Service proxy type should be an interface: " + typeof(T));

            T locInst;

            // In local scenario try to return service instance itself instead of a proxy
            // Get as object because proxy interface may be different from real interface
            if (callCtx == null && (locInst = GetService <object>(name) as T) != null)
            {
                return(locInst);
            }

            var javaProxy = DoOutOpObject(OpServiceProxy, w =>
            {
                w.WriteString(name);
                w.WriteBoolean(sticky);
            });

            var platform = GetServiceDescriptors().Cast <ServiceDescriptor>().Single(x => x.Name == name).PlatformType;

            return(ServiceProxyFactory <T> .CreateProxy((method, args) =>
                                                        InvokeProxyMethod(javaProxy, method.Name, method, args, platform, callCtx)));
        }
Exemplo n.º 5
0
        /** <inheritDoc /> */
        public IBinaryObject BuildEnum(Type type, int value)
        {
            IgniteArgumentCheck.NotNull(type, "type");
            IgniteArgumentCheck.Ensure(type.IsEnum, "type", "Type should be an Enum.");

            return(BuildEnum(type.Name, value));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the attributes of the service call context.
        /// </summary>
        /// <param name="callCtx">Service call context.</param>
        /// <returns>Service call context attributes.</returns>
        private IDictionary GetCallerContextAttributes(IServiceCallContext callCtx)
        {
            IgniteArgumentCheck.Ensure(callCtx == null || callCtx is ServiceCallContext, "callCtx",
                                       "custom implementation of " + typeof(ServiceCallContext).Name + " is not supported." +
                                       " Please use " + typeof(ServiceCallContextBuilder).Name + " to create it.");

            return(callCtx == null ? null : ((ServiceCallContext)callCtx).Values());
        }
Exemplo n.º 7
0
        private static IClusterNode GetRandomNode(IEnumerable <IClusterNode> nodes)
        {
            var nodesCol = GetNodesCollection(nodes);

            IgniteArgumentCheck.Ensure(nodesCol.Count > 0, nameof(nodes), "Nodes can't be empty.");

            var idx = ThreadLocalRandom.Instance.Next(0, nodesCol.Count);

            return(nodesCol.ElementAt(idx));
        }
Exemplo n.º 8
0
        /** <inheritDoc /> */
        public IBinaryObject BuildEnum(string typeName, int value)
        {
            IgniteArgumentCheck.NotNullOrEmpty(typeName, "typeName");

            var desc = Marshaller.GetDescriptor(typeName);

            IgniteArgumentCheck.Ensure(desc.IsEnum, "typeName", "Type should be an Enum.");

            _marsh.PutBinaryType(desc);

            return(new BinaryEnum(GetTypeId(typeName), value, Marshaller));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets the enum value as int.
        /// </summary>
        private int GetEnumValueAsInt(string typeName, string valueName, IBinaryTypeDescriptor desc)
        {
            var type = Marshaller.GetBinaryType(desc.TypeId);

            var value = type.GetEnumValue(valueName);

            IgniteArgumentCheck.Ensure(value != null, "valueName",
                                       string.Format("Enum '{0}' does not have a value {1}", typeName, valueName));

            Debug.Assert(value.HasValue);

            return(value.Value);
        }
Exemplo n.º 10
0
        /** <inheritDoc /> */
        public IBinaryObject BuildEnum(Type type, int value)
        {
            IgniteArgumentCheck.NotNull(type, "type");
            IgniteArgumentCheck.Ensure(type.IsEnum, "type", "Type should be an Enum.");
            
            var desc = Marshaller.GetDescriptor(type);

            IgniteArgumentCheck.Ensure(desc.IsEnum, "typeName", "Type should be an Enum.");

            _marsh.PutBinaryType(desc);

            return new BinaryEnum(desc.TypeId, value, Marshaller);
        }
Exemplo n.º 11
0
        public void CopyTo(Array array, int index)
        {
            IgniteArgumentCheck.NotNull(array, "array");
            IgniteArgumentCheck.Ensure(Count + index < array.Length, "array",
                                       "The number of elements in the source collection is greater than the available space " +
                                       "from specified index to the end of the array.");

            // This should return only keys.
            foreach (var entry in _list)
            {
                array.SetValue(entry.Key, index++);
            }
        }
Exemplo n.º 12
0
        /** <inheritdoc /> */
        public T GetServiceProxy <T>(string serviceName, IServiceCallContext callCtx) where T : class
        {
            IgniteArgumentCheck.NotNullOrEmpty(serviceName, "name");
            IgniteArgumentCheck.Ensure(callCtx == null || callCtx is ServiceCallContext, "callCtx",
                                       "custom implementation of " + typeof(ServiceCallContext).Name + " is not supported." +
                                       " Please use " + typeof(ServiceCallContextBuilder).Name + " to create it.");

            var         platformType = GetServiceDescriptor(serviceName).PlatformType;
            IDictionary callAttrs    = callCtx == null ? null : ((ServiceCallContext)callCtx).Values();

            return(ServiceProxyFactory <T> .CreateProxy(
                       (method, args) => InvokeProxyMethod(serviceName, method, args, platformType, callAttrs)
                       ));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Initializes Ignite caching for specified <see cref="DbConfiguration"/>.
        /// This method should be used when it is not possible to use or inherit <see cref="IgniteDbConfiguration"/>.
        /// </summary>
        /// <param name="dbConfiguration"><see cref="DbConfiguration"/> instance to be initialized
        /// for Ignite caching.</param>
        /// <param name="ignite">The ignite instance to use.</param>
        /// <param name="metaCacheConfiguration">
        /// Configuration of the metadata cache which holds entity set information. Null for default configuration.
        /// <para />
        /// This cache holds small amount of data, but should not lose entries. At least one backup recommended.
        /// </param>
        /// <param name="dataCacheConfiguration">
        /// Configuration of the data cache which holds query results. Null for default configuration.
        /// <para />
        /// This cache tolerates lost data and can have no backups.
        /// </param>
        /// <param name="policy">The caching policy. Null for default <see cref="DbCachingPolicy" />.</param>
        public static void InitializeIgniteCaching(DbConfiguration dbConfiguration, IIgnite ignite,
                                                   CacheConfiguration metaCacheConfiguration, CacheConfiguration dataCacheConfiguration,
                                                   IDbCachingPolicy policy)
        {
            IgniteArgumentCheck.NotNull(ignite, "ignite");
            IgniteArgumentCheck.NotNull(dbConfiguration, "configuration");

            IgniteArgumentCheck.Ensure(!(dbConfiguration is IgniteDbConfiguration), "dbConfiguration",
                                       "IgniteDbConfiguration.InitializeIgniteCaching should not be called for IgniteDbConfiguration " +
                                       "instance. This method should be used only when IgniteDbConfiguration can't be inherited.");

            InitializeIgniteCachingInternal(dbConfiguration, ignite, metaCacheConfiguration, dataCacheConfiguration,
                                            policy);
        }
Exemplo n.º 14
0
        /** <inheritDoc /> */
        public IBinaryObject BuildEnum(Type type, string valueName)
        {
            IgniteArgumentCheck.NotNull(type, "type");
            IgniteArgumentCheck.NotNullOrEmpty(valueName, "valueName");

            var desc = Marshaller.GetDescriptor(type);

            IgniteArgumentCheck.Ensure(desc.IsEnum, "typeName", "Type should be an Enum.");

            _marsh.PutBinaryType(desc);

            var value = GetEnumValueAsInt(type.ToString(), valueName, desc);

            return(new BinaryEnum(desc.TypeId, value, Marshaller));
        }
Exemplo n.º 15
0
        /** <inheritDoc /> */
        public T GetServiceProxy<T>(string name, bool sticky) where T : class
        {
            IgniteArgumentCheck.NotNullOrEmpty(name, "name");
            IgniteArgumentCheck.Ensure(typeof(T).IsInterface, "T", "Service proxy type should be an interface: " + typeof(T));

            // In local scenario try to return service instance itself instead of a proxy
            // Get as object because proxy interface may be different from real interface
            var locInst = GetService<object>(name) as T;

            if (locInst != null)
                return locInst;

            var javaProxy = UU.ServicesGetServiceProxy(Target, name, sticky);
            var platform = GetServiceDescriptors().Cast<ServiceDescriptor>().Single(x => x.Name == name).Platform;

            return new ServiceProxy<T>((method, args) =>
                InvokeProxyMethod(javaProxy, method, args, platform)).GetTransparentProxy();
        }
Exemplo n.º 16
0
        /** <inheritDoc /> */
        public T GetServiceProxy <T>(string name, bool sticky, IServiceCallContext callCtx) where T : class
        {
            IgniteArgumentCheck.NotNullOrEmpty(name, "name");
            IgniteArgumentCheck.Ensure(typeof(T).IsInterface, "T",
                                       "Service proxy type should be an interface: " + typeof(T));

            var javaProxy = DoOutOpObject(OpServiceProxy, w =>
            {
                w.WriteString(name);
                w.WriteBoolean(sticky);
            });

            var platform  = GetServiceDescriptors().Cast <ServiceDescriptor>().Single(x => x.Name == name).PlatformType;
            var callAttrs = GetCallerContextAttributes(callCtx);

            return(ServiceProxyFactory <T> .CreateProxy((method, args) =>
                                                        InvokeProxyMethod(javaProxy, method.Name, method, args, platform, callAttrs)));
        }
Exemplo n.º 17
0
        /// <summary>
        /// Writes a collection of service configurations using passed BinaryWriter
        /// Also it performs basic validation of each service configuration and could throw exceptions
        /// </summary>
        /// <param name="configurations">a collection of service configurations </param>
        /// <param name="writer">Binary Writer</param>
        private static void SerializeConfigurations(IEnumerable <ServiceConfiguration> configurations,
                                                    BinaryWriter writer)
        {
            var pos = writer.Stream.Position;

            writer.WriteInt(0);  // Reserve count.

            var cnt = 0;

            foreach (var cfg in configurations)
            {
                ValidateConfiguration(cfg, string.Format("configurations[{0}]", cnt));
                cfg.Write(writer);
                cnt++;
            }

            IgniteArgumentCheck.Ensure(cnt > 0, "configurations", "empty collection");

            writer.Stream.WriteInt(pos, cnt);
        }