Hi,

I don't think that you run ignite with proper configuration, because the
snippet that you sent won't work.
EventType.EVTS_CACHE_QUERY is array and you should have the folllowin
exception on logs:
Caused by: org.springframework.beans.TypeMismatchException: Failed to
convert property value of type 'java.util.ArrayList' to required type
'int[]' for property 'includeEventTypes'; nested exception is
java.lang.IllegalArgumentException: Cannot convert value of type 'int[]' to
required type 'int' for property 'includeEventTypes[9]': PropertyEditor
[org.springframework.beans.propertyeditors.CustomNumberEditor] returned
inappropriate value of type 'int[]'

replace it with:
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_CACHE_QUERY_EXECUTED"/>
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_CACHE_QUERY_OBJECT_READ"/>

I attached working example to the email.

Thanks,
Mike.

2017-11-16 10:50 GMT+03:00 opsharma1986 <[email protected]>:

> Yes, tried this below configuration
> <bean abstract="true" id="ignite.cfg"
>                 class="org.apache.ignite.configuration.
> IgniteConfiguration">
>         <property name="includeEventTypes">
>         <util:constant
> static-field="org.apache.ignite.events.EventType.EVTS_CACHE_QUERY"/>
>     </property>
> ...
> Rest-of-the-configs
>
> It did not work for me.
>
> Thanks
> Om
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
import org.apache.ignite.cache.query.SqlQuery;
import org.apache.ignite.cache.query.annotations.QuerySqlField;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.events.CacheQueryExecutedEvent;
import org.apache.ignite.events.EventAdapter;
import org.apache.ignite.events.EventType;
import org.apache.ignite.lang.IgnitePredicate;

public class QueryExecutedEvent {

    static class MyValue {
        @QuerySqlField(index = true)
        private int search;
    }

    public static void main(String[] args) {
        try (Ignite ignite = Ignition.start("example-ignite.xml")) {
            IgnitePredicate<EventAdapter> locLsnr = new IgnitePredicate<EventAdapter>()
            {
                @Override
                public boolean apply(EventAdapter evt) {
                    switch (evt.type()) {

                        case EventType.EVT_CACHE_QUERY_EXECUTED:
                            CacheQueryExecutedEvent cacheExecEvent = (CacheQueryExecutedEvent)evt;
                            String clause = cacheExecEvent.clause();
                            System.out.println("query "+clause);
                            break;
                        case EventType.EVT_CACHE_QUERY_OBJECT_READ:
                            CacheQueryExecutedEvent cacheObjReadEvent =
                                (CacheQueryExecutedEvent)evt;
                            String clause2 = cacheObjReadEvent.clause();
                            System.out.println("query "+clause2);
                            break;
                        default:
                            System.out.println(evt.getClass());
                            break;
                    }

                    return true;
                }
            };

            ignite.events().localListen(locLsnr,
                EventType.EVT_CACHE_QUERY_EXECUTED, EventType.EVT_CACHE_QUERY_OBJECT_READ);

            CacheConfiguration<Object, Object> cfg = new CacheConfiguration<>("DFLT");

            cfg.setIndexedTypes(Integer.class, MyValue.class);

            IgniteCache<Object, Object> cache = ignite.createCache(cfg);


            SqlQuery query = new SqlQuery(MyValue.class, "search = ?");
            query.setArgs(5);
            query.setLocal(true);

            cache.query(query).getAll();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>

<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<!--
    Ignite configuration with all defaults and enabled p2p deployment and enabled events.
-->
<beans xmlns="http://www.springframework.org/schema/beans";
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
       xmlns:util="http://www.springframework.org/schema/util";
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util
        http://www.springframework.org/schema/util/spring-util.xsd";>
    <bean abstract="true" id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
        <!-- Set to true to enable distributed class loading for examples, default is false. -->
        <property name="peerClassLoadingEnabled" value="true"/>

        <!-- Enable task execution events for examples. -->
        <property name="includeEventTypes">
            <list>
                <!--Task execution events-->
                <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_STARTED"/>
                <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_FINISHED"/>
                <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_FAILED"/>
                <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_TIMEDOUT"/>
                <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_SESSION_ATTR_SET"/>
                <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_REDUCED"/>

                <!--Cache events-->
                <util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_PUT"/>
                <util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_READ"/>
                <util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_REMOVED"/>

                <util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_QUERY_EXECUTED"/>
                <util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_QUERY_OBJECT_READ"/>
            </list>
        </property>

        <property name="discoverySpi">
            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
                <property name="ipFinder">
                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
                        <property name="addresses">
                            <list>
                                <value>localhost:47500..47600</value>
                            </list>
                        </property>
                    </bean>
                </property>
            </bean>
        </property>
    </bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>

<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<!--
    Ignite configuration with all defaults and enabled p2p deployment and enabled events.
-->
<beans xmlns="http://www.springframework.org/schema/beans";
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd";>
    <!-- Imports default Ignite configuration -->
    <import resource="example-default.xml"/>

    <bean parent="ignite.cfg">
        <property name="peerClassLoadingEnabled" value="true" />
        <property name="deploymentMode" value="PRIVATE" />
    </bean>
</beans>

Reply via email to