2017-03-06 11 views
0

私はApache Igniteの初心者です。私の窓のボックスで、私はignite.batファイルをダブルクリックでのApacheのIgniteを開始し、次のコードを実行しようとしている - クライアントコードを取り込むApache Ignite:ScanQuery except exception

キャッシュ

package ignite; 

import org.apache.ignite.Ignite; 
import org.apache.ignite.IgniteCache; 
import org.apache.ignite.Ignition; 
import org.apache.ignite.configuration.CacheConfiguration; 

public class SpringIgniteClient { 
    public static void main(String[] args) throws Exception { 
     System.out.println("Run example!!"); 
     Ignition.setClientMode(true); 

     // Start Ignite in client mode. 
     Ignite ignite = Ignition.start(); 

     CacheConfiguration<Integer, Person> cfg = new CacheConfiguration<Integer, Person>("myStreamCache"); 
     cfg.setIndexedTypes(Integer.class, Person.class); 

     IgniteCache<Integer, Person> cache = ignite.getOrCreateCache(cfg); 


     //for(int i = 1; i < 1000; i++){ cache.put(i, Integer.toString(i)+"sushil---"); } 


     for (int i = 0; i < 100; i++) { 
      Person person = new Person(i, i, "name_" + i, (i * 100) % 3000); 
      if(person.getSal() < 1000){ 
       System.out.println(person); 
      } 
      cache.put(i, person); 
     } 


    } 
} 

キャッシュScanQueryクライアントコード

package ignite; 

import javax.cache.Cache.Entry; 

import org.apache.ignite.Ignite; 
import org.apache.ignite.IgniteCache; 
import org.apache.ignite.Ignition; 
import org.apache.ignite.cache.query.QueryCursor; 
import org.apache.ignite.cache.query.ScanQuery; 
import org.apache.ignite.configuration.CacheConfiguration; 
import org.apache.ignite.lang.IgniteBiPredicate; 

public class SpringIgniteReceiverClient { 
    public static void main(String[] args) { 
     System.out.println("Run Receiver example!!"); 
     Ignition.setClientMode(true); 

     // Start Ignite in client mode. 
     Ignite ignite = Ignition.start(); 

     CacheConfiguration<Integer, Person> cfg = new CacheConfiguration<Integer, Person>("myStreamCache"); 
     cfg.setIndexedTypes(Integer.class, Person.class); 
     IgniteCache<Integer, Person> cache = ignite.getOrCreateCache(cfg); 


     IgniteBiPredicate<Integer, Person> filter = new MyIgniteBiPredicate(); 

     ScanQuery<Integer, Person> query = new ScanQuery<Integer, Person>(filter); 
     //query.setLocal(true); 
     QueryCursor<Entry<Integer, Person>> cursor= cache.query(query); 
     System.out.println("ALL DATA ->"+cursor.getAll()); 
    } 

} 

とIgniteBiPredicate実装

package ignite; 

import java.io.Serializable; 

import org.apache.ignite.lang.IgniteBiPredicate; 

public class MyIgniteBiPredicate implements IgniteBiPredicate<Integer, Person>, Serializable{ 
    /** 
    * 
    */ 
    private static final long serialVersionUID = 1L; 

    @Override public boolean apply(Integer key, Person p) { 
     return p.getSal() < 1000; 
    } 

} 
です

SerializeをJavaのPOJO

package ignite; 

import java.io.Serializable; 

public class Person implements Serializable{ 
    /** 
    * 
    */ 
    private static final long serialVersionUID = 1L; 
    private int age; 
    private int empId; 
    private String name; 
    private int sal; 

    public Person(int age, int empId, String name, int sal) { 
     super(); 
     this.age = age; 
     this.empId = empId; 
     this.name = name; 
     this.sal = sal; 
    } 

    public int getAge() { 
     return age; 
    } 

    public void setAge(int age) { 
     this.age = age; 
    } 

    public int getEmpId() { 
     return empId; 
    } 

    public void setEmpId(int empId) { 
     this.empId = empId; 
    } 

    public String getName() { 
     return name; 
    } 

    public void setName(String name) { 
     this.name = name; 
    } 

    public int getSal() { 
     return sal; 
    } 

    public void setSal(int sal) { 
     this.sal = sal; 
    } 

    @Override 
    public String toString() { 
     return "Person [age=" + age + ", empId=" + empId + ", name=" + name + ", sal=" + sal + "]"; 
    } 



} 

は、デバッグ時には、私はIgniteCacheProxy.classに、以下のメソッドが呼び出されると、それはnullを返していることがわかりました。

/** 
    * @param loc Enforce local. 
    * @return Local node cluster group. 
    */ 
    private ClusterGroup projection(boolean loc) { 
     if (loc || ctx.isLocal() || isReplicatedDataNode()) 
      return ctx.kernalContext().grid().cluster().forLocal(); 

     if (ctx.isReplicated()) 
      return ctx.kernalContext().grid().cluster().forDataNodes(ctx.name()).forRandom(); 

     return null; 
    } 

ScanQueryプログラムでは、次のエラーが発生します。

Run Receiver example!! 
[21:46:52] (wrn) Default Spring XML file not found (is IGNITE_HOME set?): config/default-config.xml 
Mar 05, 2017 9:46:52 PM java.util.logging.LogManager$RootLogger log 
SEVERE: Failed to resolve default logging config file: config/java.util.logging.properties 
[21:46:53] __________ ________________ 
[21:46:53] /_/ ___/ |//_/_ __/ __/ 
[21:46:53] _/ // (7 7 ////// _/ 
[21:46:53] /___/\___/_/|_/___/ /_/ /___/ 
[21:46:53] 
[21:46:53] ver. 1.8.0#20161205-sha1:9ca40dbe 
[21:46:53] 2016 Copyright(C) Apache Software Foundation 
[21:46:53] 
[21:46:53] Ignite documentation: http://ignite.apache.org 
[21:46:53] 
[21:46:53] Quiet mode. 
[21:46:53] ^-- To see **FULL** console log here add -DIGNITE_QUIET=false or "-v" to ignite.{sh|bat} 
[21:46:53] 
[21:46:53] OS: Windows 7 6.1 amd64 
[21:46:53] VM information: Java(TM) SE Runtime Environment 1.8.0_65-b17 Oracle Corporation Java HotSpot(TM) 64-Bit Server VM 25.65-b01 
[21:46:53] Initial heap size is 124MB (should be no less than 512MB, use -Xms512m -Xmx512m). 
[21:46:53] Configured plugins: 
[21:46:53] ^-- None 
[21:46:53] 
[21:46:54] Security status [authentication=off, tls/ssl=off] 
[21:46:58] To start Console Management & Monitoring run ignitevisorcmd.{sh|bat} 
[21:46:58] 
[21:46:58] Ignite node started OK (id=ae95174d) 
[21:46:58] Topology snapshot [ver=3, servers=1, clients=2, CPUs=4, heap=4.4GB] 
Exception in thread "main" javax.cache.CacheException: class org.apache.ignite.IgniteCheckedException: Query execution failed: GridCacheQueryBean [qry=GridCacheQueryAdapter [type=SCAN, clsName=null, clause=null, [email protected], transform=null, part=null, incMeta=false, metrics=GridCacheQueryMetricsAdapter [minTime=9223372036854775807, maxTime=0, sumTime=0, avgTime=0.0, execs=0, completed=0, fails=0], pageSize=1024, timeout=0, keepAll=true, incBackups=false, dedup=false, prj=null, keepBinary=false, subjId=ae95174d-ff1c-44b2-a7dc-24fab738729e, taskHash=0], rdc=null, trans=null] 
    at org.apache.ignite.internal.processors.cache.GridCacheUtils.convertToCacheException(GridCacheUtils.java:1440) 
    at org.apache.ignite.internal.processors.cache.query.GridCacheQueryFutureAdapter.next(GridCacheQueryFutureAdapter.java:174) 
    at org.apache.ignite.internal.processors.cache.query.GridCacheDistributedQueryManager$5.onHasNext(GridCacheDistributedQueryManager.java:634) 
    at org.apache.ignite.internal.util.GridCloseableIteratorAdapter.hasNextX(GridCloseableIteratorAdapter.java:53) 
    at org.apache.ignite.internal.processors.cache.IgniteCacheProxy$2$1.onHasNext(IgniteCacheProxy.java:518) 
    at org.apache.ignite.internal.util.GridCloseableIteratorAdapter.hasNextX(GridCloseableIteratorAdapter.java:53) 
    at org.apache.ignite.internal.util.lang.GridIteratorAdapter.hasNext(GridIteratorAdapter.java:45) 
    at org.apache.ignite.internal.processors.cache.QueryCursorImpl.getAll(QueryCursorImpl.java:117) 
    at ignite.SpringIgniteReceiverClient.main(SpringIgniteReceiverClient.java:31) 
Caused by: class org.apache.ignite.IgniteCheckedException: Query execution failed: GridCacheQueryBean [qry=GridCacheQueryAdapter [type=SCAN, clsName=null, clause=null, [email protected], transform=null, part=null, incMeta=false, metrics=GridCacheQueryMetricsAdapter [minTime=9223372036854775807, maxTime=0, sumTime=0, avgTime=0.0, execs=0, completed=0, fails=0], pageSize=1024, timeout=0, keepAll=true, incBackups=false, dedup=false, prj=null, keepBinary=false, subjId=ae95174d-ff1c-44b2-a7dc-24fab738729e, taskHash=0], rdc=null, trans=null] 
    at org.apache.ignite.internal.processors.cache.query.GridCacheQueryFutureAdapter.checkError(GridCacheQueryFutureAdapter.java:260) 
    at org.apache.ignite.internal.processors.cache.query.GridCacheQueryFutureAdapter.internalIterator(GridCacheQueryFutureAdapter.java:318) 
    at org.apache.ignite.internal.processors.cache.query.GridCacheQueryFutureAdapter.next(GridCacheQueryFutureAdapter.java:164) 
    ... 7 more 
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to execute query on node [query=GridCacheQueryBean [qry=GridCacheQueryAdapter [type=SCAN, clsName=null, clause=null, [email protected], transform=null, part=null, incMeta=false, metrics=GridCacheQueryMetricsAdapter [minTime=9223372036854775807, maxTime=0, sumTime=0, avgTime=0.0, execs=0, completed=0, fails=0], pageSize=1024, timeout=0, keepAll=true, incBackups=false, dedup=false, prj=null, keepBinary=false, subjId=ae95174d-ff1c-44b2-a7dc-24fab738729e, taskHash=0], rdc=null, trans=null], nodeId=366435c6-5fca-43dc-b1f2-5ff2b0d3ee2d] 
    at org.apache.ignite.internal.processors.cache.query.GridCacheQueryFutureAdapter.onPage(GridCacheQueryFutureAdapter.java:383) 
    at org.apache.ignite.internal.processors.cache.query.GridCacheDistributedQueryManager.processQueryResponse(GridCacheDistributedQueryManager.java:398) 
    at org.apache.ignite.internal.processors.cache.query.GridCacheDistributedQueryManager.access$000(GridCacheDistributedQueryManager.java:63) 
    at org.apache.ignite.internal.processors.cache.query.GridCacheDistributedQueryManager$1.apply(GridCacheDistributedQueryManager.java:93) 
    at org.apache.ignite.internal.processors.cache.query.GridCacheDistributedQueryManager$1.apply(GridCacheDistributedQueryManager.java:91) 
    at org.apache.ignite.internal.processors.cache.GridCacheIoManager.processMessage(GridCacheIoManager.java:827) 
    at org.apache.ignite.internal.processors.cache.GridCacheIoManager.onMessage0(GridCacheIoManager.java:369) 
    at org.apache.ignite.internal.processors.cache.GridCacheIoManager.access$400(GridCacheIoManager.java:95) 
    at org.apache.ignite.internal.processors.cache.GridCacheIoManager$OrderedMessageListener.onMessage(GridCacheIoManager.java:1345) 
    at org.apache.ignite.internal.managers.communication.GridIoManager.invokeListener(GridIoManager.java:1082) 
    at org.apache.ignite.internal.managers.communication.GridIoManager.access$1600(GridIoManager.java:102) 
    at org.apache.ignite.internal.managers.communication.GridIoManager$GridCommunicationMessageSet.unwind(GridIoManager.java:2332) 
    at org.apache.ignite.internal.managers.communication.GridIoManager.unwindMessageSet(GridIoManager.java:1042) 
    at org.apache.ignite.internal.managers.communication.GridIoManager.access$1900(GridIoManager.java:102) 
    at org.apache.ignite.internal.managers.communication.GridIoManager$6.run(GridIoManager.java:1011) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: class org.apache.ignite.IgniteCheckedException: ignite.MyIgniteBiPredicate 
    at org.apache.ignite.internal.util.IgniteUtils.unmarshal(IgniteUtils.java:9785) 
    at org.apache.ignite.internal.processors.cache.query.GridCacheQueryRequest.finishUnmarshal(GridCacheQueryRequest.java:322) 
    at org.apache.ignite.internal.processors.cache.GridCacheIoManager.unmarshall(GridCacheIoManager.java:1298) 
    at org.apache.ignite.internal.processors.cache.GridCacheIoManager.onMessage0(GridCacheIoManager.java:364) 
    at org.apache.ignite.internal.processors.cache.GridCacheIoManager.handleMessage(GridCacheIoManager.java:293) 
    at org.apache.ignite.internal.processors.cache.GridCacheIoManager.access$000(GridCacheIoManager.java:95) 
    at org.apache.ignite.internal.processors.cache.GridCacheIoManager$1.onMessage(GridCacheIoManager.java:238) 
    at org.apache.ignite.internal.managers.communication.GridIoManager.invokeListener(GridIoManager.java:1082) 
    at org.apache.ignite.internal.managers.communication.GridIoManager.processRegularMessage0(GridIoManager.java:710) 
    at org.apache.ignite.internal.managers.communication.GridIoManager.access$1700(GridIoManager.java:102) 
    at org.apache.ignite.internal.managers.communication.GridIoManager$5.run(GridIoManager.java:673) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    ... 1 more 
Caused by: class org.apache.ignite.binary.BinaryInvalidTypeException: ignite.MyIgniteBiPredicate 
    at org.apache.ignite.internal.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:689) 
    at org.apache.ignite.internal.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:686) 
    at org.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize0(BinaryReaderExImpl.java:1491) 
    at org.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize(BinaryReaderExImpl.java:1450) 
    at org.apache.ignite.internal.binary.GridBinaryMarshaller.deserialize(GridBinaryMarshaller.java:298) 
    at org.apache.ignite.internal.binary.BinaryMarshaller.unmarshal0(BinaryMarshaller.java:100) 
    at org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.unmarshal(AbstractNodeNameAwareMarshaller.java:82) 
    at org.apache.ignite.internal.util.IgniteUtils.unmarshal(IgniteUtils.java:9779) 
    ... 13 more 
Caused by: java.lang.ClassNotFoundException: ignite.MyIgniteBiPredicate 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366) 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358) 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Class.java:274) 
    at org.apache.ignite.internal.util.IgniteUtils.forName(IgniteUtils.java:8393) 
    at org.apache.ignite.internal.MarshallerContextAdapter.getClass(MarshallerContextAdapter.java:185) 
    at org.apache.ignite.internal.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:680) 
    ... 20 more 

答えて

2

サーバーノードにMyIgniteBiPredicateを展開する必要があります。このクラスを使用してJARファイルを作成し、このJARをクラスタ起動前にIGNITE_HOME/libsフォルダに配置します。