Example #1
0
        public void CompleteWithError(long taskHandle, PlatformMemoryStream stream)
        {
            PortableReaderImpl reader = _compute.Marshaller.StartUnmarshal(stream);

            Exception err;

            try
            {
                if (reader.ReadBoolean())
                {
                    PortableResultWrapper res = reader.ReadObject <PortableUserObject>()
                                                .Deserialize <PortableResultWrapper>();

                    err = (Exception)res.Result;
                }
                else
                {
                    err = ExceptionUtils.GetException(reader.ReadString(), reader.ReadString());
                }
            }
            catch (Exception e)
            {
                err = new IgniteException("Task completed with error, but it cannot be unmarshalled: " + e.Message, e);
            }

            CompleteWithError(taskHandle, err);
        }
Example #2
0
        /// <summary>
        /// Create lifecycle bean.
        /// </summary>
        /// <param name="reader">Reader.</param>
        /// <returns>Lifecycle bean.</returns>
        internal static ILifecycleBean CreateLifecycleBean(PortableReaderImpl reader)
        {
            // 1. Instantiate.
            string assemblyName = reader.ReadString();
            string clsName      = reader.ReadString();

            object bean = IgniteUtils.CreateInstance(assemblyName, clsName);

            // 2. Set properties.
            IDictionary <string, object> props = reader.ReadGenericDictionary <string, object>();

            IgniteUtils.SetProperties(bean, props);

            return(bean as ILifecycleBean);
        }
Example #3
0
        /// <summary>
        /// Kernal start callback.
        /// </summary>
        /// <param name="interopProc">Interop processor.</param>
        /// <param name="stream">Stream.</param>
        internal static void OnStart(IUnmanagedTarget interopProc, IPortableStream stream)
        {
            try
            {
                // 1. Read data and leave critical state ASAP.
                PortableReaderImpl reader = PU.Marshaller.StartUnmarshal(stream);

                // ReSharper disable once PossibleInvalidOperationException
                var name = reader.ReadString();

                // 2. Set ID and name so that Start() method can use them later.
                _startup.Name = name;

                if (Nodes.ContainsKey(new NodeKey(name)))
                {
                    throw new IgniteException("Ignite with the same name already started: " + name);
                }

                _startup.Ignite = new Ignite(_startup.Configuration, _startup.Name, interopProc, _startup.Marshaller,
                                             _startup.LifecycleBeans, _startup.Callbacks);
            }
            catch (Exception e)
            {
                // 5. Preserve exception to throw it later in the "Start" method and throw it further
                //    to abort startup in Java.
                _startup.Error = e;

                throw;
            }
        }
        private void FutureError(void *target, long futPtr, long memPtr)
        {
            SafeCall(() =>
            {
                IPortableStream stream = IgniteManager.Memory.Get(memPtr).Stream();

                PortableReaderImpl reader = _ignite.Marshaller.StartUnmarshal(stream);

                string errCls = reader.ReadString();
                string errMsg = reader.ReadString();

                Exception err = ExceptionUtils.GetException(errCls, errMsg, reader);

                ProcessFuture(futPtr, fut => { fut.OnError(err); });
            });
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ServiceDescriptor" /> class.
        /// </summary>
        /// <param name="name">Name.</param>
        /// <param name="reader">Reader.</param>
        /// <param name="services">Services.</param>
        public ServiceDescriptor(string name, PortableReaderImpl reader, IServices services)
        {
            Debug.Assert(reader != null);
            Debug.Assert(services != null);
            Debug.Assert(!string.IsNullOrEmpty(name));

            _services = services;
            Name      = name;

            CacheName       = reader.ReadString();
            MaxPerNodeCount = reader.ReadInt();
            TotalCount      = reader.ReadInt();
            OriginNodeId    = reader.ReadGuid() ?? Guid.Empty;
            AffinityKey     = reader.ReadObject <object>();

            var mapSize = reader.ReadInt();
            var snap    = new Dictionary <Guid, int>(mapSize);

            for (var i = 0; i < mapSize; i++)
            {
                snap[reader.ReadGuid() ?? Guid.Empty] = reader.ReadInt();
            }

            TopologySnapshot = snap.AsReadOnly();
        }
Example #6
0
        /// <summary>
        /// Process cache partial update exception.
        /// </summary>
        /// <param name="msg">Message.</param>
        /// <param name="reader">Reader.</param>
        /// <returns></returns>
        private static Exception ProcessCachePartialUpdateException(string msg, PortableReaderImpl 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 keepPortable = reader.ReadBoolean();

                PortableReaderImpl keysReader = reader.Marshaller.StartUnmarshal(reader.Stream, keepPortable);

                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(innerErrCls, innerErrMsg);

            return(new CachePartialUpdateException(msg, innerErr));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ServiceDescriptor" /> class.
        /// </summary>
        /// <param name="name">Name.</param>
        /// <param name="reader">Reader.</param>
        /// <param name="services">Services.</param>
        public ServiceDescriptor(string name, PortableReaderImpl reader, IServices services)
        {
            Debug.Assert(reader != null);
            Debug.Assert(services != null);
            Debug.Assert(!string.IsNullOrEmpty(name));

            _services = services;
            Name = name;

            CacheName = reader.ReadString();
            MaxPerNodeCount = reader.ReadInt();
            TotalCount = reader.ReadInt();
            OriginNodeId = reader.ReadGuid() ?? Guid.Empty;
            AffinityKey = reader.ReadObject<object>();

            var mapSize = reader.ReadInt();
            var snap = new Dictionary<Guid, int>(mapSize);

            for (var i = 0; i < mapSize; i++)
                snap[reader.ReadGuid() ?? Guid.Empty] = reader.ReadInt();

            TopologySnapshot = snap.AsReadOnly();
        }
        /// <summary>
        /// Process cache partial update exception.
        /// </summary>
        /// <param name="msg">Message.</param>
        /// <param name="reader">Reader.</param>
        /// <returns></returns>
        private static Exception ProcessCachePartialUpdateException(string msg, PortableReaderImpl 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 keepPortable = reader.ReadBoolean();

                PortableReaderImpl keysReader = reader.Marshaller.StartUnmarshal(reader.Stream, keepPortable);

                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(innerErrCls, innerErrMsg);

            return new CachePartialUpdateException(msg, innerErr);
        }
Example #9
0
        /// <summary>
        /// Create lifecycle bean.
        /// </summary>
        /// <param name="reader">Reader.</param>
        /// <returns>Lifecycle bean.</returns>
        internal static ILifecycleBean CreateLifecycleBean(PortableReaderImpl reader)
        {
            // 1. Instantiate.
            string assemblyName = reader.ReadString();
            string clsName = reader.ReadString();

            object bean = IgniteUtils.CreateInstance(assemblyName, clsName);

            // 2. Set properties.
            IDictionary<string, object> props = reader.ReadGenericDictionary<string, object>();

            IgniteUtils.SetProperties(bean, props);

            return bean as ILifecycleBean;
        }