Ejemplo n.º 1
0
        /// <summary>
        /// Handles continuous query events.
        /// </summary>
        private void HandleContinuousQueryEvents(IBinaryStream stream, Exception err,
                                                 ICacheEntryEventListener <TK, TV> listener, ClientContinuousQueryHandle qryHandle)
        {
            if (err != null)
            {
                qryHandle.OnError(err);
                return;
            }

            var flags  = (ClientFlags)stream.ReadShort();
            var opCode = (ClientOp)stream.ReadShort();

            if ((flags & ClientFlags.Error) == ClientFlags.Error)
            {
                var status = (ClientStatusCode)stream.ReadInt();
                var msg    = _marsh.Unmarshal <string>(stream);

                GetLogger().Error("Error while handling Continuous Query notification ({0}): {1}", status, msg);

                qryHandle.OnError(new IgniteClientException(msg, null, status));

                return;
            }

            if (opCode == ClientOp.QueryContinuousEventNotification)
            {
                var evts = ContinuousQueryUtils.ReadEvents <TK, TV>(stream, _marsh, _keepBinary);

                listener.OnEvent(evts);

                return;
            }

            GetLogger().Error("Error while handling Continuous Query notification: unexpected op '{0}'", opCode);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="qry">Query.</param>
        /// <param name="marsh">Marshaller.</param>
        /// <param name="keepPortable">Keep portable flag.</param>
        public ContinuousQueryHandleImpl(ContinuousQuery <TK, TV> qry, PortableMarshaller marsh, bool keepPortable)
        {
            _marsh        = marsh;
            _keepPortable = keepPortable;

            _lsnr   = qry.Listener;
            _filter = qry.Filter;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="qry">Query.</param>
        /// <param name="marsh">Marshaller.</param>
        /// <param name="keepBinary">Keep binary flag.</param>
        public ContinuousQueryHandleImpl(ContinuousQuery <TK, TV> qry, Marshaller marsh, bool keepBinary)
        {
            _marsh      = marsh;
            _keepBinary = keepBinary;

            _lsnr   = qry.Listener;
            _filter = qry.Filter;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="lsnr">Listener.</param>
        /// <param name="filter">Filter.</param>
        /// <param name="loc">Whether query should be executed locally.</param>
        public ContinuousQuery(ICacheEntryEventListener <TK, TV> lsnr, ICacheEntryEventFilter <TK, TV> filter, bool loc)
        {
            Listener = lsnr;
            Filter   = filter;
            Local    = loc;

            BufferSize      = DfltBufSize;
            TimeInterval    = DfltTimeInterval;
            AutoUnsubscribe = DfltAutoUnsubscribe;
        }
Ejemplo n.º 5
0
        /// <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;
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="lsnr">Listener.</param>
 /// <param name="filter">Filter.</param>
 public ContinuousQuery(ICacheEntryEventListener <TK, TV> lsnr, ICacheEntryEventFilter <TK, TV> filter)
     : this(lsnr, filter, false)
 {
     // No-op.
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="lsnr">Listener.</param>
 /// <param name="loc">Whether query should be executed locally.</param>
 public ContinuousQuery(ICacheEntryEventListener <TK, TV> lsnr, bool loc) : this(lsnr, null, loc)
 {
     // No-op.
 }