Trouble working with Data Grid Getting Started examples

classic Classic list List threaded Threaded
3 messages Options
pgarg pgarg
Reply | Threaded
Open this post in threaded view
|

Trouble working with Data Grid Getting Started examples

asked by tran nam-luc

Hello,

I am having issues working with the grid examples provided in http://apacheignite.readme.io/v1.0/docs/getting-started

I have the following code in main.java (modified for Java6):

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


public class IgniteGettingStarted {

    public static void main(String[] args) {
        final String CACHE_NAME = IgniteGettingStarted.class.getSimpleName();
        try {
            Ignite ignite = Ignition.start("examples/config/example-cache.xml");
            IgniteCache<Integer, String> cache = ignite.cache(CACHE_NAME);

            // Store keys in cache (values will end up on different cache nodes).
            for (int i = 0; i < 10; i++)
                cache.put(i, Integer.toString(i));

            for (int i = 0; i < 10; i++)
                System.out.println("Got [key=" + i + ", val=" + cache.get(i) + ']');
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}


When running the main method I get the following error:

11:29:03,775 INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions from URL [file:/home/nltran/ignite-fabric-1.0.0-incubating/examples/config/example-cache.xml]
11:29:04,015 INFO  org.springframework.context.support.GenericApplicationContext  - Refreshing org.springframework.context.support.GenericApplicationContext@1936f0f5: startup date [Wed May 06 11:29:04 CEST 2015]; root of context hierarchy
[11:29:04]    __________  ________________
[11:29:04]   /  _/ ___/ |/ /  _/_  __/ __/
[11:29:04]  _/ // (7 7    // /  / / / _/  
[11:29:04] /___/\___/_/|_/___/ /_/ /___/  
[11:29:04]  
[11:29:04] ver. 1.0.0#20150329-sha1:5fc2cd05
[11:29:04] 2015 Copyright(C) Apache Software Foundation
[11:29:04]
[11:29:04] Quiet mode.
[11:29:04]   ^-- Logging to file '/home/nltran/ignite-fabric-1.0.0-incubating/work/log/ignite-875c62e2.0.log'
[11:29:04]   ^-- To see **FULL** console log here add -DIGNITE_QUIET=false or "-v" to ignite.{sh|bat}
[11:29:04]
[11:29:04] Configured plugins:
[11:29:04]   ^-- None
[11:29:04]
[11:29:07] Performance suggestions for grid  (fix if possible)
[11:29:07] To disable, set -DIGNITE_PERFORMANCE_SUGGESTIONS_DISABLED=true
[11:29:07]   ^-- Decrease number of backups (set 'keyBackups' to 0)
[11:29:07]
[11:29:07] To start Console Management & Monitoring run ignitevisorcmd.{sh|bat}
[11:29:07]
[11:29:07] Ignite node started OK (id=875c62e2)
[11:29:07] Topology snapshot [ver=5, nodes=3, CPUs=4, heap=1.5GB]
java.lang.IllegalArgumentException: Cache is not started: IgniteGettingStarted
    at org.apache.ignite.internal.processors.cache.GridCacheProcessor.publicJCache(GridCacheProcessor.java:2271)
    at org.apache.ignite.internal.IgniteKernal.cache(IgniteKernal.java:2256)
    at org.apache.flink.ps.impl.IgniteGettingStarted.main(IgniteGettingStarted.java:45)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)


I have set the IGNITE_HOME environment variable prior to the execution. My pom.xml includes apache-ignite-core and apache-ignite-spring.

Can anyone tell me what is missing?

Best regards,

-----
This post is migrated from now discontinued Apache Ignite forum at
http://apacheignite.readme.io/v1.0/discuss
pgarg pgarg
Reply | Threaded
Open this post in threaded view
|

Re: Trouble working with Data Grid Getting Started examples

commented by valentin kulichenko

Tran,

It looks like your cache is not configured in example-cache.xml, which is perfectly OK, because Ignite supports dynamic cache starts and stops. But in this case cache you should use getOrCreateCache(..) method instead of cache(..) method. It will create the cache for you if it's not there yet.

-----
This post is migrated from now discontinued Apache Ignite forum at
http://apacheignite.readme.io/v1.0/discuss
pgarg pgarg
Reply | Threaded
Open this post in threaded view
|

Re: Trouble working with Data Grid Getting Started examples

This post was updated on .
commented by tran nam-luc

Hi Valentin and thank you for your reply.

May I suggest then to replace the call to cache(...) by getOrCreateCache(...) with a proper cache configuration in the Getting Started examples?

-----
This post is migrated from now discontinued Apache Ignite forum at
http://apacheignite.readme.io/v1.0/discuss