ClientConfiguration cfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
try (IgniteClient igniteClient = Ignition.startClient(cfg)) {
System.out.println(">>> Thin client put-get example started.");
final String CACHE_NAME = "put-get-example";
ClientCache<Integer, Object> cache = igniteClient.getOrCreateCache(CACHE_NAME);
Person p = new Person();
//put
HashMap<Integer, Person> hm = new HashMap<Integer, Person>();
hm.put(1, p);
cache.put(1, hm);
//get
HashMap<Integer, Person> map = (HashMap<Integer, Person>)cache.get(1);
Person p2 = map.get(1);
System.out.format(">>> Loaded [%s] from the cache.\n",p2);
}
catch (ClientException e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
catch (Exception e) {
System.err.format("Unexpected failure: %s\n", e);
e.printStackTrace();
}
apache-ignite のシンクライアントを使用しています。
ハッシュマップを作成し、Person クラス (org.apache.ignite.examples.model.Person) オブジェクトをそこに配置します。
ハッシュマップから取り出すと、次の例外が発生します。
> java.lang.ClassCastException:
> org.apache.enite.internal.binary.BinaryObjectImpl cannot be cast to
> org.apache.engite.examples.model.Person.
以下のコードでは例外が示されています。
Person p2 = map.get(1);
ただし、次のようにコードを変更しても例外はありません。
BinaryObject bo = (BinaryObject) map.get(1);
Person p2 = bo.deserialize();
それは必要ないと思います。別の解決策はありますか?