/** <inheritDoc /> */ internal override void Write(PortableWriterImpl writer, bool keepPortable) { writer.WriteBoolean(Local); writer.WriteInt(PageSize); writer.WriteBoolean(Partition.HasValue); if (Partition.HasValue) { writer.WriteInt(Partition.Value); } if (Filter == null) { writer.WriteObject <CacheEntryFilterHolder>(null); } else { var holder = new CacheEntryFilterHolder(Filter, (key, val) => Filter.Invoke( new CacheEntry <TK, TV>((TK)key, (TV)val)), writer.Marshaller, keepPortable); writer.WriteObject(holder); writer.WriteLong(holder.Handle); } }
/// <summary> /// Put metadata to Grid. /// </summary> /// <param name="metas">Metadatas.</param> internal void PutMetadata(IDictionary <int, IPortableMetadata> metas) { DoOutOp(OpMeta, stream => { PortableWriterImpl metaWriter = _marsh.StartMarshal(stream); metaWriter.WriteInt(metas.Count); foreach (var meta in metas.Values) { PortableMetadataImpl meta0 = (PortableMetadataImpl)meta; metaWriter.WriteInt(meta0.TypeId); metaWriter.WriteString(meta0.TypeName); metaWriter.WriteString(meta0.AffinityKeyFieldName); IDictionary <string, int> fields = meta0.FieldsMap(); metaWriter.WriteInt(fields.Count); foreach (var field in fields) { metaWriter.WriteString(field.Key); metaWriter.WriteInt(field.Value); } } _marsh.FinishMarshal(metaWriter); }); _marsh.OnMetadataSent(metas); }
/// <summary> /// Write query arguments. /// </summary> /// <param name="writer">Writer.</param> /// <param name="args">Arguments.</param> internal static void WriteQueryArgs(PortableWriterImpl writer, object[] args) { if (args == null) writer.WriteInt(0); else { writer.WriteInt(args.Length); foreach (var arg in args) writer.WriteObject(arg); } }
/// <summary> /// Start execution. /// </summary> /// <param name="grid">Ignite instance.</param> /// <param name="writer">Writer.</param> /// <param name="cb">Callback invoked when all necessary data is written to stream.</param> /// <param name="qry">Query.</param> public void Start(Ignite grid, PortableWriterImpl writer, Func <IUnmanagedTarget> cb, ContinuousQuery <TK, TV> qry) { // 1. Inject resources. ResourceProcessor.Inject(_lsnr, grid); ResourceProcessor.Inject(_filter, grid); // 2. Allocate handle. _hnd = grid.HandleRegistry.Allocate(this); // 3. Write data to stream. writer.WriteLong(_hnd); writer.WriteBoolean(qry.Local); writer.WriteBoolean(_filter != null); ContinuousQueryFilterHolder filterHolder = _filter == null || qry.Local ? null : new ContinuousQueryFilterHolder(typeof(TK), typeof(TV), _filter, _keepPortable); writer.WriteObject(filterHolder); writer.WriteInt(qry.BufferSize); writer.WriteLong((long)qry.TimeInterval.TotalMilliseconds); writer.WriteBoolean(qry.AutoUnsubscribe); // 4. Call Java. _nativeQry = cb(); // 5. Initial query. var nativeInitialQryCur = UU.ContinuousQueryGetInitialQueryCursor(_nativeQry); _initialQueryCursor = nativeInitialQryCur == null ? null : new QueryCursor <TK, TV>(nativeInitialQryCur, _marsh, _keepPortable); }
/// <summary> /// Write query arguments. /// </summary> /// <param name="writer">Writer.</param> /// <param name="args">Arguments.</param> private static void WriteQueryArgs(PortableWriterImpl writer, object[] args) { if (args == null) { writer.WriteInt(0); } else { writer.WriteInt(args.Length); foreach (var arg in args) { writer.WriteObject(arg); } } }
/// <summary> /// Write dictionary. /// </summary> /// <param name="writer">Portable writer.</param> /// <param name="vals">Values.</param> /// <returns>The same writer.</returns> protected static PortableWriterImpl WriteDictionary <T1, T2>(PortableWriterImpl writer, IDictionary <T1, T2> vals) { writer.WriteInt(vals.Count); foreach (KeyValuePair <T1, T2> pair in vals) { writer.Write(pair.Key); writer.Write(pair.Value); } return(writer); }
/** <inheritDoc /> */ internal override void Write(PortableWriterImpl writer, bool keepPortable) { if (string.IsNullOrEmpty(Text)) { throw new ArgumentException("Text cannot be null or empty"); } if (string.IsNullOrEmpty(Type)) { throw new ArgumentException("Type cannot be null or empty"); } writer.WriteBoolean(Local); writer.WriteString(Text); writer.WriteString(Type); writer.WriteInt(PageSize); }
/// <summary> /// Write node IDs. /// </summary> /// <param name="writer">Writer.</param> /// <param name="nodes">Nodes.</param> private static void WriteNodeIds(PortableWriterImpl writer, ICollection <IClusterNode> nodes) { if (nodes == null) { writer.WriteBoolean(false); } else { writer.WriteBoolean(true); writer.WriteInt(nodes.Count); foreach (IClusterNode node in nodes) { writer.WriteGuid(node.Id); } } }
/// <summary> /// Writes proxy method invocation data to the specified writer. /// </summary> /// <param name="writer">Writer.</param> /// <param name="method">Method.</param> /// <param name="arguments">Arguments.</param> public static void WriteProxyMethod(PortableWriterImpl writer, MethodBase method, object[] arguments) { Debug.Assert(writer != null); Debug.Assert(method != null); writer.WriteString(method.Name); if (arguments != null) { writer.WriteBoolean(true); writer.WriteInt(arguments.Length); foreach (var arg in arguments) writer.WriteObject(arg); } else writer.WriteBoolean(false); }
/// <summary> /// Write batch content. /// </summary> /// <param name="writer">Portable writer.</param> private void WriteTo(PortableWriterImpl writer) { writer.WriteInt(_size); object val; while (_queue.TryDequeue(out val)) { // 1. Is it a collection? ICollection <KeyValuePair <TK, TV> > entries = val as ICollection <KeyValuePair <TK, TV> >; if (entries != null) { foreach (KeyValuePair <TK, TV> item in entries) { writer.Write(item.Key); writer.Write(item.Value); } continue; } // 2. Is it a single entry? DataStreamerEntry <TK, TV> entry = val as DataStreamerEntry <TK, TV>; if (entry != null) { writer.Write(entry.Key); writer.Write(entry.Value); continue; } // 3. Is it remove merker? DataStreamerRemoveEntry <TK> rmvEntry = val as DataStreamerRemoveEntry <TK>; if (rmvEntry != null) { writer.Write(rmvEntry.Key); writer.Write <object>(null); } } }
/** <inheritDoc /> */ internal override void Write(PortableWriterImpl writer, bool keepPortable) { if (string.IsNullOrEmpty(Sql)) { throw new ArgumentException("Sql cannot be null or empty"); } if (string.IsNullOrEmpty(Type)) { throw new ArgumentException("Type cannot be null or empty"); } // 2. Prepare. writer.WriteBoolean(Local); writer.WriteString(Sql); writer.WriteString(Type); writer.WriteInt(PageSize); WriteQueryArgs(writer, Arguments); }
/// <summary> /// Write collection. /// </summary> /// <param name="writer">Portable writer.</param> /// <param name="vals">Values.</param> /// <param name="selector">A transform function to apply to each element.</param> /// <returns>The same writer for chaining.</returns> protected static PortableWriterImpl WriteCollection <T1, T2>(PortableWriterImpl writer, ICollection <T1> vals, Func <T1, T2> selector) { writer.WriteInt(vals.Count); if (selector == null) { foreach (var val in vals) { writer.Write(val); } } else { foreach (var val in vals) { writer.Write(selector(val)); } } return(writer); }
/// <summary> /// Writes proxy method invocation data to the specified writer. /// </summary> /// <param name="writer">Writer.</param> /// <param name="method">Method.</param> /// <param name="arguments">Arguments.</param> public static void WriteProxyMethod(PortableWriterImpl writer, MethodBase method, object[] arguments) { Debug.Assert(writer != null); Debug.Assert(method != null); writer.WriteString(method.Name); if (arguments != null) { writer.WriteBoolean(true); writer.WriteInt(arguments.Length); foreach (var arg in arguments) { writer.WriteObject(arg); } } else { writer.WriteBoolean(false); } }
/** <inheritDoc /> */ internal override void Write(PortableWriterImpl writer, bool keepPortable) { if (string.IsNullOrEmpty(Text)) throw new ArgumentException("Text cannot be null or empty"); if (string.IsNullOrEmpty(Type)) throw new ArgumentException("Type cannot be null or empty"); writer.WriteBoolean(Local); writer.WriteString(Text); writer.WriteString(Type); writer.WriteInt(PageSize); }
public void Map(PlatformMemoryStream inStream, PlatformMemoryStream outStream) { IList <IClusterNode> subgrid; ClusterGroupImpl prj = (ClusterGroupImpl)_compute.ClusterGroup; var ignite = (Ignite)prj.Ignite; // 1. Unmarshal topology info if topology changed. var reader = prj.Marshaller.StartUnmarshal(inStream); if (reader.ReadBoolean()) { long topVer = reader.ReadLong(); List <IClusterNode> nodes = new List <IClusterNode>(reader.ReadInt()); int nodesCnt = reader.ReadInt(); subgrid = new List <IClusterNode>(nodesCnt); for (int i = 0; i < nodesCnt; i++) { IClusterNode node = ignite.GetNode(reader.ReadGuid()); nodes.Add(node); if (reader.ReadBoolean()) { subgrid.Add(node); } } // Update parent projection to help other task callers avoid this overhead. // Note that there is a chance that topology changed even further and this update fails. // It means that some of subgrid nodes could have left the Grid. This is not critical // for us, because Java will handle it gracefully. prj.UpdateTopology(topVer, nodes); } else { IList <IClusterNode> nodes = prj.NodesNoRefresh(); Debug.Assert(nodes != null, "At least one topology update should have occurred."); subgrid = IgniteUtils.Shuffle(nodes); } // 2. Perform map. IDictionary <IComputeJob <T>, IClusterNode> map; Exception err; try { map = _task.Map(subgrid, _arg); err = null; } catch (Exception e) { map = null; err = e; // Java can receive another exception in case of marshalling failure but it is not important. Finish(default(TR), e); } // 3. Write map result to the output stream. PortableWriterImpl writer = prj.Marshaller.StartMarshal(outStream); try { if (err == null) { writer.WriteBoolean(true); // Success flag. if (map == null) { writer.WriteBoolean(false); // Map produced no result. } else { writer.WriteBoolean(true); // Map produced result. writer.WriteInt(map.Count); // Amount of mapped jobs. var jobHandles = new List <long>(map.Count); foreach (KeyValuePair <IComputeJob <T>, IClusterNode> mapEntry in map) { var job = new ComputeJobHolder(_compute.ClusterGroup.Ignite as Ignite, mapEntry.Key.ToNonGeneric()); IClusterNode node = mapEntry.Value; var jobHandle = ignite.HandleRegistry.Allocate(job); jobHandles.Add(jobHandle); writer.WriteLong(jobHandle); if (node.IsLocal) { writer.WriteBoolean(false); // Job is not serialized. } else { writer.WriteBoolean(true); // Job is serialized. writer.WriteObject(job); } writer.WriteGuid(node.Id); } _jobHandles = jobHandles; } } else { writer.WriteBoolean(false); // Map failed. // Write error as string because it is not important for Java, we need only to print // a message in the log. writer.WriteString("Map step failed [errType=" + err.GetType().Name + ", errMsg=" + err.Message + ']'); } } catch (Exception e) { // Something went wrong during marshaling. Finish(default(TR), e); outStream.Reset(); writer.WriteBoolean(false); // Map failed. writer.WriteString(e.Message); // Write error message. } finally { prj.Marshaller.FinishMarshal(writer); } }
/** <inheritDoc /> */ internal override void Write(PortableWriterImpl writer, bool keepPortable) { if (string.IsNullOrEmpty(Sql)) throw new ArgumentException("Sql cannot be null or empty"); if (string.IsNullOrEmpty(Type)) throw new ArgumentException("Type cannot be null or empty"); // 2. Prepare. writer.WriteBoolean(Local); writer.WriteString(Sql); writer.WriteString(Type); writer.WriteInt(PageSize); WriteQueryArgs(writer, Arguments); }