/** <inheritdoc /> */ public int Invoke(IPortableStream stream) { var reader = _ignite.Marshaller.StartUnmarshal(stream); var evt = EventReader.Read<IEvent>(reader); var nodeId = reader.ReadGuid() ?? Guid.Empty; return _filter(nodeId, evt) ? 1 : 0; }
/// <summary> /// Writes this instance to the stream. /// </summary> /// <param name="stream">Stream.</param> /// <param name="marsh">Marshaller.</param> public void Write(IPortableStream stream, PortableMarshaller marsh) { var writer = marsh.StartMarshal(stream); try { Marshal(writer); } finally { marsh.FinishMarshal(writer); } }
/// <summary> /// Reads proxy method invocation data from the specified reader. /// </summary> /// <param name="stream">Stream.</param> /// <param name="marsh">Marshaller.</param> /// <param name="mthdName">Method name.</param> /// <param name="mthdArgs">Method arguments.</param> public static void ReadProxyMethod(IPortableStream stream, PortableMarshaller marsh, out string mthdName, out object[] mthdArgs) { var reader = marsh.StartUnmarshal(stream); var srvKeepPortable = reader.ReadBoolean(); mthdName = reader.ReadString(); if (reader.ReadBoolean()) { mthdArgs = new object[reader.ReadInt()]; if (srvKeepPortable) reader = marsh.StartUnmarshal(stream, true); for (var i = 0; i < mthdArgs.Length; i++) mthdArgs[i] = reader.ReadObject<object>(); } else mthdArgs = null; }
/// <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; } }
/// <summary> /// Create job instance. /// </summary> /// <param name="grid">Grid.</param> /// <param name="stream">Stream.</param> /// <returns></returns> internal static ComputeJobHolder CreateJob(Ignite grid, IPortableStream stream) { try { return grid.Marshaller.StartUnmarshal(stream).ReadObject<ComputeJobHolder>(); } catch (Exception e) { throw new IgniteException("Failed to deserialize the job [errType=" + e.GetType().Name + ", errMsg=" + e.Message + ']'); } }
internal bool Serialize(IPortableStream stream) { ClusterGroupImpl prj = _ignite.ClusterGroup; PortableWriterImpl writer = prj.Marshaller.StartMarshal(stream); try { writer.Write(this); return true; } catch (Exception e) { writer.WriteString("Failed to marshal job [job=" + _job + ", errType=" + e.GetType().Name + ", errMsg=" + e.Message + ']'); return false; } finally { // 4. Process metadata. prj.FinishMarshal(writer); } }
/// <summary> /// Invokes the cache filter. /// </summary> /// <param name="input">The input stream.</param> /// <returns>Invocation result.</returns> public int Invoke(IPortableStream input) { var rawReader = _marsh.StartUnmarshal(input, _keepPortable).RawReader(); return _invoker(rawReader.ReadObject<object>(), rawReader.ReadObject<object>()) ? 1 : 0; }
/// <summary> /// Writes method invocation result. /// </summary> /// <param name="stream">Stream.</param> /// <param name="marsh">Marshaller.</param> /// <param name="methodResult">Method result.</param> /// <param name="invocationError">Method invocation error.</param> public static void WriteInvocationResult(IPortableStream stream, PortableMarshaller marsh, object methodResult, Exception invocationError) { Debug.Assert(stream != null); Debug.Assert(marsh != null); var writer = marsh.StartMarshal(stream); PortableUtils.WriteInvocationResult(writer, invocationError == null, invocationError ?? methodResult); }
/// <summary> /// Reads method invocation result. /// </summary> /// <param name="stream">Stream.</param> /// <param name="marsh">Marshaller.</param> /// <param name="keepPortable">Portable flag.</param> /// <returns> /// Method invocation result, or exception in case of error. /// </returns> public static object ReadInvocationResult(IPortableStream stream, PortableMarshaller marsh, bool keepPortable) { Debug.Assert(stream != null); Debug.Assert(marsh != null); var mode = keepPortable ? PortableMode.ForcePortable : PortableMode.Deserialize; var reader = marsh.StartUnmarshal(stream, mode); object err; var res = PortableUtils.ReadInvocationResult(reader, out err); if (err == null) return res; var portErr = err as IPortableObject; throw portErr != null ? new ServiceInvocationException("Proxy method invocation failed with a portable error. " + "Examine PortableCause for details.", portErr) : new ServiceInvocationException("Proxy method invocation failed with an exception. " + "Examine InnerException for details.", (Exception) err); }
/** * <summary>Write double.</summary> */ private static void WriteDoubleTyped(IPortableStream stream, double obj) { stream.WriteByte(PortableUtils.TypeDouble); stream.WriteDouble(obj); }
/// <summary> /// Invokes a store operation. /// </summary> /// <param name="input">Input stream.</param> /// <param name="cb">Callback.</param> /// <param name="grid">Grid.</param> /// <returns>Invocation result.</returns> /// <exception cref="IgniteException">Invalid operation type: + opType</exception> public int Invoke(IPortableStream input, IUnmanagedTarget cb, Ignite grid) { IPortableReader reader = grid.Marshaller.StartUnmarshal(input, _convertPortable ? PortableMode.Deserialize : PortableMode.ForcePortable); IPortableRawReader rawReader = reader.RawReader(); int opType = rawReader.ReadByte(); // Setup cache sessoin for this invocation. long sesId = rawReader.ReadLong(); CacheStoreSession ses = grid.HandleRegistry.Get<CacheStoreSession>(sesId, true); ses.CacheName = rawReader.ReadString(); _sesProxy.SetSession(ses); try { // Perform operation. switch (opType) { case OpLoadCache: _store.LoadCache((k, v) => WriteObjects(cb, grid, k, v), rawReader.ReadObjectArray<object>()); break; case OpLoad: object val = _store.Load(rawReader.ReadObject<object>()); if (val != null) WriteObjects(cb, grid, val); break; case OpLoadAll: var keys = rawReader.ReadCollection(); var result = _store.LoadAll(keys); foreach (DictionaryEntry entry in result) WriteObjects(cb, grid, entry.Key, entry.Value); break; case OpPut: _store.Write(rawReader.ReadObject<object>(), rawReader.ReadObject<object>()); break; case OpPutAll: _store.WriteAll(rawReader.ReadDictionary()); break; case OpRmv: _store.Delete(rawReader.ReadObject<object>()); break; case OpRmvAll: _store.DeleteAll(rawReader.ReadCollection()); break; case OpSesEnd: grid.HandleRegistry.Release(sesId); _store.SessionEnd(rawReader.ReadBoolean()); break; default: throw new IgniteException("Invalid operation type: " + opType); } return 0; } finally { _sesProxy.ClearSession(); } }
/// <summary> /// Constructor. /// </summary> /// <param name="stream">Stream.</param> public PortableStreamAdapter(IPortableStream stream) { _stream = stream; }