/// <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, IQueryBaseInternal 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(qry.IncludeExpired);
                    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.
                _nativeInitialQueryCursor = _nativeQry.OutObjectInternal(0);
                _initialQueryIsFields     = initialQry is SqlFieldsQuery;
            }
            catch (Exception)
            {
                if (_hnd > 0)
                {
                    _marsh.Ignite.HandleRegistry.Release(_hnd);
                }

                if (_nativeQry != null)
                {
                    _nativeQry.Dispose();
                }

                if (_nativeInitialQueryCursor != null)
                {
                    _nativeInitialQueryCursor.Dispose();
                }

                throw;
            }
        }
 /// <summary>
 /// Perform out operation.
 /// </summary>
 /// <param name="type">Operation type.</param>
 /// <returns>Resulting object.</returns>
 protected IPlatformTargetInternal DoOutOpObject(int type)
 {
     return(_target.OutObjectInternal(type));
 }