/// <summary> /// QueryContinuous implementation. /// </summary> private IContinuousQueryHandle <ICacheEntry <TK, TV> > QueryContinuousImpl(ContinuousQuery <TK, TV> qry, QueryBase initialQry) { qry.Validate(); var hnd = new ContinuousQueryHandleImpl <TK, TV>(qry, Marshaller, _flagKeepPortable); using (var stream = IgniteManager.Memory.Allocate().Stream()) { var writer = Marshaller.StartMarshal(stream); hnd.Start(_ignite, writer, () => { if (initialQry != null) { writer.WriteInt((int)initialQry.OpId); initialQry.Write(writer, KeepPortable); } else { writer.WriteInt(-1); // no initial query } FinishMarshal(writer); // ReSharper disable once AccessToDisposedClosure return(UU.CacheOutOpContinuousQuery(Target, (int)CacheOp.QryContinuous, stream.SynchronizeOutput())); }, qry); } return(hnd); }
/** <inheritDoc /> */ public IQueryCursor <ICacheEntry <TK, TV> > Query(QueryBase qry) { IgniteArgumentCheck.NotNull(qry, "qry"); var cursor = DoOutOpObject((int)qry.OpId, writer => qry.Write(writer, IsKeepBinary)); return(new QueryCursor <TK, TV>(cursor, _flagKeepBinary)); }
/** <inheritDoc /> */ public IQueryCursor <ICacheEntry <TK, TV> > Query(QueryBase qry) { IgniteArgumentCheck.NotNull(qry, "qry"); IUnmanagedTarget cursor; using (var stream = IgniteManager.Memory.Allocate().GetStream()) { var writer = Marshaller.StartMarshal(stream); qry.Write(writer, IsKeepBinary); FinishMarshal(writer); cursor = UU.CacheOutOpQueryCursor(Target, (int)qry.OpId, stream.SynchronizeOutput()); } return(new QueryCursor <TK, TV>(cursor, Marshaller, _flagKeepBinary)); }
/// <summary> /// Constructor. /// </summary> /// <param name="qry">Query.</param> /// <param name="marsh">Marshaller.</param> /// <param name="keepBinary">Keep binary flag.</param> /// <param name="createTargetCb">The initialization callback.</param> /// <param name="initialQry">The initial query.</param> public ContinuousQueryHandleImpl(ContinuousQuery <TK, TV> qry, Marshaller marsh, bool keepBinary, Func <Action <BinaryWriter>, IPlatformTargetInternal> createTargetCb, QueryBase initialQry) { _marsh = marsh; _keepBinary = keepBinary; _lsnr = qry.Listener; _filter = qry.Filter; // 1. Inject resources. ResourceProcessor.Inject(_lsnr, _marsh.Ignite); ResourceProcessor.Inject(_filter, _marsh.Ignite); try { // 2. Allocate handle. _hnd = _marsh.Ignite.HandleRegistry.Allocate(this); // 3. Call Java. _nativeQry = createTargetCb(writer => { writer.WriteLong(_hnd); writer.WriteBoolean(qry.Local); writer.WriteBoolean(_filter != null); var javaFilter = _filter as PlatformJavaObjectFactoryProxy; if (javaFilter != null) { writer.WriteObject(javaFilter.GetRawProxy()); } else { var filterHolder = _filter == null || qry.Local ? null : new ContinuousQueryFilterHolder(_filter, _keepBinary); writer.WriteObject(filterHolder); } writer.WriteInt(qry.BufferSize); writer.WriteLong((long)qry.TimeInterval.TotalMilliseconds); writer.WriteBoolean(qry.AutoUnsubscribe); if (initialQry != null) { writer.WriteInt((int)initialQry.OpId); initialQry.Write(writer, _keepBinary); } else { writer.WriteInt(-1); // no initial query } }); // 4. Initial query. var nativeInitialQryCur = _nativeQry.OutObjectInternal(0); _initialQueryCursor = nativeInitialQryCur == null ? null : new QueryCursor <TK, TV>(nativeInitialQryCur, _keepBinary); } catch (Exception) { if (_hnd > 0) { _marsh.Ignite.HandleRegistry.Release(_hnd); } if (_nativeQry != null) { _nativeQry.Dispose(); } if (_initialQueryCursor != null) { _initialQueryCursor.Dispose(); } throw; } }