예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PlatformCacheManager"/> class.
        /// </summary>
        /// <param name="ignite">Ignite.</param>
        public PlatformCacheManager(IIgniteInternal ignite)
        {
            Debug.Assert(ignite != null);

            _ignite = ignite;
            _ignite.GetIgnite().ClientDisconnected += OnClientDisconnected;
        }
예제 #2
0
        /// <summary>
        /// Reads the schema, maintains stream position.
        /// </summary>
        public static int[] GetFieldIds(BinaryObjectHeader hdr, IIgniteInternal ignite, IBinaryStream stream,
                                        int objectPos)
        {
            Debug.Assert(stream != null);

            if (hdr.IsCompactFooter)
            {
                // Get schema from Java
                return(GetFieldIds(hdr, ignite));
            }

            var pos = stream.Position;

            stream.Seek(objectPos + hdr.SchemaOffset, SeekOrigin.Begin);

            var count = hdr.SchemaFieldCount;

            var offsetSize = hdr.SchemaFieldOffsetSize;

            var res = new int[count];

            for (var i = 0; i < count; i++)
            {
                res[i] = stream.ReadInt();
                stream.Seek(offsetSize, SeekOrigin.Current);  // Skip offsets.
            }

            stream.Seek(pos, SeekOrigin.Begin);

            return(res);
        }
예제 #3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="grid">Grid.</param>
        /// <param name="job">Job.</param>
        public ComputeJobHolder(IIgniteInternal grid, IComputeJob job)
        {
            Debug.Assert(grid != null);
            Debug.Assert(job != null);

            _ignite = grid;
            _job    = job;
        }
예제 #4
0
        /// <summary>
        /// Default ctor for marshalling.
        /// </summary>
        /// <param name="reader"></param>
        public ComputeJobHolder(BinaryReader reader)
        {
            Debug.Assert(reader != null);

            _ignite = reader.Marshaller.Ignite;

            _job = reader.ReadObject <IComputeJob>();
        }
예제 #5
0
        /// <summary>
        /// Creates exception according to native code class and message.
        /// </summary>
        /// <param name="igniteInt">The ignite.</param>
        /// <param name="clsName">Exception class name.</param>
        /// <param name="msg">Exception message.</param>
        /// <param name="stackTrace">Native stack trace.</param>
        /// <param name="reader">Error data reader.</param>
        /// <param name="innerException">Inner exception.</param>
        /// <returns>Exception.</returns>
        public static Exception GetException(IIgniteInternal igniteInt, string clsName, string msg, string stackTrace,
                                             BinaryReader reader = null, Exception innerException = null)
        {
            // Set JavaException as immediate inner.
            var jex = new JavaException(clsName, msg, stackTrace, innerException);

            return(GetException(igniteInt, jex, reader));
        }
예제 #6
0
        /// <summary>
        /// Creates exception according to native code class and message.
        /// </summary>
        /// <param name="igniteInt">The ignite.</param>
        /// <param name="innerException">Java exception.</param>
        /// <param name="reader">Error data reader.</param>
        /// <returns>Exception.</returns>
        public static Exception GetException(IIgniteInternal igniteInt, JavaException innerException,
                                             BinaryReader reader = null)
        {
            var ignite = igniteInt == null ? null : igniteInt.GetIgnite();

            var msg     = innerException.JavaMessage;
            var clsName = innerException.JavaClassName;

            ExceptionFactory ctor;

            if (Exs.TryGetValue(clsName, out ctor))
            {
                var match = InnerClassRegex.Match(msg ?? string.Empty);

                ExceptionFactory innerCtor;

                if (match.Success && Exs.TryGetValue(match.Groups[1].Value, out innerCtor))
                {
                    return(ctor(clsName, msg,
                                innerCtor(match.Groups[1].Value, match.Groups[2].Value, innerException, ignite),
                                ignite));
                }

                return(ctor(clsName, msg, innerException, ignite));
            }

            if (ClsNoClsDefFoundErr.Equals(clsName, StringComparison.OrdinalIgnoreCase))
            {
                return(new IgniteException("Java class is not found (did you set IGNITE_HOME environment " +
                                           "variable?): " + msg, innerException));
            }

            if (ClsNoSuchMthdErr.Equals(clsName, StringComparison.OrdinalIgnoreCase))
            {
                return(new IgniteException("Java class method is not found (did you set IGNITE_HOME environment " +
                                           "variable?): " + msg, innerException));
            }

            if (ClsCachePartialUpdateErr.Equals(clsName, StringComparison.OrdinalIgnoreCase))
            {
                return(ProcessCachePartialUpdateException(igniteInt, msg, innerException.Message, reader));
            }

            // Predefined mapping not found - check plugins.
            if (igniteInt != null && igniteInt.PluginProcessor != null)
            {
                ctor = igniteInt.PluginProcessor.GetExceptionMapping(clsName);

                if (ctor != null)
                {
                    return(ctor(clsName, msg, innerException, ignite));
                }
            }

            // Return default exception.
            return(new IgniteException(string.Format("Java exception occurred [class={0}, message={1}]", clsName, msg),
                                       innerException));
        }
예제 #7
0
        /// <summary>
        /// Gets an instance of <see cref="PeerAssemblyResolver"/> when peer loading is enabled; otherwise null.
        /// </summary>
        public static PeerAssemblyResolver GetInstance(IIgniteInternal ignite, Guid originNodeId)
        {
            if (ignite == null || ignite.Configuration.PeerAssemblyLoadingMode == PeerAssemblyLoadingMode.Disabled)
            {
                return(null);
            }

            return(new PeerAssemblyResolver(ignite, originNodeId));
        }
예제 #8
0
        /// <summary>
        /// Inject resources to the given target.
        /// </summary>
        /// <param name="target">Target object.</param>
        /// <param name="grid">Grid.</param>
        public static void Inject(object target, IIgniteInternal grid)
        {
            if (target != null)
            {
                var desc = Descriptor(target.GetType());

                desc.InjectIgnite(target, grid);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MessageListenerHolder"/> class.
        /// </summary>
        /// <param name="reader">The reader.</param>
        public MessageListenerHolder(BinaryReader reader)
        {
            _filter = reader.ReadObject <object>();

            _invoker = GetInvoker(_filter);

            _ignite = reader.Marshaller.Ignite;

            ResourceProcessor.Inject(_filter, _ignite);
        }
예제 #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PeerAssemblyResolver"/> class.
        /// </summary>
        public PeerAssemblyResolver(IIgniteInternal ignite, Guid originNodeId)
        {
            Debug.Assert(ignite != null);

            _handler = (sender, args) => GetAssembly(ignite, args.Name, originNodeId);

            // AssemblyResolve handler is called only when aseembly can't be found via normal lookup,
            // so we won't end up loading assemblies that are already present.
            AppDomain.CurrentDomain.AssemblyResolve += _handler;
        }
예제 #11
0
        /// <summary>
        /// Loads the assembly.
        /// </summary>
        private static Assembly LoadAssembly(IIgniteInternal ignite, string assemblyName, Guid originNodeId)
        {
            var res = RequestAssembly(assemblyName, ignite, originNodeId);

            if (res == null)
            {
                return(null);
            }

            return(AssemblyLoader.LoadAssembly(res.AssemblyBytes, assemblyName));
        }
예제 #12
0
        /// <summary>
        /// Gets the cached schema.
        /// </summary>
        private static int[] GetCachedSchema(BinaryObjectHeader hdr, IIgniteInternal ignite)
        {
            var cachedHolder = ignite.Marshaller.GetCachedBinaryTypeHolder(hdr.TypeId);

            if (cachedHolder == null || cachedHolder.BinaryType == null || cachedHolder.BinaryType.Schema == null)
            {
                return(null);
            }

            return(cachedHolder.BinaryType.Schema.Get(hdr.SchemaId));
        }
예제 #13
0
        public ClusterGroupImpl(IPlatformTargetInternal target, Func <IClusterNode, bool> pred)
            : base(target)
        {
            _ignite = target.Marshaller.Ignite;
            _pred   = pred;

            _comp     = new Lazy <ICompute>(() => CreateCompute());
            _msg      = new Lazy <IMessaging>(() => CreateMessaging());
            _events   = new Lazy <IEvents>(() => CreateEvents());
            _services = new Lazy <IServices>(() => CreateServices());
        }
예제 #14
0
        /// <summary>
        /// Performs compute-specific resource injection.
        /// </summary>
        public static void InjectResources(IIgniteInternal ignite, object job)
        {
            var injector = job as IComputeResourceInjector;

            if (injector != null)
            {
                injector.Inject(ignite);
            }
            else
            {
                ResourceProcessor.Inject(job, ignite);
            }
        }
예제 #15
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="target">Target.</param>
        /// <param name="flagSkipStore">Skip store flag.</param>
        /// <param name="flagKeepBinary">Keep binary flag.</param>
        /// <param name="flagNoRetries">No-retries mode flag.</param>
        /// <param name="flagPartitionRecover">Partition recover mode flag.</param>
        public CacheImpl(IPlatformTargetInternal target,
                         bool flagSkipStore, bool flagKeepBinary, bool flagNoRetries, bool flagPartitionRecover)
            : base(target)
        {
            _ignite               = target.Marshaller.Ignite;
            _flagSkipStore        = flagSkipStore;
            _flagKeepBinary       = flagKeepBinary;
            _flagNoRetries        = flagNoRetries;
            _flagPartitionRecover = flagPartitionRecover;

            _txManager = GetConfiguration().AtomicityMode == CacheAtomicityMode.Transactional
                ? new CacheTransactionManager(_ignite.GetIgnite().GetTransactions())
                : null;

            _readException = stream => ReadException(Marshaller.StartUnmarshal(stream));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MessageListenerHolder" /> class.
        /// </summary>
        /// <param name="grid">Grid.</param>
        /// <param name="filter">The <see cref="IMessageListener{T}" /> to wrap.</param>
        /// <param name="invoker">The invoker func that takes key and value and invokes wrapped IMessageListener.</param>
        private MessageListenerHolder(Ignite grid, object filter, Func <Guid, object, bool> invoker)
        {
            Debug.Assert(filter != null);
            Debug.Assert(invoker != null);

            _invoker = invoker;

            _filter = filter;

            // 1. Set fields.
            Debug.Assert(grid != null);

            _ignite  = grid;
            _invoker = invoker;

            // 2. Perform injections.
            ResourceProcessor.Inject(filter, grid);
        }
예제 #17
0
        public static void ExecuteJobAndWriteResults <T>(IIgniteInternal ignite, PlatformMemoryStream stream, T job,
                                                         Func <T, object> execFunc)
        {
            Debug.Assert(stream != null);
            Debug.Assert(ignite != null);
            Debug.Assert(job != null);
            Debug.Assert(execFunc != null);

            // 0. Inject resources.
            InjectResources(ignite, job);

            // 1. Execute job.
            object res;
            bool   success;

            using (PeerAssemblyResolver.GetInstance(ignite, Guid.Empty))
            {
                try
                {
                    res     = execFunc(job);
                    success = true;
                }
                catch (Exception e)
                {
                    res     = e;
                    success = false;
                }
            }

            // 2. Try writing result to the stream.
            var writer = ignite.Marshaller.StartMarshal(stream);

            try
            {
                // 3. Marshal results.
                BinaryUtils.WriteInvocationResult(writer, success, res);
            }
            finally
            {
                // 4. Process metadata.
                ignite.Marshaller.FinishMarshal(writer);
            }
        }
예제 #18
0
        /// <summary>
        /// Gets the field ids.
        /// </summary>
        private static int[] GetFieldIds(BinaryObjectHeader hdr, IIgniteInternal ignite)
        {
            Debug.Assert(hdr.TypeId != BinaryTypeId.Unregistered);

            int[] fieldIds = null;

            if (ignite != null)
            {
                fieldIds = ignite.BinaryProcessor.GetSchema(hdr.TypeId, hdr.SchemaId);
            }

            if (fieldIds == null)
            {
                throw new BinaryObjectException("Cannot find schema for object with compact footer [" +
                                                "typeId=" + hdr.TypeId + ", schemaId=" + hdr.SchemaId + ']');
            }

            return(fieldIds);
        }
예제 #19
0
        /// <summary>
        /// Gets the assembly from remote nodes.
        /// </summary>
        /// <param name="typeName">Assembly-qualified type name.</param>
        /// <param name="ignite">Ignite.</param>
        /// <param name="originNodeId">Originating node identifier.</param>
        /// <returns>
        /// Resulting type or null.
        /// </returns>
        public static Type LoadAssemblyAndGetType(string typeName, IIgniteInternal ignite, Guid originNodeId)
        {
            Debug.Assert(!string.IsNullOrEmpty(typeName));

            var parsedName = TypeNameParser.Parse(typeName);

            var assemblyName = parsedName.GetAssemblyName();

            Debug.Assert(assemblyName != null);

            var asm = GetAssembly(ignite, assemblyName, originNodeId);

            if (asm == null)
            {
                return(null);
            }

            // Assembly.GetType does not work for assembly-qualified names. Full name is required without assembly.
            return(asm.GetType(parsedName.GetFullName(), false));
        }
예제 #20
0
        /// <summary>
        /// Gets the assembly from remote nodes.
        /// </summary>
        /// <param name="assemblyName">Name of the assembly.</param>
        /// <param name="ignite">Ignite.</param>
        /// <param name="originNodeId">The origin node identifier.</param>
        /// <returns>
        /// Successful result or null.
        /// </returns>
        /// <exception cref="IgniteException"></exception>
        private static AssemblyRequestResult RequestAssembly(string assemblyName, IIgniteInternal ignite,
                                                             Guid originNodeId)
        {
            Debug.Assert(assemblyName != null);
            Debug.Assert(ignite != null);

            if (ignite.Configuration.PeerAssemblyLoadingMode == PeerAssemblyLoadingMode.Disabled)
            {
                return(null);
            }

            Debug.WriteLine("Requesting assembly from other nodes: " + assemblyName);

            // New nodes are not tracked during the loop, since some of the existing nodes caused this call.
            var func = new GetAssemblyFunc();
            var req  = new AssemblyRequest(assemblyName);

            foreach (var node in GetDotNetNodes(ignite.GetIgnite(), originNodeId))
            {
                var compute = ignite.GetIgnite().GetCluster().ForNodeIds(node).GetCompute();
                var result  = ComputeApplySafe(compute, func, req);

                if (result != null)
                {
                    if (result.AssemblyBytes != null)
                    {
                        return(result);
                    }

                    if (result.Message != null)
                    {
                        throw new IgniteException(result.Message);
                    }
                }
            }

            return(null);
        }
예제 #21
0
        private static Exception ProcessCachePartialUpdateException(IIgniteInternal ignite, string msg,
                                                                    string stackTrace, BinaryReader reader)
        {
            if (reader == null)
            {
                return(new CachePartialUpdateException(msg, new IgniteException("Failed keys are not available.")));
            }

            bool dataExists = reader.ReadBoolean();

            Debug.Assert(dataExists);

            if (reader.ReadBoolean())
            {
                bool keepBinary = reader.ReadBoolean();

                BinaryReader keysReader = reader.Marshaller.StartUnmarshal(reader.Stream, keepBinary);

                try
                {
                    return(new CachePartialUpdateException(msg, ReadNullableList(keysReader)));
                }
                catch (Exception e)
                {
                    // Failed to deserialize data.
                    return(new CachePartialUpdateException(msg, e));
                }
            }

            // Was not able to write keys.
            string innerErrCls = reader.ReadString();
            string innerErrMsg = reader.ReadString();

            Exception innerErr = GetException(ignite, innerErrCls, innerErrMsg, stackTrace);

            return(new CachePartialUpdateException(msg, innerErr));
        }
예제 #22
0
 /// <summary>
 /// Gets the assembly.
 /// </summary>
 private static Assembly GetAssembly(IIgniteInternal ignite, string assemblyName, Guid originNodeId)
 {
     return(LoadedAssembliesResolver.Instance.GetAssembly(assemblyName)
            ?? AssemblyLoader.GetAssembly(assemblyName)
            ?? LoadAssembly(ignite, assemblyName, originNodeId));
 }
예제 #23
0
 /// <summary>
 /// Inject resources to the given object.
 /// </summary>
 /// <param name="target">Target.</param>
 /// <param name="ignite">Grid.</param>
 public void InjectIgnite(object target, IIgniteInternal ignite)
 {
     Inject0(target, ignite, _igniteInjectors);
 }
 /** <inheritDoc /> */
 public void Inject(IIgniteInternal grid)
 {
     ResourceProcessor.Inject(_clo, grid);
 }
예제 #25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CacheAffinityImpl" /> class.
        /// </summary>
        /// <param name="target">Target.</param>
        /// <param name="keepBinary">Keep binary flag.</param>
        public CacheAffinityImpl(IPlatformTargetInternal target, bool keepBinary) : base(target)
        {
            _keepBinary = keepBinary;

            _ignite = target.Marshaller.Ignite;
        }
예제 #26
0
        /// <summary>
        /// Reads the schema according to this header data.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="position">The position.</param>
        /// <param name="hdr">The header.</param>
        /// <param name="schema">The schema.</param>
        /// <param name="ignite">The ignite.</param>
        /// <returns>
        /// Schema.
        /// </returns>
        public static BinaryObjectSchemaField[] ReadSchema(IBinaryStream stream, int position, BinaryObjectHeader hdr,
                                                           BinaryObjectSchema schema, IIgniteInternal ignite)
        {
            Debug.Assert(stream != null);
            Debug.Assert(schema != null);

            return(ReadSchema(stream, position, hdr, () => GetFieldIds(hdr, schema, ignite)));
        }
예제 #27
0
 /// <summary>
 /// Gets the field ids.
 /// </summary>
 private static int[] GetFieldIds(BinaryObjectHeader hdr, BinaryObjectSchema schema, IIgniteInternal ignite)
 {
     return(schema.Get(hdr.SchemaId) ?? GetFieldIds(hdr, ignite));
 }